Skip to content

Commit

Permalink
Send client version to server
Browse files Browse the repository at this point in the history
- add an entry point for min client version
- create a middleware to verify server/client version
  • Loading branch information
natthan-pigoux committed Sep 23, 2024
1 parent b2bc8b1 commit 1551b0c
Show file tree
Hide file tree
Showing 23 changed files with 270 additions and 253 deletions.
2 changes: 1 addition & 1 deletion diracx-client/src/diracx/client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/python@6.13.19)
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/python@6.15.0)
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

Expand Down
5 changes: 3 additions & 2 deletions diracx-client/src/diracx/client/_client.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/python@6.13.19)
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/python@6.15.0)
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from copy import deepcopy
from typing import Any
from typing_extensions import Self

from azure.core import PipelineClient
from azure.core.pipeline import policies
Expand Down Expand Up @@ -112,7 +113,7 @@ def send_request(
def close(self) -> None:
self._client.close()

def __enter__(self) -> "Dirac":
def __enter__(self) -> Self:
self._client.__enter__()
return self

Expand Down
2 changes: 1 addition & 1 deletion diracx-client/src/diracx/client/_configuration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/python@6.13.19)
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/python@6.15.0)
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

Expand Down
15 changes: 15 additions & 0 deletions diracx-client/src/diracx/client/_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from __future__ import annotations

from datetime import datetime, timezone
from importlib.metadata import PackageNotFoundError, distribution
import json
import jwt
import requests
Expand Down Expand Up @@ -148,6 +149,20 @@ def __init__(
# Get .well-known configuration
openid_configuration = get_openid_configuration(self._endpoint, verify=verify)

try:
self.client_version = distribution("diracx").version
except PackageNotFoundError:
try:
self.client_version = distribution("diracx-client").version
except PackageNotFoundError:
print("Error while getting client version")
self.client_version = "Unknown"

Check warning on line 159 in diracx-client/src/diracx/client/_patch.py

View check run for this annotation

Codecov / codecov/patch

diracx-client/src/diracx/client/_patch.py#L152-L159

Added lines #L152 - L159 were not covered by tests

# Setting default headers
kwargs.setdefault("base_headers", {})[

Check warning on line 162 in diracx-client/src/diracx/client/_patch.py

View check run for this annotation

Codecov / codecov/patch

diracx-client/src/diracx/client/_patch.py#L162

Added line #L162 was not covered by tests
"DiracX-Client-Version"
] = self.client_version

# Initialize Dirac with a Dirac-specific token credential policy
super().__init__(
endpoint=self._endpoint,
Expand Down
2 changes: 2 additions & 0 deletions diracx-client/src/diracx/client/_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ def _json_attemp(data):
# context otherwise.
_LOGGER.critical("Wasn't XML not JSON, failing")
raise DeserializationError("XML is invalid") from err
elif content_type.startswith("text/"):
return data_as_str

Check warning on line 150 in diracx-client/src/diracx/client/_serialization.py

View check run for this annotation

Codecov / codecov/patch

diracx-client/src/diracx/client/_serialization.py#L149-L150

Added lines #L149 - L150 were not covered by tests
raise DeserializationError(
"Cannot deserialize content-type: {}".format(content_type)
)
Expand Down
2 changes: 1 addition & 1 deletion diracx-client/src/diracx/client/_vendor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# --------------------------------------------------------------------------
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/python@6.13.19)
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/python@6.15.0)
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion diracx-client/src/diracx/client/aio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/python@6.13.19)
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/python@6.15.0)
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

Expand Down
5 changes: 3 additions & 2 deletions diracx-client/src/diracx/client/aio/_client.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/python@6.13.19)
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/python@6.15.0)
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from copy import deepcopy
from typing import Any, Awaitable
from typing_extensions import Self

Check warning on line 9 in diracx-client/src/diracx/client/aio/_client.py

View check run for this annotation

Codecov / codecov/patch

diracx-client/src/diracx/client/aio/_client.py#L9

Added line #L9 was not covered by tests

from azure.core import AsyncPipelineClient
from azure.core.pipeline import policies
Expand Down Expand Up @@ -112,7 +113,7 @@ def send_request(
async def close(self) -> None:
await self._client.close()

async def __aenter__(self) -> "Dirac":
async def __aenter__(self) -> Self:

Check warning on line 116 in diracx-client/src/diracx/client/aio/_client.py

View check run for this annotation

Codecov / codecov/patch

diracx-client/src/diracx/client/aio/_client.py#L116

Added line #L116 was not covered by tests
await self._client.__aenter__()
return self

Expand Down
2 changes: 1 addition & 1 deletion diracx-client/src/diracx/client/aio/_configuration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/python@6.13.19)
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/python@6.15.0)
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

Expand Down
15 changes: 15 additions & 0 deletions diracx-client/src/diracx/client/aio/_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
"""
from importlib.metadata import PackageNotFoundError, distribution

Check warning on line 9 in diracx-client/src/diracx/client/aio/_patch.py

View check run for this annotation

Codecov / codecov/patch

diracx-client/src/diracx/client/aio/_patch.py#L9

Added line #L9 was not covered by tests
import json
from types import TracebackType
from pathlib import Path
Expand Down Expand Up @@ -163,6 +164,20 @@ def __init__(
# Get .well-known configuration
openid_configuration = get_openid_configuration(self._endpoint, verify=verify)

try:
self.client_version = distribution("diracx").version
except PackageNotFoundError:
try:
self.client_version = distribution("diracx-client").version
except PackageNotFoundError:
print("Error while getting client version")
self.client_version = "Unknown"

Check warning on line 174 in diracx-client/src/diracx/client/aio/_patch.py

View check run for this annotation

Codecov / codecov/patch

diracx-client/src/diracx/client/aio/_patch.py#L167-L174

Added lines #L167 - L174 were not covered by tests

# Setting default headers
kwargs.setdefault("base_headers", {})[

Check warning on line 177 in diracx-client/src/diracx/client/aio/_patch.py

View check run for this annotation

Codecov / codecov/patch

diracx-client/src/diracx/client/aio/_patch.py#L177

Added line #L177 was not covered by tests
"DiracX-Client-Version"
] = self.client_version

# Initialize Dirac with a Dirac-specific token credential policy
super().__init__(
endpoint=self._endpoint,
Expand Down
2 changes: 1 addition & 1 deletion diracx-client/src/diracx/client/aio/_vendor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# --------------------------------------------------------------------------
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/python@6.13.19)
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/python@6.15.0)
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion diracx-client/src/diracx/client/aio/operations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/python@6.13.19)
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/python@6.15.0)
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

Expand Down
Loading

0 comments on commit 1551b0c

Please sign in to comment.