Skip to content

Commit 1edb12a

Browse files
review
1 parent d54b084 commit 1edb12a

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

services/web/server/src/simcore_service_webserver/fogbugz/_client.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import httpx
1111
from aiohttp import web
12-
from pydantic import BaseModel, Field
12+
from pydantic import AnyUrl, BaseModel, Field, SecretStr
1313

1414
from ..products import products_service
1515
from ..products.models import Product
@@ -20,6 +20,10 @@
2020
_JSON_CONTENT_TYPE = "application/json"
2121
_UNKNOWN_ERROR_MESSAGE = "Unknown error occurred"
2222

23+
_FOGBUGZ_TIMEOUT: float = Field(
24+
default=45.0, description="API request timeout in seconds"
25+
)
26+
2327

2428
class FogbugzCaseCreate(BaseModel):
2529
fogbugz_project_id: str = Field(description="Project ID in Fogbugz")
@@ -30,10 +34,8 @@ class FogbugzCaseCreate(BaseModel):
3034
class FogbugzRestClient:
3135
"""REST client for Fogbugz API"""
3236

33-
def __init__(
34-
self, client: httpx.AsyncClient, api_token: str, base_url: str
35-
) -> None:
36-
self._client = client
37+
def __init__(self, api_token: SecretStr, base_url: AnyUrl) -> None:
38+
self._client = httpx.AsyncClient(timeout=_FOGBUGZ_TIMEOUT)
3739
self._api_token = api_token
3840
self._base_url = base_url
3941

@@ -53,7 +55,7 @@ async def create_case(self, data: FogbugzCaseCreate) -> str:
5355
"""Create a new case in Fogbugz"""
5456
json_payload = {
5557
"cmd": "new",
56-
"token": self._api_token,
58+
"token": self._api_token.get_secret_value(),
5759
"ixProject": data.fogbugz_project_id,
5860
"sTitle": data.title,
5961
"sEvent": data.description,
@@ -73,7 +75,7 @@ async def resolve_case(self, case_id: str) -> None:
7375
"""Resolve a case in Fogbugz"""
7476
json_payload = {
7577
"cmd": "resolve",
76-
"token": self._api_token,
78+
"token": self._api_token.get_secret_value(),
7779
"ixBug": case_id,
7880
}
7981

@@ -89,7 +91,7 @@ async def get_case_status(self, case_id: str) -> str:
8991
"""Get the status of a case in Fogbugz"""
9092
json_payload = {
9193
"cmd": "search",
92-
"token": self._api_token,
94+
"token": self._api_token.get_secret_value(),
9395
"q": case_id,
9496
"cols": "sStatus",
9597
}
@@ -143,7 +145,7 @@ async def reopen_case(self, case_id: str, assigned_fogbugz_person_id: str) -> No
143145

144146
json_payload = {
145147
"cmd": cmd,
146-
"token": self._api_token,
148+
"token": self._api_token.get_secret_value(),
147149
"ixBug": case_id,
148150
"ixPersonAssignedTo": assigned_fogbugz_person_id,
149151
}
@@ -158,9 +160,6 @@ async def reopen_case(self, case_id: str, assigned_fogbugz_person_id: str) -> No
158160

159161

160162
_APP_KEY = f"{__name__}.{FogbugzRestClient.__name__}"
161-
_FOGBUGZ_TIMEOUT: float = Field(
162-
default=45.0, description="API request timeout in seconds"
163-
)
164163

165164

166165
async def setup_fogbugz_rest_client(app: web.Application) -> None:
@@ -193,9 +192,7 @@ async def setup_fogbugz_rest_client(app: web.Application) -> None:
193192
product.name,
194193
)
195194

196-
httpx_client = httpx.AsyncClient(timeout=_FOGBUGZ_TIMEOUT)
197195
client = FogbugzRestClient(
198-
client=httpx_client,
199196
api_token=settings.FOGBUGZ_API_TOKEN,
200197
base_url=settings.FOGBUGZ_URL,
201198
)

services/web/server/src/simcore_service_webserver/fogbugz/settings.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from aiohttp import web
2+
from pydantic import AnyUrl, SecretStr
23
from servicelib.aiohttp.application_keys import APP_SETTINGS_KEY
34
from settings_library.base import BaseCustomSettings
45

56

67
class FogbugzSettings(BaseCustomSettings):
7-
FOGBUGZ_API_TOKEN: str
8-
FOGBUGZ_URL: str
8+
FOGBUGZ_API_TOKEN: SecretStr
9+
FOGBUGZ_URL: AnyUrl
910

1011

1112
def get_plugin_settings(app: web.Application) -> FogbugzSettings:

0 commit comments

Comments
 (0)