-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new plugin of group-resource-permission
JIRA: PDC-1755
- Loading branch information
1 parent
6ff3349
commit d20deb0
Showing
8 changed files
with
425 additions
and
0 deletions.
There are no files selected for viewing
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,105 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2015 Red Hat | ||
# Licensed under The MIT License (MIT) | ||
# http://opensource.org/licenses/MIT | ||
# | ||
|
||
from __future__ import print_function | ||
|
||
import json | ||
|
||
from pdc_client.plugin_helpers import (PDCClientPlugin, | ||
extract_arguments, | ||
add_parser_arguments, | ||
add_create_update_args) | ||
|
||
|
||
class GroupResourcePermissionsPlugin(PDCClientPlugin): | ||
def register(self): | ||
self.set_command('group-resource-permissions') | ||
list_parser = self.add_action('list', help='list all groups and their resource permissions') | ||
add_parser_arguments(list_parser, {'resource': {}, | ||
'permission': {}, | ||
'group': {}}, | ||
group='Filtering') | ||
list_parser.set_defaults(func=self.list_group_resource_permission) | ||
|
||
info_parser = self.add_action('info', help='display details about a group resource permission') | ||
info_parser.add_argument('id', metavar='ID') | ||
info_parser.set_defaults(func=self.group_resource_permission_info) | ||
|
||
update_parser = self.add_action('update', help='update an existing group resource permission') | ||
update_parser.add_argument('id', metavar='ID') | ||
self.add_update_argument(update_parser, required=True) | ||
update_parser.set_defaults(func=self.group_resource_permission_update) | ||
|
||
create_parser = self.add_action('create', help='grant a resource permission to a group') | ||
self.add_create_argument(create_parser, required=True) | ||
create_parser.set_defaults(func=self.group_resource_permission_create) | ||
|
||
delete_parser = self.add_action('delete', help='revoke a resource permission from a group') | ||
delete_parser.add_argument('id', metavar='ID') | ||
delete_parser.set_defaults(func=self.group_resource_permission_delete) | ||
|
||
def add_create_argument(self, parser, required=True): | ||
required_args = {'resource': {}, 'permission': {}, 'group': {}} | ||
add_create_update_args(parser, required_args, {}, required) | ||
|
||
def add_update_argument(self, parser, required=True): | ||
optional_args = {'resource': {}, 'permission': {}, 'group': {}} | ||
add_create_update_args(parser, {}, optional_args, required) | ||
|
||
def print_group_resource_permissions(self, args): | ||
fmt = '{0:<5} {1:20} {2:90} {3}' | ||
start_line = True | ||
for obj in args: | ||
if start_line: | ||
start_line = False | ||
print(fmt.format('ID', 'Group', 'Resource', 'Permission')) | ||
print() | ||
print(fmt.format(obj['id'], obj['group'], obj['resource'], obj['permission'])) | ||
|
||
def list_group_resource_permission(self, args): | ||
filters = extract_arguments(args) | ||
results = self.client.get_paged(self.client['auth/group-resource-permissions']._, **filters) | ||
if args.json: | ||
print(json.dumps(list(results))) | ||
return | ||
|
||
self.print_group_resource_permissions(results) | ||
|
||
def group_resource_permission_info(self, args, id=None): | ||
obj_id = id or args.id | ||
results = self.client['auth/group-resource-permissions'][obj_id]._() | ||
if args.json: | ||
print(json.dumps(results)) | ||
return | ||
fmt = '{0:20} {1}' | ||
print(fmt.format('ID', results['id'])) | ||
print(fmt.format('Resource', results['resource'])) | ||
print(fmt.format('Permission', results['permission'])) | ||
print(fmt.format('Group', results['group'])) | ||
|
||
def group_resource_permission_update(self, args): | ||
data = extract_arguments(args) | ||
if data: | ||
self.logger.debug('Updating group resource permission %s with data %r', args.id, data) | ||
self.client['auth/group-resource-permissions'][args.id]._ += data | ||
else: | ||
self.logger.debug('Empty data, skipping request') | ||
self.group_resource_permission_info(args) | ||
|
||
def group_resource_permission_create(self, args): | ||
data = extract_arguments(args) | ||
self.logger.debug('Creating group resource permission with data %r', data) | ||
response = self.client['auth/group-resource-permissions']._(data) | ||
self.group_resource_permission_info(args, response['id']) | ||
|
||
def group_resource_permission_delete(self, args): | ||
data = extract_arguments(args) | ||
self.logger.debug('Deleting : group resource permission %s', args.id) | ||
self.client['auth/group-resource-permissions'][args.id]._("DELETE", data) | ||
|
||
|
||
PLUGIN_CLASSES = [GroupResourcePermissionsPlugin] |
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
Empty file.
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,6 @@ | ||
{ | ||
"group": "engops", | ||
"resource": "arches", | ||
"id": 1, | ||
"permission": "create" | ||
} |
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,4 @@ | ||
ID 1 | ||
Resource arches | ||
Permission create | ||
Group engops |
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,176 @@ | ||
[ | ||
{ | ||
"id": 1, | ||
"group": "group1", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 2, | ||
"group": "group2", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 3, | ||
"group": "group3", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 4, | ||
"group": "group4", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 5, | ||
"group": "group5", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 6, | ||
"group": "group6", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 7, | ||
"group": "group7", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 8, | ||
"group": "group8", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 9, | ||
"group": "group9", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 10, | ||
"group": "group10", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 11, | ||
"group": "group11", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 12, | ||
"group": "group12", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 13, | ||
"group": "group13", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 14, | ||
"group": "group14", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 15, | ||
"group": "group15", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 16, | ||
"group": "group16", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 17, | ||
"group": "group17", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 18, | ||
"group": "group18", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 19, | ||
"group": "group19", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 20, | ||
"group": "group20", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 21, | ||
"group": "group21", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 22, | ||
"group": "group22", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 23, | ||
"group": "group23", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 24, | ||
"group": "group24", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 25, | ||
"group": "group25", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 26, | ||
"group": "group26", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 27, | ||
"group": "group27", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 28, | ||
"group": "group28", | ||
"resource": "arches", | ||
"permission": "create" | ||
}, | ||
{ | ||
"id": 29, | ||
"group": "group29", | ||
"resource": "arches", | ||
"permission": "create" | ||
} | ||
] |
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,31 @@ | ||
ID Group Resource Permission | ||
|
||
1 group1 arches create | ||
2 group2 arches create | ||
3 group3 arches create | ||
4 group4 arches create | ||
5 group5 arches create | ||
6 group6 arches create | ||
7 group7 arches create | ||
8 group8 arches create | ||
9 group9 arches create | ||
10 group10 arches create | ||
11 group11 arches create | ||
12 group12 arches create | ||
13 group13 arches create | ||
14 group14 arches create | ||
15 group15 arches create | ||
16 group16 arches create | ||
17 group17 arches create | ||
18 group18 arches create | ||
19 group19 arches create | ||
20 group20 arches create | ||
21 group21 arches create | ||
22 group22 arches create | ||
23 group23 arches create | ||
24 group24 arches create | ||
25 group25 arches create | ||
26 group26 arches create | ||
27 group27 arches create | ||
28 group28 arches create | ||
29 group29 arches create |
Oops, something went wrong.