def get_profile()

in src/ansible_collections/alibaba/apsarastack/plugins/module_utils/apsarastack_connections.py [0:0]


def get_profile(params):
    if not params['apsarastack_access_key'] and not params['ecs_role_name'] and params['profile']:
        path = params['shared_credentials_file'] if params['shared_credentials_file'] else os.getenv('HOME') + '/.apsarastack/config.json'
        auth = {}
        with open(path, 'r') as f:
            for pro in json.load(f)['profiles']:
                if params['profile'] == pro['name']:
                    auth = pro
        if auth:
            if auth['mode'] == 'AK' and auth.get('access_key_id') and auth.get('access_key_secret'):
                params['apsarastack_access_key'] = auth.get('access_key_id')
                params['apsarastack_secret_key'] = auth.get('access_key_secret')
                params['apsarastack_region'] = auth.get('region_id')
                params = get_acs_connection_info(params)
            elif auth['mode'] == 'StsToken' and auth.get('access_key_id') and auth.get('access_key_secret') and auth.get('sts_token'):
                params['apsarastack_access_key'] = auth.get('access_key_id')
                params['apsarastack_secret_key'] = auth.get('access_key_secret')
                params['security_token'] = auth.get('sts_token')
                params['apsarastack_region'] = auth.get('region_id')
                params = get_acs_connection_info(params)
    elif params.get('apsarastack_assume_role_arn') or params.get('assume_role'):
        params = get_assume_role(params)
    else:
        params = get_acs_connection_info(params)
    return params