Skip to content

Commit

Permalink
Allow disabled the secret manager
Browse files Browse the repository at this point in the history
  • Loading branch information
loicmathieu committed Sep 11, 2023
1 parent e2dc8c9 commit a012db8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,10 @@ public interface GcpBootstrapConfiguration {
*/
@WithDefault("true")
boolean accessTokenEnabled();

/**
* Whether to enable the secret manager
*/
@WithDefault("true")
boolean secretManagerEnabled();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

# Secret Manager Demo
# You can load secrets from Google Cloud Secret Manager with the ${sm//<SECRET_ID>} syntax.
my.database.password=${sm//integration-test}
%prod.my.database.password=${sm//integration-test}
%test.my.database.password=test
%test.quarkus.google.cloud.secret-manager-enabled=false

## Logging config
%dev.quarkus.google.cloud.logging.enabled=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.secretmanager.v1.AccessSecretVersionResponse;
import com.google.cloud.secretmanager.v1.SecretManagerServiceClient;
Expand All @@ -32,8 +33,13 @@ public class SecretManagerConfigSource extends AbstractConfigSource {
public SecretManagerConfigSource(final GcpBootstrapConfiguration gcpConfig, final String projectId) {
super(CONFIG_SOURCE_NAME, SECRET_MANAGER_ORDINAL);
this.projectId = projectId;
this.client = createClient(gcpConfig, projectId);
this.closed = new AtomicBoolean(false);
if (gcpConfig.secretManagerEnabled()) {
this.client = createClient(gcpConfig, projectId);
this.closed = new AtomicBoolean(false);
} else {
this.client = null;
this.closed = new AtomicBoolean(true);
}
}

@Override
Expand Down Expand Up @@ -75,7 +81,7 @@ private static SecretManagerServiceClient createClient(
return SecretManagerServiceClient.create(
SecretManagerServiceSettings.newBuilder()
.setQuotaProjectId(projectId)
.setCredentialsProvider(() -> credentials(gcpConfig))
.setCredentialsProvider(FixedCredentialsProvider.create(credentials(gcpConfig)))
.build());
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down

0 comments on commit a012db8

Please sign in to comment.