Function to return a boto3 Session based on the account passed in the first argument.

    Args:
        account (:obj:`Account`): Account to create the session object for

    Returns:
        :obj:`boto3:boto3.session.Session`
438361
def get_aws_session(account):
    
    from cloud_inquisitor.config import dbconfig
    from cloud_inquisitor.plugins.types.accounts import AWSAccount

    if not isinstance(account, AWSAccount):
        raise InquisitorError('Non AWSAccount passed to get_aws_session, got {}'.format(account.__class__.__name__))

    # If no keys are on supplied for the account, use sts.assume_role instead
    session = get_local_aws_session()
    if session.get_credentials().method in ['iam-role', 'env', 'explicit']:
        sts = session.client('sts')
    else:
        # If we are not running on an EC2 instance, assume the instance role
        # first, then assume the remote role
        temp_sts = session.client('sts')

        audit_sts_role = temp_sts.assume_role(
            RoleArn=app_config.aws_api.instance_role_arn,
            RoleSessionName='inquisitor'
        )
        sts = boto3.session.Session(
            audit_sts_role['Credentials']['AccessKeyId'],
            audit_sts_role['Credentials']['SecretAccessKey'],
            audit_sts_role['Credentials']['SessionToken']
        ).client('sts')

    role = sts.assume_role(
        RoleArn='arn:aws:iam::{}:role/{}'.format(
            account.account_number,
            dbconfig.get('role_name', default='cinq_role')
        ),
        RoleSessionName='inquisitor'
    )

    sess = boto3.session.Session(
        role['Credentials']['AccessKeyId'],
        role['Credentials']['SecretAccessKey'],
        role['Credentials']['SessionToken']
    )

    return sess
113504
def create_account(self, **kwargs):
        
        response = self.__requester.request(
            'POST',
            'accounts',
            _kwargs=combine_kwargs(**kwargs)
        )
        return Account(self.__requester, response.json())
692050
def get_account(self):
        
        api = self._get_api(iam.DeveloperApi)
        return Account(api.get_my_account_info(include="limits, policies"))
1241953
def get_account_authToken(self, account=None, account_name=''):
        
        if account is None:
            account = self.get_account(zobjects.Account(name=account_name))
        selector = account.to_selector()

        resp = self.request('DelegateAuth', {'account': selector})

        authToken = resp['authToken']
        lifetime = int(resp['lifetime'])

        return authToken, lifetime
152992
def get_accounts(self, **params):
        """"""
        response = self._get('v2', 'accounts', params=params)
        return self._make_api_object(response, Account)
1059039
def get_account(self, account):
        
        selector = account.to_selector()
        resp = self.request_single('GetAccount', {'account': selector})
        return zobjects.Account.from_dict(resp)
121879
def get(account):
        
        account = Account.get(account)
        if not account:
            return None

        acct_type = AccountType.get(account.account_type_id).account_type
        account_class = get_plugin_by_name(PLUGIN_NAMESPACES['accounts'], acct_type)

        return account_class(account)
549287
def get_logged_in_account(token_manager=None,
                          app_url=defaults.APP_URL):
    
    headers = token_manager.get_access_token_headers()
    auth_url = environment.get_auth_url(app_url=app_url)
    url = "%s/api/v1/account" % auth_url

    response = requests.get(url,
                            headers=headers)

    if response.status_code == 200:
        return response.json()

    else:
        raise JutException('Error %s; %s' % (response.status_code, response.text))
655166
def get_account(config, environment, stage=None):
    """"""
    if environment is None and stage:
        environment = get_environment(config, stage)
    account = None
    for env in config.get('environments', []):
        if env.get('name') == environment:
            account = env.get('account')
            role = env.get('role')
            username = os.environ.get(env.get('rs_username_var')) \
                if env.get('rs_username_var') else None
            apikey = os.environ.get(env.get('rs_apikey_var')) \
                if env.get('rs_apikey_var') else None
    if not account:
        sys.exit(ACCT_NOT_FOUND_ERROR.format(environment))
    return account, role, username, apikey
699348
def get_boto_session(
        region,
        aws_access_key_id=None,
        aws_secret_access_key=None,
        aws_session_token=None
        ):
    """"""
    return boto3.session.Session(
        region_name=region,
        aws_secret_access_key=aws_secret_access_key,
        aws_access_key_id=aws_access_key_id,
        aws_session_token=aws_session_token
    )
528555
def auth(self, transport, account_name, password):
        
        auth_token = AuthToken()
        auth_token.account_name = account_name

        attrs = {sconstant.A_BY: sconstant.V_NAME}
        account = SOAPpy.Types.stringType(data=account_name, attrs=attrs)

        params = {sconstant.E_ACCOUNT: account,
                  sconstant.E_PASSWORD: password}

        self.log.debug('Authenticating account %s' % account_name)
        try:
            res = transport.invoke(zconstant.NS_ZIMBRA_ACC_URL,
                                   sconstant.AuthRequest,
                                   params,
                                   auth_token)
        except SoapException as exc:
            raise AuthException(unicode(exc), exc)

        auth_token.token = res.authToken
        
        if hasattr(res, 'sessionId'):
            auth_token.session_id = res.sessionId

        self.log.info('Authenticated account %s, session id %s'
                      % (account_name, auth_token.session_id))

        return auth_token
1310666
def get_account_details(self, account):
        
        result = {}
        try:
            luser = self._get_account(account.username)
            luser = preload(luser, database=self._database)
        except ObjectDoesNotExist:
            return result

        for i, j in luser.items():
            if i != 'userPassword' and j is not None:
                result[i] = j

        return result
1198572
def account(self, key=None, address=None, name=None):
        """"""
        if key:
            return self.client.account(key, wallet=self)
        if address:
            q = dict(address=address)
        elif name:
            q = dict(name=name)
        else:
            raise TypeError("Missing param: key, address, or name is required.")

        return Account(
            self.resource.account_query(q).get(), self.client, wallet=self)
335579
def for_account_hash(parent, account_hash):
        
        account = AccountProxy(parent)
        account.account_hash = account_hash
        if account.acquire():
            return account
        return None
1171878
def current_account=(new_account)
      if self.auth_type_used != :basic
        session[:account_id] = (new_account.nil? || new_account.is_a?(Symbol)) ? nil : new_account.id
      end
      @current_account = new_account || :false
    end
857120
def create(self, session):
        
        sessionid = super().create(session)  # calls _do_create and verify
        self._cache(session, sessionid)
        return sessionid
460088
def __get(klass, account, client, params):
        
        resource = klass.RESOURCE_CONVERSATIONS.format(account_id=account.id)

        request = Request(
            account.client, klass.METHOD,
            resource, headers=klass.HEADERS, body=params)
        return Cursor(klass, request, init_with=[account])