99
1010import httpx
1111from aiohttp import web
12- from pydantic import BaseModel , Field
12+ from pydantic import AnyUrl , BaseModel , Field , SecretStr
1313
1414from ..products import products_service
1515from ..products .models import Product
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
2428class FogbugzCaseCreate (BaseModel ):
2529 fogbugz_project_id : str = Field (description = "Project ID in Fogbugz" )
@@ -30,10 +34,8 @@ class FogbugzCaseCreate(BaseModel):
3034class 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
166165async 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 )
0 commit comments