Skip to content

Commit f77c144

Browse files
committed
feat: Update ConfluenceParameters model and enhance validation methods for comma separated lists
1 parent fe1c3b6 commit f77c144

File tree

5 files changed

+126
-64
lines changed

5 files changed

+126
-64
lines changed

Diff for: admin-api-lib/pyproject.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ per-file-ignores = """
2929
./src/admin_api_lib/impl/admin_api.py: B008,
3030
./src/admin_api_lib/dependency_container.py: CCE002,CCE001,
3131
./src/admin_api_lib/apis/admin_api_base.py: WOT001,
32-
./tests/*: S101,
32+
./tests/*: S101,S106,D100,D103,PT011
33+
./src/admin_api_lib/impl/settings/confluence_settings.py: C901,N805,
34+
./src/admin_api_lib/impl/utils/comma_separated_bool_list.py: R505,
35+
./src/admin_api_lib/impl/utils/comma_separated_str_list.py: R505,
3336
"""
3437

3538
[tool.black]

Diff for: admin-api-lib/src/admin_api_lib/extractor_api_client/openapi_client/models/confluence_parameters.py

+47-19
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,40 @@
2525
from typing import Optional, Set
2626
from typing_extensions import Self
2727

28+
2829
class ConfluenceParameters(BaseModel):
2930
""" """ # noqa: E501
3031

3132
url: StrictStr = Field(description="url of the confluence space.")
3233
token: StrictStr = Field(description="api key to access confluence.")
3334
space_key: StrictStr = Field(description="the space key of the confluence pages.")
34-
include_attachments: Optional[StrictBool] = Field(default=False, description="whether to include file attachments (e.g., images, documents) in the parsed content. Default is `false`.")
35-
keep_markdown_format: Optional[StrictBool] = Field(default=True, description="whether to preserve markdown formatting in the output. Default is `true`.")
36-
keep_newlines: Optional[StrictBool] = Field(default=True, description="whether to retain newline characters in the output for better readability. Default is `true`.")
37-
document_name: StrictStr = Field(description="The name that will be used to store the confluence db in the key value db and the vectordatabase (metadata.document).")
38-
confluence_kwargs: Optional[List[KeyValuePair]] = Field(default=None, description="Additional kwargs like verify_ssl")
39-
__properties: ClassVar[List[str]] = ["url", "token", "space_key", "include_attachments", "keep_markdown_format", "keep_newlines", "document_name", "confluence_kwargs"]
35+
include_attachments: Optional[StrictBool] = Field(
36+
default=False,
37+
description="whether to include file attachments (e.g., images, documents) in the parsed content. Default is `false`.",
38+
)
39+
keep_markdown_format: Optional[StrictBool] = Field(
40+
default=True, description="whether to preserve markdown formatting in the output. Default is `true`."
41+
)
42+
keep_newlines: Optional[StrictBool] = Field(
43+
default=True,
44+
description="whether to retain newline characters in the output for better readability. Default is `true`.",
45+
)
46+
document_name: StrictStr = Field(
47+
description="The name that will be used to store the confluence db in the key value db and the vectordatabase (metadata.document)."
48+
)
49+
confluence_kwargs: Optional[List[KeyValuePair]] = Field(
50+
default=None, description="Additional kwargs like verify_ssl"
51+
)
52+
__properties: ClassVar[List[str]] = [
53+
"url",
54+
"token",
55+
"space_key",
56+
"include_attachments",
57+
"keep_markdown_format",
58+
"keep_newlines",
59+
"document_name",
60+
"confluence_kwargs",
61+
]
4062

4163
model_config = ConfigDict(
4264
populate_by_name=True,
@@ -80,7 +102,7 @@ def to_dict(self) -> Dict[str, Any]:
80102
for _item_confluence_kwargs in self.confluence_kwargs:
81103
if _item_confluence_kwargs:
82104
_items.append(_item_confluence_kwargs.to_dict())
83-
_dict['confluence_kwargs'] = _items
105+
_dict["confluence_kwargs"] = _items
84106
return _dict
85107

86108
@classmethod
@@ -92,16 +114,22 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
92114
if not isinstance(obj, dict):
93115
return cls.model_validate(obj)
94116

95-
_obj = cls.model_validate({
96-
"url": obj.get("url"),
97-
"token": obj.get("token"),
98-
"space_key": obj.get("space_key"),
99-
"include_attachments": obj.get("include_attachments") if obj.get("include_attachments") is not None else False,
100-
"keep_markdown_format": obj.get("keep_markdown_format") if obj.get("keep_markdown_format") is not None else True,
101-
"keep_newlines": obj.get("keep_newlines") if obj.get("keep_newlines") is not None else True,
102-
"document_name": obj.get("document_name"),
103-
"confluence_kwargs": [KeyValuePair.from_dict(_item) for _item in obj["confluence_kwargs"]] if obj.get("confluence_kwargs") is not None else None
104-
})
117+
_obj = cls.model_validate(
118+
{
119+
"url": obj.get("url"),
120+
"token": obj.get("token"),
121+
"space_key": obj.get("space_key"),
122+
"include_attachments": obj.get("include_attachments")
123+
if obj.get("include_attachments") is not None
124+
else False,
125+
"keep_markdown_format": obj.get("keep_markdown_format")
126+
if obj.get("keep_markdown_format") is not None
127+
else True,
128+
"keep_newlines": obj.get("keep_newlines") if obj.get("keep_newlines") is not None else True,
129+
"document_name": obj.get("document_name"),
130+
"confluence_kwargs": [KeyValuePair.from_dict(_item) for _item in obj["confluence_kwargs"]]
131+
if obj.get("confluence_kwargs") is not None
132+
else None,
133+
}
134+
)
105135
return _obj
106-
107-

Diff for: admin-api-lib/src/admin_api_lib/impl/settings/confluence_settings.py

+38-31
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,29 @@ class ConfluenceSettings(BaseSettings):
1414
"""
1515
Contains configuration settings for the Confluence integration.
1616
17-
Attributes:
18-
url: An optional list of Confluence URLs.
19-
token: An optional list of authentication tokens.
20-
space_key: An optional list of Confluence space keys.
21-
document_name: An optional list of document names.
22-
verify_ssl: An optional list of booleans indicating whether SSL verification is enabled.
23-
include_attachments: Indicates whether to include attachments in the integration.
24-
keep_markdown_format: Determines if markdown formatting is maintained.
25-
keep_newlines: Indicates whether newlines are preserved.
17+
Parameters
18+
----------
19+
url : CommaSeparatedStrList, optional
20+
List of Confluence URLs.
21+
token : CommaSeparatedStrList, optional
22+
List of authentication tokens.
23+
space_key : CommaSeparatedStrList, optional
24+
List of Confluence space keys.
25+
document_name : CommaSeparatedStrList, optional
26+
List of document names.
27+
verify_ssl : CommaSeparatedBoolList, optional
28+
List of booleans indicating whether SSL verification is enabled.
29+
include_attachments : CommaSeparatedBoolList, optional
30+
Indicates whether to include attachments in the integration.
31+
keep_markdown_format : CommaSeparatedBoolList, optional
32+
Determines if markdown formatting is maintained.
33+
keep_newlines : CommaSeparatedBoolList, optional
34+
Indicates whether newlines are preserved.
2635
"""
2736

2837
class Config:
38+
"""Config class for reading Fields from env."""
39+
2940
env_prefix = "CONFLUENCE_"
3041
case_sensitive = False
3142

@@ -41,22 +52,24 @@ class Config:
4152
@model_validator(mode="after")
4253
def check_lists_length_consistency(cls, values):
4354
"""
44-
Validate that all list-valued settings have the same length. If not, the list is adjusted accordingly.
55+
Validate that all list-valued settings have the same length.
56+
57+
If not, the list is adjusted accordingly.
4558
4659
Parameters
4760
----------
4861
values : dict
49-
Dictionary of configuration settings. Expected to contain keys with list values.
62+
Dictionary of configuration settings.
5063
5164
Returns
5265
-------
5366
dict
54-
The original values dict if all checked lists have the same length.
67+
The validated values dictionary with consistent list lengths.
5568
5669
Raises
5770
------
5871
ValueError
59-
If any list has a different length compared to the others.
72+
If any non-optional list has a different length compared to others.
6073
"""
6174
# Define the keys to check
6275
keys = [
@@ -93,71 +106,65 @@ def check_lists_length_consistency(cls, values):
93106
try:
94107
document_name = getattr(values, "document_name", None)
95108
if not document_name or len(document_name) == 0:
96-
setattr(values, "document_name", CommaSeparatedStrList([""] * n))
109+
values.document_name = CommaSeparatedStrList([""] * n)
97110
elif len(document_name) != n:
98111
raise ValueError("document_name list length mismatch")
99112
except ValueError as e:
100113
logger.error(f"Error setting document_name: {e}")
101114
logger.warning("Setting document_name to default values")
102115
document_name = getattr(values, "document_name", [])
103-
setattr(values, "document_name", CommaSeparatedStrList(document_name + [""] * (n - len(document_name))))
116+
values.document_name = CommaSeparatedStrList(document_name + [""] * (n - len(document_name)))
104117

105118
try:
106119
verify_ssl = getattr(values, "verify_ssl", None)
107120
if not verify_ssl or len(verify_ssl) == 0:
108-
setattr(values, "verify_ssl", CommaSeparatedBoolList([True] * n))
121+
values.verify_ssl = CommaSeparatedBoolList([True] * n)
109122
elif len(verify_ssl) != n:
110123
raise ValueError("verify_ssl list length mismatch")
111124
except ValueError as e:
112125
logger.error(f"Error setting verify_ssl: {e}")
113126
logger.warning("Setting verify_ssl to default values")
114127
verify_ssl = getattr(values, "verify_ssl", [])
115-
setattr(values, "verify_ssl", CommaSeparatedBoolList(verify_ssl + [True] * (n - len(verify_ssl))))
128+
values.verify_ssl = CommaSeparatedBoolList(verify_ssl + [True] * (n - len(verify_ssl)))
116129

117130
try:
118131
include_attachments = getattr(values, "include_attachments", None)
119132
if not include_attachments or len(include_attachments) == 0:
120-
setattr(values, "include_attachments", CommaSeparatedBoolList([False] * n))
133+
values.include_attachments = CommaSeparatedBoolList([False] * n)
121134
elif len(include_attachments) != n:
122135
raise ValueError("include_attachments list length mismatch")
123136
except ValueError as e:
124137
logger.error(f"Error setting include_attachments: {e}")
125138
logger.warning("Setting include_attachments to default values")
126139
include_attachments = getattr(values, "include_attachments", [])
127-
setattr(
128-
values,
129-
"include_attachments",
130-
CommaSeparatedBoolList(include_attachments + [False] * (n - len(include_attachments))),
140+
values.include_attachments = CommaSeparatedBoolList(
141+
include_attachments + [False] * (n - len(include_attachments))
131142
)
132143

133144
try:
134145
keep_markdown_format = getattr(values, "keep_markdown_format", None)
135146
if not keep_markdown_format or len(keep_markdown_format) == 0:
136-
setattr(values, "keep_markdown_format", CommaSeparatedBoolList([True] * n))
147+
values.keep_markdown_format = CommaSeparatedBoolList([True] * n)
137148
elif len(keep_markdown_format) != n:
138149
raise ValueError("keep_markdown_format list length mismatch")
139150
except ValueError as e:
140151
logger.error(f"Error setting keep_markdown_format: {e}")
141152
logger.warning("Setting keep_markdown_format to default values")
142153
keep_markdown_format = getattr(values, "keep_markdown_format", [])
143-
setattr(
144-
values,
145-
"keep_markdown_format",
146-
CommaSeparatedBoolList(keep_markdown_format + [True] * (n - len(keep_markdown_format))),
154+
values.keep_markdown_format = CommaSeparatedBoolList(
155+
keep_markdown_format + [True] * (n - len(keep_markdown_format))
147156
)
148157

149158
try:
150159
keep_newlines = getattr(values, "keep_newlines", None)
151160
if not keep_newlines or len(keep_newlines) == 0:
152-
setattr(values, "keep_newlines", CommaSeparatedBoolList([True] * n))
161+
values.keep_newlines = CommaSeparatedBoolList([True] * n)
153162
elif len(keep_newlines) != n:
154163
raise ValueError("keep_newlines list length mismatch")
155164
except ValueError as e:
156165
logger.error(f"Error setting keep_newlines: {e}")
157166
logger.warning("Setting keep_newlines to default values")
158167
keep_newlines = getattr(values, "keep_newlines", [])
159-
setattr(
160-
values, "keep_newlines", CommaSeparatedBoolList(keep_newlines + [True] * (n - len(keep_newlines)))
161-
)
168+
values.keep_newlines = CommaSeparatedBoolList(keep_newlines + [True] * (n - len(keep_newlines)))
162169

163170
return values

Diff for: admin-api-lib/src/admin_api_lib/impl/utils/comma_separated_bool_list.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ class CommaSeparatedBoolList(list):
1515
- For list inputs, each element is converted to a boolean.
1616
"""
1717

18-
@classmethod
19-
def __get_validators__(cls):
20-
yield cls.validate
21-
2218
@classmethod
2319
def validate(cls, v: Any, info) -> list[bool]:
2420
"""
@@ -52,3 +48,19 @@ def str_to_bool(s: str) -> bool:
5248
elif isinstance(v, list):
5349
return [bool(item) for item in v]
5450
raise ValueError("Not a valid comma separated boolean list")
51+
52+
@classmethod
53+
def __get_validators__(cls):
54+
"""
55+
Get validator functions for Pydantic to use with this data type.
56+
57+
This method is called by Pydantic during model initialization to collect
58+
validator functions for fields using this custom data type.
59+
60+
Returns
61+
-------
62+
generator
63+
A generator yielding validator functions, specifically `cls.validate`,
64+
which will be applied to validate and convert input values.
65+
"""
66+
yield cls.validate

Diff for: admin-api-lib/src/admin_api_lib/impl/utils/comma_separated_str_list.py

+21-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""
2-
Comma Separated String List Utility Module
3-
============================================
2+
Comma Separated String List Utility Module.
43
54
This module provides a custom list type to validate and convert inputs into
65
a list of strings. It splits comma separated strings and converts list elements
@@ -22,15 +21,12 @@ class CommaSeparatedStrList(list):
2221
- If input is a string: splits by commas and strips whitespace.
2322
- If input is a list: converts all elements to strings.
2423
25-
Raises:
26-
-------
27-
ValueError: For invalid input type.
24+
Raises
25+
------
26+
ValueError
27+
For invalid input type.
2828
"""
2929

30-
@classmethod
31-
def __get_validators__(cls):
32-
yield cls.validate
33-
3430
@classmethod
3531
def validate(cls, v: Any, info) -> list[str]:
3632
"""
@@ -60,3 +56,19 @@ def validate(cls, v: Any, info) -> list[str]:
6056
elif isinstance(v, list):
6157
return [str(item) for item in v]
6258
raise ValueError("Not a valid comma separated string list")
59+
60+
@classmethod
61+
def __get_validators__(cls):
62+
"""
63+
Get validator functions for Pydantic to use with this data type.
64+
65+
This method is called by Pydantic during model initialization to collect
66+
validator functions for fields using this custom data type.
67+
68+
Returns
69+
-------
70+
generator
71+
A generator yielding validator functions, specifically `cls.validate`,
72+
which will be applied to validate and convert input values.
73+
"""
74+
yield cls.validate

0 commit comments

Comments
 (0)