Skip to content

Commit

Permalink
Merge pull request #26 from siemens/refactor/sentry-21-02-0-changes
Browse files Browse the repository at this point in the history
Refactor/sentry 21 02 0 changes
  • Loading branch information
ercanucan authored Mar 5, 2021
2 parents 147eea1 + e39dcd1 commit 2a01115
Show file tree
Hide file tree
Showing 17 changed files with 471 additions and 144 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Publish

on:
push:
branches:
- master

env:
PY_COLORS: 1

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: "3.6"
- uses: abatilo/actions-poetry@v2.0.0
- name: Publish package
run: |
poetry install -n --no-dev
poetry publish --build -u __token__ -p ${{ secrets.PYPI_SECRET }}
69 changes: 69 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Test

on:
push:
branches:
- master
pull_request:
branches:
- master

env:
PY_COLORS: 1

jobs:
black:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: "3.6"
- uses: psf/black@stable
with:
args: "--check ."
commitlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: wagoid/commitlint-github-action@v3
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:9.6
env:
POSTGRES_HOST_AUTH_METHOD: trust
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
memcached:
image: memcached:1.5-alpine
ports:
- 11211:11211
redis:
image: redis:5.0-alpine
ports:
- 6379:6379

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: "3.6"
- uses: abatilo/actions-poetry@v2.0.0
- uses: actions/setup-node@v2
with:
node-version: '12'
- run: |
sudo apt-get update && sudo apt-get install -y libxmlsec1-dev libmaxminddb-dev
pip3 install -U wheel
make develop
make test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/build
venv
.venv
.coverage
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.6.12
46 changes: 0 additions & 46 deletions .travis.yml

This file was deleted.

3 changes: 0 additions & 3 deletions MANIFEST.in

This file was deleted.

24 changes: 7 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
.PHONY: clean develop install-tests lint publish test
.PHONY: clean develop test

develop:
pip2 install "pip>=7"
pip2 install -e git+https://github.com/getsentry/sentry.git#egg=sentry[dev]
pip2 install -e .
make install-tests

install-tests:
pip install .[tests]

lint:
@echo "--> Linting python"
flake8
@echo ""
pip3 install -e git+https://github.com/getsentry/sentry.git#egg=sentry[dev]
poetry install -n --no-dev
poetry build
pip3 install -U dist/*.whl
pip3 install codecov

test:
@echo "--> Running Python tests"
py.test tests || exit 1
pytest tests || exit 1
@echo ""

publish:
python setup.py sdist bdist_wheel upload

clean:
rm -rf *.egg-info src/*.egg-info
rm -rf dist build
4 changes: 1 addition & 3 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import absolute_import

import sys
import os
import sys

os.environ.setdefault("DB", "postgres")

Expand Down
1 change: 0 additions & 1 deletion oidc/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from __future__ import absolute_import
2 changes: 1 addition & 1 deletion oidc/apps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
from django.apps import AppConfig


Expand All @@ -7,6 +6,7 @@ class Config(AppConfig):

def ready(self):
from sentry import auth

from .provider import OIDCProvider

auth.register("oidc", OIDCProvider)
5 changes: 1 addition & 4 deletions oidc/constants.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from __future__ import absolute_import, print_function

from django.conf import settings
import requests

from django.conf import settings

AUTHORIZATION_ENDPOINT = getattr(settings, "OIDC_AUTHORIZATION_ENDPOINT", None)
TOKEN_ENDPOINT = getattr(settings, "OIDC_TOKEN_ENDPOINT", None)
Expand Down
22 changes: 10 additions & 12 deletions oidc/provider.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
from __future__ import absolute_import, print_function
import time

import requests

from sentry.auth.provider import MigratingIdentityId
from sentry.auth.providers.oauth2 import OAuth2Callback, OAuth2Provider, OAuth2Login
from sentry.auth.providers.oauth2 import OAuth2Callback, OAuth2Login, OAuth2Provider

from .constants import (
AUTHORIZATION_ENDPOINT,
USERINFO_ENDPOINT,
ISSUER,
TOKEN_ENDPOINT,
CLIENT_SECRET,
CLIENT_ID,
SCOPE,
CLIENT_SECRET,
DATA_VERSION,
ISSUER,
SCOPE,
TOKEN_ENDPOINT,
USERINFO_ENDPOINT,
)
from .views import FetchUser, OIDCConfigureView
import time


class OIDCLogin(OAuth2Login):
Expand All @@ -26,10 +24,10 @@ class OIDCLogin(OAuth2Login):

def __init__(self, client_id, domains=None):
self.domains = domains
super(OIDCLogin, self).__init__(client_id=client_id)
super().__init__(client_id=client_id)

def get_authorize_params(self, state, redirect_uri):
params = super(OIDCLogin, self).get_authorize_params(state, redirect_uri)
params = super().get_authorize_params(state, redirect_uri)
# TODO(dcramer): ideally we could look at the current resulting state
# when an existing auth happens, and if they're missing a refresh_token
# we should re-prompt them a second time with ``approval_prompt=force``
Expand Down Expand Up @@ -59,7 +57,7 @@ def __init__(self, domain=None, domains=None, version=None, **config):
else:
version = None
self.version = version
super(OIDCProvider, self).__init__(**config)
super().__init__(**config)

def get_configure_view(self):
return OIDCConfigureView.as_view()
Expand Down
14 changes: 4 additions & 10 deletions oidc/views.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
from __future__ import absolute_import, print_function

import logging

from sentry.auth.view import AuthView, ConfigureView
from sentry.utils import json
from sentry.utils.compat import map
from sentry.utils.signing import urlsafe_b64decode
from six.moves import map as _map

from .constants import ERR_INVALID_RESPONSE, ISSUER

logger = logging.getLogger("sentry.auth.oidc")


def map(a, b, *c):
return list(_map(a, b, *c))


class FetchUser(AuthView):
def __init__(self, domains, version, *args, **kwargs):
self.domains = domains
self.version = version
super(FetchUser, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def dispatch(self, request, helper):
data = helper.fetch_state("data")
Expand All @@ -34,13 +28,13 @@ def dispatch(self, request, helper):
try:
_, payload, _ = map(urlsafe_b64decode, id_token.split(".", 2))
except Exception as exc:
logger.error(u"Unable to decode id_token: %s" % exc, exc_info=True)
logger.error("Unable to decode id_token: %s" % exc, exc_info=True)
return helper.error(ERR_INVALID_RESPONSE)

try:
payload = json.loads(payload)
except Exception as exc:
logger.error(u"Unable to decode id_token payload: %s" % exc, exc_info=True)
logger.error("Unable to decode id_token payload: %s" % exc, exc_info=True)
return helper.error(ERR_INVALID_RESPONSE)

if not payload.get("email"):
Expand Down
Loading

0 comments on commit 2a01115

Please sign in to comment.