Пример #1
0
    def set_user_token(self):
        """
        From HealthBot 3.0.0 APIs will be token based. This function helps in
        setting user based token. This token will be used in header of any
        REST API calls.

        """
        conf = Configuration()
        conf.host = self.url
        conf.verify_ssl = False
        self.api_client = ApiClient(configuration=conf)
        self._auth = AuthenticationApi(api_client=self.api_client)
        try:
            self._user_token = self._auth.user_login(credential={
                "userName": self.user,
                "password": self.password
            })
            self._token_expire_time = time.time() + \
                                      int(self._user_token.token_expires)
            self.hbot_session.headers.update(
                {'Authorization': 'Bearer ' + self._user_token.access_token})
            self.connected = True
        except ApiException as ex:
            logger.debug(
                "Check if given HealthBot version support authorization key")
            # set user/password used by older healthbot version APIs
            self.hbot_session.auth = (self.user, self.password)
            return False
        except Exception as ex:
            logger.error("User Login Error: {}".format(ex))
            raise ex
        return True
Пример #2
0
 def __init__(self, api_client=None):
     if api_client is None:
         api_client = ApiClient()
     self.api_client = api_client