Skip to content

Commit

Permalink
dird: fix for director resource not showing up
Browse files Browse the repository at this point in the history
  • Loading branch information
alaaeddineelamri authored and joergsteffens committed Nov 30, 2022
1 parent 61e1976 commit 39bab43
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 102 deletions.
56 changes: 0 additions & 56 deletions core/src/dird/show_cmd_available_resources.h

This file was deleted.

75 changes: 35 additions & 40 deletions core/src/dird/ua_output.cc
Expand Up @@ -40,7 +40,6 @@
#include "dird/ua_db.h"
#include "dird/ua_output.h"
#include "dird/ua_select.h"
#include "dird/show_cmd_available_resources.h"
#include "lib/edit.h"
#include "lib/parse_conf.h"
#include "dird/jcr_util.h"
Expand Down Expand Up @@ -224,10 +223,22 @@ bool show_cmd(UaContext* ua, const char*)
bool show_verbose = false;
if (FindArg(ua, NT_("verbose")) > 0) { show_verbose = true; }

if (FindArg(ua, "help") > 0) {
ua->InfoMsg(_("Keywords for the show command are:\n"));
for (const auto& command : show_cmd_available_resources) {
ua->InfoMsg("%s\n", command.first.c_str());
}
return true;
}

LockRes(my_config);

// Without parameter, show all ressources.
if (ua->argc == 1) { ShowAll(ua, hide_sensitive_data, show_verbose); }
if (ua->argc == 1 || FindArg(ua, "all") > 0) {
ShowAll(ua, hide_sensitive_data, show_verbose);
UnlockRes(my_config);
return true;
}

for (int i = 1; i < ua->argc; i++) {
// skip verbose keyword, already handled earlier.
Expand All @@ -253,62 +264,46 @@ bool show_cmd(UaContext* ua, const char*)
return true;
}

int type = 0;
int type = -1;
int recurse = 0;
char* res_name = ua->argk[i];
int len = strlen(res_name);
BareosResource* res = nullptr;
if (!ua->argv[i]) { /* was a name given? */
// No name, dump all resources of specified type
recurse = 1;
int len = strlen(res_name);
for (int j = 0; show_cmd_available_resources[j].res_name; j++) {
if (bstrncasecmp(res_name, _(show_cmd_available_resources[j].res_name),
len)) {
type = show_cmd_available_resources[j].type;
if (type > 0) {
res = my_config->config_resources_container_
->configuration_resources_[type];
} else {
res = nullptr;
}
for (const auto& command : show_cmd_available_resources) {
if (bstrncasecmp(res_name, command.first.c_str(), len)) {
type = command.second;
res = my_config->config_resources_container_
->configuration_resources_[type];
break;
}
}
} else {
// Dump a single resource with specified name
recurse = 0;
int len = strlen(res_name);
for (int j = 0; show_cmd_available_resources[j].res_name; j++) {
if (bstrncasecmp(res_name, _(show_cmd_available_resources[j].res_name),
len)) {
type = show_cmd_available_resources[j].type;
for (const auto& command : show_cmd_available_resources) {
if (bstrncasecmp(res_name, command.first.c_str(), len)) {
type = command.second;
res = (BareosResource*)ua->GetResWithName(type, ua->argv[i], true);
if (!res) { type = -3; }
if (!res) {
ua->ErrorMsg(_("%s resource %s not found.\n"), res_name,
ua->argv[i]);
UnlockRes(my_config);
return true;
}
break;
}
}
}

switch (type) {
case -1: /* all */
ShowAll(ua, hide_sensitive_data, show_verbose);
break;
case -2:
ua->InfoMsg(_("Keywords for the show command are:\n"));
for (int j = 0; show_cmd_available_resources[j].res_name; j++) {
ua->InfoMsg("%s\n", _(show_cmd_available_resources[j].res_name));
}
break;
case -3:
ua->ErrorMsg(_("%s resource %s not found.\n"), res_name, ua->argv[i]);
break;
case 0:
ua->ErrorMsg(_("Resource %s not found\n"), res_name);
break;
default:
my_config->DumpResourceCb_(recurse ? type : -type, res, bsendmsg, ua,
hide_sensitive_data, show_verbose);
break;
if (type >= 0) {
my_config->DumpResourceCb_(recurse ? type : -type, res, bsendmsg, ua,
hide_sensitive_data, show_verbose);

} else {
ua->ErrorMsg(_("Resource %s not found\n"), res_name);
}
}

Expand Down
13 changes: 12 additions & 1 deletion core/src/dird/ua_output.h
@@ -1,7 +1,7 @@
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2018-2020 Bareos GmbH & Co. KG
Copyright (C) 2018-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand All @@ -23,9 +23,20 @@
#define BAREOS_DIRD_UA_OUTPUT_H_

#include "lib/output_formatter.h"
#include "dird/dird_conf.h"

#include <unordered_map>

namespace directordaemon {

static std::unordered_map<std::string, int> show_cmd_available_resources = {
{"directors", R_DIRECTOR}, {"clients", R_CLIENT}, {"jobdefs", R_JOBDEFS},
{"jobs", R_JOB}, {"storages", R_STORAGE}, {"catalogs", R_CATALOG},
{"schedules", R_SCHEDULE}, {"filesets", R_FILESET}, {"pools", R_POOL},
{"messages", R_MSGS}, {"counters", R_COUNTER}, {"profiles", R_PROFILE},
{"consoles", R_CONSOLE}, {"users", R_USER}};


class RunResource;

bool bsendmsg(void* ua_ctx, const char* fmt, ...);
Expand Down
Expand Up @@ -30,7 +30,6 @@
#include "dird/dird_globals.h"
#include "dird/dird_conf.h"
#include "dird/ua_output.h"
#include "dird/show_cmd_available_resources.h"

#include <set>

Expand All @@ -53,10 +52,8 @@ TEST(available_resources_equals_config_resources, check_contents)

std::set<uint32_t> set_of_show_cmd_resources;

for (int i = 0; show_cmd_available_resources[i].res_name; i++) {
if (show_cmd_available_resources[i].type >= 0) {
set_of_show_cmd_resources.insert(show_cmd_available_resources[i].type);
}
for (const auto& command : show_cmd_available_resources) {
set_of_show_cmd_resources.insert(command.second);
}

EXPECT_EQ(set_of_config_resources, set_of_show_cmd_resources)
Expand Down

0 comments on commit 39bab43

Please sign in to comment.