From 0ba5f29d456f19c77541c7d598900f9e34141d7e Mon Sep 17 00:00:00 2001 From: Jim Laney Date: Tue, 24 May 2022 09:22:25 -0700 Subject: [PATCH 1/3] update to python3.8 --- Dockerfile | 2 +- docker/prod-values.yml | 6 +----- setup.py | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 54292a8..1b923ef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.6 +FROM python:3.8 ENV LOG_FILE stdout WORKDIR /app/ ENV PYTHONUNBUFFERED 1 diff --git a/docker/prod-values.yml b/docker/prod-values.yml index ac49a94..9e071d2 100644 --- a/docker/prod-values.yml +++ b/docker/prod-values.yml @@ -45,10 +45,6 @@ service: deploymentInitialization: enabled: false -image: - repository: gcr.io/uwit-mci-axdd/linkbot - tag: IMAGE_TAG - daemon: enabled: false @@ -90,7 +86,7 @@ externalSecrets: enabled: true secrets: - name: linkbot-dev-secrets - externalKey: axdd/kv/data/linkbot/secrets + externalKey: linkbot/secrets data: - name: slack-bot-token property: slack_bot_token diff --git a/setup.py b/setup.py index bfd2c74..c5e1702 100644 --- a/setup.py +++ b/setup.py @@ -24,6 +24,6 @@ 'License :: OSI Approved :: Apache Software License', 'Operating System :: OS Independent', 'Programming Language :: Python', - 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.8', ], ) From 34a71c7b6e4c514531b0261387e64ae877d7953a Mon Sep 17 00:00:00 2001 From: Jim Laney Date: Tue, 24 May 2022 09:23:18 -0700 Subject: [PATCH 2/3] add pycodestyle to workflow and fix issues --- .github/workflows/cicd.yml | 18 ++++++++++++++---- linkbots/__init__.py | 2 +- linkbots/jirabot.py | 14 +++++++++----- util/__init__.py | 5 +++-- util/endpoint.py | 3 ++- util/metrics.py | 8 +++++--- util/saml.py | 14 ++++++++++---- util/slash_cmd.py | 16 ++++++++-------- 8 files changed, 52 insertions(+), 28 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 7162310..e372a3c 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -13,7 +13,7 @@ on: jobs: context: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 outputs: commit_hash: ${{ steps.context.outputs.commit_hash }} @@ -28,7 +28,7 @@ jobs: release_name: ${{ env.RELEASE_NAME }} build: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 needs: context @@ -36,6 +36,16 @@ jobs: - name: Checkout Repo uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.8 + + - name: Run Python Linters + uses: uw-it-aca/actions/python-linters@main + with: + app_name: '.' + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 @@ -68,7 +78,7 @@ jobs: needs: [context, build] - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 outputs: context: ${{ steps.context.outputs.context }} @@ -98,7 +108,7 @@ jobs: needs: [context, build, deploy] - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - name: House Keeping diff --git a/linkbots/__init__.py b/linkbots/__init__.py index a3f3c5b..12c9a01 100644 --- a/linkbots/__init__.py +++ b/linkbots/__init__.py @@ -84,7 +84,7 @@ def _quip(self, link): try: if len(self._quiplist) < 1: self.quip_reset() - + quip = choice(self._quiplist) self._quiplist.remove(quip) return quip.format(link) diff --git a/linkbots/jirabot.py b/linkbots/jirabot.py index bd54608..33f1c62 100644 --- a/linkbots/jirabot.py +++ b/linkbots/jirabot.py @@ -11,9 +11,13 @@ class UwSamlJira: - """A Jira client with a saml session to handle authn on an SSO redirect""" + """ + A Jira client with a saml session to handle authn on an SSO redirect + """ def __init__(self, host='', auth=(None, None)): - """Initialize with the basic auth so we use our _session.""" + """ + Initialize with the basic auth so we use our _session. + """ self._session = UwSamlSession(credentials=auth) self.host = host @@ -41,10 +45,10 @@ def issue(self, issue_number): class LinkBot(LinkBotBase): - """Subclass LinkBot to customize response for JIRA links - """ - default_match = '[A-Z]{3,}\-[0-9]+' + Subclass LinkBot to customize response for JIRA links + """ + default_match = r'[A-Z]{3,}\-[0-9]+' def __init__(self, conf): if 'LINK' not in conf: diff --git a/util/__init__.py b/util/__init__.py index 8dfbf82..e588791 100644 --- a/util/__init__.py +++ b/util/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2021 UW-IT, University of Washington +# Copyright 2022 UW-IT, University of Washington # SPDX-License-Identifier: Apache-2.0 """ Helper functions @@ -8,7 +8,8 @@ def channel_name(channel_id, client): - """ Given a channel id, return corresponding channel name + """ + Given a channel id, return corresponding channel name """ channel = str(channel_id) if channel not in channel_cache: diff --git a/util/endpoint.py b/util/endpoint.py index 2f8eab1..2bf4837 100644 --- a/util/endpoint.py +++ b/util/endpoint.py @@ -1,4 +1,4 @@ -# Copyright 2021 UW-IT, University of Washington +# Copyright 2022 UW-IT, University of Washington # SPDX-License-Identifier: Apache-2.0 """ Functions providing linkbot events endpoint @@ -10,6 +10,7 @@ tornado_api = None + # prepare slack event endpoint def init_endpoint_server(slack_app): global tornado_api diff --git a/util/metrics.py b/util/metrics.py index e7a5000..611b7dc 100644 --- a/util/metrics.py +++ b/util/metrics.py @@ -1,4 +1,4 @@ -# Copyright 2021 UW-IT, University of Washington +# Copyright 2022 UW-IT, University of Washington # SPDX-License-Identifier: Apache-2.0 """ Functions supporting Prometheus metrics @@ -13,12 +13,14 @@ def metrics_counter(channel_name): - """ Increment channel_name message counter + """ + Increment channel_name message counter """ linkbot_message_count.labels(channel_name).inc() def metrics_server(port): - """ Serve metrics requests + """ + Serve metrics requests """ start_http_server(port) diff --git a/util/saml.py b/util/saml.py index 6106c30..9a75217 100644 --- a/util/saml.py +++ b/util/saml.py @@ -1,6 +1,8 @@ -# Copyright 2021 UW-IT, University of Washington +# Copyright 2022 UW-IT, University of Washington # SPDX-License-Identifier: Apache-2.0 -"""Utilities for working with sites behind UW SSO.""" +""" +Utilities for working with sites behind UW SSO. +""" import requests from bs4 import BeautifulSoup from urllib.parse import urljoin @@ -8,7 +10,9 @@ class UwSamlSession(requests.Session): - """A requests.Session that checks responses for IdP redirects.""" + """ + A requests.Session that checks responses for IdP redirects. + """ def __init__(self, credentials=(None, None)): self._credentials = credentials super(UwSamlSession, self).__init__() @@ -40,7 +44,9 @@ def request(self, method, url, *args, **kwargs): @staticmethod def _form_data(content): - """Return a tuple of (form url, form data) from response content.""" + """ + Return a tuple of (form url, form data) from response content. + """ bs = BeautifulSoup(content, 'html.parser') form = bs.find('form') url = urljoin(IDP, form['action']) diff --git a/util/slash_cmd.py b/util/slash_cmd.py index 536fe3c..4339f6d 100644 --- a/util/slash_cmd.py +++ b/util/slash_cmd.py @@ -1,4 +1,4 @@ -# Copyright 2021 UW-IT, University of Washington +# Copyright 2022 UW-IT, University of Washington # SPDX-License-Identifier: Apache-2.0 """ Class implementing linkbot Slack slash command @@ -12,10 +12,10 @@ class SlashCommand: OPERATIONS = [ {'name': ['help', '?', ''], 'method': 'op_help', - 'description': "*[help|?|]* Offer this helpful message" }, + 'description': "*[help|?|]* Offer this helpful message"}, {'name': ['debug'], 'method': 'op_debug', - 'description': "*debug [on|off]* Adjust verbose logging" }, + 'description': "*debug [on|off]* Adjust verbose logging"}, {'name': ['quips'], 'method': 'op_quips', 'description': "*quips [on|off|reset]* Control link quip display"}, @@ -35,12 +35,12 @@ def __init__(self, *args, **kwargs): def command(self, command, client, ack): ack() - self._client = client + self._client = client self._channel_id = command.get('channel_id') - self._user_id = command.get('user_id') - parts = command.get('text', '').split() - op = parts[0].lower() if len(parts) > 0 else '' - argv = parts[1:] if len(parts) > 1 else [None] + self._user_id = command.get('user_id') + parts = command.get('text', '').split() + op = parts[0].lower() if len(parts) > 0 else '' + argv = parts[1:] if len(parts) > 1 else [None] for operation in self.OPERATIONS: if op in operation['name']: From d717a96a04bbf8bf49ed7e8a5681b0b236bab33e Mon Sep 17 00:00:00 2001 From: Jim Laney Date: Tue, 24 May 2022 09:26:40 -0700 Subject: [PATCH 3/3] add license --- linkconfig_example.py | 3 +++ setup.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/linkconfig_example.py b/linkconfig_example.py index 2719bbc..39031bb 100644 --- a/linkconfig_example.py +++ b/linkconfig_example.py @@ -1,3 +1,6 @@ +# Copyright 2022 UW-IT, University of Washington +# SPDX-License-Identifier: Apache-2.0 + # LinkBot Configuration import os diff --git a/setup.py b/setup.py index c5e1702..51d955c 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,6 @@ +# Copyright 2022 UW-IT, University of Washington +# SPDX-License-Identifier: Apache-2.0 + from setuptools import setup README = """