Search in sources :

Example 11 with V1ServiceAccount

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);
}
Also used : Type(java.lang.reflect.Type) V1ServiceAccount(io.kubernetes.client.models.V1ServiceAccount)

Example 12 with V1ServiceAccount

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
}
Also used : V1ServiceAccount(io.kubernetes.client.models.V1ServiceAccount) Test(org.junit.Test)

Example 13 with V1ServiceAccount

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;
}
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 14 with V1ServiceAccount

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;
}
Also used : V1ServiceAccountList(io.kubernetes.client.models.V1ServiceAccountList) ArrayList(java.util.ArrayList) V1ServiceAccount(io.kubernetes.client.models.V1ServiceAccount) ApiException(io.kubernetes.client.ApiException)

Aggregations

V1ServiceAccount (io.kubernetes.client.models.V1ServiceAccount)14 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)2 V1ServiceAccountList (io.kubernetes.client.models.V1ServiceAccountList)2 V1ObjectReference (io.kubernetes.client.models.V1ObjectReference)1 V1Secret (io.kubernetes.client.models.V1Secret)1 ArrayList (java.util.ArrayList)1