Skip to content

Commit fc7c3c7

Browse files
authored
Don't use key-service if it does not exist (#453)
* Don't use key-service if it does not exist * Disable API key if not using SSEv2
1 parent 718930c commit fc7c3c7

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

cli/pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ Documentation = "https://etos.readthedocs.io/"
3333
Homepage = "https://github.com/eiffel-community/etos"
3434
Repository = "https://github.com/eiffel-community/etos"
3535

36+
[tool.black]
37+
line-length = 100
38+
3639
[tool.build]
3740
# Use this option if your package is pure-python
3841
universal = true
@@ -57,4 +60,4 @@ testpaths = ["tests"]
5760
find = { where = ["src"], exclude = ["tests"] }
5861

5962
[tool.setuptools_scm]
60-
root = ".."
63+
root = ".."

cli/src/etos_client/etos/v1alpha/etos.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,32 @@
1515
# limitations under the License.
1616
"""ETOS v1alpha."""
1717

18-
import os
1918
import logging
20-
import time
19+
import os
2120
import shutil
22-
from pathlib import Path
21+
import time
2322
from json import JSONDecodeError
23+
from pathlib import Path
2424
from typing import Optional, Union
2525

26-
from requests.exceptions import HTTPError
27-
from etos_lib.lib.http import Http
2826
from etos_lib import ETOS as ETOSLibrary
27+
from etos_lib.lib.http import Http
28+
from requests.exceptions import HTTPError
2929
from urllib3.util import Retry
3030

31-
from etos_client.types.result import Result, Verdict, Conclusion
32-
from etos_client.shared.downloader import Downloader
33-
from etos_client.shared.utilities import directories
34-
from etos_client.sse.v2alpha.client import SSEClient as SSEV2AlphaClient, TokenExpired
35-
from etos_client.sse.v1.client import SSEClient as SSEV1Client
36-
37-
from etos_client.etos.v0.test_run import TestRun as V0TestRun
3831
from etos_client.etos.v0.event_repository import graphql
3932
from etos_client.etos.v0.events.collector import Collector
4033
from etos_client.etos.v0.test_results import TestResults
41-
from etos_client.etos.v1alpha.test_run import TestRun as V1AlphaTestRun
42-
from etos_client.etos.v1alpha.schema.response import ResponseSchema
34+
from etos_client.etos.v0.test_run import TestRun as V0TestRun
4335
from etos_client.etos.v1alpha.schema.request import RequestSchema
44-
36+
from etos_client.etos.v1alpha.schema.response import ResponseSchema
37+
from etos_client.etos.v1alpha.test_run import TestRun as V1AlphaTestRun
38+
from etos_client.shared.downloader import Downloader
39+
from etos_client.shared.utilities import directories
40+
from etos_client.sse.v1.client import SSEClient as SSEV1Client
41+
from etos_client.sse.v2alpha.client import SSEClient as SSEV2AlphaClient
42+
from etos_client.sse.v2alpha.client import TokenExpired
43+
from etos_client.types.result import Conclusion, Result, Verdict
4544

4645
# Max total time for a ping request including delays with backoff factor 0.5 will be:
4746
# 0.5 + 1.5 + 3.5 + 7.5 + 15.5 = 28.5 (seconds)
@@ -80,8 +79,8 @@ def __init__(self, args: dict, sse_client: Union[SSEV1Client, SSEV2AlphaClient])
8079
@property
8180
def apikey(self) -> str:
8281
"""Generate and return an API key."""
82+
http = Http(retry=HTTP_RETRY_PARAMETERS, timeout=10)
8383
if self.__apikey is None:
84-
http = Http(retry=HTTP_RETRY_PARAMETERS, timeout=10)
8584
url = f"{self.cluster}/keys/v1alpha/generate"
8685
response = http.post(
8786
url,
@@ -115,9 +114,12 @@ def __start(self) -> tuple[Optional[ResponseSchema], Optional[str]]:
115114

116115
response_json = {}
117116
http = Http(retry=HTTP_RETRY_PARAMETERS, timeout=10)
118-
response = http.post(
119-
url, json=request.model_dump(), headers={"Authorization": f"Bearer {self.apikey}"}
120-
)
117+
if isinstance(self.sse_client, SSEV2AlphaClient):
118+
response = http.post(
119+
url, json=request.model_dump(), headers={"Authorization": f"Bearer {self.apikey}"}
120+
)
121+
else:
122+
response = http.post(url, json=request.model_dump())
121123
try:
122124
response.raise_for_status()
123125
response_json = response.json()

0 commit comments

Comments
 (0)