Skip to content

Commit

Permalink
Merge pull request #13 from uw-it-aca/task/python-3.8
Browse files Browse the repository at this point in the history
Task/python 3.8
  • Loading branch information
jlaney authored May 24, 2022
2 parents cfc090b + d717a96 commit 69d29d5
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 35 deletions.
18 changes: 14 additions & 4 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -28,14 +28,24 @@ jobs:
release_name: ${{ env.RELEASE_NAME }}

build:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04

needs: context

steps:
- 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

Expand Down Expand Up @@ -68,7 +78,7 @@ jobs:

needs: [context, build]

runs-on: ubuntu-18.04
runs-on: ubuntu-20.04

outputs:
context: ${{ steps.context.outputs.context }}
Expand Down Expand Up @@ -98,7 +108,7 @@ jobs:

needs: [context, build, deploy]

runs-on: ubuntu-18.04
runs-on: ubuntu-20.04

steps:
- name: House Keeping
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.6
FROM python:3.8
ENV LOG_FILE stdout
WORKDIR /app/
ENV PYTHONUNBUFFERED 1
Expand Down
6 changes: 1 addition & 5 deletions docker/prod-values.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ service:
deploymentInitialization:
enabled: false

image:
repository: gcr.io/uwit-mci-axdd/linkbot
tag: IMAGE_TAG

daemon:
enabled: false

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion linkbots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 9 additions & 5 deletions linkbots/jirabot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions linkconfig_example.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright 2022 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

# LinkBot Configuration

import os
Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright 2022 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from setuptools import setup

README = """
Expand All @@ -24,6 +27,6 @@
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.8',
],
)
5 changes: 3 additions & 2 deletions util/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion util/endpoint.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,6 +10,7 @@

tornado_api = None


# prepare slack event endpoint
def init_endpoint_server(slack_app):
global tornado_api
Expand Down
8 changes: 5 additions & 3 deletions util/metrics.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
14 changes: 10 additions & 4 deletions util/saml.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# 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
IDP = 'https://idp.u.washington.edu/'


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__()
Expand Down Expand Up @@ -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'])
Expand Down
16 changes: 8 additions & 8 deletions util/slash_cmd.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"},
Expand All @@ -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']:
Expand Down

0 comments on commit 69d29d5

Please sign in to comment.