provider.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:alfred-ec2 作者: SoMuchToGrok 项目源码 文件源码
def _populate_keys_from_metadata_server(self):
        # get_instance_metadata is imported here because of a circular
        # dependency.
        boto.log.debug("Retrieving credentials from metadata server.")
        from boto.utils import get_instance_metadata
        timeout = config.getfloat('Boto', 'metadata_service_timeout', 1.0)
        attempts = config.getint('Boto', 'metadata_service_num_attempts', 1)
        # The num_retries arg is actually the total number of attempts made,
        # so the config options is named *_num_attempts to make this more
        # clear to users.
        metadata = get_instance_metadata(
            timeout=timeout, num_retries=attempts,
            data='meta-data/iam/security-credentials/')
        if metadata:
            creds = self._get_credentials_from_metadata(metadata)
            self._access_key = creds[0]
            self._secret_key = creds[1]
            self._security_token = creds[2]
            expires_at = creds[3]
            # I'm assuming there's only one role on the instance profile.
            self._credential_expiry_time = datetime.strptime(
                expires_at, "%Y-%m-%dT%H:%M:%SZ")
            boto.log.debug("Retrieved credentials will expire in %s at: %s",
                           self._credential_expiry_time - datetime.now(),
                           expires_at)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号