From 86ea6b2e0eb697833f7ff11bd0bb8c32ecc89e9a Mon Sep 17 00:00:00 2001 From: Maor Friedman Date: Thu, 10 Sep 2020 08:56:06 +0300 Subject: [PATCH] sentry-helper fixes (#1053) --- reconcile/queries.py | 7 ++++++- reconcile/sentry_helper.py | 5 ++++- utils/smtp_client.py | 10 +++++----- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/reconcile/queries.py b/reconcile/queries.py index dd28db288..fe6a9cb2e 100644 --- a/reconcile/queries.py +++ b/reconcile/queries.py @@ -1,3 +1,5 @@ +import logging + import utils.gql as gql @@ -1232,5 +1234,8 @@ def get_dns_zones(): def get_slack_workspace(): """ Returns a single Slack workspace """ gqlapi = gql.get_api() - # assuming a single Slack workspace for now + slack_workspaces = \ + gqlapi.query(SLACK_WORKSPACES_QUERY)['slack_workspaces'] + if len(slack_workspaces) != 1: + logging.warning('multiple Slack workspaces found.') return gqlapi.query(SLACK_WORKSPACES_QUERY)['slack_workspaces'][0] diff --git a/reconcile/sentry_helper.py b/reconcile/sentry_helper.py index 83f8c409f..625fed0ab 100644 --- a/reconcile/sentry_helper.py +++ b/reconcile/sentry_helper.py @@ -56,6 +56,7 @@ def run(dry_run): for user_name in user_names: guesses = guess_user(user_name, users) if not guesses: + logging.debug(f'no users guessed for {user_name}') continue slack_username = \ guesses[0].get('slack_username') or guesses[0]['org_username'] @@ -65,5 +66,7 @@ def run(dry_run): if not dry_run: state.add(slack_username) slack.chat_post_message( - f'yo <@{slack_username}>! ' + + f'yo <@{slack_username}>! it appears that you have ' + + 'requested access to a project in Sentry. ' + + 'access is managed automatically via app-interface. ' 'checkout https://url.corp.redhat.com/sentry-help') diff --git a/utils/smtp_client.py b/utils/smtp_client.py index be559cd80..bf6c84420 100644 --- a/utils/smtp_client.py +++ b/utils/smtp_client.py @@ -17,7 +17,7 @@ _mail_address = None -def init(host, port, username, password): +def init(host, port, username, password, client_only): global _client global _server @@ -30,7 +30,7 @@ def init(host, port, username, password): s.starttls() s.login(username, password) _client = s - if _server is None: + if _server is None and not client_only: s = imaplib.IMAP4_SSL( host=host ) @@ -46,7 +46,7 @@ def teardown(): _client.quit() -def init_from_config(settings): +def init_from_config(settings, client_only=True): global _username global _mail_address @@ -59,7 +59,7 @@ def init_from_config(settings): password = smtp_config['password'] _mail_address = config['smtp']['mail_address'] - return init(host, port, _username, password) + return init(host, port, _username, password, client_only=client_only) def get_smtp_config(path, settings): @@ -82,7 +82,7 @@ def get_mails(folder='INBOX', criteria='ALL', settings=None): global _server if _server is None: - init_from_config(settings) + init_from_config(settings, client_only=False) _server.select(f'"{folder}"')