Exemple #1
0
    async def async_init(self, user_login, **kwargs):
        self.logger.debug("aiohttp session initialized.")
        self.aio_sess = ClientSession()
        if self.enc_path.startswith('/'):
            self.unix_sess = ClientSession(connector=UnixConnector(
                path=self.enc_path))
            self.logger.debug("Unix session initialized.")
        self.user = await self.get_user_id(user_login)
        if not self.user:
            self.logger.critical('Cannot find user %s', user_login)
            await self.close()
            raise RuntimeError(f'Cannot find user {user_login}')

        if kwargs.get('no_notifications', False):
            self.logger.info('No notifications')
        else:
            if not self.notifier:
                kwargs['sess'] = self.aio_sess
                try:
                    self.notifier = Notifier(loop=self.loop, **kwargs)
                    await self.notifier.init_task
                except Exception:
                    self.logger.exception('Cannot initialize Notifier')

            embed = self.make_embed()
            embed.colour = Colour.light_grey()
            embed.description = 'Started'
            await self.send_notification(embed=embed)
        self.check_en.set()
Exemple #2
0
 async def login(self):
     if self._session is None:
         self._session = aiohttp.ClientSession(connector=UnixConnector(
             path='/home/tjtimer/.tmp/arango1.sock'))
     response = await self.request('POST',
                                   '/_open/auth',
                                   data={
                                       'username': self.__credentials[0],
                                       'password': self.__credentials[1]
                                   })
     data = await response.json()
     self._headers['Authorization'] = f"bearer {data['jwt']}"
     self.__credentials = None
Exemple #3
0
    def _connector(self):
        """Return a connector for the HTTP session."""
        if self.uri.scheme == "unix":
            return UnixConnector(path=self.uri.path)

        ssl_context = None
        if self.certs:  # pragma: no cover
            ssl_context = ssl.create_default_context(purpose=ssl.Purpose.CLIENT_AUTH)
            ssl_context.load_verify_locations(cafile=self.certs.server_cert)
            ssl_context.load_cert_chain(
                self.certs.client_cert, keyfile=self.certs.client_key
            )
        return TCPConnector(ssl=ssl_context)
Exemple #4
0
    def get_client(self):
        from aiohttp import ClientSession, DummyCookieJar, UnixConnector, TCPConnector

        if self._client is None:
            jar = DummyCookieJar()
            if self.outbound_unix_socket:
                conn = UnixConnector(path=self.outbound_unix_socket, )
            else:
                conn = TCPConnector(limit=30)
            self._client = ClientSession(
                connector=conn,
                auto_decompress=False,
                cookie_jar=jar,
            )
        return self._client
Exemple #5
0
 async def run(self):
     if self.server.startswith('/'):
         self.api_uri = self.api_uri.format('localhost')
         self.ws_uri = self.ws_uri.format('localhost')
         self.sess = ClientSession(connector=UnixConnector(
             path=self.server))
         self.ws = await websockets.unix_connect(self.server,
                                                 uri=self.ws_uri)
     else:
         self.api_uri = self.api_uri.format(self.server)
         self.ws_uri = self.ws_uri.format(self.server)
         self.sess = ClientSession()
         self.ws = await websockets.connect(self.ws_uri)
     await self.get_updates_api()
     print(self.get_numupdates())
     while True:
         try:
             await self.ws_task()
         except Exception:
             print('WS ERR')
             await self.reconnect()
Exemple #6
0
 def __init__(self, path="/var/run/control.unit.sock"):
     self.control_connector = UnixConnector(path=path)
Exemple #7
0
    def __init__(self, client):
        self.client = client

        super().__init__(connector=UnixConnector(path='/var/run/docker.sock'),
                         raise_for_status=True)