|
| 1 | +import fnmatch |
| 2 | +import os |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +from helpers import get_logger |
| 6 | +import ruamel.yaml |
| 7 | + |
| 8 | +logger = get_logger("cn-analyze-chart ") |
| 9 | + |
| 10 | + |
| 11 | +def find_replace(directory, find, replace, filepatterm): |
| 12 | + for path, _dirs, files in os.walk(os.path.abspath(directory)): |
| 13 | + for filename in fnmatch.filter(files, filepatterm): |
| 14 | + filepath = os.path.join(path, filename) |
| 15 | + with open(filepath) as f: |
| 16 | + s = f.read() |
| 17 | + s = s.replace(find, replace) |
| 18 | + with open(filepath, "w") as f: |
| 19 | + f.write(s) |
| 20 | + |
| 21 | + |
| 22 | +def clean_keys(values_dict: {}) -> None: |
| 23 | + for key, value in values_dict.items(): |
| 24 | + try: |
| 25 | + if value: |
| 26 | + continue |
| 27 | + del main_values_file_parser[key] |
| 28 | + except KeyError: |
| 29 | + logger.info("Key {} has been removed previously or does not exist".format(key)) |
| 30 | + |
| 31 | + |
| 32 | +main_dir = "../gluu/" |
| 33 | + |
| 34 | +# load original values.yaml |
| 35 | +yaml = ruamel.yaml.YAML() |
| 36 | +yaml.indent(mapping=4, sequence=4, offset=2) |
| 37 | +yaml.preserve_quotes = True |
| 38 | +main_values_file = Path(main_dir + "values.yaml").resolve() |
| 39 | +with open(main_values_file, "r") as f: |
| 40 | + |
| 41 | + y = f.read() |
| 42 | + main_values_file_parser = yaml.load(y) |
| 43 | + |
| 44 | +non_janssen_yaml = ruamel.yaml.YAML() |
| 45 | +non_janssen_yaml.indent(mapping=4, sequence=4, offset=2) |
| 46 | +non_janssen_yaml.preserve_quotes = True |
| 47 | +# load keys to be cleaned from original values.yaml |
| 48 | +with open (Path("./non_janssen.yaml").resolve(), "r") as f: |
| 49 | + non_janssen = f.read() |
| 50 | + non_janssen_keys = non_janssen_yaml.load(non_janssen) |
| 51 | +# generate janssen values yaml |
| 52 | +clean_keys(main_values_file_parser) |
| 53 | +clean_keys(main_values_file_parser["global"]) |
| 54 | +clean_keys(main_values_file_parser["global"]["istio"]) |
| 55 | +clean_keys(main_values_file_parser["config"]) |
| 56 | +clean_keys(main_values_file_parser["config"]["configmap"]) |
| 57 | +clean_keys(main_values_file_parser["nginx-ingress"]["ingress"]) |
| 58 | +yaml.dump(main_values_file_parser, main_values_file) |
| 59 | + |
| 60 | +# load Chart.yaml and clean it from non janssen charts |
| 61 | +chart_yaml = ruamel.yaml.YAML() |
| 62 | +chart_yaml.indent(mapping=4, sequence=4, offset=2) |
| 63 | +chart_yaml.preserve_quotes = True |
| 64 | +main_chart_file = Path(main_dir + "Chart.yaml").resolve() |
| 65 | +with open (main_chart_file, "r") as f: |
| 66 | + chart = f.read() |
| 67 | + chart_keys = chart_yaml.load(chart) |
| 68 | + |
| 69 | +non_janssen_charts = ["jackrabbit", "admin-ui", "oxshibboleth", "oxpassport", "casa", "cn-istio-ingress"] |
| 70 | +chart_dependencies = [] |
| 71 | +for chart in chart_keys["dependencies"]: |
| 72 | + if chart["name"] not in non_janssen_charts: |
| 73 | + chart_dependencies.append(chart) |
| 74 | +chart_keys["dependencies"] = chart_dependencies |
| 75 | +chart_keys["appVersion"] = "1.0.0" |
| 76 | +chart_yaml.dump(chart_keys, main_chart_file) |
| 77 | + |
| 78 | + |
| 79 | +def main(): |
| 80 | + find_replace( main_dir, "[email protected]", "[email protected]", "*.*") |
| 81 | + find_replace(main_dir, "https://gluu.org/docs/oxd", "https://github.com/JanssenProject/jans/jans-client-api", "*.*") |
| 82 | + find_replace(main_dir, "https://gluu.org/docs/gluu-server/reference/container-configs/", |
| 83 | + "https://github.com/JanssenProject/jans/docker-jans-configurator", "*.*") |
| 84 | + find_replace(main_dir, "https://www.gluu.org", "https://jans.io", "*.*") |
| 85 | + find_replace(main_dir, "https://gluu.org/docs/gluu-server", "https://jans.io", "*.*") |
| 86 | + find_replace(main_dir, "demoexample.gluu.org", "demoexample.jans.io", "*.*") |
| 87 | + find_replace(main_dir, "https://gluu.org/docs/gluu-server/favicon.ico", |
| 88 | + "https://github.com/JanssenProject/jans/raw/main/docs/logo/janssen%20project%20favicon%20transparent%2050px%2050px.png", |
| 89 | + "*.*") |
| 90 | + find_replace(main_dir, "Gluu", "Janssen", "*.*") |
| 91 | + find_replace(main_dir, "gluu", "janssen", "*.*") |
| 92 | + find_replace(main_dir, "5.0.0", "1.0.0", "*.*") |
| 93 | + find_replace(main_dir, "5.0.2", "1.0.0-beta.15", "*.*") |
| 94 | + |
| 95 | + |
| 96 | +if __name__ == "__main__": |
| 97 | + main() |
0 commit comments