Esempio n. 1
0
def decrypt_docker_compose_files(
    cli_context: CliContext,
    docker_compose_file_relative_path: Path,
    docker_compose_override_directory_relative_path: Path,
) -> List[Path]:
    """Decrypt docker-compose and docker-compose override files.

    Args:
        cli_context (CliContext): The current CLI context.
        docker_compose_file_relative_path (Path): The relative path to the docker-compose file. Path is relative to the
            generated configuration directory.
        docker_compose_override_directory_relative_path (Path): The relative path to a directory containing
            docker-compose override files. Path is relative to the generated configuration directory.

    Returns:
        List[Path]: sorted list of absolute paths to decrypted docker-compose files. The first path is the decrypted
            docker-compose file, and the rest of the paths are the alphanumerically sorted docker compose override
            files in the docker compose override directory.
    """

    compose_files = []

    if docker_compose_file_relative_path is not None:
        docker_compose_file = cli_context.get_generated_configuration_dir().joinpath(
            docker_compose_file_relative_path
        )
        if os.path.isfile(docker_compose_file):
            compose_files.append(docker_compose_file)

    if docker_compose_override_directory_relative_path is not None:
        docker_compose_override_directory = (
            cli_context.get_generated_configuration_dir().joinpath(
                docker_compose_override_directory_relative_path
            )
        )
        if os.path.isdir(docker_compose_override_directory):
            docker_compose_override_files: List[Path] = [
                Path(os.path.join(docker_compose_override_directory, file))
                for file in os.listdir(docker_compose_override_directory)
                if os.path.isfile(os.path.join(docker_compose_override_directory, file))
            ]

            if len(docker_compose_override_files) > 0:
                docker_compose_override_files.sort()
                logger.debug(
                    "Detected docker compose override files [%s]",
                    docker_compose_override_files,
                )
                compose_files.extend(docker_compose_override_files)

    # decrypt files if key is available
    key_file = cli_context.get_key_file()
    decrypted_files = [
        decrypt_file(encrypted_file, key_file) for encrypted_file in compose_files
    ]
    return decrypted_files
    def __get_generated_configuration_metadata_file(
        self, cli_context: CliContext
    ) -> Path:
        """Get the path to the generated configuration's metadata file

        Args:
            cli_context (CliContext): The current CLI context.

        Returns:
            Path: the path to the metadata file
        """
        generated_configuration_dir = cli_context.get_generated_configuration_dir()
        return generated_configuration_dir.joinpath(METADATA_FILE_NAME)
Esempio n. 3
0
def confirm_generated_config_dir_exists(cli_context: CliContext):
    """Confirm that the generated configuration repository exists.
    If this fails, it will raise a general Exception with the error message.

    Args:
        cli_context (CliContext): The current CLI context.

    Raises:
        Exception: Raised if the generated configuration repository does not exist.
    """
    if not __is_git_repo(cli_context.get_generated_configuration_dir()):
        raise Exception(
            f"Generated configuration does not exist at [{cli_context.get_generated_configuration_dir()}]. Please run `configure apply`."
        )
Esempio n. 4
0
 def __init__(self, cli_context: CliContext):
     super().__init__(cli_context.get_generated_configuration_dir())
     self.rename_current_branch(
         self.generate_branch_name(cli_context.app_version))