|
15 | 15 | # limitations under the License. |
16 | 16 | """ETOS v1alpha.""" |
17 | 17 |
|
18 | | -import os |
19 | 18 | import logging |
20 | | -import time |
| 19 | +import os |
21 | 20 | import shutil |
22 | | -from pathlib import Path |
| 21 | +import time |
23 | 22 | from json import JSONDecodeError |
| 23 | +from pathlib import Path |
24 | 24 | from typing import Optional, Union |
25 | 25 |
|
26 | | -from requests.exceptions import HTTPError |
27 | | -from etos_lib.lib.http import Http |
28 | 26 | from etos_lib import ETOS as ETOSLibrary |
| 27 | +from etos_lib.lib.http import Http |
| 28 | +from requests.exceptions import HTTPError |
29 | 29 | from urllib3.util import Retry |
30 | 30 |
|
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 |
38 | 31 | from etos_client.etos.v0.event_repository import graphql |
39 | 32 | from etos_client.etos.v0.events.collector import Collector |
40 | 33 | 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 |
43 | 35 | 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 |
45 | 44 |
|
46 | 45 | # Max total time for a ping request including delays with backoff factor 0.5 will be: |
47 | 46 | # 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]) |
80 | 79 | @property |
81 | 80 | def apikey(self) -> str: |
82 | 81 | """Generate and return an API key.""" |
| 82 | + http = Http(retry=HTTP_RETRY_PARAMETERS, timeout=10) |
83 | 83 | if self.__apikey is None: |
84 | | - http = Http(retry=HTTP_RETRY_PARAMETERS, timeout=10) |
85 | 84 | url = f"{self.cluster}/keys/v1alpha/generate" |
86 | 85 | response = http.post( |
87 | 86 | url, |
@@ -115,9 +114,12 @@ def __start(self) -> tuple[Optional[ResponseSchema], Optional[str]]: |
115 | 114 |
|
116 | 115 | response_json = {} |
117 | 116 | 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()) |
121 | 123 | try: |
122 | 124 | response.raise_for_status() |
123 | 125 | response_json = response.json() |
|
0 commit comments