Polishing.

Improve null handling.

See gh-112.
This commit is contained in:
Mark Paluch
2017-07-14 22:27:22 +02:00
parent 14bbb44199
commit 41a75fce38
6 changed files with 50 additions and 77 deletions

View File

@@ -43,6 +43,7 @@ import org.springframework.vault.support.VaultMount;
import org.springframework.vault.support.VaultResponseSupport;
import org.springframework.vault.support.VaultToken;
import org.springframework.vault.support.VaultUnsealStatus;
import org.springframework.vault.support.VaultMount.VaultMountBuilder;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestOperations;
@@ -268,19 +269,25 @@ public class VaultSysTemplate implements VaultSysOperations {
@JsonAnySetter
public void set(String name, Object value) {
if (value instanceof Map) {
if (!(value instanceof Map)) {
return;
}
Map<String, Object> map = (Map) value;
Map<String, Object> map = (Map) value;
if (map.containsKey("type")) {
if (map.containsKey("type")) {
VaultMount vaultMount = VaultMount.builder() //
.type((String) map.get("type")) //
.description((String) map.get("description")) //
.config((Map) map.get("config")).build();
VaultMountBuilder builder = VaultMount.builder() //
.type((String) map.get("type")) //
.description((String) map.get("description"));// ;
topLevelMounts.put(name, vaultMount);
if (map.containsKey("config")) {
builder.config((Map) map.get("config"));
}
VaultMount vaultMount = builder.build();
topLevelMounts.put(name, vaultMount);
}
}
}

View File

@@ -60,14 +60,13 @@ public class VaultCertificateRequest {
VaultCertificateRequest(String commonName, List<String> altNames,
List<String> ipSubjectAltNames, @Nullable Duration ttl,
@Nullable Boolean excludeCommonNameFromSubjectAltNames) {
boolean excludeCommonNameFromSubjectAltNames) {
this.commonName = commonName;
this.altNames = altNames;
this.ipSubjectAltNames = ipSubjectAltNames;
this.ttl = ttl;
this.excludeCommonNameFromSubjectAltNames = excludeCommonNameFromSubjectAltNames != null
&& excludeCommonNameFromSubjectAltNames.booleanValue();
this.excludeCommonNameFromSubjectAltNames = excludeCommonNameFromSubjectAltNames;
}
/**
@@ -118,8 +117,7 @@ public class VaultCertificateRequest {
@Nullable
private Duration ttl;
@Nullable
private Boolean excludeCommonNameFromSubjectAltNames;
private boolean excludeCommonNameFromSubjectAltNames;
VaultCertificateRequestBuilder() {
}

View File

@@ -50,9 +50,10 @@ public class VaultMount {
*/
private final Map<String, Object> config;
private VaultMount(@JsonProperty("type") String type,
VaultMount(@JsonProperty("type") String type,
@Nullable @JsonProperty("description") String description,
@Nullable @JsonProperty("config") Map<String, Object> config) {
this.type = type;
this.description = description;
this.config = config != null ? config : Collections.emptyMap();

View File

@@ -42,15 +42,12 @@ public class VaultTokenRequest {
private final Map<String, String> meta;
@Nullable
private final Boolean noParent;
private final boolean noParent;
@JsonProperty("no_default_policy")
@Nullable
private final Boolean noDefaultPolicy;
private final boolean noDefaultPolicy;
@Nullable
private final Boolean renewable;
private final boolean renewable;
@Nullable
private final String ttl;
@@ -60,18 +57,15 @@ public class VaultTokenRequest {
private final String explicitMaxTtl;
@JsonProperty("display_name")
@Nullable
private final String displayName;
@JsonProperty("num_uses")
@Nullable
private final Integer numUses;
private final int numUses;
VaultTokenRequest(@Nullable String id, List<String> policies,
Map<String, String> meta, @Nullable Boolean noParent,
@Nullable Boolean noDefaultPolicy, @Nullable Boolean renewable,
@Nullable String ttl, @Nullable String explicitMaxTtl,
@Nullable String displayName, @Nullable Integer numUses) {
Map<String, String> meta, boolean noParent, boolean noDefaultPolicy,
boolean renewable, @Nullable String ttl, @Nullable String explicitMaxTtl,
String displayName, int numUses) {
this.id = id;
this.policies = policies;
@@ -110,7 +104,6 @@ public class VaultTokenRequest {
}
/**
*
* @return map of string to string valued metadata, passed through to the audit
* backends.
*/
@@ -119,34 +112,27 @@ public class VaultTokenRequest {
}
/**
*
* @return {@literal true} if the token should not have the parent.
*/
@Nullable
public Boolean getNoParent() {
public boolean getNoParent() {
return noParent;
}
/**
*
* @return {@literal true} if the default policy should not be be applied.
*/
@Nullable
public Boolean getNoDefaultPolicy() {
public boolean getNoDefaultPolicy() {
return noDefaultPolicy;
}
/**
*
* @return {@literal true} if then the token should be renewable.
*/
@Nullable
public Boolean getRenewable() {
public boolean getRenewable() {
return renewable;
}
/**
*
* @return TTL period of the token.
*/
@Nullable
@@ -155,7 +141,6 @@ public class VaultTokenRequest {
}
/**
*
* @return explicit TTL of the token.
*/
@Nullable
@@ -164,20 +149,16 @@ public class VaultTokenRequest {
}
/**
*
* @return the display name.
*/
@Nullable
public String getDisplayName() {
return displayName;
}
/**
*
* @return the number of allowed token uses.
*/
@Nullable
public Integer getNumUses() {
public int getNumUses() {
return numUses;
}
@@ -193,14 +174,11 @@ public class VaultTokenRequest {
private Map<String, String> meta = new LinkedHashMap<>();
@Nullable
private Boolean noParent;
private boolean noParent;
@Nullable
private Boolean noDefaultPolicy;
private boolean noDefaultPolicy;
@Nullable
private Boolean renewable;
private boolean renewable;
@Nullable
private String ttl;
@@ -208,11 +186,9 @@ public class VaultTokenRequest {
@Nullable
private String explicitMaxTtl;
@Nullable
private String displayName;
private String displayName = "";
@Nullable
private Integer numUses;
private int numUses;
VaultTokenRequestBuilder() {
}
@@ -289,6 +265,7 @@ public class VaultTokenRequest {
* @return {@code this} {@link VaultTokenRequestBuilder}.
*/
public VaultTokenRequestBuilder noParent(boolean noParent) {
this.noParent = noParent;
return this;
}
@@ -332,6 +309,7 @@ public class VaultTokenRequest {
* @return {@code this} {@link VaultTokenRequestBuilder}.
*/
public VaultTokenRequestBuilder renewable(boolean renewable) {
this.renewable = renewable;
return this;
}

View File

@@ -36,6 +36,7 @@ public class VaultTransitKeyConfiguration {
private VaultTransitKeyConfiguration(@Nullable Boolean deletionAllowed,
@Nullable Integer latestVersion) {
this.deletionAllowed = deletionAllowed;
this.latestVersion = latestVersion;
}

View File

@@ -17,7 +17,6 @@ package org.springframework.vault.support;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -28,21 +27,18 @@ import org.springframework.util.Assert;
*/
public class VaultTransitKeyCreationRequest {
@Nullable
private final Boolean derived;
private final boolean derived;
@JsonProperty("type")
private final String type;
@JsonProperty("convergent_encryption")
@Nullable
private final Boolean convergentEncryption;
private final boolean convergentEncryption;
@Nullable
private final Boolean exportable;
private final boolean exportable;
private VaultTransitKeyCreationRequest(@Nullable Boolean derived, String type,
@Nullable Boolean convergentEncryption, @Nullable Boolean exportable) {
private VaultTransitKeyCreationRequest(boolean derived, String type,
boolean convergentEncryption, boolean exportable) {
this.derived = derived;
this.type = type;
this.convergentEncryption = convergentEncryption;
@@ -60,8 +56,7 @@ public class VaultTransitKeyCreationRequest {
*
* @return {@literal true} if key derivation MUST be used.
*/
@Nullable
public Boolean getDerived() {
public boolean getDerived() {
return derived;
}
@@ -70,8 +65,7 @@ public class VaultTransitKeyCreationRequest {
* @return {@literal true} if convergent encryption should be used (where the same
* plaintext creates the same cipher text).
*/
@Nullable
public Boolean getConvergentEncryption() {
public boolean getConvergentEncryption() {
return convergentEncryption;
}
@@ -87,8 +81,7 @@ public class VaultTransitKeyCreationRequest {
*
* @return {@literal true} if key MUST be exportable.
*/
@Nullable
public Boolean getExportable() {
public boolean getExportable() {
return this.exportable;
}
@@ -97,15 +90,10 @@ public class VaultTransitKeyCreationRequest {
*/
public static class VaultTransitKeyCreationRequestBuilder {
@Nullable
private Boolean derived;
private boolean derived;
private String type = "aes256-gcm96";
@Nullable
private Boolean convergentEncryption;
@Nullable
private Boolean exportable;
private boolean convergentEncryption;
private boolean exportable;
VaultTransitKeyCreationRequestBuilder() {
}