Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-m-sullivan committed Dec 10, 2024
2 parents 765d8ce + 698a8ae commit 83713ac
Show file tree
Hide file tree
Showing 866 changed files with 980 additions and 17,070 deletions.
6 changes: 3 additions & 3 deletions .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

codecov:
notify:
after_n_builds: 5 # Number of test matrix+lint jobs uploading coverage
after_n_builds: 6 # Number of test matrix+lint jobs uploading coverage
wait_for_ci: false

require_ci_to_pass: false
Expand Down Expand Up @@ -34,7 +34,7 @@ coverage:
- pytest
paths:
- awx/
target: 100%
target: 75%
tests:
flags:
- pytest
Expand All @@ -48,7 +48,7 @@ coverage:
**/test/**
- >-
**/tests/**
target: 100%
target: 95%
typing:
flags:
- MyPy
Expand Down
25 changes: 0 additions & 25 deletions awx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,6 @@ def version_file():
from django.db import connection


def oauth2_getattribute(self, attr):
# Custom method to override
# oauth2_provider.settings.OAuth2ProviderSettings.__getattribute__
from django.conf import settings
from oauth2_provider.settings import DEFAULTS

val = None
if (isinstance(attr, str)) and (attr in DEFAULTS) and (not attr.startswith('_')):
# certain Django OAuth Toolkit migrations actually reference
# setting lookups for references to model classes (e.g.,
# oauth2_settings.REFRESH_TOKEN_MODEL)
# If we're doing an OAuth2 setting lookup *while running* a migration,
# don't do our usual database settings lookup
val = settings.OAUTH2_PROVIDER.get(attr)
if val is None:
val = object.__getattribute__(self, attr)
return val


def prepare_env():
# Update the default settings environment variable based on current mode.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'awx.settings.%s' % MODE)
Expand All @@ -89,12 +70,6 @@ def prepare_env():
if not settings.DEBUG: # pragma: no cover
warnings.simplefilter('ignore', DeprecationWarning)

# Monkeypatch Oauth2 toolkit settings class to check for settings
# in django.conf settings each time, not just once during import
import oauth2_provider.settings

oauth2_provider.settings.OAuth2ProviderSettings.__getattribute__ = oauth2_getattribute


def manage():
# Prepare the AWX environment.
Expand Down
16 changes: 0 additions & 16 deletions awx/api/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
# Django REST Framework
from rest_framework import authentication

# Django-OAuth-Toolkit
from oauth2_provider.contrib.rest_framework import OAuth2Authentication

logger = logging.getLogger('awx.api.authentication')


Expand All @@ -36,16 +33,3 @@ def authenticate_header(self, request):
class SessionAuthentication(authentication.SessionAuthentication):
def authenticate_header(self, request):
return 'Session'


class LoggedOAuth2Authentication(OAuth2Authentication):
def authenticate(self, request):
ret = super(LoggedOAuth2Authentication, self).authenticate(request)
if ret:
user, token = ret
username = user.username if user else '<none>'
logger.info(
smart_str(u"User {} performed a {} to {} through the API using OAuth 2 token {}.".format(username, request.method, request.path, token.pk))
)
setattr(user, 'oauth_scopes', [x for x in token.scope.split() if x])
return ret
23 changes: 0 additions & 23 deletions awx/api/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

# AWX
from awx.conf import fields, register, register_validate
from awx.api.fields import OAuth2ProviderField
from oauth2_provider.settings import oauth2_settings


register(
Expand Down Expand Up @@ -46,27 +44,6 @@
category=_('Authentication'),
category_slug='authentication',
)
register(
'OAUTH2_PROVIDER',
field_class=OAuth2ProviderField,
default={
'ACCESS_TOKEN_EXPIRE_SECONDS': oauth2_settings.ACCESS_TOKEN_EXPIRE_SECONDS,
'AUTHORIZATION_CODE_EXPIRE_SECONDS': oauth2_settings.AUTHORIZATION_CODE_EXPIRE_SECONDS,
'REFRESH_TOKEN_EXPIRE_SECONDS': oauth2_settings.REFRESH_TOKEN_EXPIRE_SECONDS,
},
label=_('OAuth 2 Timeout Settings'),
help_text=_(
'Dictionary for customizing OAuth 2 timeouts, available items are '
'`ACCESS_TOKEN_EXPIRE_SECONDS`, the duration of access tokens in the number '
'of seconds, `AUTHORIZATION_CODE_EXPIRE_SECONDS`, the duration of '
'authorization codes in the number of seconds, and `REFRESH_TOKEN_EXPIRE_SECONDS`, '
'the duration of refresh tokens, after expired access tokens, '
'in the number of seconds.'
),
category=_('Authentication'),
category_slug='authentication',
unit=_('seconds'),
)
register(
'LOGIN_REDIRECT_OVERRIDE',
field_class=fields.CharField,
Expand Down
14 changes: 0 additions & 14 deletions awx/api/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from rest_framework import serializers

# AWX
from awx.conf import fields
from awx.main.models import Credential

__all__ = ['BooleanNullField', 'CharNullField', 'ChoiceNullField', 'VerbatimField']
Expand Down Expand Up @@ -79,19 +78,6 @@ def to_representation(self, value):
return value


class OAuth2ProviderField(fields.DictField):
default_error_messages = {'invalid_key_names': _('Invalid key names: {invalid_key_names}')}
valid_key_names = {'ACCESS_TOKEN_EXPIRE_SECONDS', 'AUTHORIZATION_CODE_EXPIRE_SECONDS', 'REFRESH_TOKEN_EXPIRE_SECONDS'}
child = fields.IntegerField(min_value=1)

def to_internal_value(self, data):
data = super(OAuth2ProviderField, self).to_internal_value(data)
invalid_flags = set(data.keys()) - self.valid_key_names
if invalid_flags:
self.fail('invalid_key_names', invalid_key_names=', '.join(list(invalid_flags)))
return data


class DeprecatedCredentialField(serializers.IntegerField):
def __init__(self, **kwargs):
kwargs['allow_null'] = True
Expand Down
11 changes: 3 additions & 8 deletions awx/api/generics.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from django.core.exceptions import FieldDoesNotExist
from django.db import connection, transaction
from django.db.models.fields.related import OneToOneRel
from django.http import QueryDict
from django.http import QueryDict, JsonResponse
from django.shortcuts import get_object_or_404, redirect
from django.template.loader import render_to_string
from django.utils.encoding import smart_str
Expand Down Expand Up @@ -81,6 +81,7 @@


class LoggedLoginView(auth_views.LoginView):

def get(self, request, *args, **kwargs):
if is_proxied_request():
next = request.GET.get('next', "")
Expand All @@ -105,7 +106,7 @@ def get(self, request, *args, **kwargs):
def post(self, request, *args, **kwargs):
if is_proxied_request():
# Give a message, saying to login via AAP
return Response(
return JsonResponse(
{
'detail': _('Please log in via Platform Authentication.'),
},
Expand Down Expand Up @@ -373,12 +374,6 @@ def dispatch(self, request, *args, **kwargs):
kwargs.pop('version')
return super(APIView, self).dispatch(request, *args, **kwargs)

def check_permissions(self, request):
if request.method not in ('GET', 'OPTIONS', 'HEAD'):
if 'write' not in getattr(request.user, 'oauth_scopes', ['write']):
raise PermissionDenied()
return super(APIView, self).check_permissions(request)


class GenericAPIView(generics.GenericAPIView, APIView):
# Base class for all model-based views.
Expand Down
Loading

0 comments on commit 83713ac

Please sign in to comment.