def get_user_id(self, username): """ Get the jumpcloud user id from the user name :param username :return: the user id """ users = self.get_users(limit='', fields="username") for user in users: if user['username'] == username: return user['id'] raise SystemUserNotFoundError('No user found for username: %s' % (username, ))
def delete_user(info, username): """ Delete a jumpcloud user """ if username is None: raise MissingRequiredArgumentError("Deleting a user requires a username") api1 = JumpcloudApiV1(info.key) click.echo("Delete jumpcloud user " + username) id = api1.get_user_id(username) if id is None: raise SystemUserNotFoundError("System user {} not found".format(username)) response = api1.delete_user(id) click.echo(response)
def get_user(self, username): """ Get detail view of a user object. :param user_id: :return: user properties dict """ # FIXME: As soon as we figure out how the `filter` parameter works on systemusers_list(), we should start # filtering based on username users = self.system_users_api.systemusers_list( accept='application/json', content_type='application/json').results for user in users: if user.username == username: return user.to_dict() raise SystemUserNotFoundError('No user found for username: %s' % (username, ))
def delete_user(self, username): """ Delete a user from jumpcloud :param id: The jumpcloud id of the user :return: """ user_id = self.get_user_id(username) if user_id is None: raise SystemUserNotFoundError(f"System user {username} not found") try: api_response = self.system_users_api.systemusers_delete(user_id, content_type='application/json', accept='application/json', x_org_id='') return api_response except ApiException as error: raise "Exception when calling SystemusersApi->systemusers_post: %s\n" % error