Skip to content

Commit

Permalink
[pre-commit.ci] Apply automatic pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Jan 9, 2025
1 parent 24ea2f7 commit 5ee3524
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ class CondaStoreServer(Application):
)

enable_registry = Bool(
False, help="(deprecated) enable the docker registry for conda-store", config=True
False,
help="(deprecated) enable the docker registry for conda-store",
config=True,
)

enable_metrics = Bool(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
# license that can be found in the LICENSE file.

import datetime
from typing import Any, Dict, List, Optional, TypedDict, Callable
from functools import wraps
from typing import Any, Callable, Dict, List, Optional, TypedDict

import pydantic
import yaml
from celery.result import AsyncResult
from fastapi import APIRouter, Body, Depends, HTTPException, Query, Request
from fastapi.responses import JSONResponse, PlainTextResponse, RedirectResponse
from functools import wraps

from conda_store_server import __version__, api
from conda_store_server._internal import orm, schema
Expand Down Expand Up @@ -133,6 +133,7 @@ def paginated_api_response(
"count": count,
}


def deprecated(sunset_date: datetime.date) -> Callable:
"""Decorator to add deprecation headers to a HTTP response. These will include:
{
Expand All @@ -148,14 +149,19 @@ def deprecated(sunset_date: datetime.date) -> Callable:
sunset_date : datetime.date
the date that the endpoint will have it's functionality removed
"""

def decorator(func):
@wraps(func)
def add_deprecated_headers(*args, **kwargs):
response = func(*args, **kwargs)
response.headers["Deprecation"] = "True"
response.headers["Sunset"] = sunset_date.strftime("%a, %d %b %Y 00:00:00 UTC")
response.headers["Sunset"] = sunset_date.strftime(
"%a, %d %b %Y 00:00:00 UTC"
)
return response

return add_deprecated_headers

return decorator


Expand Down Expand Up @@ -1403,7 +1409,8 @@ async def api_get_build_docker_image_url(
"message": f"Build {build_id} doesn't have a docker manifest",
}
return JSONResponse(
status_code=400, content=content,
status_code=400,
content=content,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

import datetime
import json
import time
import datetime

from fastapi import APIRouter, Depends, HTTPException, Request
from fastapi.responses import RedirectResponse, Response

from conda_store_server import api
from conda_store_server._internal.server.views.api import deprecated
from conda_store_server._internal import orm, schema
from conda_store_server._internal.schema import Permissions
from conda_store_server._internal.server import dependencies
from conda_store_server._internal.server.views.api import deprecated

router_registry = APIRouter(tags=["registry"])

Expand Down Expand Up @@ -78,6 +78,7 @@ def replace_words(s, words):
)
return environment_name


@deprecated(sunset_date=datetime.date(2025, 3, 17))
def get_docker_image_manifest(conda_store, image, tag, timeout=10 * 60):
namespace, *image_name = image.split("/")
Expand Down Expand Up @@ -134,6 +135,7 @@ def get_docker_image_blob(conda_store, image, blobsum):
blob_key = f"docker/blobs/{blobsum}"
return RedirectResponse(conda_store.storage.get_url(blob_key))


@router_registry.get("/v2/", deprecated=True)
@deprecated(sunset_date=datetime.date(2025, 3, 17))
def v2(
Expand All @@ -146,9 +148,7 @@ def v2(
return _json_response({})


@router_registry.get(
"/v2/{rest:path}", deprecated=True
)
@router_registry.get("/v2/{rest:path}", deprecated=True)
@deprecated(sunset_date=datetime.date(2025, 3, 17))
def list_tags(
rest: str,
Expand Down
14 changes: 8 additions & 6 deletions conda-store-server/tests/_internal/server/views/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# license that can be found in the LICENSE file.

import contextlib
import datetime
import json
import os
import sys
import time
import datetime

import pytest
import traitlets
Expand Down Expand Up @@ -46,17 +46,19 @@ def mock_get_entity():

def test_deprecation_warning():
from fastapi.responses import JSONResponse

from conda_store_server._internal.server.views.api import deprecated

@deprecated(datetime.date(2024, 12, 17))
def api_status():
return JSONResponse(
status_code=400, content={"ok": "ok"},
)

status_code=400,
content={"ok": "ok"},
)

result = api_status()
assert(result.headers.get("Deprecation") == "True")
assert(result.headers.get("Sunset") == "Tue, 17 Dec 2024 00:00:00 UTC")
assert result.headers.get("Deprecation") == "True"
assert result.headers.get("Sunset") == "Tue, 17 Dec 2024 00:00:00 UTC"


def test_api_version_unauth(testclient):
Expand Down
2 changes: 1 addition & 1 deletion docusaurus-docs/conda-store/explanations/artifacts.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ To install the tarball, follow the [instructions for the target machine in the c
## Docker images (deprecated)

:::warning[Deprecation notice]
Docker image creation is currently not supported. This feature is scheduled to be
Docker image creation is currently not supported. This feature is scheduled to be
removed March 17, 2025.
:::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ bindings that an authenticated user assumes.
`Authentication.cookie_name` is the name for the browser cookie used
to authenticate users.

`Authentication.cookie_domain` use when wanting to set a subdomain wide
cookie. For example setting this to `example.com` would allow the cookie
`Authentication.cookie_domain` use when wanting to set a subdomain wide
cookie. For example setting this to `example.com` would allow the cookie
to be valid for `example.com` along with `*.example.com`.

`Authentication.authentication_backend` is the class to use for
Expand Down Expand Up @@ -486,10 +486,10 @@ is a regular python fastapi function.

### Deprecated configuration options for `conda_store_server._internal.server.app.CondaStoreServer`

`CondaStoreServer.enable_registry` (deprecated) a Boolean on whether to
`CondaStoreServer.enable_registry` (deprecated) a Boolean on whether to
expose the registry endpoints. Default False.

`CondaStoreServer.registry_external_url` (deprecated) is the external hostname
`CondaStoreServer.registry_external_url` (deprecated) is the external hostname
and port to access docker registry cannot contain `http://` or `https://`.

## `conda_store_server._internal.worker.app.CondaStoreWorker`
Expand Down

0 comments on commit 5ee3524

Please sign in to comment.