use of io.kubernetes.client.models.V1ServiceAccount in project java by kubernetes-client.
the class CoreV1Api method replaceNamespacedServiceAccountWithHttpInfo.
/**
* replace the specified ServiceAccount
* @param name name of the ServiceAccount (required)
* @param namespace object name and auth scope, such as for teams and projects (required)
* @param body (required)
* @param pretty If 'true', then the output is pretty printed. (optional)
* @return ApiResponse<V1ServiceAccount>
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/
public ApiResponse<V1ServiceAccount> replaceNamespacedServiceAccountWithHttpInfo(String name, String namespace, V1ServiceAccount body, String pretty) throws ApiException {
com.squareup.okhttp.Call call = replaceNamespacedServiceAccountValidateBeforeCall(name, namespace, body, pretty, null, null);
Type localVarReturnType = new TypeToken<V1ServiceAccount>() {
}.getType();
return apiClient.execute(call, localVarReturnType);
}
use of io.kubernetes.client.models.V1ServiceAccount in project java by kubernetes-client.
the class CoreV1ApiTest method createNamespacedServiceAccountTest.
/**
* create a ServiceAccount
*
* @throws ApiException
* if the Api call fails
*/
@Test
public void createNamespacedServiceAccountTest() throws ApiException {
String namespace = null;
V1ServiceAccount body = null;
String pretty = null;
V1ServiceAccount response = api.createNamespacedServiceAccount(namespace, body, pretty);
// TODO: test validations
}
use of io.kubernetes.client.models.V1ServiceAccount 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.V1ServiceAccount in project weblogic-kubernetes-operator by oracle.
the class Helpers method findServiceAccount.
/**
* Find the servivce account by name.
*
* @param serviceAccountName The name of the Service Account.
* @param namespace The Namespace the Service Account is defined in.
* @return V1ServiceAccount object that matches the requested Service Account name and Namespace (if found).
* @throws ApiException if an API error occurs.
*/
protected V1ServiceAccount findServiceAccount(String serviceAccountName, String namespace) throws ApiException {
LOGGER.entering();
// list all service accounts and look for the one we want.
// But make sure there are no duplicates spread across
// multiple namespaces if a specific name space is not specified
V1ServiceAccountList serviceAccountList = getAllServiceAccounts();
ArrayList<V1ServiceAccount> sas = new ArrayList<>();
if (serviceAccountList != null) {
for (V1ServiceAccount sa : serviceAccountList.getItems()) {
String name = sa.getMetadata().getName();
if (name.equals(serviceAccountName)) {
if (namespace != null) {
String ns = sa.getMetadata().getNamespace();
if (ns.equals(namespace)) {
LOGGER.exiting(sa);
return sa;
}
}
sas.add(sa);
}
}
}
if (sas.isEmpty()) {
ApiException e = new ApiException("serviceAccount " + serviceAccountName + " not found");
LOGGER.throwing(e);
throw e;
}
if (sas.size() > 1) {
ApiException e = new ApiException("serviceAccount " + serviceAccountName + " appears in more than one namespace");
LOGGER.throwing(e);
throw e;
}
V1ServiceAccount result = sas.get(0);
LOGGER.exiting(result);
return result;
}
Aggregations