Skip to content

Commit

Permalink
trying again
Browse files Browse the repository at this point in the history
Signed-off-by: vsoch <vsoch@users.noreply.github.com>
  • Loading branch information
vsoch committed May 25, 2022
1 parent f95338c commit 4247928
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
4 changes: 4 additions & 0 deletions django_oci/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def is_authenticated(

# If authentication is disabled, return the original view
if settings.DISABLE_AUTHENTICATION or view_name not in settings.AUTHENTICATED_VIEWS:
print(f"{settings.DISABLE_AUTHENTICATION}")
print(
f"{view_name} is not in authenticated views: {settings.AUTHENTICATED_VIEWS}"
)
return True, None, None

# Ensure repository is valid, only if provided
Expand Down
2 changes: 2 additions & 0 deletions django_oci/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"django_oci.views.blobs.BlobDownload",
"django_oci.views.image.ImageTags",
"django_oci.views.image.ImageManifest",
"django_oci.views.image.view",
"django_oci.views.blobs.view",
]

DEFAULTS = {
Expand Down
4 changes: 2 additions & 2 deletions django_oci/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@


urlpatterns = [
re_path(
r"^auth/token/?$",
path(
"auth/token/",
views.GetAuthToken.as_view(),
name="get_auth_token",
),
Expand Down
8 changes: 6 additions & 2 deletions django_oci/views/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,18 @@
@permission_classes([])
@method_decorator(never_cache, name="dispatch")
class GetAuthToken(APIView):
"""Given a GET request for a token, validate and return it."""
"""
Given a GET request for a token, validate and return it.
"""

permission_classes = []
allowed_methods = ("GET",)

@method_decorator(never_cache)
def get(self, request, *args, **kwargs):
"""GET /auth/token"""
"""
GET /auth/token
"""
print("GET /auth/token")
user = get_user(request)

Expand Down
1 change: 1 addition & 0 deletions runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ DISABLE_AUTHENTICATION=yes python manage.py test tests.test_conformance
cleanup

# python manage.py test --noinput
fuser -k 8000/tcp
18 changes: 13 additions & 5 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@


def calculate_digest(blob):
"""Given a blob (the body of a response) calculate the sha256 digest"""
"""
Given a blob (the body of a response) calculate the sha256 digest
"""
hasher = hashlib.sha256()
hasher.update(blob)
return hasher.hexdigest()


def get_auth_header(username, password):
"""django oci requires the user token as the password to generate a longer
"""
django oci requires the user token as the password to generate a longer
auth token that will expire after some number of seconds
"""
auth_str = "%s:%s" % (username, password)
Expand All @@ -48,7 +51,8 @@ def get_auth_header(username, password):


def get_authentication_headers(response):
"""Given a requests.Response, assert that it has status code 401 and
"""
Given a requests.Response, assert that it has status code 401 and
provides the Www-Authenticate header that can be parsed for the request
"""
assert response.status_code == 401
Expand Down Expand Up @@ -78,7 +82,9 @@ def get_authentication_headers(response):


def read_in_chunks(image, chunk_size=1024):
"""Helper function to read file in chunks, with default size 1k."""
"""
Helper function to read file in chunks, with default size 1k.
"""
while True:
data = image.read(chunk_size)
if not data:
Expand All @@ -87,7 +93,9 @@ def read_in_chunks(image, chunk_size=1024):


def get_manifest(config_digest, layer_digest):
"""A dummy image manifest with a config and single image layer"""
"""
A dummy image manifest with a config and single image layer
"""
return json.dumps(
{
"schemaVersion": 2,
Expand Down

0 comments on commit 4247928

Please sign in to comment.