Search in sources :

Example 1 with SecretKeys

use of io.fabric8.arquillian.utils.SecretKeys in project fabric8 by fabric8io.

the class SessionListener method generateSecrets.

private Set<Secret> generateSecrets(KubernetesClient client, Session session, ObjectMeta meta) {
    Set<Secret> secrets = new HashSet<>();
    Map<String, String> annotations = meta.getAnnotations();
    if (annotations != null && !annotations.isEmpty()) {
        for (Map.Entry<String, String> entry : annotations.entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue();
            if (SecretKeys.isSecretKey(key)) {
                SecretKeys keyType = SecretKeys.fromValue(key);
                for (String name : Secrets.getNames(value)) {
                    Map<String, String> data = new HashMap<>();
                    Secret secret = null;
                    try {
                        secret = client.secrets().inNamespace(session.getNamespace()).withName(name).get();
                    } catch (Exception e) {
                    // ignore - probably doesn't exist
                    }
                    if (secret == null) {
                        for (String c : Secrets.getContents(value, name)) {
                            data.put(c, keyType.generate());
                        }
                        secret = client.secrets().inNamespace(session.getNamespace()).createNew().withNewMetadata().withName(name).endMetadata().withData(data).done();
                        secrets.add(secret);
                    }
                }
            }
        }
    }
    return secrets;
}
Also used : Util.readAsString(io.fabric8.arquillian.utils.Util.readAsString) SecretKeys(io.fabric8.arquillian.utils.SecretKeys) MultiException(io.fabric8.utils.MultiException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException)

Aggregations

SecretKeys (io.fabric8.arquillian.utils.SecretKeys)1 Util.readAsString (io.fabric8.arquillian.utils.Util.readAsString)1 MultiException (io.fabric8.utils.MultiException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1