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;
}
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();
}
}
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);
}
Aggregations