From 71f4fd7acb2b1e44df090991aeaffcab5aa3028a Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Fri, 10 Jan 2020 02:56:39 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20Drop=20tracking=20installs=20in?= =?UTF-8?q?=20gh=20app=20obj?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- octomachinery/app/server/machinery.py | 2 +- octomachinery/github/api/app_client.py | 33 ++++---------------------- 2 files changed, 6 insertions(+), 29 deletions(-) diff --git a/octomachinery/app/server/machinery.py b/octomachinery/app/server/machinery.py index 1870ac8..cf44d43 100644 --- a/octomachinery/app/server/machinery.py +++ b/octomachinery/app/server/machinery.py @@ -94,7 +94,7 @@ async def run_forever(config): config.github, http_session=aiohttp_client_session, ) - await github_app.pre_fetch_installs() + await github_app.log_installs_list() await _prepare_github_app(github_app) await _launch_web_server_and_wait_until_it_stops( config.server, github_app, diff --git a/octomachinery/github/api/app_client.py b/octomachinery/github/api/app_client.py index df44610..cfda8c6 100644 --- a/octomachinery/github/api/app_client.py +++ b/octomachinery/github/api/app_client.py @@ -49,30 +49,19 @@ def __attrs_post_init__(self): ' SIGNATURE VERIFICATION WILL BE ENFORCED' if webhook_secret else '', ) - # pylint: disable=attribute-defined-outside-init - self._installations = defaultdict(dict) async def event_from_request(self, request): """Get an event object out of HTTP request.""" - event = Event.from_http( + return Event.from_http( request.headers, await request.read(), secret=self._config.webhook_secret, ) - await self.pre_process_webhook_event(event) - return event - async def pre_process_webhook_event(self, event): - """Get an event object out of HTTP request.""" - action = event.data.get('action') - if event.event in GH_INSTALL_EVENTS and action == 'created': - await self.add_installation(event) - - async def pre_fetch_installs(self) -> 'GitHubApp': + async def log_installs_list(self) -> None: """Store all installations data before starting.""" - # pylint: disable=attribute-defined-outside-init try: - self._installations = await self.get_installations() + installations = await self.get_installations() except ClientConnectorError as client_error: logger.info('It looks like the GitHub API is offline...') logger.error( @@ -80,19 +69,17 @@ async def pre_fetch_installs(self) -> 'GitHubApp': 'installations list: %s', client_error, ) - self._installations = defaultdict(dict) + return logger.info('This GitHub App is installed into:') # pylint: disable=protected-access - for install_id, install_val in self._installations.items(): + for install_id, install_val in installations.items(): logger.info( '* Installation id %s (installed to %s)', install_id, install_val._metadata.account['login'], ) - return self - @property def gh_jwt(self): """Generate app's JSON Web Token, valid for 60 seconds.""" @@ -110,16 +97,6 @@ def api_client(self): # noqa: D401 user_agent=self._config.user_agent, ) - async def add_installation(self, event): - """Retrieve an installation creds from store.""" - install = event.data['installation'] - install_id = install['id'] - self._installations[install_id] = GitHubAppInstallation( - GitHubAppInstallationModel(**install), - self, - ) - return self._installations[install_id] - async def get_installation(self, event): """Retrieve an installation creds from store.""" if 'installation' not in event.data: