def create_user_credential(accountname, username, credential): """ POST /accounts/{accountname}/users/{username}/credentials :param accountname: str account id for account account record :param username: str username :param credential: json object of the credential type :return: credential json object """ try: with session_scope() as session: mgr = manager_factory.for_session(session) usr = mgr.get_user(username) if not usr or usr['account_name'] != accountname: return make_response_error('Username not found in account'), 404 # For now, only support passwords via the api if credential['type'] != 'password': return make_response_error('Invalid credential type'), 400 if not credential.get('value'): return make_response_error('Invalid credential value, must be non-null and non-empty'), 400 try: cred_type = UserAccessCredentialTypes(credential['type']) except: return make_response_error(errmsg='Invalid credential type'), 400 cred = mgr.add_user_credential(session, creator_name=ApiRequestContextProxy.user(), username=username, credential_type=cred_type, value=credential['value']) return credential_db_to_msg(cred), 200 except Exception as ex: logger.exception('API Error') return make_response_error(errmsg=str(ex)), 500
def create_user(accountname, user): """ POST /accounts/{accountname}/users :param accountname: :param user: :return: """ try: with session_scope() as session: mgr = manager_factory.for_session(session) usr = mgr.create_user(account_name=accountname, username=user['username'], creator_name=ApiRequestContextProxy.user(), password=user['password']) return user_db_to_msg(usr), 200 except Exception as ex: logger.exception('API Error') return make_response_error(errmsg=str(ex)), 500