Skip to content

Commit 5ef5fc8

Browse files
authored
MPT-17825: resolve WPS410, WPS412, WPS203, WPS322, WPS347 violations (#164)
🤖 **Codex-generated PR** — Please review carefully. ## Summary - Updated Flake8 config to add global ignores for WPS410 and WPS412. - Removed unused WPS codes from per-file ignores (WPS203, WPS322, WPS347) and removed redundant WPS410/WPS412 there. - Applied scoped lint-error fixes in table formatters, alias resolution, stats string formatting, and audit plugin API URL calls. ## Validation - make check-all <!-- This is an auto-generated comment: release notes by coderabbit.ai --> Closes [MPT-17825](https://softwareone.atlassian.net/browse/MPT-17825) ## Release Notes - Updated Flake8 linter configuration to move unspecified WPS codes (WPS410, WPS412) into global ignores and remove redundant file-specific ignore entries - Refactored token masking logic in `wrap_token` to improve code structure using string concatenation with `"".join()` pattern - Updated error message construction in `get_command` to use intermediate variable for better readability - Improved string output building in `ErrorMessagesCollector.__str__` by using a list-based approach instead of incremental concatenation - Enhanced `get_audit_records_by_object` to add explicit exit signal when no records are found - Simplified HTTP query string construction across audit plugin endpoints using f-string formatting - All 366 tests passed; code coverage maintained at 98%; all linting and formatting checks passed <!-- end of auto-generated comment: release notes by coderabbit.ai --> [MPT-17825]: https://softwareone.atlassian.net/browse/MPT-17825?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
2 parents c5b9a6c + f20b71e commit 5ef5fc8

File tree

5 files changed

+24
-21
lines changed

5 files changed

+24
-21
lines changed

cli/core/accounts/table_formatters.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ def wrap_token(account: Account, *, to_wrap_secret: bool) -> str:
2929

3030
if to_wrap_secret:
3131
visible_token_prefix = token[:TOKEN_MASK_PREFIX_LENGTH]
32+
token_tail = f"*****{visible_token_prefix}"
3233
if is_new_token:
33-
token = f"{token[:NEW_TOKEN_MASK_PREFIX_LENGTH]}*****{visible_token_prefix}"
34+
token = "".join((token[:NEW_TOKEN_MASK_PREFIX_LENGTH], token_tail))
3435
else:
35-
token = f"{token[:TOKEN_MASK_PREFIX_LENGTH]}*****{visible_token_prefix}"
36+
token = "".join((token[:TOKEN_MASK_PREFIX_LENGTH], token_tail))
3637

3738
return token

cli/core/alias_group.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def get_command(self, ctx: click.Context, cmd_name: str) -> click.Command | None
3131
if len(matches) == 1:
3232
return click.Group.get_command(self, ctx, matches[0])
3333

34-
ctx.fail(f"Too many matches: {', '.join(sorted(matches))}")
34+
commands = ", ".join(sorted(matches))
35+
ctx.fail(f"Too many matches: {commands}")
3536
return None
3637

3738
def resolve_command(

cli/core/stats.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,21 @@ def is_empty(self) -> bool:
6868
return self._is_empty
6969

7070
def __str__(self) -> str:
71-
msg = ""
71+
lines: list[str] = []
7272
for section_name, section in self._sections.items():
73-
msg = f"{msg}{section_name}:"
7473
section_messages = section.get("", [])
7574
if section_messages:
76-
msg = f"{msg} {', '.join(section_messages)}\n"
75+
lines.append(f"{section_name}: {', '.join(section_messages)}")
7776
else:
78-
msg += "\n"
77+
lines.append(f"{section_name}:")
7978

8079
for item_name, item_messages in section.items():
8180
if not item_name:
8281
continue
8382

84-
msg = f"{msg}\t\t{item_name}: {', '.join(item_messages)}"
83+
lines.append(f"\t\t{item_name}: {', '.join(item_messages)}")
8584

86-
return msg
85+
return "\n".join(lines)
8786

8887

8988
class StatsCollector(ABC):

cli/plugins/audit_plugin/api.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
def get_audit_trail(client: Any, record_id: str) -> dict[str, Any]:
88
"""Retrieve audit trail for a specific record."""
9+
endpoint = f"/audit/records/{record_id}"
10+
query_string = "render()&select=object,actor,details,documents,request.api.geolocation"
11+
912
try:
10-
endpoint = f"/audit/records/{record_id}"
11-
query_string = "render()&select=object,actor,details,documents,request.api.geolocation"
12-
response = client.get(endpoint + "?" + query_string)
13+
response = client.get(f"{endpoint}?{query_string}")
1314
return response.json()
1415
except Exception as error:
1516
console.print(
@@ -22,13 +23,14 @@ def get_audit_records_by_object(
2223
client: Any, object_id: str, limit: int = 10
2324
) -> list[dict[str, Any]]:
2425
"""Retrieve all audit records for a specific object."""
26+
endpoint = "/audit/records"
27+
query_string = (
28+
"render()&select=object,actor,details,documents,request.api.geolocation"
29+
f"&eq(object.id,'{object_id}')&order=-timestamp&limit={limit}"
30+
)
31+
2532
try:
26-
endpoint = "/audit/records"
27-
query_string = (
28-
"render()&select=object,actor,details,documents,request.api.geolocation"
29-
f"&eq(object.id,'{object_id}')&order=-timestamp&limit={limit}"
30-
)
31-
response = client.get(endpoint + "?" + query_string)
33+
response = client.get(f"{endpoint}?{query_string}")
3234
records = response.json().get("data", [])
3335
if not records:
3436
console.print(f"[red]No audit records found for object {object_id}[/red]")

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ omit = [
103103
allowed-domain-names = ["result"]
104104
aaa_act_block_style = "large"
105105
doctests = true
106-
extend-ignore = ["WPS226"]
106+
extend-ignore = ["WPS226", "WPS410", "WPS412"]
107107
extend-exclude = [
108108
".coverage",
109109
".github",
@@ -121,8 +121,8 @@ select = ["AAA", "E999", "WPS"]
121121
show-source = true
122122
statistics = false
123123
per-file-ignores = [
124-
"*.py:WPS204,WPS210,WPS211,WPS213,WPS214,WPS218,WPS221,WPS229,WPS231,WPS232,WPS234,WPS235,WPS237,WPS322,WPS327,WPS332,WPS335,WPS336,WPS338,WPS339,WPS342,WPS347,WPS349,WPS410,WPS412,WPS432",
125-
"tests/**:WPS202,WPS203,WPS204,WPS210,WPS211,WPS213,WPS218,WPS221,WPS235,WPS322,WPS335,WPS339,WPS342,WPS432"
124+
"*.py:WPS204,WPS210,WPS211,WPS213,WPS214,WPS218,WPS221,WPS229,WPS231,WPS232,WPS234,WPS235,WPS237,WPS327,WPS332,WPS335,WPS336,WPS338,WPS339,WPS342,WPS349,WPS432",
125+
"tests/**:WPS202,WPS204,WPS210,WPS211,WPS213,WPS218,WPS221,WPS235,WPS335,WPS339,WPS342,WPS432"
126126
]
127127

128128
[tool.ruff]

0 commit comments

Comments
 (0)