Skip to content

Commit c169218

Browse files
authored
Merge pull request #9608 from vsevel/credentials_rename_field
Rename credentials-provider-type into credentials-provider-name
2 parents dcbdf1a + 9963802 commit c169218

File tree

6 files changed

+17
-25
lines changed

6 files changed

+17
-25
lines changed

docs/src/main/asciidoc/credentials-provider.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,12 @@ First, you need to name it to avoid collisions in case multiple credentials prov
175175
public class MyCredentialsProvider implements CredentialsProvider {
176176
----
177177

178-
It is the responsibility of the consumer to allow a `credentials-provider-type` property:
178+
It is the responsibility of the consumer to allow a `credentials-provider-name` property:
179179

180180
[source, properties]
181181
----
182182
quarkus.datasource.credentials-provider = custom
183-
quarkus.datasource.credentials-provider-type = my-credentials-provider
183+
quarkus.datasource.credentials-provider-name = my-credentials-provider
184184
----
185185

186186
The extension should allow runtime config, such as the `CredentialsProviderConfig` from the `vault` extension

extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSources.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import io.quarkus.agroal.runtime.DataSourcesJdbcRuntimeConfig.DataSourceJdbcOuterNamedRuntimeConfig;
3939
import io.quarkus.agroal.runtime.JdbcDriver.JdbcDriverLiteral;
4040
import io.quarkus.arc.Arc;
41-
import io.quarkus.arc.ArcContainer;
4241
import io.quarkus.arc.InstanceHandle;
4342
import io.quarkus.credentials.CredentialsProvider;
4443
import io.quarkus.credentials.runtime.CredentialsProviderFinder;
@@ -53,7 +52,7 @@
5352

5453
/**
5554
* This class is sort of a producer for {@link AgroalDataSource}.
56-
*
55+
* <p>
5756
* It isn't a CDI producer in the literal sense, but it created a synthetic bean
5857
* from {@code AgroalProcessor}
5958
* The {@code createDataSource} method is called at runtime (see
@@ -105,11 +104,11 @@ public DataSources(DataSourcesBuildTimeConfig dataSourcesBuildTimeConfig,
105104
* Meant to be used from recorders that create synthetic beans that need access to {@code Datasource}.
106105
* In such using {@code Arc.container.instance(DataSource.class)} is not possible because
107106
* {@code Datasource} is itself a synthetic bean.
108-
*
107+
* <p>
109108
* This method relies on the fact that {@code DataSources} should - given the same input -
110109
* always return the same {@code AgroalDataSource} no matter how many times it is invoked
111110
* (which makes sense because {@code DataSource} is a {@code Singleton} bean).
112-
*
111+
* <p>
113112
* This method is thread-safe
114113
*/
115114
public static AgroalDataSource fromName(String dataSourceName) {
@@ -266,8 +265,8 @@ private void applyNewConfiguration(AgroalDataSourceConfigurationSupplier dataSou
266265

267266
// credentials provider
268267
if (dataSourceRuntimeConfig.credentialsProvider.isPresent()) {
269-
String type = dataSourceRuntimeConfig.credentialsProviderType.orElse(null);
270-
CredentialsProvider credentialsProvider = CredentialsProviderFinder.find(type);
268+
String beanName = dataSourceRuntimeConfig.credentialsProviderName.orElse(null);
269+
CredentialsProvider credentialsProvider = CredentialsProviderFinder.find(beanName);
271270
String name = dataSourceRuntimeConfig.credentialsProvider.get();
272271
connectionFactoryConfiguration
273272
.credential(new AgroalVaultCredentialsProviderPassword(name, credentialsProvider));
@@ -361,17 +360,10 @@ private void applyLegacyConfiguration(AgroalDataSourceConfigurationSupplier data
361360
.credential(new SimplePassword(dataSourceRuntimeConfig.password.get()));
362361
}
363362

364-
// Vault credentials provider
363+
// credentials provider
365364
if (dataSourceRuntimeConfig.credentialsProvider.isPresent()) {
366-
ArcContainer container = Arc.container();
367-
String type = dataSourceRuntimeConfig.credentialsProviderType.orElse(null);
368-
CredentialsProvider credentialsProvider = type != null
369-
? (CredentialsProvider) container.instance(type).get()
370-
: container.instance(CredentialsProvider.class).get();
371-
372-
if (credentialsProvider == null) {
373-
throw new RuntimeException("unable to find credentials provider of type " + (type == null ? "default" : type));
374-
}
365+
String beanName = dataSourceRuntimeConfig.credentialsProviderName.orElse(null);
366+
CredentialsProvider credentialsProvider = CredentialsProviderFinder.find(beanName);
375367

376368
String name = dataSourceRuntimeConfig.credentialsProvider.get();
377369
connectionFactoryConfiguration

extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DataSourceRuntimeConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ public class DataSourceRuntimeConfig {
2727
public Optional<String> credentialsProvider = Optional.empty();
2828

2929
/**
30-
* The credentials provider type.
30+
* The credentials provider bean name.
3131
* <p>
3232
* It is the {@code &#64;Named} value of the credentials provider bean. It is used to discriminate if multiple
3333
* CredentialsProvider beans are available.
3434
* <p>
3535
* For Vault it is: vault-credentials-provider. Not necessary if there is only one credentials provider available.
3636
*/
3737
@ConfigItem
38-
public Optional<String> credentialsProviderType = Optional.empty();
38+
public Optional<String> credentialsProviderName = Optional.empty();
3939
}

extensions/reactive-mysql-client/runtime/src/main/java/io/quarkus/reactive/mysql/client/runtime/MySQLPoolRecorder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ private MySQLConnectOptions toMySQLConnectOptions(DataSourceRuntimeConfig dataSo
9898

9999
// credentials provider
100100
if (dataSourceRuntimeConfig.credentialsProvider.isPresent()) {
101-
String type = dataSourceRuntimeConfig.credentialsProviderType.orElse(null);
102-
CredentialsProvider credentialsProvider = CredentialsProviderFinder.find(type);
101+
String beanName = dataSourceRuntimeConfig.credentialsProviderName.orElse(null);
102+
CredentialsProvider credentialsProvider = CredentialsProviderFinder.find(beanName);
103103
String name = dataSourceRuntimeConfig.credentialsProvider.get();
104104
Map<String, String> credentials = credentialsProvider.getCredentials(name);
105105
String user = credentials.get(USER_PROPERTY_NAME);

extensions/reactive-pg-client/runtime/src/main/java/io/quarkus/reactive/pg/client/runtime/PgPoolRecorder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ private PgConnectOptions toPgConnectOptions(DataSourceRuntimeConfig dataSourceRu
100100

101101
// credentials provider
102102
if (dataSourceRuntimeConfig.credentialsProvider.isPresent()) {
103-
String type = dataSourceRuntimeConfig.credentialsProviderType.orElse(null);
104-
CredentialsProvider credentialsProvider = CredentialsProviderFinder.find(type);
103+
String beanName = dataSourceRuntimeConfig.credentialsProviderName.orElse(null);
104+
CredentialsProvider credentialsProvider = CredentialsProviderFinder.find(beanName);
105105
String name = dataSourceRuntimeConfig.credentialsProvider.get();
106106
Map<String, String> credentials = credentialsProvider.getCredentials(name);
107107
String user = credentials.get(USER_PROPERTY_NAME);

integration-tests/vault-agroal/src/test/resources/application-vault-datasource.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ quarkus.datasource.staticDS.jdbc.url=jdbc:postgresql://localhost:6543/mydb
1919
quarkus.datasource.dynamicDS.db-kind=postgresql
2020
quarkus.datasource.dynamicDS.username=postgres
2121
quarkus.datasource.dynamicDS.credentials-provider=dynamic-ds
22-
quarkus.datasource.dynamicDS.credentials-provider-type=vault-credentials-provider
22+
quarkus.datasource.dynamicDS.credentials-provider-name=vault-credentials-provider
2323
quarkus.datasource.dynamicDS.jdbc.url=jdbc:postgresql://localhost:6543/mydb
2424

2525
quarkus.log.category."io.quarkus.vault".level=DEBUG

0 commit comments

Comments
 (0)