fix(tools): striker-access-database->anvil->access->module; execute any sub on any module

main
Tsu-ba-me 3 years ago
parent d1f7a731bd
commit a7a2cc70d7
  1. 1
      tools/Makefile.am
  2. 19
      tools/anvil-access-module

@ -5,6 +5,7 @@ EXTRA_DIST = \
watch_drbd
dist_sbin_SCRIPTS = \
anvil-access-module \
anvil-boot-server \
anvil-change-password \
anvil-check-memory \

@ -41,22 +41,23 @@ if (not $anvil->data->{sys}{database}{connections})
$anvil->nice_exit({ exit_code => 1 });
}
my $db_uuid = $anvil->data->{switches}{'uuid'};
my $db_sub_name = defined $anvil->data->{switches}{'sub'} ? $anvil->data->{switches}{'sub'} : "";
my $db_sub_params = defined $anvil->data->{switches}{'sub-params'} ? $anvil->data->{switches}{'sub-params'} : "{}";
my $sql_query = $anvil->data->{switches}{'query'};
my $access_mode = defined $anvil->data->{switches}{'mode'} ? $anvil->data->{switches}{'mode'} : "";
my $db_uuid = $anvil->data->{switches}{'uuid'};
my $sub_name = defined $anvil->data->{switches}{'sub'} ? $anvil->data->{switches}{'sub'} : "";
my $sub_module_name = defined $anvil->data->{switches}{'sub-module'} ? $anvil->data->{switches}{'sub-module'} : "Database";
my $sub_params = defined $anvil->data->{switches}{'sub-params'} ? $anvil->data->{switches}{'sub-params'} : "{}";
my $sql_query = $anvil->data->{switches}{'query'};
my $access_mode = defined $anvil->data->{switches}{'mode'} ? $anvil->data->{switches}{'mode'} : "";
if ($sql_query)
{
my $results = db_access({ db_uuid => $db_uuid, sql_query => $sql_query, access_mode => $access_mode });
print JSON->new->utf8->encode($results)."\n";
}
elsif ($anvil->Database->can($db_sub_name))
elsif ($anvil->${sub_module_name}->can($sub_name))
{
my $decoded_db_sub_params;
my $decoded_sub_params;
my $is_decode_json_success = eval {
$decoded_db_sub_params = decode_json($db_sub_params);
$decoded_sub_params = decode_json($sub_params);
};
if (not $is_decode_json_success)
@ -65,7 +66,7 @@ elsif ($anvil->Database->can($db_sub_name))
$anvil->nice_exit({ exit_code => 1 });
}
my $results = $anvil->Database->${db_sub_name}($decoded_db_sub_params);
my $results = $anvil->${sub_module_name}->${sub_name}($decoded_sub_params);
print JSON->new->utf8->encode({ sub_results => $results })."\n";
}
else
Loading…
Cancel
Save