confirmation_prompt=True,
help='user password')
@click.option('--projects',
- prompt="Comma separate list of projects",
+ # prompt="Comma separate list of projects",
multiple=True,
callback=lambda ctx, param, value: ''.join(value).split(',') if all(len(x)==1 for x in value) else value,
help='list of project ids that the user belongs to')
-@click.option('--project-role-mapping', 'project_role_mappings',
+@click.option('--project-role-mappings', 'project_role_mappings',
default=None, multiple=True,
help='creating user project/role(s) mapping')
@click.pass_context
user['username'] = username
user['password'] = password
user['projects'] = projects
- user['project-role-mappings'] = project_role_mappings
+ user['project_role_mappings'] = project_role_mappings
try:
check_client_version(ctx.obj, ctx.command.name)
@cli.command(name='user-update')
@click.argument('username')
@click.option('--password',
- prompt=True,
- hide_input=True,
- confirmation_prompt=True,
+ # prompt=True,
+ # hide_input=True,
+ # confirmation_prompt=True,
help='user password')
@click.option('--set-project', 'set_project',
default=None, multiple=True,
def create(self, name, user):
"""Creates a new OSM user
"""
- if len(user["projects"]) == 1:
+ if not user["projects"] or (len(user["projects"]) == 1 and not user["projects"][0]):
+ del user["projects"]
+ elif len(user["projects"]) == 1:
user["projects"] = user["projects"][0].split(",")
- if user["project-role-mappings"]:
+ if user["project_role_mappings"]:
project_role_mappings = []
- for set_mapping in user["project-role-mappings"]:
- set_mapping_clean = [m.trim() for m in set_mapping.split(",")]
+ for set_mapping in user["project_role_mappings"]:
+ set_mapping_clean = [m.strip() for m in set_mapping.split(",")]
project, roles = set_mapping_clean[0], set_mapping_clean[1:]
for role in roles:
if mapping not in project_role_mappings:
project_role_mappings.append(mapping)
- user["project-role-mappings"] = project_role_mappings
+ user["project_role_mappings"] = project_role_mappings
+ else:
+ del user["project_role_mappings"]
http_code, resp = self._http.post_cmd(endpoint=self._apiBase,
postfields_dict=user)
"""
myuser = self.get(name)
update_user = {
- "_id": myuser["_id"],
- "name": myuser["user"],
+ "username": myuser["username"],
"project_role_mappings": myuser["project_role_mappings"]
}
if user["set-project"]:
for set_project in user["set-project"]:
- set_project_clean = [m.trim() for m in set_project.split(",")]
+ set_project_clean = [m.strip() for m in set_project.split(",")]
project, roles = set_project_clean[0], set_project_clean[1:]
update_user["project_role_mappings"] = [mapping for mapping
if user["add-project-role"]:
for add_project_role in user["add-project-role"]:
- add_project_role_clean = [m.trim() for m in add_project_role.split(",")]
+ add_project_role_clean = [m.strip() for m in add_project_role.split(",")]
project, roles = add_project_role_clean[0], add_project_role_clean[1:]
for role in roles:
if user["remove-project-role"]:
for remove_project_role in user["remove-project-role"]:
- remove_project_role_clean = [m.trim() for m in remove_project_role.split(",")]
+ remove_project_role_clean = [m.strip() for m in remove_project_role.split(",")]
project, roles = remove_project_role_clean[0], remove_project_role_clean[1:]
for role in roles:
and not user["add-project-role"] and not user["remove-project-role"]:
raise ClientException("At least one parameter should be defined.")
- http_code, resp = self._http.put_cmd(endpoint='{}/{}'.format(self._apiBase,myuser['_id']),
+ http_code, resp = self._http.put_cmd(endpoint='{}/{}'.format(self._apiBase, myuser['_id']),
postfields_dict=update_user)
- #print('HTTP CODE: {}'.format(http_code))
- #print('RESP: {}'.format(resp))
- if http_code in (200, 201, 202, 204):
+ # print('HTTP CODE: {}'.format(http_code))
+ # print('RESP: {}'.format(resp))
+ if http_code in (200, 201, 202):
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
raise ClientException('unexpected response from server - {}'.format(
resp))
print(resp['id'])
+ elif http_code == 204:
+ pass
else:
msg = ""
if resp: