Skip to content

Commit f68b097

Browse files
authored
Update API spec and format with Ruff (#79)
* Do all formatting and linting with Ruff * Rename "audit log rotation" to "purge" * Import custom root models in `parser.py` * Format fragments with Ruff manually * Update API spec * Remove unused `type: ignore` comments * Run linting and formatting on all files * Add Python 3.12 support * Add `SBOMOverview` to changelog * Remove all unnecessary "# type: ignore" comments * Format and lint tests
1 parent 748ef14 commit f68b097

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+348
-206
lines changed

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
fail-fast: false
3131
matrix:
3232
os: [ubuntu-latest]
33-
python-version: ["3.8", "3.9", "3.10", "3.11"]
33+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
3434

3535
steps:
3636
- uses: actions/checkout@v3

.pre-commit-config.yaml

+5-8
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@ repos:
88
- id: end-of-file-fixer
99
- id: check-yaml
1010
- id: check-added-large-files
11-
- repo: https://github.com/asottile/reorder_python_imports
12-
rev: v3.12.0
13-
hooks:
14-
- id: reorder-python-imports
15-
args: [--py38-plus, --add-import, "from __future__ import annotations"]
16-
- repo: https://github.com/charliermarsh/ruff-pre-commit
17-
rev: "v0.1.7"
11+
- repo: https://github.com/astral-sh/ruff-pre-commit
12+
# Ruff version.
13+
rev: v0.4.8
1814
hooks:
1915
# Run the linter.
2016
- id: ruff
21-
args: [--fix]
17+
args: [ --fix ]
18+
exclude: '^codegen/ast/fragments/.*'
2219
# Run the formatter.
2320
- id: ruff-format

CHANGELOG.md

+17-26
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,21 @@ While the project is still on major version 0, breaking changes may be introduce
1212

1313
<!-- changelog follows -->
1414

15-
<!-- ## Unreleased -->
15+
## Unreleased
16+
17+
### Added
18+
19+
- Python 3.12 support.
20+
- `harborapi.models.SBOMOverview` which represents the SBOM overview for an artifact. Can be accessed via `Artifact.sbom_overview`.
21+
22+
### Changed
23+
24+
- Added compatibility methods for purge endpoint methods that were renamed in HarborAPI v0.11.0.
25+
- The `*audit_log_rotation*` methods are now deprecated and will be removed in a future release.
26+
- It never made sense to create an opinionated naming for these methods.
27+
- Project is now formatted and linted with Ruff.
28+
- Code generation now explicitly imports `StrDictRootModel` and `StrRootModel`.
29+
- Updated API spec to [ec8d692](https://github.com/goharbor/harbor/blob/6a38ed3d7769e3598c6cf829aae4e0e152f93a83/api/v2.0/swagger.yaml)
1630

1731
## [0.23.4](https://github.com/unioslo/harborapi/tree/harborapi-v0.23.4) - 2024-03-01
1832

@@ -52,6 +66,7 @@ While the project is still on major version 0, breaking changes may be introduce
5266
The big Pydantic V2 update. This is a major update in terms of both scope and API compatibility.
5367

5468
### Changed
69+
5570
- Model validation has become more strict.
5671
- Most importantly, `str` fields will no longer coerce `int` values to strings.
5772
- See [Pydantic docs](https://docs.pydantic.dev/latest/api/standard_library_types/) for more information.
@@ -111,10 +126,8 @@ The big Pydantic V2 update. This is a major update in terms of both scope and AP
111126
- Pydantic version capped at <2.0.0.
112127
- Migration to Pydantic V2 will begin soon.
113128

114-
115129
## [0.21.0](https://github.com/unioslo/harborapi/tree/harborapi-v0.21.0) - 2023-06-08
116130

117-
118131
### Added
119132

120133
- Missing optional `limit` argument for methods that fetch multiple resources:
@@ -139,12 +152,10 @@ The big Pydantic V2 update. This is a major update in terms of both scope and AP
139152

140153
## [0.20.0](https://github.com/unioslo/harborapi/tree/harborapi-v0.20.0) - 2023-05-30
141154

142-
143155
### Changed
144156

145157
- `HarborAsyncClient.delete_scanner` now raises `HarborAPIException` if no scanner response is returned from the API (was `UnprocessableEntity` before).
146158

147-
148159
### Removed
149160

150161
- Loguru dependency. The library now uses the standard Python logging library for logging purposes. See [Logging](https://unioslo.github.io/harborapi/usage/logging/) in the docs for more information.
@@ -175,15 +186,12 @@ The big Pydantic V2 update. This is a major update in terms of both scope and AP
175186
- Remove model:`SearchResult` (deprecated)
176187
- Remove field `Project.chart_count`(deprecated)
177188

178-
179189
## [0.18.1](https://github.com/unioslo/harborapi/tree/harborapi-v0.18.1) - 2023-05-12
180190

181-
182191
### Added
183192

184193
- `BaseModel.convert_to`, which allows converting a model to another model type that has a similar schema, such as `Project` to `ProjectReq`.
185194

186-
187195
### Fixed
188196

189197
- Bool to string converter on `BaseModel` now correctly handles assignments.
@@ -192,7 +200,6 @@ The big Pydantic V2 update. This is a major update in terms of both scope and AP
192200

193201
### Added
194202

195-
196203
- New context manager for temporarily disabling retrying: `HarborAsyncClient.no_retry`
197204
- New context manager for temporarily disabling validation: `HarborAsyncClient.no_validation`
198205
- New context manager for temporarily enabling raw mode: `HarborAsyncClient.raw_mode`
@@ -227,7 +234,6 @@ The big Pydantic V2 update. This is a major update in terms of both scope and AP
227234

228235
- Disclaimer for `harborapi.HarborAsyncClient.delete_retention_policy`, warning that it can break a project due to a bug in Harbor.
229236

230-
231237
### Changed
232238

233239
- Move `harborapi.client.ResponseLog` and `harborapi.client.ResponseLogEntry` to `harborapi.responselog` module.
@@ -238,7 +244,6 @@ The big Pydantic V2 update. This is a major update in terms of both scope and AP
238244
- `harborapi.ext.regex.match` return type annotation is now correctly marked as `Optional[Match[str]]` instead of `Match[str]`.
239245
- `harborapi.HarborAsyncClient.get_retention_tasks` missing `limit` parameter in docstring.
240246

241-
242247
## [0.16.1](https://github.com/unioslo/harborapi/tree/harborapi-v0.16.1) - 2023-04-24
243248

244249
### Fixed
@@ -267,7 +272,6 @@ Until the official API spec is fixed, this is the best we can do.
267272

268273
- `harbor` being added as an executable script installed by the project. This was a mistake, as the `harbor` executable script is intended to be exposed by [harbor-cli](https://github.com/unioslo/harbor-cli).
269274

270-
271275
## [0.15.1](https://github.com/unioslo/harborapi/tree/harborapi-v0.15.1) - 2023-04-17
272276

273277
### Added
@@ -279,9 +283,8 @@ Until the official API spec is fixed, this is the best we can do.
279283
- `HarborAsyncClient.get_artifact_vulnerabilities()` now always returns a `harborapi.models.HarborVulnerabilityReport` object. If the artifact has no vulnerabilities or the report cannot be processed, an exception is raised.
280284

281285
### Removed
282-
- `config` argument from `HarborAsyncClient.__init__()`. The `config` argument was never implemented.
283-
284286

287+
- `config` argument from `HarborAsyncClient.__init__()`. The `config` argument was never implemented.
285288

286289
## [0.15.0](https://github.com/unioslo/harborapi/tree/harborapi-v0.15.0) - 2023-04-13
287290

@@ -330,7 +333,6 @@ Until the official API spec is fixed, this is the best we can do.
330333

331334
- `HarborAsyncClient.update_project_member_role()` now accepts integer arguments for its `role_id` parameter, since `RoleRequest` only has a single field (`role_id`).
332335

333-
334336
### Fixed
335337

336338
- Potential bug with `models.VulnerabilitySummary` if `summary` is `None`.
@@ -366,7 +368,6 @@ Until the official API spec is fixed, this is the best we can do.
366368
- `HarborAsyncClient.get_system_certificate()`
367369
- Returns the system certificate. (`GET /api/v2.0/systeminfo/getcert`)
368370

369-
370371
### Changed
371372

372373
- **BREAKING**: Methods that download files, now return `FileResponse` instead of a bytes object. `FileResponse` contains the file contents along with its metadata. The object can be passed to `bytes()` to get the response contents, otherwise it can be accessed via the `FileResponse.content` attribute.
@@ -435,12 +436,10 @@ Until the official API spec is fixed, this is the best we can do.
435436
- DEPRECATED: Using `credentials` as a parameter for `HarborAsyncClient.__init__` is deprecated. Use `basicauth` instead.
436437
- `HarborAsyncClient.credentials` is now a Pydantic SecretStr, which prevents it from being printed in clear text when locals are dumped, such as when printing the client object. To access the value, use `HarborAsyncClient.credentials.get_secret_value()`.
437438

438-
439439
### Removed
440440

441441
- Explicit logging calls from `HarborAsyncClient.set_user_cli_secret()` and `HarborAsyncClient.set_user_password()`. The exception handler handles logging if configured.
442442

443-
444443
## [0.9.0](https://github.com/unioslo/harborapi/tree/harborapi-v0.9.0) - 2023-02-21
445444

446445
### Changed
@@ -451,19 +450,16 @@ Until the official API spec is fixed, this is the best we can do.
451450

452451
## [0.8.6](https://github.com/unioslo/harborapi/tree/harborapi-v0.8.6) - 2023-02-20
453452

454-
455453
### Fixed
456454

457455
- Models with `harborapi.models.ScheduleObj` fields are now correctly validated when the Harbor API responds with a value of `"Schedule"` for the field `ScheduleObj.type`, which is not a valid value for the enum according to their own spec.
458456

459-
460457
## [0.8.5](https://github.com/unioslo/harborapi/tree/harborapi-v0.8.5) - 2023-02-20
461458

462459
### Added
463460

464461
`NativeReportSummary.severity_enum` which returns the severity of the report as a `harborarpi.scanner.Severity` enum, which can be used for comparisons between reports.
465462

466-
467463
### Fixed
468464

469465
`harborarpi.scanner.Severity` enum not having a `None` value, which is observed when a report has no vulnerabilities.
@@ -475,7 +471,6 @@ Until the official API spec is fixed, this is the best we can do.
475471
- Certain resource enumeration methods missing the `limit` parameter.
476472
- `HarborAsyncClient.get_gc_jobs()` ignoring user parameters.
477473

478-
479474
## [0.8.3](https://github.com/unioslo/harborapi/tree/harborapi-v0.8.3) - 2023-02-14
480475

481476
### Changed
@@ -493,7 +488,6 @@ Until the official API spec is fixed, this is the best we can do.
493488

494489
- `HarborAsyncClient.get_registry_providers` now returns a `RegistryProviders` object, which is a model whose only attribute `providers` is a dict of `RegistryProviderInfo` objects. Previously this method attempted to return a list of `RegistryProviderInfo` objects, but this was incorrect.
495490

496-
497491
## [0.8.1](https://github.com/unioslo/harborapi/tree/harborapi-v0.8.1) - 2023-02-09
498492

499493
### Changed
@@ -506,7 +500,6 @@ Until the official API spec is fixed, this is the best we can do.
506500

507501
- `limit` parameter for all methods that return a list of items. This parameter is used to limit the number of items returned by the API. See the [docs](https://unioslo.github.io/harborapi/usage/limit/) for more details.
508502

509-
510503
### Removed
511504

512505
- `retrieve_all` parameter for all methods that return a list of items. Use the new `limit` parameter to control the number of results to retrieve. Passing `retrieve_all` to these methods will be silently ignored. In the future this will raise a DeprecationWarning.
@@ -517,7 +510,6 @@ Until the official API spec is fixed, this is the best we can do.
517510

518511
- New parameters `raw` and `validate` to `HarborAsyncClient` and `HarborClient` to control whether the client returns the raw data from the API, and whether the client validates the data from the API, respectively. See the [docs](https://unioslo.github.io/harborapi/usage/validation/) for more details.
519512

520-
521513
## [0.7.0](https://github.com/unioslo/harborapi/tree/harborapi-v0.7.0) - 2023-02-06
522514

523515
### Added
@@ -533,7 +525,6 @@ Until the official API spec is fixed, this is the best we can do.
533525

534526
- `HarborAsyncClient.search()` raising an error when finding Helm Charts with an empty `engine` field.
535527

536-
537528
### Removed
538529

539530
- **BREAKING**: `HarborAsyncClient.get_internal_config()`. This endpoint is meant for internal usage only, and the new model definitions don't seem to play well with it. If you need this endpoint, please open an issue.

codegen/ast/fragments/main/_common.py

-4
This file was deleted.

codegen/ast/fragments/main/immutablerule.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from typing import Dict
55
from typing import Optional
66

7-
87
# Changed: change params field type
98
# Reason: params is a dict of Any, not a dict of dicts
109

codegen/ast/fragments/main/projectmetadata.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from typing import Union
77

88
from pydantic import Field
9-
from pydantic import field_validator
109
from pydantic import ValidationInfo
10+
from pydantic import field_validator
1111

1212

1313
class ProjectMetadata(BaseModel):

codegen/ast/fragments/main/retentionrule.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from typing import Dict
55
from typing import Optional
66

7-
87
# Changed: change params field type
98
# Reason: params is a dict of Any, not a dict of dicts
109
# TODO: add descriptions

codegen/ast/fragments/scanner/_common.py

-4
This file was deleted.

codegen/ast/fragments/scanner/scanner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

3-
from ..version import get_semver
43
from ..version import SemVer
4+
from ..version import get_semver
55

66

77
class Scanner(BaseModel):

codegen/ast/fragments/scanner/vulnerabilityitem.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
from __future__ import annotations
22

3-
from typing import Dict
43
from typing import Iterable
54
from typing import Optional
65
from typing import Union
76

8-
from pydantic import field_validator
97
from pydantic import ValidationInfo
8+
from pydantic import field_validator
109

1110
from ..log import logger
12-
from ..version import get_semver
1311
from ..version import SemVer
12+
from ..version import get_semver
1413

1514

1615
class VulnerabilityItem(BaseModel):

codegen/ast/parser.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,9 @@ def modify_module(tree: ast.Module, fragment_dir: FragmentDir) -> ast.Module:
321321

322322

323323
# Imports that should be added to every file
324-
ADD_IMPORTS = {} # type: dict[str, list[str]] # module: list[import_name]
324+
ADD_IMPORTS = {
325+
"harborapi.models.base": ["StrDictRootModel", "StrRootModel"],
326+
} # type: dict[str, list[str]] # module: list[import_name]
325327

326328

327329
def add_imports(tree: ast.Module) -> ast.Module:
@@ -498,11 +500,11 @@ def insert_or_update_classdefs(
498500
) and getattr(
499501
stmt.target,
500502
"id",
501-
None, # type: ignore
503+
None,
502504
) == getattr(
503505
class_stmt.target,
504506
"id",
505-
None, # type: ignore
507+
None,
506508
):
507509
node.body[i] = class_stmt
508510
break

codegen/generate.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ if [ "$fetch_spec" = true ]; then
5151
fi
5252

5353
python codegen/ast/parser.py "$output_file" "$final_file" "$source_type"
54-
reorder-python-imports "$final_file"
55-
ruff --fix "$final_file"
54+
ruff check --fix "$final_file"
5655
ruff format "$final_file"
5756
cp "$final_file" "./harborapi/models/$(basename "$final_file")"

docs/endpoints/auditlogs.md

-7
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,3 @@
44
options:
55
members:
66
- get_audit_logs
7-
- get_audit_log_rotation
8-
- stop_audit_log_rotation
9-
- get_audit_log_rotation_log
10-
- get_audit_log_rotation_history
11-
- get_audit_log_rotation_schedule
12-
- create_audit_log_rotation_schedule
13-
- update_audit_log_rotation_schedule

docs/endpoints/purge.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Purge
2+
3+
::: harborapi.client.HarborAsyncClient
4+
options:
5+
members:
6+
- get_purge_job
7+
- stop_purge_job
8+
- get_purge_job_log
9+
- get_purge_job_schedule
10+
- create_purge_job_schedule
11+
- update_purge_job_schedule
12+
- get_purge_job_history

0 commit comments

Comments
 (0)