forked from dbharris/repoman
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding and removing users from groups
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
repoman-client/repoman_client/subcommands/group_membership.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from repoman_client.subcommand import SubCommand | ||
from repoman_client.client import RepomanClient, RepomanError | ||
from repoman_client.config import config | ||
from argparse import ArgumentParser | ||
|
||
|
||
class AddUser(SubCommand): | ||
command_group = 'advanced' | ||
command = 'add-users-to-group' | ||
alias = None | ||
description = 'Add make specifed users members of a group' | ||
|
||
def get_parser(self): | ||
p = ArgumentParser(self.description) | ||
p.add_argument('group', help='group to add users to') | ||
p.add_argument('-u', '--users', nargs='+', metavar='USER', help='users to add') | ||
return p | ||
|
||
def __call__(self, args, extra_args=None): | ||
repo = RepomanClient(config.host, config.port, config.proxy) | ||
for user in args.users: | ||
status = "Adding user: `%s` to group: '%s'\t\t" % (user, args.group) | ||
try: | ||
repo.add_user_to_group(user, args.group) | ||
print '[OK] %s' % status | ||
except RepomanError, e: | ||
print '[FAILED] %s\n\t-%s' % (status, e.message) | ||
|
||
|
||
|
||
class RemoveUser(SubCommand): | ||
command_group = 'advanced' | ||
command = 'remove-users-from-group' | ||
alias = None | ||
description = 'Remove specifed users from group' | ||
|
||
def get_parser(self): | ||
p = ArgumentParser(self.description) | ||
p.add_argument('group', help='group to add users to') | ||
p.add_argument('-u', '--users', nargs='+', metavar='USER', help='users to add') | ||
return p | ||
|
||
def __call__(self, args, extra_args=None): | ||
repo = RepomanClient(config.host, config.port, config.proxy) | ||
for user in args.users: | ||
status = "Removing user: `%s` from group: '%s'\t\t" % (user, args.group) | ||
try: | ||
repo.remove_user_from_group(user, args.group) | ||
print '[OK] %s' % status | ||
except RepomanError, e: | ||
print '[FAILED] %s\n\t-%s' % (status, e.message) | ||
|