From 2217e5c8d1e5d2b2d64818cb9b5177d2e1ab7fa8 Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Fri, 11 Aug 2023 16:16:03 +0200 Subject: [PATCH] add token & improve artifact validation --- src/main/python/ddadevops/domain/release.py | 33 ++++++++++++++------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/main/python/ddadevops/domain/release.py b/src/main/python/ddadevops/domain/release.py index b28e5da..29f78c1 100644 --- a/src/main/python/ddadevops/domain/release.py +++ b/src/main/python/ddadevops/domain/release.py @@ -1,4 +1,4 @@ -from typing import Optional, List +from typing import Optional, List, Dict from pathlib import Path from .common import ( Validateable, @@ -25,6 +25,7 @@ class Release(Validateable): self.release_artifact_server_url = inp.get("release_artifact_server_url") self.release_organisation = inp.get("release_organisation") self.release_repository_name = inp.get("release_repository_name") + self.release_artifact_token = inp.get("release_artifact_token") def update_release_type(self, release_type: ReleaseType): self.release_type = release_type @@ -62,21 +63,24 @@ class Release(Validateable): ) return result + def validate_for_artifact(self): + result = [] + result += self.__validate_is_not_empty__("release_artifact_server_url") + result += self.__validate_is_not_empty__("release_organisation") + result += self.__validate_is_not_empty__("release_repository_name") + result += self.__validate_is_not_empty__("release_artifacts") + result += self.__validate_is_not_empty__("release_artifact_token") + return result + def build_files(self) -> List[str]: result = [self.release_primary_build_file] result += self.release_secondary_build_files return result def forgejo_release_api_endpoint(self): - if ( - self.release_artifact_server_url is None - or self.release_organisation is None - or self.release_repository_name is None - ): - raise RuntimeError( - "when doing artifact release, release_artifact_server_url, " - + "release_organisation, release_repository_name may not be None." - ) + validation = self.validate_for_artifact() + if validation != []: + raise RuntimeError(f"not valid for creating artifacts: {validation}") server_url = self.release_artifact_server_url.removeprefix("/").removesuffix( "/" @@ -84,3 +88,12 @@ class Release(Validateable): organisation = self.release_organisation.removeprefix("/").removesuffix("/") repository = self.release_repository_name.removeprefix("/").removesuffix("/") return f"{server_url}/api/v1/repos/{organisation}/{repository}/releases" + + @classmethod + def get_mapping_default(cls) -> List[Dict[str, str]]: + return [ + { + "gopass_path": "server/meissa/repo/buero-rw", + "name": "release_artifact_token", + } + ]