Пример #1
0
    def _refresh_session_ak_and_sk(self):
        request_url = "http://100.100.100.200/latest/meta-data/ram/security-credentials/" + \
            self._credential.role_name
        content = urlopen(request_url).read()
        response = json.loads(content.decode('utf-8'))
        if response.get("Code") != "Success":
            message = 'refresh Ecs sts token err, code is ' + \
                response.get("Code")
            raise ServerException(
                response.get("Code"), message, None)

        session_ak = response.get("AccessKeyId")
        session_sk = response.get("AccessKeySecret")
        token = response.get("SecurityToken")
        self._session_credential = session_ak, session_sk, token
        self._last_update_time = int(time.time())
Пример #2
0
 def _refresh_session_ak_and_sk(self):
     try:
         request_url = "http://100.100.100.200/latest/meta-data/ram/security-credentials/" + self._credential.role_name
         content = urlopen(request_url).read()
         response = json.loads(content.deconde('utf-8'))
         if response.get("Code") != "Success":
             logging.error('refresh Ecs sts token err, code is ' +
                           response.get("Code"))
             return
         session_ak = response.get("AccessKeyId")
         session_sk = response.get("AccessKeySecret")
         token = response.get("SecurityToken")
         self._session_credential = session_ak, session_sk, token
         self._expiration = response.get("Expiration")
     except IOError as e:
         # logging.error('refresh Ecs sts token err', e)
         logging.error('refresh Ecs sts token err:%s', e)