self._apiName = '/admin'
self._apiVersion = '/v1'
self._apiResource = '/roles'
self._apiBase = '{}{}{}'.format(self._apiName,
self._apiVersion, self._apiResource)
self._apiName = '/admin'
self._apiVersion = '/v1'
self._apiResource = '/roles'
self._apiBase = '{}{}{}'.format(self._apiName,
self._apiVersion, self._apiResource)
:raises ClientException: when receives an unexpected from the server.
:raises ClientException: when fails creating a role.
"""
:raises ClientException: when receives an unexpected from the server.
:raises ClientException: when fails creating a role.
"""
- if not isinstance(role_definition, dict):
- raise ClientException('Role definition should be provided in a key-value fashion')
+ if not isinstance(role_permissions, dict):
+ raise ClientException('Role permissions should be provided in a key-value fashion')
- def update(self, name, definition=None, add=None, remove=None):
+ def update(self, name, new_name, permissions, add=None, remove=None):
"""
Updates an OSM role identified by name.
NOTE: definition and add/remove are mutually exclusive.
:param name: name of the role
"""
Updates an OSM role identified by name.
NOTE: definition and add/remove are mutually exclusive.
:param name: name of the role
- :param definition: if provided, overwrites the existing role specification.
+ :param set_name: if provided, change the name.
+ :param permissions: if provided, overwrites the existing role specification. NOT IMPLEMENTED
:param add: if provided, adds new rules to the definition.
:param remove: if provided, removes rules from the definition.
:raises ClientException: when receives an unexpected response from the server.
:raises ClientException: when fails updating a role.
"""
:param add: if provided, adds new rules to the definition.
:param remove: if provided, removes rules from the definition.
:raises ClientException: when receives an unexpected response from the server.
:raises ClientException: when fails updating a role.
"""
- elif definition and (add or remove):
- raise ClientException('Definition and add/remove are mutually exclusive')
+ elif permissions and (add or remove):
+ raise ClientException('permissions and add/remove are mutually exclusive')
- new_role_obj = {
- "_id": role_obj["_id"],
- "name": role_obj["name"]
- }
+ new_role_obj = {"permissions": {}}
+ if new_name:
+ new_role_obj["name"] = new_name
- if not isinstance(value, bool):
- raise ClientException('Value in a role definition should be boolean')
+ if not isinstance(value, bool) and value is not None:
+ raise ClientException('Value in a role permissions should be boolean or None to remove')
if not isinstance(keys_from_remove, list):
raise ClientException('Keys should be provided in a list fashion')
if not isinstance(keys_from_remove, list):
raise ClientException('Keys should be provided in a list fashion')
for key in keys_from_remove:
if not isinstance(key, str):
raise ClientException('Individual keys should be strings')
for key in keys_from_remove:
if not isinstance(key, str):
raise ClientException('Individual keys should be strings')
if not isinstance(add_roles, dict):
raise ClientException('Add should be provided in a key-value fashion')
for key, value in add_roles.items():
if not isinstance(value, bool):
if not isinstance(add_roles, dict):
raise ClientException('Add should be provided in a key-value fashion')
for key, value in add_roles.items():
if not isinstance(value, bool):
- http_code, resp = self._http.put_cmd(endpoint='{}/{}'.format(self._apiBase, role_obj['_id']),
+ http_code, resp = self._http.patch_cmd(endpoint='{}/{}'.format(self._apiBase, role_obj['_id']),
postfields_dict=new_role_obj)
# print('HTTP CODE: {}'.format(http_code))
# print('RESP: {}'.format(resp))
postfields_dict=new_role_obj)
# print('HTTP CODE: {}'.format(http_code))
# print('RESP: {}'.format(resp))
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'])
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'])