예제 #1
0
def __up_policies():
    global message
    try:
        LOG.log(
            TRACE,
            "[usermgnt.modules.policies] [__up_policies] Checking policies ..."
        )

        # get current profile
        user_profile = data_adapter.get_current_user_profile()
        if user_profile is None:
            LOG.error(
                '[usermgnt.modules.policies] [__up_policies] user_profile not found / error'
            )
        elif user_profile == -1:
            LOG.warning(
                '[usermgnt.modules.policies] [__up_policies] user_profile not found'
            )
        else:
            LOG.log(
                TRACE,
                '[usermgnt.modules.policies] [__up_policies] user_profile found. checking values ...'
            )
            if user_profile['resource_contributor']:
                message = message + "ALLOWED: resource_contributor is set to TRUE; "
                return True
            message = message + "NOT ALLOWED: resource_contributor is set to FALSE; "
    except:
        LOG.exception('[usermgnt.modules.policies] [__up_policies] Exception')
    return False
예제 #2
0
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)
예제 #3
0
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'])
예제 #4
0
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'])
예제 #5
0
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
            })
예제 #6
0
def __daemon():
    global execute
    try:
        while execute:
            LOG.debug(
                '[usermgnt.modules.assessment] [__daemon] << Assessment Process Thread >> executing ...'
            )

            device_id = None
            user_id = None

            # 1. get current profile
            user_profile = data_adapter.get_current_user_profile()
            if user_profile is None:
                LOG.error(
                    '[usermgnt.modules.assessment] [__daemon] << Assessment Process Thread >> user_profile not found / error'
                )
            elif user_profile == -1:
                LOG.warning(
                    '[usermgnt.modules.assessment] [__daemon] << Assessment Process Thread >> user_profile not found'
                )
            else:
                user_id = user_profile['user_id']
                device_id = user_profile['device_id']
                LOG.log(
                    TRACE,
                    '[usermgnt.modules.assessment] [__daemon] << Assessment Process Thread >> user_profile found'
                )

            # 2. get current sharing model
            sharing_model = data_adapter.get_current_sharing_model()
            if sharing_model is None:
                LOG.error(
                    '[usermgnt.modules.assessment] [__daemon] << Assessment Process Thread >> sharing_model not found / error'
                )
            elif sharing_model == -1:
                LOG.warning(
                    '[usermgnt.modules.assessment] [__daemon] << Assessment Process Thread >> sharing_model not found'
                )
            else:
                user_id = sharing_model['user_id']
                device_id = sharing_model['device_id']
                LOG.log(
                    TRACE,
                    '[usermgnt.modules.assessment] [__daemon] << Assessment Process Thread >> sharing_model found'
                )

            if not user_id is None and not device_id is None:
                LOG.log(
                    TRACE,
                    '[usermgnt.modules.assessment] [__daemon] << Assessment Process Thread >> checking values ...'
                )
                # 3. Get information:
                #   - battery
                battery_level = data_adapter.get_power()
                # battery_level = 50 # TODO
                #   - total services running
                total_services = data_adapter.get_total_services_running()

                # 4. check information and send warning to Lifecycle if needed
                result = __check_resources_used(user_profile, sharing_model,
                                                battery_level, total_services)
                if not result:
                    LOG.debug(
                        "[usermgnt.modules.assessment] [__daemon] << Assessment Process Thread >> no violations: result: "
                        + str(result))
                else:
                    LOG.debug(
                        "[usermgnt.modules.assessment] [__daemon] << Assessment Process Thread >> violations found: result: "
                        + str(result))
                    LOG.log(
                        TRACE,
                        '[usermgnt.modules.assessment] [__daemon] << Assessment Process Thread >> generating warning / sending notification ...'
                    )
                    mf2c.send_warning(user_id, device_id, user_profile,
                                      sharing_model, result)
            else:
                LOG.warning(
                    '[usermgnt.modules.assessment] [__daemon] << Assessment Process Thread >> cannot check values'
                )

            # wait 300 seconds
            LOG.debug(
                '[usermgnt.modules.assessment] [__daemon] << Assessment Process Thread >> Waiting 5m (300s) for next execution ...'
            )
            time.sleep(300)
    except:
        LOG.exception(
            '[usermgnt.modules.assessment] [__daemon] << Assessment Process Thread >> Exception'
        )