]> git.proxmox.com Git - pve-access-control.git/commitdiff
domains: dry-run: adapt log messages and improve variable name
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Sat, 25 Apr 2020 16:55:35 +0000 (18:55 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Sat, 25 Apr 2020 17:06:24 +0000 (19:06 +0200)
keep variable names aligned with the params the relate to, "write"
was quite ambiguous too (write what?)

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/API2/Domains.pm

index d2d9a2b786403e2ba724f12828c581c583e6f115..9c2b2548028790f19baaa81bde4cf0f071bb7719 100644 (file)
@@ -427,9 +427,7 @@ __PACKAGE__->register_method ({
        my $rpcenv = PVE::RPCEnvironment::get();
        my $authuser = $rpcenv->get_user();
 
        my $rpcenv = PVE::RPCEnvironment::get();
        my $authuser = $rpcenv->get_user();
 
-       my $write = !(extract_param($param, 'dry-run'));
-       my $dryrunstring = $write ? '' : ' (dry run)';
-
+       my $dry_run = extract_param($param, 'dry-run');
        my $realm = $param->{realm};
        my $cfg = cfs_read_file($domainconfigfile);
        my $realmconfig = $cfg->{ids}->{$realm};
        my $realm = $param->{realm};
        my $cfg = cfs_read_file($domainconfigfile);
        my $realmconfig = $cfg->{ids}->{$realm};
@@ -449,7 +447,8 @@ __PACKAGE__->register_method ({
        my $plugin = PVE::Auth::Plugin->lookup($type);
 
        my $worker = sub {
        my $plugin = PVE::Auth::Plugin->lookup($type);
 
        my $worker = sub {
-           print "starting sync$dryrunstring for realm $realm\n";
+           print "(dry test run) " if $dry_run;
+           print "starting sync for realm $realm\n";
 
            my ($synced_users, $dnmap) = $plugin->get_users($realmconfig, $realm);
            my $synced_groups = {};
 
            my ($synced_users, $dnmap) = $plugin->get_users($realmconfig, $realm);
            my $synced_groups = {};
@@ -469,16 +468,16 @@ __PACKAGE__->register_method ({
                    $update_groups->($usercfg, $realm, $synced_groups, $opts);
                }
 
                    $update_groups->($usercfg, $realm, $synced_groups, $opts);
                }
 
-               if ($write) {
-                   cfs_write_file("user.cfg", $usercfg) if $write;
-                   print "successfully updated $whatstring configuration\n" if $write;
-               } else {
-                   print "NOTE: This is just a dry run. No actual data was written.\n";
+               if ($dry_run) {
+                   print "\nNOTE: Dry test run, changes were NOT written to the configuration.\n";
+                   return;
                }
                }
+               cfs_write_file("user.cfg", $usercfg);
+               print "successfully updated $whatstring configuration\n";
            }, "syncing $whatstring failed");
        };
 
            }, "syncing $whatstring failed");
        };
 
-       my $workerid = $write ? 'auth-realm-sync' : 'auth-realm-sync-test';
+       my $workerid = !$dry_run ? 'auth-realm-sync' : 'auth-realm-sync-test';
        return $rpcenv->fork_worker($workerid, $realm, $authuser, $worker);
     }});
 
        return $rpcenv->fork_worker($workerid, $realm, $authuser, $worker);
     }});