Ejemplo n.º 1
0
def serialise_cfg(
        cfg_dir: CliHints.existing_dir(), cfg_sets: [str], out_file: str):
    factory = ConfigFactory.from_cfg_dir(cfg_dir=cfg_dir)
    cfg_sets = [factory.cfg_set(cfg_set) for cfg_set in cfg_sets]
    serialiser = CSS(cfg_sets=cfg_sets, cfg_factory=factory)
    with open(out_file, 'w') as f:
        f.write(serialiser.serialise())
Ejemplo n.º 2
0
def render_pipeline(
    definition_file: CliHints.existing_file(),
    template_path: CliHints.existing_dir(),
    cfg_name: str,
    out_dir: CliHints.existing_dir(),
    template_include_dir: str=None,
):
    cfg_factory = ctx().cfg_factory()
    cfg_set = cfg_factory.cfg_set(cfg_name=cfg_name)

    def_enumerators = [
        SimpleFileDefinitionEnumerator(
            definition_file=definition_file,
            cfg_set=cfg_set,
            repo_path='example/example',
            repo_branch='master',
            repo_host='github.com',
        )
    ]

    preprocessor = DefinitionDescriptorPreprocessor()

    if not template_include_dir:
        template_include_dir = template_path

    template_retriever = TemplateRetriever(template_path=template_path)
    renderer = Renderer(
        template_retriever=template_retriever,
        template_include_dir=template_include_dir,
        cfg_set=cfg_set,
    )

    deployer = FilesystemDeployer(base_dir=out_dir)

    replicator = PipelineReplicator(
        definition_enumerators=def_enumerators,
        descriptor_preprocessor=preprocessor,
        definition_renderer=renderer,
        definition_deployer=deployer
    )

    replicator.replicate()
Ejemplo n.º 3
0
def deploy_or_upgrade_webhook_dispatcher(
    config_set_name: CliHint(typehint=str, help=CONFIG_SET_HELP),
    chart_dir: CliHints.existing_dir(
        help="directory of webhook dispatcher chart"),
    deployment_name: str = 'webhook-dispatcher',
):
    chart_dir = os.path.abspath(chart_dir)

    cfg_factory = ctx().cfg_factory()
    cfg_set = cfg_factory.cfg_set(config_set_name)

    webhook_dispatcher_deployment_cfg = cfg_set.webhook_dispatcher_deployment()

    setup_whd.deploy_webhook_dispatcher_landscape(
        cfg_set=cfg_set,
        webhook_dispatcher_deployment_cfg=webhook_dispatcher_deployment_cfg,
        chart_dir=chart_dir,
        deployment_name=deployment_name,
    )
Ejemplo n.º 4
0
def deploy_pipeline(
        pipeline_file: CliHint('generated pipeline definition to deploy'),
        pipeline_name: CliHint('the name under which the pipeline shall be deployed'),
        team_name: CliHint('name of the target team'),
        config_dir: CliHints.existing_dir('directory containing Concourse configuration'),
        config_name: CliHint('identifier of the configuration in the config directory to use')
):
    cfg_factory = ConfigFactory.from_cfg_dir(cfg_dir=config_dir)
    concourse_cfg = cfg_factory.concourse(config_name)
    team_credentials = concourse_cfg.team_credentials(team_name)

    with open(pipeline_file) as f:
        pipeline_definition = f.read()

    pipelines.deploy_pipeline(
        pipeline_definition=pipeline_definition,
        pipeline_name=pipeline_name,
        concourse_cfg=concourse_cfg,
        team_credentials=team_credentials,
    )
Ejemplo n.º 5
0
def update_certificate(
    tls_config_name: CliHint(typehint=str, help="TLS config element name to update"),
    certificate_file: CliHints.existing_file(help="certificate file path"),
    key_file: CliHints.existing_file(help="private key file path"),
    output_path: CliHints.existing_dir(help="TLS config file output path")
):
    # Stuff used for yaml formatting, when dumping a dictionary
    class LiteralStr(str):
        """Used to create yaml block style indicator | """

    def literal_str_representer(dumper, data):
        """Used to create yaml block style indicator"""
        return dumper.represent_scalar('tag:yaml.org,2002:str', data, style='|')

    # read new certificate data
    certificate_file = os.path.abspath(certificate_file)
    private_key_file = os.path.abspath(key_file)
    with open(certificate_file) as f:
        certificate = f.read()
    with open(private_key_file) as f:
        private_key = f.read()

    # set new certificate data to specified argument 'tls_config_name'
    cfg_factory = ctx().cfg_factory()
    tls_config_element = cfg_factory.tls_config(tls_config_name)
    tls_config_element.set_private_key(private_key)
    tls_config_element.set_certificate(certificate)

    # patch tls config dict so that yaml.dump outputs literal strings using '|'
    yaml.add_representer(LiteralStr, literal_str_representer)
    configs = cfg_factory._configs('tls_config')
    for k1, v1 in configs.items():
        for k2, _ in v1.items():
            configs[k1][k2] = LiteralStr(configs[k1][k2])

    # dump updated tls config to given output path
    tls_config_type = cfg_factory._cfg_types()['tls_config']
    tls_config_file = list(tls_config_type.sources())[0].file()
    with open(os.path.join(output_path, tls_config_file), 'w') as f:
        yaml.dump(configs, f, indent=2, default_flow_style=False)
Ejemplo n.º 6
0
def render_secrets(cfg_dir: CliHints.existing_dir(), cfg_name: str, out_file: str, external_url: str = None):
    fail('currrently no longer implemented')