Esempio n. 1
0
    async def _request(self,
                       method,
                       url=None,
                       auth=None,
                       headers=None,
                       json=None,
                       raise_if=None,
                       raise_ex=None,
                       repeat_if=None,
                       repeat_wait=3,
                       repeat_delta=None,
                       verify_ssl=True,
                       **kwargs):

        start = datetime.now()
        connector = aiohttp.TCPConnector(verify_ssl=verify_ssl)
        async with aiohttp.ClientSession(connector=connector,
                                         loop=self._loop) as session:
            repeat = 0
            while True:
                send_datetime = datetime.utcnow()
                async with session.request(
                        method,
                        url,
                        headers=headers,
                        auth=aiohttp.helpers.BasicAuth(*auth),
                        data=json_dumps(json) if json else None,
                        **kwargs) as response:

                    text = await response.text()
                    recv_datetime = datetime.utcnow()
                    send = AttrDict(method=method,
                                    url=url,
                                    json=json,
                                    headers=headers,
                                    datetime=send_datetime)
                    json = None
                    if response.headers['Content-Type'] == 'application/json':
                        json = await response.json()
                    recv = AttrDict(headers=dict(response.headers.items()),
                                    status=response.status,
                                    text=windows2unix(text),
                                    json=json,
                                    repeat=repeat,
                                    datetime=datetime.utcnow())
                    call = AttrDict(response=response, send=send, recv=recv)
                self.calls += [call]
                if repeat_if and repeat_if(call):
                    delta = datetime.now() - start
                    if repeat_delta and delta < repeat_delta:
                        repeat += 1
                        pfmt('{delta} < {repeat_delta}; repeat {repeat}')
                        await asyncio.sleep(repeat_wait)
                        continue
                if raise_if and raise_if(call):
                    if raise_ex:
                        raise raise_ex(call)
                    raise RaiseIfError(call)
                break
        return call
Esempio n. 2
0
 def add_env_vars():
     print('docker-compose.yml.wo-envs -> docker-compose.yml')
     print('adding env vars to docker-compose.yml file')
     dcy = yaml.safe_load(open('docker-compose.yml.wo-envs'))
     for svc in dcy['services'].keys():
         envs = dcy['services'][svc].get('environment', [])
         envs += get_user_uid_gid()
         envs += get_env_vars(
             re.compile('(no|http|https)_proxy', re.IGNORECASE))
         pfmt('{svc}:')
         for env in envs:
             pfmt('  - {env}')
         dcy['services'][svc]['environment'] = envs
     with open('docker-compose.yml', 'w') as f:
         yaml.dump(dcy, f, default_flow_style=False)
Esempio n. 3
0
 def execute(self, **kwargs):
     status = 200
     cert_name_pns = [
         self.sanitize(cert_name_pn)
         for cert_name_pn in self.args.cert_name_pns
     ]
     certs = self.tardata.get_certdata_from_tarfiles(
         None if self.args.expired else self.timestamp, *cert_name_pns)
     certs2 = []
     if self.verbosity > 1:
         #FIXME: this should be driven by the yml in the cert tarball
         certs1 = self.authorities.digicert.display_certificates(certs)
         for name, dests in self.args.destinations.items():
             pfmt('name={name} dests={dests}')
             certs2.extend(self.destinations[name].fetch_certificates(
                 certs1, *dests))
     else:
         certs2 = certs
     json = self.transform(certs2)
     return json, status