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 _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]
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))
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'))
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))
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'))
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()
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()