Ejemplo n.º 1
0
 def wrapper(*args, **kwargs):
     action = kwargs.pop('action')
     profile_name = kwargs.pop('profile', None) or profile_utils.DEFAULT_PROFILE_NAME
     if action != 'configure':
         try:
             profile_utils.get_profile(profile_name, info=True)
         except AssertionError:
             prompt.show_warning(prompt.NO_PROFILE_MSG, stop=True)
         except ValueError as e:
             prompt.show_warning(e.args[0], stop=True)
     return func(action, profile_name, *args, **kwargs)
Ejemplo n.º 2
0
 def wrapper(profile_name, *args, **kwargs):
     profile_name = profile_name or profile_utils.DEFAULT_PROFILE_NAME
     profile = profile_utils.get_profile(profile_name)
     secret = getattr(profile, 'APP_SECRET', None)
     if secret:
         prompt.show_warning(auth_login_msg.format('login', 'authentication'))
     f = func(profile_name, profile, *args, **kwargs)
     if secret:
         profile_utils.remove_profile_value(profile.NAME, secret)
     return f
Ejemplo n.º 3
0
 def wrapper(profile_name, *args, **kwargs):
     profile_name = profile_name or profile_utils.DEFAULT_PROFILE_NAME
     profile = profile_utils.get_profile(profile_name)
     username = getattr(profile, 'USERNAME', None)
     if username:
         prompt.show_warning(auth_login_msg.format('authentication', 'login'))
     f = func(profile_name, profile, *args, **kwargs)
     if username:
         profile_utils.remove_profile_value(profile.NAME, username)
     return f
Ejemplo n.º 4
0
def prepare_api_object(profile_name, session=False):
    profile_name = profile_name or profile_utils.DEFAULT_PROFILE_NAME
    profile = profile_utils.get_profile(profile_name, info=True)
    api = PicovicoAPI(profile.APP_ID, profile.DEVICE_ID)
    if session:
        sess = profile_utils.get_session_info()
        if sess and sess.PROFILE == profile.NAME:
            api.set_access_tokens(sess.ACCESS_KEY, sess.ACCESS_TOKEN)
            api._ready_component_property()
        else:
            auth_names = profile_utils.get_auth_names(profile.NAME)
            if not auth_names:
                prompt.show_no_session(profile.NAME)
            action = {
                profile_utils.LOGIN_INFO: 'login',
                profile_utils.AUTHENTICATE_INFO: 'authenticate',
            }.get(auth_names, None)
            if not all(getattr(profile, k, None) for k in auth_names):
                prompt.show_no_session(profile.NAME)
            else:
                arguments = {k.lower(): getattr(profile, k) for k in auth_names}
                api = auth_action(action, profile.NAME, **arguments)
    return api
Ejemplo n.º 5
0
def call_api_actions(action, profile, **kwargs):
    assert action, 'State your command'
    api_action = get_action_from_command(action, profile)
    if action in custom_command:
        if kwargs:
            kwargs.update({'profile_name': profile})
        else:
            kwargs = {'profile_name': profile}
    try:
        kwargs = _sanitize_args_kwargs(**kwargs) 
        result = api_action(**kwargs) if kwargs else api_action()
    except (pv_exceptions.PicovicoRequestError, pv_exceptions.PicovicoServerError) as  e:
        prompt.show_action_error(action, profile, e.status, e.message)
    else:
        if result:
            prompt.show_action_result(action, result, profile)
        else:
            if action == 'project':
                project_driver.finalize_project_action(**kwargs)
            else:
                prompt.show_action_success(action, profile)
        prof = profile_utils.get_profile(profile)
        if prof.LOG and action not in custom_command:
            pv_cli_log.log_actions(prof.NAME, action, result, **kwargs)