]> git.proxmox.com Git - pve-access-control.git/commitdiff
pveum: implement bash completion hooks
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 1 Oct 2015 15:22:09 +0000 (17:22 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 1 Oct 2015 15:22:09 +0000 (17:22 +0200)
PVE/API2/AccessControl.pm
PVE/API2/Group.pm
PVE/API2/User.pm
PVE/AccessControl.pm

index f01180d138863ee50c21c25bf5f32b9868efb00b..fee774a07c666ac6eaac5452ce00e8cb1fe94af1 100644 (file)
@@ -235,10 +235,13 @@ __PACKAGE__->register_method ({
                description => "User name",
                type => 'string',
                maxLength => 64,
+               completion => \&PVE::AccessControl::complete_username,
            },
            realm =>  get_standard_option('realm', {
                description => "You can optionally pass the realm using this parameter. Normally the realm is simply added to the username <username>\@<relam>.",
-               optional => 1}),
+               optional => 1,
+               completion => \&PVE::AccessControl::complete_realm,
+           }),
            password => { 
                description => "The secret password. This can also be a valid ticket.",
                type => 'string',
@@ -325,7 +328,9 @@ __PACKAGE__->register_method ({
     parameters => {
        additionalProperties => 0,
        properties => {
-           userid => get_standard_option('userid'),
+           userid => get_standard_option('userid', {
+               completion => \&PVE::AccessControl::complete_username,
+           }),
            password => { 
                description => "The new password.",
                type => 'string',
index 27051a457a5364f0ef3a84342bcf13e5eab87b12..fca8a2ae831d2043e420119562f66b2d51dc65a5 100644 (file)
@@ -107,7 +107,10 @@ __PACKAGE__->register_method ({
     parameters => {
        additionalProperties => 0,
        properties => {
-           groupid => { type => 'string', format => 'pve-groupid' },
+           groupid => {
+               type => 'string', format => 'pve-groupid',
+               completion => \&PVE::AccessControl::complete_group,
+           },
            comment => { type => 'string', optional => 1 },
        },
     },
@@ -195,7 +198,10 @@ __PACKAGE__->register_method ({
     parameters => {
        additionalProperties => 0,
        properties => {
-           groupid => { type => 'string' , format => 'pve-groupid' },
+           groupid => {
+               type => 'string' , format => 'pve-groupid',
+               completion => \&PVE::AccessControl::complete_group,
+           },
        }
     },
     returns => { type => 'null' },
index 6208ad5bdfa94e65e374937d926ef1eae34ef37f..6f8dcd7886afc7c5d1e837ba930567c275312fde 100644 (file)
@@ -119,7 +119,11 @@ __PACKAGE__->register_method ({
                minLength => 5, 
                maxLength => 64 
            },
-           groups => { type => 'string', optional => 1, format => 'pve-groupid-list'},
+           groups => {
+               type => 'string', format => 'pve-groupid-list',
+               optional => 1,
+               completion => \&PVE::AccessControl::complete_group,
+           },
            firstname => { type => 'string', optional => 1 },
            lastname => { type => 'string', optional => 1 },
            email => { type => 'string', optional => 1, format => 'email-opt' },
@@ -238,8 +242,14 @@ __PACKAGE__->register_method ({
     parameters => {
        additionalProperties => 0,
        properties => {
-           userid => get_standard_option('userid'),
-           groups => { type => 'string', optional => 1,  format => 'pve-groupid-list'  },
+           userid => get_standard_option('userid', {
+               completion => \&PVE::AccessControl::complete_username,
+           }),
+           groups => {
+               type => 'string', format => 'pve-groupid-list',
+               optional => 1,
+               completion => \&PVE::AccessControl::complete_group,
+           },
            append => { 
                type => 'boolean', 
                optional => 1,
@@ -325,7 +335,9 @@ __PACKAGE__->register_method ({
     parameters => {
        additionalProperties => 0,
        properties => {
-           userid => get_standard_option('userid'),
+           userid => get_standard_option('userid', {
+               completion => \&PVE::AccessControl::complete_username,
+           }),
        }
     },
     returns => { type => 'null' },
index 9b70902f031291076e661eae3d1a202975838257..db311213f170a3eea679ee3f4627e285e85e3f4d 100644 (file)
@@ -1294,4 +1294,27 @@ sub oath_verify_otp {
     die "oath auth failed\n" if !$found;
 }
 
+# bash completion helpers
+
+sub complete_username {
+
+    my $user_cfg = cfs_read_file('user.cfg');
+
+    return [ keys %{$user_cfg->{users}} ];
+}
+
+sub complete_group {
+
+    my $user_cfg = cfs_read_file('user.cfg');
+
+    return [ keys %{$user_cfg->{groups}} ];
+}
+
+sub complete_realm {
+
+    my $domain_cfg = cfs_read_file('domains.cfg');
+
+    return [ keys %{$domain_cfg->{ids}} ];
+}
+
 1;