-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Python clients (#165)
- Changes vault auto-config to only add port number when it is not 443 - Adds example links to readme - Clarifies port configuration in case of Docker container {patch} Signed-off-by: Esta Nagy <[email protected]>
- Loading branch information
Showing
4 changed files
with
105 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...ey-vault-app/src/main/java/com/github/nagyesta/lowkeyvault/context/util/VaultUriUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.github.nagyesta.lowkeyvault.context.util; | ||
|
||
import lombok.NonNull; | ||
|
||
import java.net.URI; | ||
|
||
public final class VaultUriUtil { | ||
|
||
private static final int DEFAULT_HTTPS_PORT = 443; | ||
private static final String HTTPS_SCHEME = "https://"; | ||
|
||
private VaultUriUtil() { | ||
throw new IllegalCallerException("Utility cannot be instantiated."); | ||
} | ||
|
||
public static URI vaultUri(@NonNull final String hostname, final int optionalPort) { | ||
final StringBuilder builder = new StringBuilder(HTTPS_SCHEME).append(hostname); | ||
if (optionalPort != DEFAULT_HTTPS_PORT) { | ||
builder.append(":").append(optionalPort); | ||
} | ||
return URI.create(builder.toString()); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...ault-app/src/test/java/com/github/nagyesta/lowkeyvault/context/util/VaultUriUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.github.nagyesta.lowkeyvault.context.util; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.net.URI; | ||
import java.util.stream.Stream; | ||
|
||
class VaultUriUtilTest { | ||
|
||
@SuppressWarnings("checkstyle:MagicNumber") | ||
public static Stream<Arguments> validSource() { | ||
return Stream.<Arguments>builder() | ||
.add(Arguments.of("localhost", 443, URI.create("https://localhost"))) | ||
.add(Arguments.of("localhost", 8443, URI.create("https://localhost:8443"))) | ||
.add(Arguments.of("localhost", 8444, URI.create("https://localhost:8444"))) | ||
.add(Arguments.of("lowkey-vault.local", 443, URI.create("https://lowkey-vault.local"))) | ||
.add(Arguments.of("lowkey-vault.local", 8080, URI.create("https://lowkey-vault.local:8080"))) | ||
.add(Arguments.of("lowkey-vault.local", 8443, URI.create("https://lowkey-vault.local:8443"))) | ||
.build(); | ||
} | ||
|
||
@Test | ||
void testConstructorShouldThrowExceptionWhenCalled() throws NoSuchMethodException { | ||
//given | ||
final Constructor<VaultUriUtil> constructor = VaultUriUtil.class.getDeclaredConstructor(); | ||
constructor.setAccessible(true); | ||
|
||
//when | ||
Assertions.assertThrows(InvocationTargetException.class, constructor::newInstance); | ||
|
||
//then + exception | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("validSource") | ||
void testVaultUriShouldOmitPortNumberWhenCalledWithDefault(final String host, final int port, final URI expectedUri) { | ||
//given | ||
|
||
//when | ||
final URI actual = VaultUriUtil.vaultUri(host, port); | ||
|
||
//then | ||
Assertions.assertEquals(expectedUri, actual); | ||
} | ||
|
||
@SuppressWarnings("ConstantConditions") | ||
@Test | ||
void testVaultUriShouldThrowExceptionWhenCalledWithNull() { | ||
//given | ||
|
||
//when | ||
Assertions.assertThrows(IllegalArgumentException.class, () -> VaultUriUtil.vaultUri(null, 1)); | ||
|
||
//then + exception | ||
} | ||
} |