Skip to content

Commit 57c478f

Browse files
authored
Merge pull request #4 from jarrodcodes/vault-1+
Vault 1+
2 parents 0a3b1c9 + d2864ce commit 57c478f

3 files changed

Lines changed: 22 additions & 9 deletions

File tree

src/main/java/com/bettercloud/vault/Vault.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public class Vault {
6565
*/
6666
public Vault(final VaultConfig vaultConfig) {
6767
this.vaultConfig = vaultConfig;
68+
if (this.vaultConfig.getNameSpace() != null && !this.vaultConfig.getNameSpace().isEmpty()) {
69+
System.out.println(String.format("The NameSpace %s has been bound to this Vault instance. Please keep this in mind when running operations.", this.vaultConfig.getNameSpace()));
70+
}
6871
if (this.vaultConfig.getSecretsEnginePathMap().isEmpty() && this.vaultConfig.getGlobalEngineVersion() == null) {
6972
System.out.println("Constructing a Vault instance with no provided Engine version, defaulting to version 2.");
7073
this.vaultConfig.setEngineVersion(2);
@@ -81,6 +84,9 @@ public Vault(final VaultConfig vaultConfig, final Integer engineVersion) {
8184
}
8285
vaultConfig.setEngineVersion(engineVersion);
8386
this.vaultConfig = vaultConfig;
87+
if (this.vaultConfig.getNameSpace() != null && !this.vaultConfig.getNameSpace().isEmpty()) {
88+
System.out.println(String.format("The Namespace %s has been bound to this Vault instance. Please keep this in mind when running operations.", this.vaultConfig.getNameSpace()));
89+
}
8490
}
8591

8692
/**
@@ -97,6 +103,9 @@ public Vault(final VaultConfig vaultConfig, final Integer engineVersion) {
97103
public Vault(final VaultConfig vaultConfig, final Boolean useSecretsEnginePathMap, final Integer globalFallbackVersion)
98104
throws VaultException {
99105
this.vaultConfig = vaultConfig;
106+
if (this.vaultConfig.getNameSpace() != null && !this.vaultConfig.getNameSpace().isEmpty()) {
107+
System.out.println(String.format("The Namespace %s has been bound to this Vault instance. Please keep this in mind when running operations.", this.vaultConfig.getNameSpace()));
108+
}
100109
this.vaultConfig.setEngineVersion(globalFallbackVersion);
101110
if (useSecretsEnginePathMap && this.vaultConfig.getSecretsEnginePathMap().isEmpty()) {
102111
try {

src/main/java/com/bettercloud/vault/VaultConfig.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,11 @@ public VaultConfig environmentLoader(final EnvironmentLoader environmentLoader)
8484
* @return This object, with the namespace populated, ready for additional builder-pattern method calls or else
8585
* finalization with the build() method
8686
*/
87-
public VaultConfig nameSpace(final String nameSpace) {
88-
this.nameSpace = nameSpace;
89-
return this;
87+
public VaultConfig nameSpace(final String nameSpace) throws VaultException {
88+
if (nameSpace != null && !nameSpace.isEmpty()) {
89+
this.nameSpace = nameSpace;
90+
return this;
91+
} else throw new VaultException("A namespace cannot be empty.");
9092
}
9193

9294
/**

src/test/java/com/bettercloud/vault/VaultTests.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,19 @@ public void testGlobalEngineVersionVaultConstructor() {
2929
}
3030

3131
@Test
32-
public void testNameSpaceProvidedVaultConstructor() {
33-
VaultConfig vaultConfig = new VaultConfig().nameSpace("namespace");
32+
public void testNameSpaceProvidedVaultConstructor() throws VaultException {
33+
VaultConfig vaultConfig = new VaultConfig().nameSpace("testNameSpace");
3434
Vault vault = new Vault(vaultConfig, 1);
3535
Assert.assertNotNull(vault);
3636
}
3737

3838
@Test
39-
public void testNameSpaceNotProvidedVaultConstructor() {
40-
VaultConfig vaultConfig = new VaultConfig().nameSpace(null);
41-
Vault vault = new Vault(vaultConfig, 1);
42-
Assert.assertNotNull(vault);
39+
public void testNameSpaceProvidedVaultConstructorCannotBeEmpty() {
40+
try {
41+
VaultConfig vaultConfig = new VaultConfig().nameSpace("");
42+
} catch (VaultException e) {
43+
Assert.assertEquals(e.getMessage(), "A namespace cannot be empty.");
44+
}
4345
}
4446

4547
@Test(expected = IllegalArgumentException.class)

0 commit comments

Comments
 (0)