def check_policies(): global message message = "" if __up_policies() and __sm_policies(): # return content of sharing model, which includes the 'device_id' sharing_model = data_adapter.get_current_sharing_model() if sharing_model is None or sharing_model == -1: return common.gen_response_ok("User Management Policies", "result", True, "message", message, "sharing_model", {}) else: return common.gen_response_ok("User Management Policies", "result", True, "message", message, "sharing_model", sharing_model) return common.gen_response_ok("User Management Policies", "result", False, "message", message, "sharing_model", {})
def get_current_sharing_model(): LOG.info("[usermgnt.modules.um_sharing_model] [get_current_sharing_model] Getting current sharing model ...") sharing_model = data_adapter.get_current_sharing_model() if sharing_model is None: return common.gen_response(500, 'Error', 'sharing_model', 'not found / error', 'sharing_model', {}) elif sharing_model == -1: return common.gen_response_ko('Warning: Sharing-model not found', 'sharing_model', 'not found / error', 'sharing_model', {}) else: return common.gen_response_ok('Sharing-model found', 'sharing_model', sharing_model)
def delete_sharing_model_by_id(sharing_model_id): LOG.info("[usermgnt.modules.um_sharing_model] [delete_sharing_model_by_id] sharing_model_id=" + sharing_model_id) # deletes sharing_model res = data_adapter.delete_sharing_model_by_id(sharing_model_id) if res is None: return common.gen_response(500, 'Exception', 'sharing_model_id', sharing_model_id) elif res == -1: return common.gen_response_ko('Warning: Sharing-model not found', 'sharing_model_id', sharing_model_id) else: return common.gen_response_ok('Sharing-model deleted', 'sharing_model_id', sharing_model_id)
def update_sharing_model_by_id(sharing_model_id, data): LOG.info("[usermgnt.modules.um_sharing_model] [update_sharing_model_by_id] sharing_model_id=" + sharing_model_id + ", data=" + str(data)) # updates sharing_model sharing_model = data_adapter.update_sharing_model_by_id(sharing_model_id, data) if sharing_model is None: return common.gen_response(500, 'Exception', 'data', str(data), 'sharing_model', {}) elif sharing_model == -1: return common.gen_response_ko('Warning: Sharing model not found', 'sharing_model_id', sharing_model_id, 'sharing_model', {}) else: return common.gen_response_ok('Sharing-model updated', 'data', str(data), 'sharing_model', sharing_model)
def get_sharing_model_by_id(sharing_model_id): LOG.info("[usermgnt.modules.um_sharing_model] [get_sharing_model_by_id] sharing_model_id=" + sharing_model_id) # get sharing_model sharing_model = data_adapter.get_sharing_model_by_id(sharing_model_id) if sharing_model is None: return common.gen_response(500, 'Exception', 'sharing_model_id', sharing_model_id, 'sharing_model', {}) elif sharing_model == -1: return common.gen_response_ko('Warning: Sharing-model not found', 'sharing_model_id', sharing_model_id, 'sharing_model', {}) else: return common.gen_response_ok('Sharing model found', 'sharing_model_id', sharing_model_id, 'sharing_model', sharing_model)
def delete_user_profile_by_id(profile_id): LOG.info( "[usermgnt.modules.um_profiling] [delete_user_profile_by_id] profile_id=" + profile_id) # delete profile if data_adapter.delete_user_profile_by_id(profile_id) is None: return common.gen_response(500, 'Error', 'profile_id', profile_id) else: return common.gen_response_ok('Profile deleted', 'profile_id', profile_id)
def status(): LOG.info("[usermgnt.modules.um_assessment] [status] get process status") try: p_status = process.get_status() return common.gen_response_ok('Assessment process status', 'status', p_status) except: LOG.exception('[usermgnt.modules.um_assessment] [status] Exception') return common.gen_response( 500, 'Exception getting the assessment process status', 'status', '')
def __stop(): LOG.info("[usermgnt.modules.um_assessment] [__stop] stop process") try: p_status = process.stop() return common.gen_response_ok('Assessment process stopped', 'status', p_status) except: LOG.exception('[usermgnt.modules.um_assessment] [__stop] Exception') return common.gen_response( 500, 'Exception when stopping the assessment process', 'status', '')
def get_user(user_id): LOG.debug("[usermgnt.modules.um_user] [get_user] user_id=" + str(user_id)) user = data_adapter.get_user_info(user_id) if user is None: return common.gen_response(500, 'Error or User not found', 'user_id', user_id, 'user', {}) elif user == -1: return common.gen_response( 403, "Warning: User " + user_id + " has no permissions on this device", 'user_id', user_id, 'user', {}) else: return common.gen_response_ok('User found', 'user_id', user_id, 'user', user)
def get_user_profile_by_id(profile_id): LOG.debug( "[usermgnt.modules.um_profiling] [get_user_profile_by_id] profile_id=" + profile_id) user_profile = data_adapter.get_user_profile_by_id(profile_id) if user_profile is None: return common.gen_response(500, 'Error', 'profile_id', profile_id, 'profile', {}) elif user_profile == -1: return common.gen_response_ko('Warning: User profile not found', 'profile_id', profile_id, 'profile', {}) else: return common.gen_response_ok('User found', 'profile_id', profile_id, 'profile', user_profile)
def update_user_profile_by_id(profile_id, data): LOG.debug( "[usermgnt.modules.um_profiling] [update_user_profile_by_id] profile_id=" + profile_id + ", data=" + str(data)) # update user user_profile = data_adapter.update_user_profile_by_id(profile_id, data) if user_profile is None: return common.gen_response(500, 'Error', 'profile_id', profile_id, 'profile', {}) elif user_profile == -1: return common.gen_response_ko('Warning: User profile not found', 'profile_id', profile_id, 'profile', {}) else: return common.gen_response_ok('User updated', 'profile_id', profile_id, 'profile', user_profile)
def get_current_user_profile(): LOG.info( "[usermgnt.modules.um_profiling] [get_current_user_profile] Getting current user-profile value ..." ) user_profile = data_adapter.get_current_user_profile() if user_profile is None: return common.gen_response(500, 'Error', 'user_profile', 'not found / error', 'profile', {}) elif user_profile == -1: return common.gen_response_ko('Warning: User profile not found', 'user_profile', 'not found / error', 'profile', {}) else: return common.gen_response_ok('User found', 'user_profile', user_profile)
def __getCurrentUser(): LOG.info( "[usermgnt.modules.current] [__getCurrentUser] Getting current user ..." ) user_profile = data_adapter.get_current_user_profile() if user_profile is None: return common.gen_response(500, 'Error', 'cause', 'not found / error', 'user', '') elif user_profile == -1: return common.gen_response_ko('Warning: User profile not found', 'cause', 'not found / error', 'user', '') else: return common.gen_response_ok( 'User found', 'user_profile', user_profile, 'user_id', user_profile['acl']['owner']['principal'])
def __getCurrentDevice(): LOG.info( "[usermgnt.modules.current] [__getCurrentDevice] Getting current device ..." ) user_profile = data_adapter.get_current_user_profile() if user_profile is None: return common.gen_response(500, 'Error', 'cause', 'not found / error', 'device', '') elif user_profile == -1: return common.gen_response_ko('Warning: User profile not found', 'cause', 'not found / error', 'device', '') else: return common.gen_response_ok('User found', 'user_profile', user_profile, 'device', user_profile['device_id'])
def __getCurrentAll(): LOG.info( "[usermgnt.modules.current] [__getCurrentAll] Getting current device ..." ) user_profile = data_adapter.get_current_user_profile() sharing_model = data_adapter.get_current_sharing_model() agent = data_adapter.get_agent_info() if user_profile is None: return common.gen_response(500, 'Error', 'cause', 'not found / error', 'info', {}) elif user_profile == -1: return common.gen_response_ko( 'Warning: user_profile / sharing_model / agent not found', 'cause', 'not found / error', 'info', {}) else: return common.gen_response_ok( 'User found', 'info', { "user_profile": user_profile, "sharing_model": sharing_model, "agent": agent })
def delete_user(data): if 'user_id' not in data: LOG.warning( '[usermgnt.modules.um_user] [delete_user] parameter not found: user_id' ) return common.gen_response(405, 'parameter not found: user_id', 'data', str(data)) user_id = data['user_id'] LOG.debug("[usermgnt.modules.um_user] [delete_user] user_id=" + str(user_id)) user = data_adapter.delete_user(user_id) if user is None: return common.gen_response(500, 'Error or User not found', 'user_id', user_id, 'user', {}) elif user == -1: return common.gen_response( 403, "Warning: User " + user_id + " has no permissions on this device", 'user_id', user_id, 'user', {}) else: return common.gen_response_ok('User deleted', 'user_id', user_id)