Search in sources :

Example 1 with K8SecretYaml

use of org.wso2.mi.tooling.security.output.K8SecretYaml in project product-mi-tooling by wso2.

the class IOUtils method writeYamlFile.

/**
 * Writes k8 secret .yml file
 *
 * @param filePath file destination
 * @param yaml     K8SecretYaml object
 */
public static void writeYamlFile(String filePath, K8SecretYaml yaml) {
    DumperOptions options = new DumperOptions();
    // Configuration to hide the bean type (org.wso2.mi.tooling.security.output.K8SecretYaml)
    Representer representer = new Representer();
    representer.addClassTag(K8SecretYaml.class, Tag.MAP);
    options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
    options.setPrettyFlow(true);
    Yaml output = new Yaml(representer, options);
    try (FileWriter writer = new FileWriter(filePath)) {
        output.dump(yaml, writer);
        System.out.println("Kubernetes secret file created in " + filePath + " with default name and namespace");
        System.out.println("You can change the default values as required before applying.");
    } catch (IOException e) {
        throw new EncryptionToolException("Error while creating " + filePath);
    }
}
Also used : Representer(org.yaml.snakeyaml.representer.Representer) EncryptionToolException(org.wso2.mi.tooling.security.exception.EncryptionToolException) FileWriter(java.io.FileWriter) DumperOptions(org.yaml.snakeyaml.DumperOptions) IOException(java.io.IOException) Yaml(org.yaml.snakeyaml.Yaml) K8SecretYaml(org.wso2.mi.tooling.security.output.K8SecretYaml)

Aggregations

FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 EncryptionToolException (org.wso2.mi.tooling.security.exception.EncryptionToolException)1 K8SecretYaml (org.wso2.mi.tooling.security.output.K8SecretYaml)1 DumperOptions (org.yaml.snakeyaml.DumperOptions)1 Yaml (org.yaml.snakeyaml.Yaml)1 Representer (org.yaml.snakeyaml.representer.Representer)1