示例#1
0
 def _archive_from_url(self, archive, auth_config):
     tf = tempfile.TemporaryFile()
     opts = util.req_opts({'auth': auth_config.get_auth(None)})
     util.EtagCheckedResponse(requests.get(archive, **opts)).write_to(tf)
     tf.flush()
     tf.seek(0, os.SEEK_SET)
     return tf
 def _archive_from_url(self, archive, auth_config):
     tf = tempfile.TemporaryFile()
     opts = util.req_opts({'auth': auth_config.get_auth(None)})
     util.EtagCheckedResponse(requests.get(archive, **opts)).write_to(tf)
     tf.flush()
     tf.seek(0, os.SEEK_SET)
     return tf
示例#3
0
    def _msi_from_url(self, archive, auth_config):
        tf = tempfile.mkstemp(suffix='.msi', prefix='cfn-init-tmp')

        with os.fdopen(tf[0], 'wb') as temp_dest:
            opts = util.req_opts({'auth': auth_config.get_auth(None)})
            util.EtagCheckedResponse(requests.get(archive, **opts)).write_to(temp_dest)

        return tf[1]
示例#4
0
    def _write_remote_file(self, source, auth, dest, context):
        opts = util.req_opts({'auth': auth})
        remote_contents = util.EtagCheckedResponse(requests.get(source, **opts))

        if context is None:
            remote_contents.write_to(dest)
        else:
            dest.write(self._render_template(remote_contents.contents(), context))
示例#5
0
    def _msi_from_url(self, archive, auth_config):
        tf = tempfile.mkstemp(suffix='.msi', prefix='cfn-init-tmp')

        with os.fdopen(tf[0], 'wb') as temp_dest:
            opts = util.req_opts({'auth': auth_config.get_auth(None)})
            util.EtagCheckedResponse(requests.get(archive,
                                                  **opts)).write_to(temp_dest)

        return tf[1]
示例#6
0
def get_role_creds(name):
    resp = requests.get(
        'http://169.254.169.254/latest/meta-data/iam/security-credentials/%s' %
        name,
        proxies={'no_proxy': '169.254.169.254/32'})
    resp.raise_for_status()
    role = resp.json()
    return Credentials(
        role['AccessKeyId'], role['SecretAccessKey'], role['Token'],
        datetime.datetime.strptime(role['Expiration'], '%Y-%m-%dT%H:%M:%SZ'))
示例#7
0
    def _write_remote_file(self, source, auth, dest, context):
        opts = util.req_opts({'auth': auth})
        remote_contents = util.EtagCheckedResponse(requests.get(
            source, **opts))

        if context is None:
            remote_contents.write_to(dest)
        else:
            dest.write(
                self._render_template(remote_contents.contents(), context))
示例#8
0
def get_role_creds(name):
    resp = requests.get('http://169.254.169.254/latest/meta-data/iam/security-credentials/%s' % name, proxies = {'no_proxy' : '169.254.169.254/32'})
    resp.raise_for_status()
    role = resp.json()
    return Credentials(role['AccessKeyId'], role['SecretAccessKey'], role['Token'], datetime.datetime.strptime(role['Expiration'], '%Y-%m-%dT%H:%M:%SZ'))
示例#9
0
def _fetch_instance_id():
    resp = requests.get('http://169.254.169.254/latest/meta-data/instance-id', timeout=2, proxies = {'no_proxy' : '169.254.169.254/32'})
    resp.raise_for_status()
    return resp.text.strip()
示例#10
0
def get_instance_identity_signature():
    resp = requests.get('http://169.254.169.254/latest/dynamic/instance-identity/signature', proxies = {'no_proxy' : '169.254.169.254/32'})
    resp.raise_for_status()
    return resp.text.rstrip()