Skip to content

Commit

Permalink
feat: Remove useless VO parameter from /config
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisburr committed Jan 28, 2024
1 parent 7502815 commit 1b75d16
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 32 deletions.
3 changes: 1 addition & 2 deletions diracx-cli/src/diracx/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
@app.async_command()
async def dump():
async with DiracClient() as api:
user_info = await api.auth.userinfo()
config = await api.config.serve_config(user_info.vo)
config = await api.config.serve_config()
display(config)

Check warning on line 22 in diracx-cli/src/diracx/cli/config.py

View check run for this annotation

Codecov / codecov/patch

diracx-cli/src/diracx/cli/config.py#L20-L22

Added lines #L20 - L22 were not covered by tests


Expand Down
5 changes: 0 additions & 5 deletions diracx-client/src/diracx/client/aio/operations/_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,24 +788,20 @@ def __init__(self, *args, **kwargs) -> None:
@distributed_trace_async
async def serve_config(
self,
vo: str,
*,
if_none_match: Optional[str] = None,
if_modified_since: Optional[str] = None,
**kwargs: Any,
) -> Any:
"""Serve Config.
"
Get the latest view of the config.
If If-None-Match header is given and matches the latest ETag, return 304
If If-Modified-Since is given and is newer than latest,
return 304: this is to avoid flip/flopping.
:param vo: Required.
:type vo: str
:keyword if_none_match: Default value is None.
:paramtype if_none_match: str
:keyword if_modified_since: Default value is None.
Expand All @@ -828,7 +824,6 @@ async def serve_config(
cls: ClsType[Any] = kwargs.pop("cls", None)

request = build_config_serve_config_request(
vo=vo,
if_none_match=if_none_match,
if_modified_since=if_modified_since,
headers=_headers,
Expand Down
13 changes: 1 addition & 12 deletions diracx-client/src/diracx/client/operations/_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ def build_auth_userinfo_request(**kwargs: Any) -> HttpRequest:


def build_config_serve_config_request(
vo: str,
*,
if_none_match: Optional[str] = None,
if_modified_since: Optional[str] = None,
Expand All @@ -275,12 +274,7 @@ def build_config_serve_config_request(
accept = _headers.pop("Accept", "application/json")

# Construct URL
_url = "/api/config/{vo}"
path_format_arguments = {
"vo": _SERIALIZER.url("vo", vo, "str"),
}

_url: str = _format_url_section(_url, **path_format_arguments) # type: ignore
_url = "/api/config/"

Check warning on line 277 in diracx-client/src/diracx/client/operations/_operations.py

View check run for this annotation

Codecov / codecov/patch

diracx-client/src/diracx/client/operations/_operations.py#L277

Added line #L277 was not covered by tests

# Construct headers
if if_none_match is not None:
Expand Down Expand Up @@ -1505,24 +1499,20 @@ def __init__(self, *args, **kwargs):
@distributed_trace
def serve_config(
self,
vo: str,
*,
if_none_match: Optional[str] = None,
if_modified_since: Optional[str] = None,
**kwargs: Any,
) -> Any:
"""Serve Config.
"
Get the latest view of the config.
If If-None-Match header is given and matches the latest ETag, return 304
If If-Modified-Since is given and is newer than latest,
return 304: this is to avoid flip/flopping.
:param vo: Required.
:type vo: str
:keyword if_none_match: Default value is None.
:paramtype if_none_match: str
:keyword if_modified_since: Default value is None.
Expand All @@ -1545,7 +1535,6 @@ def serve_config(
cls: ClsType[Any] = kwargs.pop("cls", None)

request = build_config_serve_config_request(
vo=vo,
if_none_match=if_none_match,
if_modified_since=if_modified_since,
headers=_headers,
Expand Down
5 changes: 2 additions & 3 deletions diracx-routers/src/diracx/routers/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
router = DiracxRouter()


@router.get("/{vo}")
@router.get("/")
async def serve_config(
vo: str,
config: Config,
response: Response,
if_none_match: Annotated[str | None, Header()] = None,
if_modified_since: Annotated[str | None, Header()] = None,
):
""" "
"""
Get the latest view of the config.
Expand Down
20 changes: 10 additions & 10 deletions diracx-routers/tests/test_config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ def normal_user_client(client_factory):

def test_unauthenticated(client_factory):
with client_factory.unauthenticated() as client:
response = client.get("/api/config/lhcb/")
response = client.get("/api/config/")
assert response.status_code == status.HTTP_403_FORBIDDEN


def test_get_config(normal_user_client):
r = normal_user_client.get("/api/config/lhcb")
r = normal_user_client.get("/api/config/")
assert r.status_code == status.HTTP_200_OK, r.json()
assert r.json(), r.text

last_modified = r.headers["Last-Modified"]
etag = r.headers["ETag"]

r = normal_user_client.get(
"/api/config/lhcb",
"/api/config/",
headers={
"If-None-Match": etag,
"If-Modified-Since": last_modified,
Expand All @@ -37,7 +37,7 @@ def test_get_config(normal_user_client):

# If only an invalid ETAG is passed, we expect a response
r = normal_user_client.get(
"/api/config/lhcb",
"/api/config/",
headers={
"If-None-Match": "wrongEtag",
},
Expand All @@ -47,7 +47,7 @@ def test_get_config(normal_user_client):

# If an past ETAG and an past timestamp as give, we expect an response
r = normal_user_client.get(
"/api/config/lhcb",
"/api/config/",
headers={
"If-None-Match": "pastEtag",
"If-Modified-Since": "Mon, 1 Apr 2000 00:42:42 GMT",
Expand All @@ -58,7 +58,7 @@ def test_get_config(normal_user_client):

# If an future ETAG and an new timestamp as give, we expect 304
r = normal_user_client.get(
"/api/config/lhcb",
"/api/config/",
headers={
"If-None-Match": "futureEtag",
"If-Modified-Since": "Mon, 1 Apr 9999 00:42:42 GMT",
Expand All @@ -69,7 +69,7 @@ def test_get_config(normal_user_client):

# If an invalid ETAG and an invalid modified time, we expect a response
r = normal_user_client.get(
"/api/config/lhcb",
"/api/config/",
headers={
"If-None-Match": "futureEtag",
"If-Modified-Since": "wrong format",
Expand All @@ -80,7 +80,7 @@ def test_get_config(normal_user_client):

# If the correct ETAG and a past timestamp as give, we expect 304
r = normal_user_client.get(
"/api/config/lhcb",
"/api/config/",
headers={
"If-None-Match": etag,
"If-Modified-Since": "Mon, 1 Apr 2000 00:42:42 GMT",
Expand All @@ -91,7 +91,7 @@ def test_get_config(normal_user_client):

# If the correct ETAG and a new timestamp as give, we expect 304
r = normal_user_client.get(
"/api/config/lhcb",
"/api/config/",
headers={
"If-None-Match": etag,
"If-Modified-Since": "Mon, 1 Apr 9999 00:42:42 GMT",
Expand All @@ -102,7 +102,7 @@ def test_get_config(normal_user_client):

# If the correct ETAG and an invalid modified time, we expect 304
r = normal_user_client.get(
"/api/config/lhcb",
"/api/config/",
headers={
"If-None-Match": etag,
"If-Modified-Since": "wrong format",
Expand Down

0 comments on commit 1b75d16

Please sign in to comment.