From d4f0ccf0663127c83790549a5ef036cb91a57376 Mon Sep 17 00:00:00 2001 From: "geo-ghci-int[bot]" <146321879+geo-ghci-int[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 15:37:24 +0000 Subject: [PATCH] Apply pre-commit fix From the artifact of the previous workflow run --- c2cciutils/__init__.py | 11 +++++ c2cciutils/applications_definition.py | 6 +-- c2cciutils/configuration.py | 64 +++++++++++++-------------- c2cciutils/lib/oidc.py | 2 + c2cciutils/publish.py | 7 ++- c2cciutils/scripts/clean.py | 1 + c2cciutils/scripts/publish.py | 2 + 7 files changed, 57 insertions(+), 36 deletions(-) diff --git a/c2cciutils/__init__.py b/c2cciutils/__init__.py index bf2565953..33ed3d6de 100644 --- a/c2cciutils/__init__.py +++ b/c2cciutils/__init__.py @@ -44,6 +44,7 @@ def merge(default_config: Any, config: Any) -> Any: Arguments: default_config: The default config that will be applied config: The base config, will be modified + """ if not isinstance(default_config, dict) or not isinstance(config, dict): return config @@ -155,6 +156,7 @@ def error( line: The line number of the error col: The column number of the error error_type: The kind of error (error or warning) + """ result = "" on_ci = os.environ.get("CI", "false").lower() == "true" @@ -197,6 +199,7 @@ def compile_re(config: c2cciutils.configuration.VersionTransform, prefix: str = prefix: The version prefix Return the compiled transform config. + """ result = [] for conf in config: @@ -226,6 +229,7 @@ def match( Returns the re match object, the matched config and the value as a tuple On no match it returns None, value + """ for conf in config: matched = conf["from"].match(value) @@ -243,6 +247,7 @@ def does_match(value: str, config: list[VersionTransform]) -> bool: config: The result of `compile` Returns True it it does match else False + """ matched, _, _ = match(value, config) return matched is not None @@ -262,6 +267,7 @@ def get_value(matched: Optional[Match[str]], config: Optional[VersionTransform], value: The default value on returned no match Return the value + """ return matched.expand(config.get("to", r"\1")) if matched is not None and config is not None else value @@ -272,6 +278,7 @@ def print_versions(config: c2cciutils.configuration.PrintVersions) -> bool: Arguments: config: The print configuration + """ for version in config.get("versions", c2cciutils.configuration.PRINT_VERSIONS_VERSIONS_DEFAULT): try: @@ -310,6 +317,7 @@ def gopass(key: str, default: Optional[str] = None) -> Optional[str]: default: the value to return if gopass is not found Return the value + """ try: return subprocess.check_output(["gopass", "show", key]).strip().decode() @@ -326,6 +334,7 @@ def gopass_put(secret: str, key: str) -> None: Arguments: secret: The secret value key: The key + """ subprocess.check_output(["gopass", "insert", "--force", key], input=secret.encode()) @@ -338,6 +347,7 @@ def add_authorization_header(headers: dict[str, str]) -> dict[str, str]: headers: The headers Return the headers (to be chained) + """ try: token = ( @@ -375,6 +385,7 @@ def graphql(query_file: str, variables: dict[str, Any], default: Any = None) -> Return the data result In case of error it throw an exception + """ with open(os.path.join(os.path.dirname(__file__), query_file), encoding="utf-8") as query_open: query = query_open.read() diff --git a/c2cciutils/applications_definition.py b/c2cciutils/applications_definition.py index 49fec80e6..7435e944b 100644 --- a/c2cciutils/applications_definition.py +++ b/c2cciutils/applications_definition.py @@ -2,7 +2,7 @@ Automatically generated file from a JSON schema. """ -from typing import Literal, TypedDict, Union +from typing import Dict, List, Literal, TypedDict, Union # | Application configuration. # | @@ -29,13 +29,13 @@ # | The tile name to get in the tar file. "tar-file-name": str, # | The commands to run after the tile creation. - "finish-commands": list[list[str]], + "finish-commands": List[List[str]], }, total=False, ) -ApplicationsConfiguration = dict[str, "ApplicationConfiguration"] +ApplicationsConfiguration = Dict[str, "ApplicationConfiguration"] """ Applications configuration. diff --git a/c2cciutils/configuration.py b/c2cciutils/configuration.py index c8102f522..d00912162 100644 --- a/c2cciutils/configuration.py +++ b/c2cciutils/configuration.py @@ -2,7 +2,7 @@ Automatically generated file from a JSON schema. """ -from typing import Any, Literal, TypedDict, Union +from typing import Any, Dict, List, Literal, TypedDict, Union class Configuration(TypedDict, total=False): @@ -61,11 +61,11 @@ class Configuration(TypedDict, total=False): """ -DB_CONFIGURATION_DEFAULT: dict[str, Any] = {} +DB_CONFIGURATION_DEFAULT: Dict[str, Any] = {} """ Default value of the field path 'K8s configuration db' """ -DISPATCH_CONFIG_DEFAULT: dict[str, Any] = {} +DISPATCH_CONFIG_DEFAULT: Dict[str, Any] = {} """ Default value of the field path 'Publish Docker config dispatch oneof0' """ @@ -101,7 +101,7 @@ class Configuration(TypedDict, total=False): # | tls.autoGenerated: 'true' # | tls.enabled: 'true' # | volumePermissions.enabled: 'true' - "chart-options": dict[str, str], + "chart-options": Dict[str, str], }, total=False, ) @@ -140,14 +140,14 @@ class Dpkg(TypedDict, total=False): The configuration use t manage the dpkg packages """ - packages_mapping: dict[str, str] + packages_mapping: Dict[str, str] """ dpkg packages mapping. The mapping of source package found in the image to package present in repology.org """ - ignored_packages: list[str] + ignored_packages: List[str] """ dpkg ignored packages. @@ -171,13 +171,13 @@ class Dpkg(TypedDict, total=False): # | - test-cluster # | - --no-lb # | - --no-rollback - "install-commands": list[list[str]], + "install-commands": List[List[str]], }, total=False, ) -K3D_CONFIGURATION_DEFAULT: dict[str, Any] = {} +K3D_CONFIGURATION_DEFAULT: Dict[str, Any] = {} """ Default value of the field path 'K8s configuration k3d' """ @@ -212,7 +212,7 @@ class K8SConfiguration(TypedDict, total=False): """ -K8S_CONFIGURATION_DEFAULT: dict[str, Any] = {} +K8S_CONFIGURATION_DEFAULT: Dict[str, Any] = {} """ Default value of the field path 'configuration k8s' """ @@ -272,11 +272,11 @@ class K8SConfiguration(TypedDict, total=False): """ Default value of the field path 'Publish Docker config snyk test_args' """ -PUBLISH_GOOGLE_CALENDAR_CONFIG_DEFAULT: dict[str, Any] = {} +PUBLISH_GOOGLE_CALENDAR_CONFIG_DEFAULT: Dict[str, Any] = {} """ Default value of the field path 'Publish Google calendar oneof0' """ -PUBLISH_GOOGLE_CALENDAR_DEFAULT: dict[str, Any] = {} +PUBLISH_GOOGLE_CALENDAR_DEFAULT: Dict[str, Any] = {} """ Default value of the field path 'publish_google_calendar' """ @@ -288,11 +288,11 @@ class K8SConfiguration(TypedDict, total=False): """ Default value of the field path 'publish pypi package group' """ -PUBLISH_PYPI_CONFIG_DEFAULT: dict[str, Any] = {} +PUBLISH_PYPI_CONFIG_DEFAULT: Dict[str, Any] = {} """ Default value of the field path 'publish pypi oneof0' """ -PUBLISH_PYPI_DEFAULT: dict[str, Any] = {} +PUBLISH_PYPI_DEFAULT: Dict[str, Any] = {} """ Default value of the field path 'publish_pypi' """ @@ -303,7 +303,7 @@ class PrintVersions(TypedDict, total=False): The print versions configuration """ - versions: list["_PrintVersionsVersionsItem"] + versions: List["_PrintVersionsVersionsItem"] """ Print versions versions. @@ -446,10 +446,10 @@ class PublishDockerConfig(TypedDict, total=False): default: True """ - images: list["PublishDockerImage"] + images: List["PublishDockerImage"] """ List of images to be published """ - repository: dict[str, "PublishDockerRepository"] + repository: Dict[str, "PublishDockerRepository"] """ Docker repository. @@ -495,7 +495,7 @@ class PublishDockerImage(TypedDict, total=False): name: str """ The image name """ - tags: list[str] + tags: List[str] """ publish docker image tags. @@ -512,7 +512,7 @@ class PublishDockerRepository(TypedDict, total=False): server: str """ The server URL """ - versions: list[str] + versions: List[str] """ Publish Docker repository versions. @@ -550,7 +550,7 @@ class PublishGoogleCalendarConfig(TypedDict, total=False): {} """ - on: list[str] + on: List[str] """ Publish Google calendar on. @@ -579,10 +579,10 @@ class PublishHelmConfig(TypedDict, total=False): Configuration to publish on Helm charts on GitHub release """ - folders: list[str] + folders: List[str] """ The folders that will be published """ - versions: list[str] + versions: List[str] """ The kind or version that should be published, tag, branch or value of the --version argument of the c2cciutils-publish script """ @@ -610,10 +610,10 @@ class PublishPypiConfig(TypedDict, total=False): {} """ - packages: list["PublishPypiPackage"] + packages: List["PublishPypiPackage"] """ The configuration of packages that will be published """ - versions: list[str] + versions: List[str] """ The kind or version that should be published, tag, branch or value of the --version argument of the c2cciutils-publish script """ @@ -636,7 +636,7 @@ class PublishPypiPackage(TypedDict, total=False): path: str """ The path of the pypi package """ - build_command: list[str] + build_command: List[str] """ The command used to do the build """ @@ -662,7 +662,7 @@ class Version(TypedDict, total=False): """ -VersionTransform = list["_VersionTransformItem"] +VersionTransform = List["_VersionTransformItem"] """ Version transform. @@ -670,11 +670,11 @@ class Version(TypedDict, total=False): """ -_PUBLISH_DOCKER_CONFIG_DISPATCH_DEFAULT: dict[str, Any] = {} +_PUBLISH_DOCKER_CONFIG_DISPATCH_DEFAULT: Dict[str, Any] = {} """ Default value of the field path 'Publish Docker config dispatch' """ -_PUBLISH_DOCKER_CONFIG_DISPATCH_ONEOF1_DEFAULT: dict[str, Any] = {} +_PUBLISH_DOCKER_CONFIG_DISPATCH_ONEOF1_DEFAULT: Dict[str, Any] = {} """ Default value of the field path 'Publish Docker config dispatch oneof1' """ @@ -694,16 +694,16 @@ class Version(TypedDict, total=False): """ Default value of the field path 'Publish Docker Snyk test args oneof1' """ -_PUBLISH_GOOGLE_CALENDAR_ONEOF1_DEFAULT: dict[str, Any] = {} +_PUBLISH_GOOGLE_CALENDAR_ONEOF1_DEFAULT: Dict[str, Any] = {} """ Default value of the field path 'Publish Google calendar oneof1' """ -_PUBLISH_PYPI_ONEOF1_DEFAULT: dict[str, Any] = {} +_PUBLISH_PYPI_ONEOF1_DEFAULT: Dict[str, Any] = {} """ Default value of the field path 'publish pypi oneof1' """ class _PrintVersionsVersionsItem(TypedDict, total=False): - cmd: list[str] + cmd: List[str] """ The command that should be used """ name: str @@ -749,7 +749,7 @@ class _PublishDockerConfigSnyk(TypedDict, total=False): """ -_PublishDockerSnykMonitorArgsOneof0 = list[str] +_PublishDockerSnykMonitorArgsOneof0 = List[str] """ default: - --app-vulns @@ -763,7 +763,7 @@ class _PublishDockerConfigSnyk(TypedDict, total=False): """ -_PublishDockerSnykTestArgsOneof0 = list[str] +_PublishDockerSnykTestArgsOneof0 = List[str] """ default: - --app-vulns diff --git a/c2cciutils/lib/oidc.py b/c2cciutils/lib/oidc.py index 82abd5303..84a2f9513 100755 --- a/c2cciutils/lib/oidc.py +++ b/c2cciutils/lib/oidc.py @@ -154,8 +154,10 @@ def pypi_login() -> None: Connect to PyPI using OpenID Connect and mint a token for the user. See Also + -------- - https://docs.github.com/en/actions/security-for-github-actions/security-hardening-your-deployments/about-security-hardening-with-openid-connect - https://docs.github.com/en/actions/security-for-github-actions/security-hardening-your-deployments/configuring-openid-connect-in-pypi + """ pypirc_filename = os.path.expanduser("~/.pypirc") diff --git a/c2cciutils/publish.py b/c2cciutils/publish.py index 3ae07c5e6..efc3af156 100644 --- a/c2cciutils/publish.py +++ b/c2cciutils/publish.py @@ -10,11 +10,11 @@ import re import subprocess # nosec import sys -import tomllib import uuid from typing import Optional import ruamel.yaml +import tomllib from google.auth.transport.requests import Request from google.oauth2.credentials import Credentials from google_auth_oauthlib.flow import InstalledAppFlow @@ -129,6 +129,7 @@ def print_latest_events(self, time_min: Optional[datetime.datetime] = None) -> N Arguments: time_min: The time to be considered. + """ now = datetime.datetime.utcnow() if not time_min: @@ -163,6 +164,7 @@ def create_event( Arguments: summary: The event summary description: The event description + """ now = datetime.datetime.now() start = now.isoformat() @@ -254,6 +256,7 @@ def pip( version_branch, feature_branch, feature_tag (for pull request) publish: If False only check the package package: The package configuration + """ print(f"::group::{'Publishing' if publish else 'Checking'} '{package.get('path')}' to pypi") sys.stdout.flush() @@ -352,6 +355,7 @@ def docker( tag_src: The source tag (usually latest) dst_tags: Publish using the provided tags images_full: The list of published images (with tag), used to build the dispatch event + """ print( f"::group::Publishing {image_config['name']} to the server {name} using the tags {', '.join(dst_tags)}" @@ -411,6 +415,7 @@ def helm(folder: str, version: str, owner: str, repo: str, commit_sha: str, toke repo: The GitHub repository name commit_sha: The sha of the current commit token: The GitHub token + """ print(f"::group::Publishing Helm chart from '{folder}' to GitHub release") sys.stdout.flush() diff --git a/c2cciutils/scripts/clean.py b/c2cciutils/scripts/clean.py index b90d089c1..581d895ee 100644 --- a/c2cciutils/scripts/clean.py +++ b/c2cciutils/scripts/clean.py @@ -24,6 +24,7 @@ def clean(image: str, tag: str, token: str) -> None: image: The image name that should be deleted (/) tag: The tag that should be deleted token: The token used to be authenticated on Docker hub + """ print(f"Delete image '{image}:{tag}'.") diff --git a/c2cciutils/scripts/publish.py b/c2cciutils/scripts/publish.py index f3db17aa1..0e9487792 100644 --- a/c2cciutils/scripts/publish.py +++ b/c2cciutils/scripts/publish.py @@ -34,6 +34,7 @@ def match(tpe: str, base_re: str) -> Optional[Match[str]]: Arguments: tpe: The type of ref we want to match (heads, tag, ...) base_re: The regular expression to match the value + """ if base_re[0] == "^": base_re = base_re[1:] @@ -50,6 +51,7 @@ def to_version(full_config: c2cciutils.configuration.Configuration, value: str, full_config: The full configuration value: The value to be transformed kind: The name of the transformer in the configuration + """ item_re = c2cciutils.compile_re( cast(