use of com.google.storage.v2.ServiceAccount in project yakc by manusa.
the class AuthIT method retrieveSecretForServiceAccount.
private Secret retrieveSecretForServiceAccount() throws IOException {
final ServiceAccount sa = KC.create(CoreV1Api.class).listNamespacedServiceAccount(NAMESPACE).stream().findFirst().orElseThrow(() -> new AssertionError("No Service Account found"));
final String secretName = sa.getSecrets() == null ? null : sa.getSecrets().stream().findFirst().map(ObjectReference::getName).orElse(null);
if (secretName != null) {
return KC.create(CoreV1Api.class).listNamespacedSecret(NAMESPACE).stream().filter(s -> s.getType().equals("kubernetes.io/service-account-token")).filter(s -> s.getMetadata().getName().equals(secretName)).findAny().orElseThrow(() -> new AssertionError(String.format("Secret %s doesn't exist", secretName)));
} else {
// https://kubernetes.io/docs/concepts/configuration/secret/#service-account-token-secrets
final Secret serviceAccountTokenSecret = Secret.builder().metadata(ObjectMeta.builder().name(sa.getMetadata().getName() + "-token").putInAnnotations("kubernetes.io/service-account.name", sa.getMetadata().getName()).build()).type("kubernetes.io/service-account-token").putInStringData("token", "my-secret-token").build();
return KC.create(CoreV1Api.class).createNamespacedSecret(NAMESPACE, serviceAccountTokenSecret).get();
}
}
use of com.google.storage.v2.ServiceAccount in project yakc by manusa.
the class ServiceAccountIT method deleteNamespacedServiceAccount.
@Test
@DisplayName("deleteNamespacedServiceAccount, should delete existing ServiceAccount")
void deleteNamespacedServiceAccount() throws IOException {
// When
final ServiceAccount result = KC.create(CoreV1Api.class).deleteNamespacedServiceAccount(serviceAccountName, NAMESPACE, DeleteOptions.builder().propagationPolicy("Background").build()).get();
// Then
assertThat(result).isNotNull().extracting(ServiceAccount::getMetadata).hasFieldOrPropertyWithValue("name", serviceAccountName);
}
use of com.google.storage.v2.ServiceAccount in project yakc by manusa.
the class ServiceAccountIT method readNamespacedServiceAccount.
@Test
@DisplayName("readNamespacedServiceAccount, should read newly created ServiceAccount")
void readNamespacedServiceAccount() throws IOException {
// When
final ServiceAccount serviceAccountFromServer = KC.create(CoreV1Api.class).readNamespacedServiceAccount(serviceAccountName, NAMESPACE).get();
// Then
assertThat(serviceAccountFromServer).isNotNull().hasFieldOrPropertyWithValue("metadata.name", serviceAccountName).extracting(ServiceAccount::getSecrets).asList().hasSizeGreaterThanOrEqualTo(1).element(0).hasFieldOrPropertyWithValue("name", "doesnt-exist");
}
Aggregations