2
2
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
3
3
package com .oracle .cloud .spring .vault ;
4
4
5
- import java .io .IOException ;
6
-
7
- import com .oracle .bmc .auth .RegionProvider ;
8
- import com .oracle .bmc .secrets .Secrets ;
9
- import com .oracle .bmc .vault .Vaults ;
10
- import com .oracle .cloud .spring .autoconfigure .core .CredentialsProperties ;
11
- import com .oracle .cloud .spring .autoconfigure .core .CredentialsProvider ;
12
- import com .oracle .cloud .spring .autoconfigure .core .RegionProperties ;
13
5
import org .springframework .boot .SpringApplication ;
14
6
import org .springframework .boot .context .config .ConfigDataEnvironmentPostProcessor ;
15
- import org .springframework .boot .context .properties .bind .Bindable ;
16
- import org .springframework .boot .context .properties .bind .Binder ;
17
7
import org .springframework .boot .env .EnvironmentPostProcessor ;
18
8
import org .springframework .core .Ordered ;
19
9
import org .springframework .core .env .ConfigurableEnvironment ;
20
- import org .springframework .core .env .MutablePropertySources ;
21
10
import org .springframework .util .ClassUtils ;
22
11
23
- import static com .oracle .cloud .spring .autoconfigure .core .RegionProviderAutoConfiguration .createRegionProvider ;
24
- import static com .oracle .cloud .spring .vault .VaultAutoConfiguration .createSecretsClient ;
25
- import static com .oracle .cloud .spring .vault .VaultAutoConfiguration .createVaultClient ;
26
- import static org .springframework .core .env .StandardEnvironment .SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME ;
27
-
28
12
/**
29
13
* Injects a VaultPropertySource for each OCI Vault property source specified in the application properties.
30
14
* OCI Vault property sources will only be loaded if the com.oracle.cloud.spring.vault.VaulTemplate class is on the classpath.
@@ -33,33 +17,7 @@ public class VaultEnvironmentPostProcessor implements EnvironmentPostProcessor,
33
17
@ Override
34
18
public void postProcessEnvironment (ConfigurableEnvironment environment , SpringApplication application ) {
35
19
if (areClassesLoaded ()) {
36
- // Load Vault Properties
37
- Binder binder = Binder .get (environment );
38
- CredentialsProperties credentialsProperties = binder .bind (CredentialsProperties .PREFIX , Bindable .of (CredentialsProperties .class ))
39
- .orElse (new CredentialsProperties ());
40
- RegionProperties regionProperties = binder .bind (RegionProperties .PREFIX , Bindable .of (RegionProperties .class ))
41
- .orElse (new RegionProperties ());
42
- VaultProperties vaultProperties = binder .bind (VaultProperties .PREFIX , Bindable .of (VaultProperties .class ))
43
- .orElse (new VaultProperties ());
44
-
45
- // Create vault/secrets clients
46
- RegionProvider regionProvider = createRegionProvider (regionProperties );
47
- CredentialsProvider credentialsProvider = getCredentialsProvider (credentialsProperties );
48
- Secrets secretsClient = createSecretsClient (regionProvider , credentialsProvider );
49
- Vaults vaultClient = createVaultClient (regionProvider , credentialsProvider );
50
-
51
- // Inject VaultPropertySources into the system property sources
52
- MutablePropertySources propertySources = environment .getPropertySources ();
53
- for (VaultPropertySourceProperties properties : vaultProperties .getPropertySources ()) {
54
- VaultTemplate vaultTemplate = new VaultTemplateImpl (vaultClient , secretsClient , properties .getVaultId (), vaultProperties .getCompartment ());
55
- VaultPropertyLoader vaultPropertyLoader = new VaultPropertyLoader (vaultTemplate , vaultProperties .getPropertyRefreshInterval ());
56
- VaultPropertySource vaultPropertySource = new VaultPropertySource (properties .getVaultId (), vaultPropertyLoader );
57
- if (propertySources .contains (SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME )) {
58
- propertySources .addAfter (SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME , vaultPropertySource );
59
- } else {
60
- propertySources .addFirst (vaultPropertySource );
61
- }
62
- }
20
+ VaultPropertySource .configure (environment );
63
21
}
64
22
}
65
23
@@ -71,12 +29,4 @@ public int getOrder() {
71
29
private boolean areClassesLoaded () {
72
30
return ClassUtils .isPresent ("com.oracle.cloud.spring.vault.VaultTemplate" , VaultEnvironmentPostProcessor .class .getClassLoader ());
73
31
}
74
-
75
- private CredentialsProvider getCredentialsProvider (CredentialsProperties credentialsProperties ) {
76
- try {
77
- return new CredentialsProvider (credentialsProperties );
78
- } catch (IOException e ) {
79
- throw new RuntimeException (e );
80
- }
81
- }
82
32
}
0 commit comments