Search in sources :

Example 16 with V1Secret

use of io.kubernetes.client.models.V1Secret in project weblogic-kubernetes-operator by oracle.

the class Helpers method findServiceAccountByToken.

/**
 * Find the service account by supplied token
 *
 * @param token authentication token to search for
 * @return V1ServiceAccount where token is secreted
 * @throws ApiException if there is an API error
 */
protected V1ServiceAccount findServiceAccountByToken(String token) throws ApiException {
    LOGGER.entering();
    V1ServiceAccountList serviceAccounts = getAllServiceAccounts();
    for (V1ServiceAccount serviceAccount : serviceAccounts.getItems()) {
        for (V1ObjectReference reference : serviceAccount.getSecrets()) {
            V1Secret secret = readSecretByReference(reference, serviceAccount.getMetadata().getNamespace());
            Map<String, byte[]> secretMap = secret.getData();
            for (Entry<String, byte[]> entry : secretMap.entrySet()) {
                String secretToken = new String(entry.getValue());
                if (entry.getKey().equals("token") && token.equals(secretToken)) {
                    LOGGER.exiting(serviceAccount);
                    return serviceAccount;
                }
            }
        }
    }
    ApiException e = new ApiException("token does not match any secret");
    LOGGER.throwing(e);
    throw e;
}
Also used : V1ServiceAccountList(io.kubernetes.client.models.V1ServiceAccountList) V1ObjectReference(io.kubernetes.client.models.V1ObjectReference) V1ServiceAccount(io.kubernetes.client.models.V1ServiceAccount) V1Secret(io.kubernetes.client.models.V1Secret) ApiException(io.kubernetes.client.ApiException)

Example 17 with V1Secret

use of io.kubernetes.client.models.V1Secret in project weblogic-kubernetes-operator by oracle.

the class SecretHelper method getSecretData.

/**
 * Get Data for Specified Secret
 *
 * @param secretType the secret to retrieve
 * @param secretName the name of the secret.
 * @return a Map containing the secret data fields and values
 */
public Map<String, byte[]> getSecretData(SecretType secretType, String secretName) {
    LOGGER.entering();
    CallBuilderFactory factory = ContainerResolver.getInstance().getContainer().getSPI(CallBuilderFactory.class);
    try {
        if (secretType != SecretType.AdminCredentials) {
            throw new IllegalArgumentException("Invalid secret type");
        } else if (secretName == null) {
            throw new IllegalArgumentException("Invalid secret name");
        }
        LOGGER.fine(MessageKeys.RETRIEVING_SECRET, secretName);
        V1Secret secret = factory.create().readSecret(secretName, namespace);
        if (secret == null || secret.getData() == null) {
            LOGGER.warning(MessageKeys.SECRET_NOT_FOUND, secretName);
            LOGGER.exiting(null);
            return null;
        }
        return harvestAdminSecretData(secret);
    } catch (Throwable e) {
        LOGGER.severe(MessageKeys.EXCEPTION, e);
        return null;
    } finally {
        LOGGER.exiting();
    }
}
Also used : V1Secret(io.kubernetes.client.models.V1Secret)

Example 18 with V1Secret

use of io.kubernetes.client.models.V1Secret in project weblogic-kubernetes-operator by oracle.

the class SecretHelperTest method createInvalidSecret.

// Create a named secret with no username / password in specified namespace
private V1Secret createInvalidSecret(String name, String namespace) throws Exception {
    CallBuilderFactory factory = new CallBuilderFactory(null);
    try {
        V1Secret existing = factory.create().readSecret(name, namespace);
        if (existing != null)
            return existing;
    } catch (ApiException ignore) {
    // Just ignore and try to create it
    }
    if (isVersion18)
        return null;
    V1Secret body = new V1Secret();
    // Set the required api version and kind of resource
    body.setApiVersion("v1");
    body.setKind("Secret");
    // Setup the standard object metadata
    V1ObjectMeta meta = new V1ObjectMeta();
    meta.setName(name);
    meta.setNamespace(namespace);
    body.setMetadata(meta);
    return factory.create().createSecret(namespace, body);
}
Also used : V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) CallBuilderFactory(oracle.kubernetes.operator.helpers.CallBuilderFactory) V1Secret(io.kubernetes.client.models.V1Secret) ApiException(io.kubernetes.client.ApiException)

Aggregations

V1Secret (io.kubernetes.client.models.V1Secret)18 Type (java.lang.reflect.Type)8 ProgressRequestBody (io.kubernetes.client.ProgressRequestBody)4 ProgressResponseBody (io.kubernetes.client.ProgressResponseBody)4 Test (org.junit.Test)4 ApiException (io.kubernetes.client.ApiException)3 V1ObjectMeta (io.kubernetes.client.models.V1ObjectMeta)2 V1ObjectReference (io.kubernetes.client.models.V1ObjectReference)2 CallBuilderFactory (oracle.kubernetes.operator.helpers.CallBuilderFactory)2 ApiClient (io.kubernetes.client.ApiClient)1 V1ServiceAccount (io.kubernetes.client.models.V1ServiceAccount)1 V1ServiceAccountList (io.kubernetes.client.models.V1ServiceAccountList)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 HashMap (java.util.HashMap)1