Skip to content

Commit 94a0b56

Browse files
authored
Merge pull request #9 from mondaycom/feat/ori/add-logger-payload-option
Add option for payload in the logger
2 parents 7c57e8d + ad8344e commit 94a0b56

File tree

5 files changed

+161
-40
lines changed

5 files changed

+161
-40
lines changed

docs/WriteLogRequestBody.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
Name | Type | Description | Notes
77
------------ | ------------- | ------------- | -------------
8+
**payload** | **Dict[str, object]** | Construct a type with a set of properties K of type T | [optional]
89
**error** | [**WriteLogRequestBodyError**](WriteLogRequestBodyError.md) | | [optional]
910
**message** | **str** | |
1011
**method** | [**LogMethods**](LogMethods.md) | |

monday_code/configuration.py

+152-37
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,123 @@
1313

1414

1515
import copy
16+
import http.client as httplib
1617
import logging
1718
from logging import FileHandler
1819
import multiprocessing
1920
import sys
20-
from typing import Optional
21+
from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict
22+
from typing_extensions import NotRequired, Self
23+
2124
import urllib3
2225

23-
import http.client as httplib
2426

2527
JSON_SCHEMA_VALIDATION_KEYWORDS = {
2628
'multipleOf', 'maximum', 'exclusiveMaximum',
2729
'minimum', 'exclusiveMinimum', 'maxLength',
2830
'minLength', 'pattern', 'maxItems', 'minItems'
2931
}
3032

33+
ServerVariablesT = Dict[str, str]
34+
35+
GenericAuthSetting = TypedDict(
36+
"GenericAuthSetting",
37+
{
38+
"type": str,
39+
"in": str,
40+
"key": str,
41+
"value": str,
42+
},
43+
)
44+
45+
46+
OAuth2AuthSetting = TypedDict(
47+
"OAuth2AuthSetting",
48+
{
49+
"type": Literal["oauth2"],
50+
"in": Literal["header"],
51+
"key": Literal["Authorization"],
52+
"value": str,
53+
},
54+
)
55+
56+
57+
APIKeyAuthSetting = TypedDict(
58+
"APIKeyAuthSetting",
59+
{
60+
"type": Literal["api_key"],
61+
"in": str,
62+
"key": str,
63+
"value": Optional[str],
64+
},
65+
)
66+
67+
68+
BasicAuthSetting = TypedDict(
69+
"BasicAuthSetting",
70+
{
71+
"type": Literal["basic"],
72+
"in": Literal["header"],
73+
"key": Literal["Authorization"],
74+
"value": Optional[str],
75+
},
76+
)
77+
78+
79+
BearerFormatAuthSetting = TypedDict(
80+
"BearerFormatAuthSetting",
81+
{
82+
"type": Literal["bearer"],
83+
"in": Literal["header"],
84+
"format": Literal["JWT"],
85+
"key": Literal["Authorization"],
86+
"value": str,
87+
},
88+
)
89+
90+
91+
BearerAuthSetting = TypedDict(
92+
"BearerAuthSetting",
93+
{
94+
"type": Literal["bearer"],
95+
"in": Literal["header"],
96+
"key": Literal["Authorization"],
97+
"value": str,
98+
},
99+
)
100+
101+
102+
HTTPSignatureAuthSetting = TypedDict(
103+
"HTTPSignatureAuthSetting",
104+
{
105+
"type": Literal["http-signature"],
106+
"in": Literal["header"],
107+
"key": Literal["Authorization"],
108+
"value": None,
109+
},
110+
)
111+
112+
113+
AuthSettings = TypedDict(
114+
"AuthSettings",
115+
{
116+
},
117+
total=False,
118+
)
119+
120+
121+
class HostSettingVariable(TypedDict):
122+
description: str
123+
default_value: str
124+
enum_values: List[str]
125+
126+
127+
class HostSetting(TypedDict):
128+
url: str
129+
description: str
130+
variables: NotRequired[Dict[str, HostSettingVariable]]
131+
132+
31133
class Configuration:
32134
"""This class contains various settings of the API client.
33135
@@ -61,20 +163,26 @@ class Configuration:
61163
62164
"""
63165

64-
_default = None
65-
66-
def __init__(self, host=None,
67-
api_key=None, api_key_prefix=None,
68-
username=None, password=None,
69-
access_token=None,
70-
server_index=None, server_variables=None,
71-
server_operation_index=None, server_operation_variables=None,
72-
ignore_operation_servers=False,
73-
ssl_ca_cert=None,
74-
retries=None,
75-
*,
76-
debug: Optional[bool] = None
77-
) -> None:
166+
_default: ClassVar[Optional[Self]] = None
167+
168+
def __init__(
169+
self,
170+
host: Optional[str]=None,
171+
api_key: Optional[Dict[str, str]]=None,
172+
api_key_prefix: Optional[Dict[str, str]]=None,
173+
username: Optional[str]=None,
174+
password: Optional[str]=None,
175+
access_token: Optional[str]=None,
176+
server_index: Optional[int]=None,
177+
server_variables: Optional[ServerVariablesT]=None,
178+
server_operation_index: Optional[Dict[int, int]]=None,
179+
server_operation_variables: Optional[Dict[int, ServerVariablesT]]=None,
180+
ignore_operation_servers: bool=False,
181+
ssl_ca_cert: Optional[str]=None,
182+
retries: Optional[int] = None,
183+
*,
184+
debug: Optional[bool] = None,
185+
) -> None:
78186
"""Constructor
79187
"""
80188
self._base_path = "http://localhost:59999" if host is None else host
@@ -198,7 +306,7 @@ def __init__(self, host=None,
198306
"""date format
199307
"""
200308

201-
def __deepcopy__(self, memo):
309+
def __deepcopy__(self, memo: Dict[int, Any]) -> Self:
202310
cls = self.__class__
203311
result = cls.__new__(cls)
204312
memo[id(self)] = result
@@ -212,11 +320,11 @@ def __deepcopy__(self, memo):
212320
result.debug = self.debug
213321
return result
214322

215-
def __setattr__(self, name, value):
323+
def __setattr__(self, name: str, value: Any) -> None:
216324
object.__setattr__(self, name, value)
217325

218326
@classmethod
219-
def set_default(cls, default):
327+
def set_default(cls, default: Optional[Self]) -> None:
220328
"""Set default instance of configuration.
221329
222330
It stores default configuration, which can be
@@ -227,7 +335,7 @@ def set_default(cls, default):
227335
cls._default = default
228336

229337
@classmethod
230-
def get_default_copy(cls):
338+
def get_default_copy(cls) -> Self:
231339
"""Deprecated. Please use `get_default` instead.
232340
233341
Deprecated. Please use `get_default` instead.
@@ -237,7 +345,7 @@ def get_default_copy(cls):
237345
return cls.get_default()
238346

239347
@classmethod
240-
def get_default(cls):
348+
def get_default(cls) -> Self:
241349
"""Return the default configuration.
242350
243351
This method returns newly created, based on default constructor,
@@ -247,11 +355,11 @@ def get_default(cls):
247355
:return: The configuration object.
248356
"""
249357
if cls._default is None:
250-
cls._default = Configuration()
358+
cls._default = cls()
251359
return cls._default
252360

253361
@property
254-
def logger_file(self):
362+
def logger_file(self) -> Optional[str]:
255363
"""The logger file.
256364
257365
If the logger_file is None, then add stream handler and remove file
@@ -263,7 +371,7 @@ def logger_file(self):
263371
return self.__logger_file
264372

265373
@logger_file.setter
266-
def logger_file(self, value):
374+
def logger_file(self, value: Optional[str]) -> None:
267375
"""The logger file.
268376
269377
If the logger_file is None, then add stream handler and remove file
@@ -282,7 +390,7 @@ def logger_file(self, value):
282390
logger.addHandler(self.logger_file_handler)
283391

284392
@property
285-
def debug(self):
393+
def debug(self) -> bool:
286394
"""Debug status
287395
288396
:param value: The debug status, True or False.
@@ -291,7 +399,7 @@ def debug(self):
291399
return self.__debug
292400

293401
@debug.setter
294-
def debug(self, value):
402+
def debug(self, value: bool) -> None:
295403
"""Debug status
296404
297405
:param value: The debug status, True or False.
@@ -313,7 +421,7 @@ def debug(self, value):
313421
httplib.HTTPConnection.debuglevel = 0
314422

315423
@property
316-
def logger_format(self):
424+
def logger_format(self) -> str:
317425
"""The logger format.
318426
319427
The logger_formatter will be updated when sets logger_format.
@@ -324,7 +432,7 @@ def logger_format(self):
324432
return self.__logger_format
325433

326434
@logger_format.setter
327-
def logger_format(self, value):
435+
def logger_format(self, value: str) -> None:
328436
"""The logger format.
329437
330438
The logger_formatter will be updated when sets logger_format.
@@ -335,7 +443,7 @@ def logger_format(self, value):
335443
self.__logger_format = value
336444
self.logger_formatter = logging.Formatter(self.__logger_format)
337445

338-
def get_api_key_with_prefix(self, identifier, alias=None):
446+
def get_api_key_with_prefix(self, identifier: str, alias: Optional[str]=None) -> Optional[str]:
339447
"""Gets API key (with prefix if set).
340448
341449
:param identifier: The identifier of apiKey.
@@ -352,7 +460,9 @@ def get_api_key_with_prefix(self, identifier, alias=None):
352460
else:
353461
return key
354462

355-
def get_basic_auth_token(self):
463+
return None
464+
465+
def get_basic_auth_token(self) -> Optional[str]:
356466
"""Gets HTTP basic authentication header (string).
357467
358468
:return: The token for basic HTTP authentication.
@@ -367,15 +477,15 @@ def get_basic_auth_token(self):
367477
basic_auth=username + ':' + password
368478
).get('authorization')
369479

370-
def auth_settings(self):
480+
def auth_settings(self)-> AuthSettings:
371481
"""Gets Auth Settings dict for api client.
372482
373483
:return: The Auth Settings information dict.
374484
"""
375-
auth = {}
485+
auth: AuthSettings = {}
376486
return auth
377487

378-
def to_debug_report(self):
488+
def to_debug_report(self) -> str:
379489
"""Gets the essential information for debugging.
380490
381491
:return: The report for debugging.
@@ -387,7 +497,7 @@ def to_debug_report(self):
387497
"SDK Package Version: 0.0.1".\
388498
format(env=sys.platform, pyversion=sys.version)
389499

390-
def get_host_settings(self):
500+
def get_host_settings(self) -> List[HostSetting]:
391501
"""Gets an array of host settings
392502
393503
:return: An array of host settings
@@ -399,7 +509,12 @@ def get_host_settings(self):
399509
}
400510
]
401511

402-
def get_host_from_settings(self, index, variables=None, servers=None):
512+
def get_host_from_settings(
513+
self,
514+
index: Optional[int],
515+
variables: Optional[ServerVariablesT]=None,
516+
servers: Optional[List[HostSetting]]=None,
517+
) -> str:
403518
"""Gets host URL based on the index and variables
404519
:param index: array index of the host settings
405520
:param variables: hash of variable and the corresponding value
@@ -439,12 +554,12 @@ def get_host_from_settings(self, index, variables=None, servers=None):
439554
return url
440555

441556
@property
442-
def host(self):
557+
def host(self) -> str:
443558
"""Return generated host."""
444559
return self.get_host_from_settings(self.server_index, variables=self.server_variables)
445560

446561
@host.setter
447-
def host(self, value):
562+
def host(self, value: str) -> None:
448563
"""Fix base path."""
449564
self._base_path = value
450565
self.server_index = None

monday_code/models/write_log_request_body.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import re # noqa: F401
1818
import json
1919

20-
from pydantic import BaseModel, ConfigDict, StrictStr
20+
from pydantic import BaseModel, ConfigDict, Field, StrictStr
2121
from typing import Any, ClassVar, Dict, List, Optional
2222
from monday_code.models.log_methods import LogMethods
2323
from monday_code.models.write_log_request_body_error import WriteLogRequestBodyError
@@ -28,10 +28,11 @@ class WriteLogRequestBody(BaseModel):
2828
"""
2929
WriteLogRequestBody
3030
""" # noqa: E501
31+
payload: Optional[Dict[str, Any]] = Field(default=None, description="Construct a type with a set of properties K of type T")
3132
error: Optional[WriteLogRequestBodyError] = None
3233
message: StrictStr
3334
method: LogMethods
34-
__properties: ClassVar[List[str]] = ["error", "message", "method"]
35+
__properties: ClassVar[List[str]] = ["payload", "error", "message", "method"]
3536

3637
model_config = ConfigDict(
3738
populate_by_name=True,
@@ -87,6 +88,7 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
8788
return cls.model_validate(obj)
8889

8990
_obj = cls.model_validate({
91+
"payload": obj.get("payload"),
9092
"error": WriteLogRequestBodyError.from_dict(obj["error"]) if obj.get("error") is not None else None,
9193
"message": obj.get("message"),
9294
"method": obj.get("method")

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# prerequisite: setuptools
2222
# http://pypi.python.org/pypi/setuptools
2323
NAME = "monday-code"
24-
VERSION = "0.2.1"
24+
VERSION = "0.2.2"
2525
PYTHON_REQUIRES = ">= 3.8"
2626
REQUIRES = [
2727
"urllib3 >= 1.25.3, < 3.0.0",

0 commit comments

Comments
 (0)