gopass in question

This commit is contained in:
Michael Jerger 2023-05-19 13:39:49 +02:00
parent de1bd0570b
commit db0d560e12
3 changed files with 53 additions and 45 deletions

View file

@ -28,7 +28,7 @@ use_plugin("python.distutils")
default_task = "publish"
name = "ddadevops"
version = "4.0.0-dev19"
version = "4.0.0-dev21"
summary = "tools to support builds combining gopass, terraform, dda-pallet, aws & hetzner-cloud"
description = __doc__
authors = [Author("meissa GmbH", "buero@meissa-gmbh.de")]

View file

@ -9,10 +9,7 @@ PROJECT_ROOT_PATH = "../.."
@init
def initialize(project):
tag = environ.get("CI_COMMIT_TAG")
if not tag:
tag = get_tag_from_latest_commit()
input = {
"name": name,
"module": MODULE,
@ -20,20 +17,6 @@ def initialize(project):
"project_root_path": PROJECT_ROOT_PATH,
"build_types": ["IMAGE"],
"mixin_types": [],
"image_dockerhub_user": "dockerhub_user",
"image_dockerhub_password": "dockerhub_password",
"image_tag": tag,
"credentials_mappings": [
{
"gopass_path": "meissa/web/docker.com",
"gopass_field": "login",
"name": "image_dockerhub_user"
},
{
"gopass_path": "meissa/web/docker.com",
"name": "image_dockerhub_password"
},
],
}
project.build_depends_on("ddadevops>=4.0.0-dev")

View file

@ -5,16 +5,18 @@ from .credentials import Credentials, GopassType
from .devops_factory import DevopsFactory
from .version import Version
from .release import ReleaseType
from ..infrastructure import (
BuildFileRepository,
CredentialsApi,
EnvironmentApi,
GitApi
)
from ..infrastructure import BuildFileRepository, CredentialsApi, EnvironmentApi, GitApi
class InitService:
def __init__(self, devops_factory, build_file_repository, credentials_api, environment_api, git_api):
def __init__(
self,
devops_factory,
build_file_repository,
credentials_api,
environment_api,
git_api,
):
self.devops_factory = devops_factory
self.build_file_repository = build_file_repository
self.credentials_api = credentials_api
@ -39,7 +41,7 @@ class InitService:
default_mappings = []
if BuildType.C4K in build_types:
default_mappings = [
default_mappings += [
{
"gopass_path": "server/meissa/grafana-cloud",
"gopass_field": "grafana-cloud-user",
@ -50,15 +52,21 @@ class InitService:
"name": "c4k_grafana_cloud_password",
},
]
credentials = Credentials(input, default_mappings)
authorization = self.authorization(credentials)
if BuildType.IMAGE in build_types:
default_mappings += [
{
"gopass_path": "meissa/web/docker.com",
"gopass_field": "login",
"name": "image_dockerhub_user",
},
{
"gopass_path": "meissa/web/docker.com",
"name": "image_dockerhub_password",
},
]
context = self.context()
merged = self.devops_factory.merge(input, context, authorization)
if MixinType.RELEASE in mixin_types:
primary_build_file_id = merged.get(
primary_build_file_id = input.get(
"release_primary_build_file", "./project.clj"
)
primary_build_file = self.build_file_repository.get(
@ -66,24 +74,41 @@ class InitService:
)
version = primary_build_file.get_version()
credentials = Credentials(input, default_mappings)
authorization = self.authorization(credentials)
context = self.context(mixin_types, version)
merged = self.devops_factory.merge(input, context, authorization)
return self.devops_factory.build_devops(merged, version=version)
def context(self) -> dict:
def context(self, mixin_types, version) -> dict:
result = {}
release_type = self.environment_api.get("RELEASE_TYPE")
if not release_type:
latest_commit = self.git_api.get_latest_commit()
if latest_commit in [ReleaseType.MAJOR.name, ReleaseType.MINOR.name,
ReleaseType.PATCH.name, ReleaseType.NONE.name]:
release_type = latest_commit
result["release_type"] = release_type
result["release_current_branch"] = self.git_api.get_current_branch()
tag = self.environment_api.get("IMAGE_TAG")
if MixinType.RELEASE in mixin_types:
release_type = self.environment_api.get("RELEASE_TYPE")
if not release_type:
latest_commit = self.git_api.get_latest_commit()
if latest_commit in [
ReleaseType.MAJOR.name,
ReleaseType.MINOR.name,
ReleaseType.PATCH.name,
ReleaseType.NONE.name,
]:
release_type = latest_commit
result["release_type"] = release_type
result["release_current_branch"] = self.git_api.get_current_branch()
if not tag:
tag = version.to_string()
result["image_tag"] = tag
return result
def authorization(self, credentials: Credentials) -> List[str]:
result = {}
for name in credentials.mappings.keys():