Skip to content

Commit

Permalink
sentry-helper fixes (app-sre#1053)
Browse files Browse the repository at this point in the history
  • Loading branch information
maorfr committed Sep 10, 2020
1 parent 79c1686 commit 86ea6b2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
7 changes: 6 additions & 1 deletion reconcile/queries.py
@@ -1,3 +1,5 @@
import logging

import utils.gql as gql


Expand Down Expand Up @@ -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]
5 changes: 4 additions & 1 deletion reconcile/sentry_helper.py
Expand Up @@ -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']
Expand All @@ -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')
10 changes: 5 additions & 5 deletions utils/smtp_client.py
Expand Up @@ -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

Expand All @@ -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
)
Expand All @@ -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

Expand All @@ -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):
Expand All @@ -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}"')

Expand Down

0 comments on commit 86ea6b2

Please sign in to comment.