Search in sources :

Example 26 with Secret

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret 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();
    }
}
Also used : Node(com.marcnuri.yakc.model.io.k8s.api.core.v1.Node) KC(com.marcnuri.yakc.KubernetesClientExtension.KC) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ServiceAccount(com.marcnuri.yakc.model.io.k8s.api.core.v1.ServiceAccount) IOException(java.io.IOException) Secret(com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret) Test(org.junit.jupiter.api.Test) CoreV1Api(com.marcnuri.yakc.api.core.v1.CoreV1Api) ObjectMeta(com.marcnuri.yakc.model.io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta) Configuration(com.marcnuri.yakc.config.Configuration) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) ObjectReference(com.marcnuri.yakc.model.io.k8s.api.core.v1.ObjectReference) Secret(com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret) ServiceAccount(com.marcnuri.yakc.model.io.k8s.api.core.v1.ServiceAccount) ObjectReference(com.marcnuri.yakc.model.io.k8s.api.core.v1.ObjectReference)

Example 27 with Secret

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret in project yakc by manusa.

the class SecretIT method readNamespacedSecret.

@Test
@DisplayName("readNamespacedSecret, should read newly created Secret")
void readNamespacedSecret() throws IOException {
    // When
    final Secret secretFromServer = KC.create(CoreV1Api.class).readNamespacedSecret(secretName, NAMESPACE).get();
    // Then
    assertThat(secretFromServer).isNotNull().hasFieldOrPropertyWithValue("metadata.name", secretName).extracting(Secret::getData).asInstanceOf(InstanceOfAssertFactories.MAP).hasSize(3).containsEntry("FOO", "QkFS");
}
Also used : Secret(com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

Secret (com.google.cloud.secretmanager.v1.Secret)21 ProjectName (com.google.cloud.secretmanager.v1.ProjectName)11 SecretManagerServiceClient (com.google.cloud.secretmanager.v1.SecretManagerServiceClient)11 SecretName (com.google.cloud.secretmanager.v1.SecretName)5 CreateSecretRequest (com.google.cloud.secretmanager.v1.CreateSecretRequest)4 ByteString (com.google.protobuf.ByteString)4 Secret (com.google.cloud.secretmanager.v1beta1.Secret)3 FieldMask (com.google.protobuf.FieldMask)3 Secret (com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret)3 Test (org.junit.Test)3 Test (org.junit.jupiter.api.Test)3 AccessSecretVersionResponse (com.google.cloud.secretmanager.v1.AccessSecretVersionResponse)2 ListSecretsRequest (com.google.cloud.secretmanager.v1.ListSecretsRequest)2 ListSecretsPagedResponse (com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretsPagedResponse)2 SecretPayload (com.google.cloud.secretmanager.v1.SecretPayload)2 SecretVersion (com.google.cloud.secretmanager.v1.SecretVersion)2 Configuration (com.marcnuri.yakc.config.Configuration)2 Node (com.marcnuri.yakc.model.io.k8s.api.core.v1.Node)2 ArrayList (java.util.ArrayList)2 AddSecretVersionRequest (com.google.cloud.secretmanager.v1beta1.AddSecretVersionRequest)1