Ejemplo n.º 1
0
    def rotate_credentials(self):

        try:
            r = requests.get(url=self.URL_PATH + self.role_name)
        except requests.exceptions.ConnectionError:
            raise ConnectionUsingEcsRamRoleException()
        data = json.loads(r.text)
        if data.get("Code") != "Success":
            message = "Failed to get instance profile. Code={}".format(
                +data.get("Code"))
            raise ClientException(msg=message)

        expiration = data.get("Expiration")
        if expiration:
            self._expiration = time.mktime(
                time.strptime(expiration, '%Y-%m-%dT%H:%M:%SZ'))
        else:
            # FIXME Why?
            self._expiration = expiration

        return SecurityCredentials(
            data['AccessKeyId'],
            data['AccessKeySecret'],
            data['SecurityToken'],
        )
 def test_call_rpc_request_with_role_name(
         self, InstanceProfileCredentialsProvider):
     with MyServer() as f:
         os.environ["ALIBABA_CLOUD_ROLE_NAME"] = self.default_ram_role_name
         InstanceProfileCredentialsProvider.rotate_credentials.return_value = \
             requests.get(url="http://localhost:51352")
         InstanceProfileCredentialsProvider.rotate_credentials. \
             return_value = role_name
         self.assertTrue(
             InstanceProfileCredentialsProvider.rotate_credentials)