+ except ClientException as inst:
+ print((inst.message))
+ exit(1)
+
+ table = PrettyTable(['key', 'attribute'])
+ for k, v in list(resp.items()):
+ table.add_row([k, json.dumps(v, indent=2)])
+ table.align = 'l'
+ print(table)
+
+
+####################
+# Project mgmt operations
+####################
+
+@cli.command(name='project-create')
+@click.argument('name')
+#@click.option('--description',
+# default='no description',
+# help='human readable description')
+@click.pass_context
+def project_create(ctx, name):
+ '''Creates a new project
+
+ NAME: name of the project
+ '''
+ project = {}
+ project['name'] = name
+ try:
+ check_client_version(ctx.obj, ctx.command.name)
+ ctx.obj.project.create(name, project)
+ except ClientException as inst:
+ print(inst.message)
+
+
+@cli.command(name='project-delete')
+@click.argument('name')
+#@click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')
+@click.pass_context
+def project_delete(ctx, name):
+ '''deletes a project
+
+ NAME: name or ID of the project to be deleted
+ '''
+ try:
+ check_client_version(ctx.obj, ctx.command.name)
+ ctx.obj.project.delete(name)
+ except ClientException as inst:
+ print(inst.message)
+ exit(1)
+
+
+@cli.command(name='project-list')
+@click.option('--filter', default=None,
+ help='restricts the list to the projects matching the filter')
+@click.pass_context
+def project_list(ctx, filter):
+ '''list all projects'''
+ try:
+ check_client_version(ctx.obj, ctx.command.name)
+ resp = ctx.obj.project.list(filter)
+ except ClientException as inst:
+ print(inst.message)
+ exit(1)
+ table = PrettyTable(['name', 'id'])
+ for proj in resp:
+ table.add_row([proj['name'], proj['_id']])
+ table.align = 'l'
+ print(table)
+
+
+@cli.command(name='project-show')
+@click.argument('name')
+@click.pass_context
+def project_show(ctx, name):
+ '''shows the details of a project
+
+ NAME: name or ID of the project
+ '''
+ try:
+ check_client_version(ctx.obj, ctx.command.name)
+ resp = ctx.obj.project.get(name)
+ except ClientException as inst:
+ print(inst.message)
+ exit(1)
+
+ table = PrettyTable(['key', 'attribute'])
+ for k, v in resp.items():
+ table.add_row([k, json.dumps(v, indent=2)])
+ table.align = 'l'
+ print(table)
+
+
+####################
+# User mgmt operations
+####################
+
+@cli.command(name='user-create')
+@click.argument('username')
+@click.option('--password',
+ prompt=True,
+ hide_input=True,
+ confirmation_prompt=True,
+ help='user password')
+@click.option('--projects',
+ default=None,
+ help='list of project ids that the user belongs to')
+#@click.option('--description',
+# default='no description',
+# help='human readable description')
+@click.pass_context
+def user_create(ctx, username, password, projects):
+ '''Creates a new user
+
+ USERNAME: name of the user
+ '''
+ user = {}
+ user['username'] = username
+ user['password'] = password
+ user['projects'] = projects
+ try:
+ check_client_version(ctx.obj, ctx.command.name)
+ ctx.obj.user.create(username, user)
+ except ClientException as inst:
+ print(inst.message)
+
+
+@cli.command(name='user-delete')
+@click.argument('name')
+#@click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')
+@click.pass_context
+def user_delete(ctx, name):
+ '''deletes a user
+
+ NAME: name or ID of the user to be deleted
+ '''
+ try:
+ check_client_version(ctx.obj, ctx.command.name)
+ ctx.obj.user.delete(name)
+ except ClientException as inst:
+ print(inst.message)
+ exit(1)
+
+
+@cli.command(name='user-list')
+@click.option('--filter', default=None,
+ help='restricts the list to the users matching the filter')
+@click.pass_context
+def user_list(ctx, filter):
+ '''list all users'''
+ try:
+ check_client_version(ctx.obj, ctx.command.name)
+ resp = ctx.obj.user.list(filter)
+ except ClientException as inst:
+ print(inst.message)
+ exit(1)
+ table = PrettyTable(['name', 'id'])
+ for user in resp:
+ table.add_row([user['name'], user['_id']])
+ table.align = 'l'
+ print(table)
+
+
+@cli.command(name='user-show')
+@click.argument('name')
+@click.pass_context
+def user_show(ctx, name):
+ '''shows the details of a user
+
+ NAME: name or ID of the user
+ '''
+ try:
+ check_client_version(ctx.obj, ctx.command.name)
+ resp = ctx.obj.user.get(name)
+ if 'password' in resp:
+ resp['password']='********'