Пример #1
0
    def __init__(self,
                 access_key_id=None,
                 secret_key=None,
                 aims_token=None,
                 account_id=None,
                 profile=None,
                 global_endpoint=None,
                 residency="us",
                 raise_for_status=True):
        """
        :param region: a Region object
        :param access_key_id: your Alert Logic ActiveWatchaccess_key_id
                              or username
        :param secret_key: your Alert Logic ActiveWatchsecret_key or password
        :param aims_token: aims_token to be used for authentication.
                           If aims_token is specified,
                           access_key_id and secret_key paramters are ignored
        : param account_id: Alert Logic Account ID to initialize a session for.
                            Unless account_id is provided explicitly
                            during service connection initialization,
                            this account id is used.
                            If this parameter isn't specified,
                            the account id of the access_key_id is used.
        :param: profile: name of the profile section of the configuration file
        :param: global_endpoint: Name of the global endpoint.
                                 'production' or 'integration' are
                                 the only valid values
        :param residency: Data residency name to perform
                          data residency dependend actions.
                          Currently, 'default', 'us' and 'emea'
                          are the only valid entries
        :param raise_for_status: Raise an exception for failed http requests
                                 instead of returning response object
        """

        self._config = Config(access_key_id=access_key_id,
                              secret_key=secret_key,
                              account_id=account_id,
                              profile=profile,
                              global_endpoint=global_endpoint,
                              residency=residency)

        self._token = None
        self._defaults = None
        self._account_id = self._config.account_id
        self._residency = self._config.residency
        self._global_endpoint = self._config.global_endpoint
        self._global_endpoint_url = Region.get_global_endpoint(
            self._global_endpoint)
        self._raise_for_status = raise_for_status

        # Setup session object
        self._session = requests.Session()
        retries = Retry(total=5, backoff_factor=1, status_forcelist=[502, 503])
        self._session.mount('https://', HTTPAdapter(max_retries=retries))

        if aims_token:
            self._token = aims_token
        else:
            self._access_key_id, self._secret_key = self._config.get_auth()
Пример #2
0
    def _init_session(self, *args, **kwargs):
        """ Initialize session object based on the kwargs provided """

        if not len(kwargs):
            return

        access_key_id = kwargs.get('access_key_id')
        secret_key = kwargs.get('secret_key')
        account_id = kwargs.get('account_id')
        profile = kwargs.get('profile')
        global_endpoint = kwargs.get('global_endpoint')
        residency = kwargs.get('residency', 'default')
        aims_token = kwargs.get('aims_token')

        self._config = Config(
                access_key_id=access_key_id,
                secret_key=secret_key,
                account_id=account_id,
                profile=profile,
                global_endpoint=global_endpoint,
                residency=residency
            )

        self._account_id = self._config.account_id
        self._residency = self._config.residency
        self._global_endpoint = self._config.global_endpoint
        self._endpoint_map = self._config.endpoint_map
        self._global_endpoint_url = Region.get_global_endpoint(
                                                        self._global_endpoint)
        self._raise_for_status = kwargs.get('raise_for_status')

        if aims_token:
            self._token = aims_token
        else:
            self._access_key_id, self._secret_key = self._config.get_auth()

        logger.debug(
                "Initialized session. "
                f"access_key_id={self._access_key_id}, "
                f"account_id={self._account_id}, "
                f"profile={profile}, "
                f"global_endpoint={self._global_endpoint}, "
                f"residency={self._residency}"
            )