Skip to content

Commit

Permalink
Merge pull request #537 from UW-GAC/main
Browse files Browse the repository at this point in the history
Deploy to stage
  • Loading branch information
amstilp authored Apr 26, 2024
2 parents ce4006f + f207995 commit 7e190f8
Show file tree
Hide file tree
Showing 44 changed files with 664 additions and 863 deletions.
23 changes: 1 addition & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,6 @@ concurrency:
cancel-in-progress: true

jobs:
linter:
runs-on: ubuntu-latest
steps:

- name: Checkout Code Repository
uses: actions/checkout@v4

- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: 3.9
cache: pip
cache-dependency-path: |
requirements/requirements.txt
requirements/test-requirements.txt
# Run all pre-commit hooks on all the files.
# Getting only staged files can be tricky in case a new PR is opened
# since the action is run on a branch in detached head state
- name: Install and Run Pre-commit
uses: pre-commit/[email protected]

pytest-mariadb:
runs-on: ubuntu-latest
Expand All @@ -50,7 +29,7 @@ jobs:
# ahead of planned upgrades we can add versions as
# needed
python-version: [3.8]
mariadb-version: ["10.4"]
mariadb-version: ["10.4", "10.5"]

services:
mysql:
Expand Down
23 changes: 8 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,15 @@ repos:
- id: end-of-file-fixer
- id: check-yaml

- repo: https://github.com/psf/black
rev: 22.3.0
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.2
hooks:
- id: black

- repo: https://github.com/timothycrosley/isort
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
hooks:
- id: flake8
args: ['--config=setup.cfg']
additional_dependencies: [flake8-isort]
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format

- repo: https://github.com/gitleaks/gitleaks
rev: v8.16.1
Expand Down
20 changes: 20 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
line-length = 120
exclude = [
"**/migrations/**",
"*/static/CACHE/*",
"venv",
"docs",
]

[lint]
extend-select = [
"E",
"F",
"W", # pycodestyle warnings
"I", # isort
"DJ", # flake8-django
"E501", # line-too-long
]

[lint.isort]
known-first-party = ["gregor_django", "config", ]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ GREGoR Dynamic Web Apps Oauth Client Site

[![Black code style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)

[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/UW-GAC/gregor-django/main.svg)](https://results.pre-commit.ci/latest/github/UW-GAC/gregor-django/main)

[![image](https://img.shields.io/badge/License-MIT-blue.svg)](https://lbesson.mit-license.org/)

[![Built with Cookiecutter Django](https://img.shields.io/badge/built%20with-Cookiecutter%20Django-ff69b4.svg?logo=cookiecutter)](https://github.com/pydanny/cookiecutter-django/)
Expand Down
14 changes: 4 additions & 10 deletions config/settings/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Base settings to build other settings files upon.
"""

from pathlib import Path

import environ
Expand Down Expand Up @@ -129,9 +130,7 @@
]
# https://docs.djangoproject.com/en/dev/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"
},
{"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"},
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"},
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
Expand Down Expand Up @@ -257,12 +256,7 @@
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"verbose": {
"format": "%(levelname)s %(asctime)s %(module)s "
"%(process)d %(thread)d %(message)s"
}
},
"formatters": {"verbose": {"format": "%(levelname)s %(asctime)s %(module)s " "%(process)d %(thread)d %(message)s"}},
"handlers": {
"console": {
"level": "DEBUG",
Expand Down Expand Up @@ -380,7 +374,7 @@
# Specify the path to the service account to use for managing access on AnVIL.
ANVIL_API_SERVICE_ACCOUNT_FILE = env("ANVIL_API_SERVICE_ACCOUNT_FILE")
ANVIL_WORKSPACE_ADAPTERS = [
"gregor_django.gregor_anvil.adapters.ExampleWorkspaceAdapter",
"gregor_django.gregor_anvil.adapters.ResourceWorkspaceAdapter",
"gregor_django.gregor_anvil.adapters.TemplateWorkspaceAdapter",
"gregor_django.gregor_anvil.adapters.UploadWorkspaceAdapter",
"gregor_django.gregor_anvil.adapters.PartnerUploadWorkspaceAdapter",
Expand Down
4 changes: 1 addition & 3 deletions config/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
# EMAIL
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
EMAIL_BACKEND = env(
"DJANGO_EMAIL_BACKEND", default="django.core.mail.backends.console.EmailBackend"
)
EMAIL_BACKEND = env("DJANGO_EMAIL_BACKEND", default="django.core.mail.backends.console.EmailBackend")

# WhiteNoise
# ------------------------------------------------------------------------------
Expand Down
19 changes: 4 additions & 15 deletions config/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,11 @@
# in our apache configuration. Having in both places causes duplicate header
SECURE_HSTS_SECONDS = 0
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-include-subdomains
SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool(
"DJANGO_SECURE_HSTS_INCLUDE_SUBDOMAINS", default=True
)
SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool("DJANGO_SECURE_HSTS_INCLUDE_SUBDOMAINS", default=True)
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-preload
SECURE_HSTS_PRELOAD = env.bool("DJANGO_SECURE_HSTS_PRELOAD", default=True)
# https://docs.djangoproject.com/en/dev/ref/middleware/#x-content-type-options-nosniff
SECURE_CONTENT_TYPE_NOSNIFF = env.bool(
"DJANGO_SECURE_CONTENT_TYPE_NOSNIFF", default=True
)
SECURE_CONTENT_TYPE_NOSNIFF = env.bool("DJANGO_SECURE_CONTENT_TYPE_NOSNIFF", default=True)
# Since we have disabled HSTS above we get a warning when running check --deploy
# we are manually silencing this as we have verified apache is enforcing
# https://docs.djangoproject.com/en/dev/ref/checks/#security
Expand All @@ -79,9 +75,7 @@
# EMAIL
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#default-from-email
DEFAULT_FROM_EMAIL = env(
"DJANGO_DEFAULT_FROM_EMAIL", default="gac-django <[email protected]>"
)
DEFAULT_FROM_EMAIL = env("DJANGO_DEFAULT_FROM_EMAIL", default="gac-django <[email protected]>")
# https://docs.djangoproject.com/en/dev/ref/settings/#server-email
SERVER_EMAIL = env("DJANGO_SERVER_EMAIL", default=DEFAULT_FROM_EMAIL)
# https://docs.djangoproject.com/en/dev/ref/settings/#email-subject-prefix
Expand Down Expand Up @@ -130,12 +124,7 @@
"()": "maintenance_mode.logging.RequireNotMaintenanceMode503",
},
},
"formatters": {
"verbose": {
"format": "%(levelname)s %(asctime)s %(module)s "
"%(process)d %(thread)d %(message)s"
}
},
"formatters": {"verbose": {"format": "%(levelname)s %(asctime)s %(module)s " "%(process)d %(thread)d %(message)s"}},
"handlers": {
"mail_admins": {
"level": "ERROR",
Expand Down
4 changes: 1 addition & 3 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

urlpatterns = [
path("", TemplateView.as_view(template_name="pages/home.html"), name="home"),
path(
"about/", TemplateView.as_view(template_name="pages/about.html"), name="about"
),
path("about/", TemplateView.as_view(template_name="pages/about.html"), name="about"),
# Django Admin, use {% url 'admin:index' %}
path(settings.ADMIN_URL, admin.site.urls),
# User management
Expand Down
1 change: 1 addition & 0 deletions config/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
framework.
"""

import os
import sys
from pathlib import Path
Expand Down
7 changes: 1 addition & 6 deletions gregor_django/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
__version__ = "0.1.0"
__version_info__ = tuple(
[
int(num) if num.isdigit() else num
for num in __version__.replace("-", ".", 1).split(".")
]
)
__version_info__ = tuple([int(num) if num.isdigit() else num for num in __version__.replace("-", ".", 1).split(".")])
1 change: 0 additions & 1 deletion gregor_django/drupal_oauth_provider/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class CustomAccount(ProviderAccount):


class CustomProvider(OAuth2Provider):

id = DRUPAL_PROVIDER_ID
name = OVERRIDE_NAME
account_class = CustomAccount
Expand Down
4 changes: 1 addition & 3 deletions gregor_django/drupal_oauth_provider/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,4 @@ def test_custom_provider_has_scope(self):
}
]
with override_settings(SOCIALACCOUNT_PROVIDERS=custom_provider_settings):
CustomProvider(request).get_provider_managed_scope_status(
scopes_granted=["X"]
)
CustomProvider(request).get_provider_managed_scope_status(scopes_granted=["X"])
17 changes: 4 additions & 13 deletions gregor_django/drupal_oauth_provider/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,9 @@ def _get_public_key_jwk(self, headers):
return keys[0]

def get_public_key(self, headers):

public_key_jwk = self._get_public_key_jwk(headers)
try:
public_key = jwt.algorithms.RSAAlgorithm.from_jwk(
json.dumps(public_key_jwk)
)
public_key = jwt.algorithms.RSAAlgorithm.from_jwk(json.dumps(public_key_jwk))
except Exception as e:
logger.error(f"[get_public_key] failed to convert jwk to public key {e}")
else:
Expand Down Expand Up @@ -83,9 +80,7 @@ def get_scopes_from_token(self, id_token, headers):
logger.error(f"Invalid id_token {e} {id_token.token}")
raise OAuth2Error("Invalid id_token") from e
except Exception as e:
logger.error(
f"Other exception parsing token {e} header {unverified_header} token {id_token}"
)
logger.error(f"Other exception parsing token {e} header {unverified_header} token {id_token}")
raise OAuth2Error("Error when decoding token {e}")
else:
scopes = token_payload.get("scope")
Expand All @@ -96,9 +91,7 @@ def complete_login(self, request, app, token, **kwargs):
headers = {"Authorization": "Bearer {0}".format(token.token)}

scopes_granted = self.get_scopes_from_token(token, headers)
managed_scope_status = self.get_provider().get_provider_managed_scope_status(
scopes_granted
)
managed_scope_status = self.get_provider().get_provider_managed_scope_status(scopes_granted)

resp = requests.get(self.profile_url, headers=headers)
resp.raise_for_status()
Expand All @@ -110,9 +103,7 @@ def complete_login(self, request, app, token, **kwargs):
)
extra_data["scopes_granted"] = scopes_granted
extra_data["managed_scope_status"] = managed_scope_status
social_login = self.get_provider().sociallogin_from_response(
request, extra_data
)
social_login = self.get_provider().sociallogin_from_response(request, extra_data)

return social_login

Expand Down
Loading

0 comments on commit 7e190f8

Please sign in to comment.