def get_lineage(certificate_config: Dict[str, Any]) -> str: lineage = (certificate_config.get("name") if certificate_config.get("name") else utils.normalize_lineage( certificate_config.get("domains", [None])[0])) if not lineage: raise ValueError( "Could not find the certificate name for certificate config: {0}". format(certificate_config)) return lineage
def _extract_certificates(envs: Dict[str, str], profile: str) -> List[Dict[str, Any]]: certificates: List[Dict[str, Any]] = [] with open(os.path.join(LEGACY_CONFIGURATION_PATH)) as f: lines = f.read().splitlines() for line in lines: if line.strip(): domains = [] autorestart = [] autocmd = [] items = re.split("\\s+", line) for index, item in enumerate(items): if item.startswith("autorestart-containers="): containers = item.replace("autorestart-containers=", "").split(",") containers = [ container.strip() for container in containers ] autorestart.append({ "swarm_services" if envs.get("DOCKER_CLUSTER_PROVIDER") == "swarm" else "containers": containers, }) continue if item.startswith("autocmd-containers="): item = " ".join(items[index:]) directives = item.replace("autocmd-containers=", "").split(",") for directive in directives: [container, command] = directive.split(":") autocmd.append({ "containers": [container], "cmd": command }) break domains.append(item) if domains: certificate: Dict[str, Any] = { "name": utils.normalize_lineage(domains[0]), "domains": domains, "profile": profile, } if autorestart: certificate["autorestart"] = autorestart if autocmd: certificate["autocmd"] = autocmd certificates.append(certificate) return certificates