Skip to content

Commit

Permalink
Add permission plugin to client
Browse files Browse the repository at this point in the history
This plugin implements subcommands for listing current login user
permissions.

JIRA: PDC-1018
  • Loading branch information
erichuanggit committed Sep 21, 2015
1 parent 904b791 commit dc147ac
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pdc_client/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ def worker():
return itertools.chain.from_iterable(worker())


def get_permissions(res, **kwargs):
"""
This call returns current login user's permissions.
"""
response = res(**kwargs)
return response.get('permissions', None)


def add_parser_arguments(parser, args, group=None, prefix=DATA_PREFIX):
"""
Helper method that populates parser arguments. The argument values can
Expand Down
27 changes: 27 additions & 0 deletions pdc_client/plugins/permission.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2015 Red Hat
# Licensed under The MIT License (MIT)
# http://opensource.org/licenses/MIT
#
import json

from pdc_client.plugins import PDCClientPlugin, get_permissions


class PermissionPlugin(PDCClientPlugin):
def register(self):
subcmd = self.add_command('list-my-permissions', help='list my permissions')
subcmd.set_defaults(func=self.permission_list)

def permission_list(self, args):
permissions = get_permissions(self.client.auth['current-user'])
if args.json:
print json.dumps(list(permissions))

This comment has been minimized.

Copy link
@lubomir

lubomir Sep 21, 2015

Member

One more thing: the call to list is not required here. The other modules are using it because of get_paged, which returns iterable that is not serializable by json.dumps.

This comment has been minimized.

Copy link
@erichuanggit

erichuanggit Sep 21, 2015

Author Collaborator

Right, thanks for correcting.

return

for permission in sorted(permissions):
print permission


PLUGIN_CLASSES = [PermissionPlugin]

1 comment on commit dc147ac

@lubomir
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you expect the get_permissions function to be used in some other place? I think it would make sense to move it the plugin or even inline it.

Please sign in to comment.