Skip to content

Commit 3949175

Browse files
slashburygingmelikov
authored andcommitted
use uv instead pip
1 parent 8ccf577 commit 3949175

20 files changed

Lines changed: 3392 additions & 257 deletions

.github/workflows/tests.yaml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,30 @@ jobs:
1616
- uses: actions/setup-python@v5
1717
with:
1818
python-version: ${{ matrix.python-version }}
19-
- name: Install tox
20-
run: pip install tox
21-
- name: Black
19+
- name: Install uv
20+
uses: astral-sh/setup-uv@v7
21+
- name: Install tox-uv
22+
run: uv tool install tox --with tox-uv
23+
- name: ruff
2224
run: |
23-
tox -e black-check
25+
tox -e ruff-check
2426
tests:
2527
runs-on: ubuntu-24.04
2628
strategy:
2729
fail-fast: true
2830
matrix:
29-
python-version: ["3.8", "3.10", "3.12", "3.13"]
31+
python-version: ["3.8", "3.10", "3.11", "3.12", "3.13", "3.14"]
3032
steps:
3133
- uses: actions/checkout@v3
3234
- uses: actions/setup-python@v5
3335
with:
3436
python-version: ${{ matrix.python-version }}
35-
- name: Install required packages
36-
run: |
37-
sudo apt update
38-
sudo apt install libev-dev -y
39-
- name: Install tox
40-
run: pip install tox
37+
- name: Install dependencies
38+
run: sudo apt update && sudo apt install --yes libev-dev
39+
- name: Install uv
40+
uses: astral-sh/setup-uv@v7
41+
- name: Install tox-uv
42+
run: uv tool install tox --with tox-uv
4143
- name: Unit tests
4244
run: |
4345
tox -e ${{ matrix.python-version }}

gcl_iam/algorithms.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ def encrypt_hs256_jwks_secret(
6767
)
6868

6969
nonce_b64 = base64.urlsafe_b64encode(nonce).rstrip(b"=").decode("ascii")
70-
ciphertext_b64 = (
71-
base64.urlsafe_b64encode(ciphertext).rstrip(b"=").decode("ascii")
72-
)
70+
ciphertext_b64 = base64.urlsafe_b64encode(ciphertext).rstrip(b"=").decode("ascii")
7371
return f"aesgcm:{nonce_b64}.{ciphertext_b64}"
7472

7573

@@ -124,9 +122,7 @@ def generate_rsa_private_key_pem(
124122
) -> str:
125123
allowed_bitness = {2048, 3072, 4096}
126124
if bitness not in allowed_bitness:
127-
raise ValueError(
128-
"Invalid RSA bitness. Allowed values: 2048, 3072, 4096."
129-
)
125+
raise ValueError("Invalid RSA bitness. Allowed values: 2048, 3072, 4096.")
130126

131127
private_key = crypto_rsa.generate_private_key(
132128
public_exponent=public_exponent,
@@ -168,7 +164,6 @@ def get_rsa_bitness_from_private_key_pem(private_key_pem: str) -> int:
168164

169165

170166
class AbstractAlgorithm(metaclass=abc.ABCMeta):
171-
172167
@abc.abstractmethod
173168
def decode(self, data: str) -> tp.Dict[str, tp.Any]:
174169
raise NotImplementedError("Not implemented")
@@ -179,7 +174,6 @@ def encode(self, data: tp.Dict[str, tp.Any]) -> str:
179174

180175

181176
class BaseJwtAlgorithm(AbstractAlgorithm):
182-
183177
@property
184178
@abc.abstractmethod
185179
def algorithm(self) -> str:
@@ -249,7 +243,6 @@ def decode(
249243

250244

251245
class HS256(BaseJwtAlgorithm):
252-
253246
def __init__(self, key: str, previous_key: tp.Optional[str] = None):
254247
super().__init__()
255248
self._key = key
@@ -268,7 +261,6 @@ def encode(self, data: tp.Dict[str, tp.Any]) -> str:
268261

269262

270263
class RS256VerifyOnly(BaseJwtAlgorithm):
271-
272264
def __init__(
273265
self,
274266
public_key: str,
@@ -291,7 +283,6 @@ def encode(self, data):
291283

292284

293285
class RS256(RS256VerifyOnly):
294-
295286
def __init__(
296287
self,
297288
private_key: str,

gcl_iam/contexts.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929

3030
class GenesisCoreAuthContext(contexts.ContextWithStorage):
31-
3231
def __init__(
3332
self,
3433
req,
@@ -58,9 +57,7 @@ def get_real_url_with_prefix(self):
5857
port = forwarded_port or parsed.port
5958

6059
new_uri = (
61-
f"{scheme}://{host}:{port}"
62-
if port is not None
63-
else f"{scheme}://{host}"
60+
f"{scheme}://{host}:{port}" if port is not None else f"{scheme}://{host}"
6461
)
6562

6663
if forwarded_prefix:

gcl_iam/controllers.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,13 @@
2727

2828

2929
class PolicyBasedControllerMixin(object):
30-
3130
__policy_service_name__ = ""
3231
__policy_name__ = None
3332
_otp_mandatory = set()
3433

3534
def __init__(self, *args, **kwargs):
3635
super().__init__(*args, **kwargs)
37-
self._introspection = (
38-
contexts.get_context().iam_context.introspection_info()
39-
)
36+
self._introspection = contexts.get_context().iam_context.introspection_info()
4037

4138
self._ctx_project_id = self._introspection.get("project_id", None)
4239
if isinstance(self._ctx_project_id, str):
@@ -74,23 +71,17 @@ def _enforce_and_override_project_id_in_kwargs(self, method, kwargs):
7471
if "project_id" in kwargs:
7572
self._force_project_id(kwargs["project_id"])
7673
else:
77-
kwargs["project_id"] = types.UUID().from_simple_type(
78-
self._ctx_project_id
79-
)
74+
kwargs["project_id"] = types.UUID().from_simple_type(self._ctx_project_id)
8075

8176
def _check_otp(self, method):
82-
if (
83-
self._introspection.get("otp_enabled")
84-
or method in self._otp_mandatory
85-
):
77+
if self._introspection.get("otp_enabled") or method in self._otp_mandatory:
8678
if not self._introspection.get("otp_verified"):
8779
raise exceptions.OTPInvalidCodeError()
8880

8981

9082
class PolicyBasedController(
9183
PolicyBasedControllerMixin, controllers.BaseResourceController
9284
):
93-
9485
def create(self, **kwargs):
9586
self._enforce_and_override_project_id_in_kwargs("create", kwargs)
9687

@@ -103,9 +94,7 @@ def get(self, **kwargs):
10394

10495
def filter(self, filters, order_by=None):
10596
self._enforce_and_override_project_id_in_kwargs("read", filters)
106-
return super(PolicyBasedController, self).filter(
107-
filters, order_by=order_by
108-
)
97+
return super(PolicyBasedController, self).filter(filters, order_by=order_by)
10998

11099
def delete(self, uuid):
111100
filters = {}
@@ -127,7 +116,6 @@ def update(self, uuid, **kwargs):
127116
class NestedPolicyBasedController(
128117
PolicyBasedControllerMixin, controllers.BaseNestedResourceController
129118
):
130-
131119
# Nested resources may not have projects, so it will be checked via parent
132120
def create(self, parent_resource, **kwargs):
133121
if "project_id" in self.model.properties:
@@ -165,7 +153,6 @@ def update(self, parent_resource, uuid, **kwargs):
165153
class PolicyBasedWithoutProjectController(
166154
PolicyBasedControllerMixin, controllers.BaseResourceController
167155
):
168-
169156
def create(self, **kwargs):
170157
self._enforce("create")
171158
return super().create(**kwargs)

gcl_iam/drivers.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737

3838
class AbstractAuthDriver(metaclass=abc.ABCMeta):
39-
4039
@abc.abstractmethod
4140
def get_introspection_info(self, token_info, otp_code=None):
4241
raise NotImplementedError("Not implemented")
@@ -143,7 +142,6 @@ def get_algorithm(
143142

144143

145144
class HttpDriver(AbstractAuthDriver):
146-
147145
def __init__(
148146
self,
149147
iam_endpoint: str,
@@ -160,9 +158,7 @@ def __init__(
160158
self._cache_ttl_seconds = cache_ttl_seconds
161159
self._hs256_jwks_decryption_key = hs256_jwks_decryption_key
162160

163-
self._get_algorithm_cached = functools.lru_cache(
164-
maxsize=cache_maxsize
165-
)(
161+
self._get_algorithm_cached = functools.lru_cache(maxsize=cache_maxsize)(
166162
self._get_algorithm_uncached,
167163
)
168164

gcl_iam/enforcers.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626

2727
class OrderedEnum(Enum):
28-
2928
def __ge__(self, other):
3029
if self.__class__ is other.__class__:
3130
return self.value >= other.value
@@ -55,7 +54,6 @@ def __bool__(self):
5554

5655

5756
class Grant(BasicOrderedGrant):
58-
5957
DENY = 0
6058
# VIEWER = 1
6159
# REGULAR = 10

gcl_iam/engines.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ def permissions(self):
6969

7070

7171
class IamEngine:
72-
73-
def __init__(
74-
self, auth_token, algorithm, driver, enforcer=None, otp_code=None
75-
):
72+
def __init__(self, auth_token, algorithm, driver, enforcer=None, otp_code=None):
7673
super().__init__()
7774
self._token_info = tokens.AuthToken(
7875
auth_token,

gcl_iam/middlewares.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434

3535
class AbstactEndpointComparator(metaclass=abc.ABCMeta):
36-
3736
def _build_full_path(self, path):
3837
return re.compile(path)
3938

@@ -53,7 +52,6 @@ def compare(self, req):
5352

5453

5554
class GenesisCoreAuthMiddleware(contexts_mw.ContextMiddleware):
56-
5755
def __init__(
5856
self,
5957
application,
@@ -90,9 +88,7 @@ def _get_otp_code(self, req):
9088
return None
9189
return int(req.headers["X-OTP"])
9290

93-
def _get_unverified_token_info(
94-
self, auth_token: str
95-
) -> tokens.UnverifiedToken:
91+
def _get_unverified_token_info(self, auth_token: str) -> tokens.UnverifiedToken:
9692
return tokens.UnverifiedToken(auth_token)
9793

9894
def _get_response(self, ctx, req):
@@ -105,9 +101,7 @@ def _get_response(self, ctx, req):
105101
auth_token = self._get_auth_token(req)
106102
token_info = self._get_unverified_token_info(auth_token)
107103

108-
algorithm = self._iam_engine_driver.get_algorithm(
109-
token_info
110-
)
104+
algorithm = self._iam_engine_driver.get_algorithm(token_info)
111105
iam_context = engines.IamEngine(
112106
auth_token=auth_token,
113107
algorithm=algorithm,
@@ -126,7 +120,6 @@ def _get_response(self, ctx, req):
126120

127121

128122
class ErrorsHandlerMiddleware(errors_mw.ErrorsHandlerMiddleware):
129-
130123
forbidden_exc = (exc.CommonForbiddenError,)
131124

132125
def _construct_error_response(self, req, e):

0 commit comments

Comments
 (0)