introduce init service
parent
17f41dbd7a
commit
c13b70150b
@ -0,0 +1,29 @@
|
||||
from pathlib import Path
|
||||
from .common import Devops, MixinType
|
||||
from .devops_factory import DevopsFactory
|
||||
from .version import Version
|
||||
from src.main.python.ddadevops.infrastructure import (
|
||||
BuildFileRepository
|
||||
)
|
||||
|
||||
class InitService:
|
||||
def __init__(self, devops_factory, build_file_repository):
|
||||
self.devops_factory = devops_factory
|
||||
self.build_file_repository = build_file_repository
|
||||
|
||||
@classmethod
|
||||
def prod(cls):
|
||||
return cls(
|
||||
DevopsFactory(),
|
||||
BuildFileRepository(),
|
||||
)
|
||||
|
||||
def initialize(self, input: dict) -> Devops:
|
||||
mixin_types = self.devops_factory.__parse_mixin_types__(input["mixin_types"])
|
||||
|
||||
if MixinType.RELEASE in mixin_types:
|
||||
primary_build_file_id = input.get("release_primary_build_file", "./project.clj")
|
||||
primary_build_file = self.build_file_repository.get(Path(primary_build_file_id))
|
||||
version = primary_build_file.get_version()
|
||||
|
||||
return self.devops_factory.build_devops(input, version=version)
|
@ -1 +1,2 @@
|
||||
from .infrastructure import FileApi, ImageApi, ResourceApi, ExecutionApi, ProjectRepository
|
||||
from .repository import DevopsRepository, BuildFileRepository
|
@ -0,0 +1,35 @@
|
||||
from pathlib import Path
|
||||
from sys import stdout
|
||||
from os import chmod
|
||||
from subprocess import run
|
||||
from pkg_resources import resource_string
|
||||
import yaml
|
||||
import deprecation
|
||||
from ..domain import Devops, Image, C4k, Release, BuildFile
|
||||
from ..python_util import execute
|
||||
|
||||
|
||||
class DevopsRepository:
|
||||
def get_devops(self, project) -> Devops:
|
||||
devops = project.get_property("devops")
|
||||
devops.throw_if_invalid()
|
||||
return devops
|
||||
|
||||
def set_devops(self, project, devops: Devops):
|
||||
devops.throw_if_invalid()
|
||||
project.set_property("devops", devops)
|
||||
|
||||
|
||||
class BuildFileRepository:
|
||||
def get(self, path: Path) -> BuildFile:
|
||||
with open(path, "r", encoding="utf-8") as file:
|
||||
content = file.read()
|
||||
result = BuildFile(path, content)
|
||||
result.throw_if_invalid()
|
||||
return result
|
||||
|
||||
def write(self, build_file: BuildFile):
|
||||
build_file.throw_if_invalid()
|
||||
with open(build_file.file_path, "r+", encoding="utf-8") as file:
|
||||
file.seek(0)
|
||||
file.write(build_file.content)
|
@ -0,0 +1,19 @@
|
||||
import pytest
|
||||
from src.main.python.ddadevops.domain import (
|
||||
InitService,
|
||||
DevopsFactory,
|
||||
Version,
|
||||
MixinType,
|
||||
)
|
||||
from .test_helper import BuildFileRepositoryMock, devops_config
|
||||
|
||||
|
||||
def test_sould_load_build_file():
|
||||
sut = InitService(
|
||||
DevopsFactory(),
|
||||
BuildFileRepositoryMock(),
|
||||
)
|
||||
assert (
|
||||
Version.from_str("1.1.5-SNAPSHOT")
|
||||
== sut.initialize(devops_config({})).mixins[MixinType.RELEASE].version
|
||||
)
|
Loading…
Reference in New Issue