TokenBuilder with policies as vararg
This commit is contained in:
parent
d7e4e7e5be
commit
ce2de2df81
@ -18,10 +18,7 @@ package de.stklcode.jvault.connector.model;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A builder for vault tokens.
|
* A builder for vault tokens.
|
||||||
@ -144,6 +141,19 @@ public class TokenBuilder {
|
|||||||
return withNoDefaultPolicy(true);
|
return withNoDefaultPolicy(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add given policies
|
||||||
|
*
|
||||||
|
* @param policies the policies
|
||||||
|
* @return self
|
||||||
|
* @since 0.5.0
|
||||||
|
*/
|
||||||
|
public TokenBuilder withPolicies(final String... policies) {
|
||||||
|
if (this.policies == null)
|
||||||
|
return withPolicies(Arrays.asList(policies));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add given policies
|
* Add given policies
|
||||||
*
|
*
|
||||||
|
@ -45,7 +45,8 @@ public class TokenBuilderTest {
|
|||||||
private static final Integer NUM_USES = 4;
|
private static final Integer NUM_USES = 4;
|
||||||
private static final List<String> POLICIES = new ArrayList<>();
|
private static final List<String> POLICIES = new ArrayList<>();
|
||||||
private static final String POLICY = "policy";
|
private static final String POLICY = "policy";
|
||||||
private static final String POLICY_2 = "policy";
|
private static final String POLICY_2 = "policy2";
|
||||||
|
private static final String POLICY_3 = "policy3";
|
||||||
private static final Map<String, String> META = new HashMap<>();
|
private static final Map<String, String> META = new HashMap<>();
|
||||||
private static final String META_KEY = "key";
|
private static final String META_KEY = "key";
|
||||||
private static final String META_VALUE = "value";
|
private static final String META_VALUE = "value";
|
||||||
@ -138,11 +139,11 @@ public class TokenBuilderTest {
|
|||||||
assertThat(token.getPolicies(), hasSize(1));
|
assertThat(token.getPolicies(), hasSize(1));
|
||||||
assertThat(token.getPolicies(), contains(POLICY_2));
|
assertThat(token.getPolicies(), contains(POLICY_2));
|
||||||
token = new TokenBuilder()
|
token = new TokenBuilder()
|
||||||
.withPolicies(POLICIES)
|
.withPolicies(POLICY, POLICY_2)
|
||||||
.withPolicy(POLICY_2)
|
.withPolicy(POLICY_3)
|
||||||
.build();
|
.build();
|
||||||
assertThat(token.getPolicies(), hasSize(2));
|
assertThat(token.getPolicies(), hasSize(3));
|
||||||
assertThat(token.getPolicies(), contains(POLICY, POLICY_2));
|
assertThat(token.getPolicies(), contains(POLICY, POLICY_2, POLICY_3));
|
||||||
|
|
||||||
/* Add single metadata */
|
/* Add single metadata */
|
||||||
token = new TokenBuilder().withMeta(META_KEY_2, META_VALUE_2).build();
|
token = new TokenBuilder().withMeta(META_KEY_2, META_VALUE_2).build();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user