Skip to content

Commit e3dd3a6

Browse files
Merge pull request #109 from khos2ow/sys-mounts-api
Implementation of /v1/sys/mounts backend
2 parents 36c9465 + 3254b68 commit e3dd3a6

13 files changed

Lines changed: 1306 additions & 1 deletion

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ build/
99
node_modules/
1010
ssl/
1111

12+
bin
13+
.settings
14+
.classpath
15+
.project

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.bettercloud.vault.api.Leases;
66
import com.bettercloud.vault.api.Logical;
77
import com.bettercloud.vault.api.Seal;
8+
import com.bettercloud.vault.api.mounts.Mounts;
89
import com.bettercloud.vault.api.pki.Pki;
910
import com.bettercloud.vault.json.Json;
1011
import com.bettercloud.vault.json.JsonObject;
@@ -209,6 +210,15 @@ public Debug debug() {
209210
return new Debug(vaultConfig);
210211
}
211212

213+
/**
214+
* Returns the implementing class for Vault's sys mounts operations (i.e. <code>/v1/sys/mounts/*</code> REST endpoints).
215+
*
216+
* @return the implementing class for Vault's sys mounts operations
217+
*/
218+
public Mounts mounts() {
219+
return new Mounts(vaultConfig);
220+
}
221+
212222
/**
213223
* Returns the implementing class for Vault's seal operations (e.g. seal, unseal, sealStatus).
214224
*
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.bettercloud.vault.api.mounts;
2+
3+
import java.io.Serializable;
4+
5+
import lombok.Getter;
6+
7+
/**
8+
* <p>A container for options returned by mounts endpoints on the Secret Engine backend. This class is
9+
* meant for use with a builder pattern style. Example usage:</p>
10+
*
11+
* <blockquote>
12+
* <pre>{@code
13+
* final Mount options = new Mount()
14+
* .type(MountType.PKI)
15+
* .description("Some description about the secret engine");
16+
* }</pre>
17+
* </blockquote>
18+
*/
19+
public class Mount implements Serializable {
20+
private static final long serialVersionUID = 45748211702309181L;
21+
22+
@Getter private MountType type;
23+
@Getter private String description;
24+
@Getter private MountConfig config;
25+
@Getter private Boolean local;
26+
@Getter private Boolean sealWrap;
27+
28+
public Mount type(final MountType type) {
29+
this.type = type;
30+
return this;
31+
}
32+
33+
public Mount description(final String description) {
34+
this.description = description;
35+
return this;
36+
}
37+
38+
public Mount config(final MountConfig config) {
39+
this.config = config;
40+
return this;
41+
}
42+
43+
public Mount local(final Boolean local) {
44+
this.local = local;
45+
return this;
46+
}
47+
48+
public Mount sealWrap(final Boolean sealWrap) {
49+
this.sealWrap = sealWrap;
50+
return this;
51+
}
52+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package com.bettercloud.vault.api.mounts;
2+
3+
import java.io.Serializable;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
7+
import lombok.Getter;
8+
9+
/**
10+
* <p>A container for options returned by mounts endpoints on the Secret Engine backend. This class is
11+
* meant for use with a builder pattern style. Example usage:</p>
12+
*
13+
* <p>Most of the time this will be wrapped inside <code>Mount</code> object rather than directly sent to Vault backend
14+
* or back to the user.</p>
15+
*
16+
* <blockquote>
17+
* <pre>{@code
18+
* final MountConfig config = new MountConfig()
19+
* .defaultLeaseTtl(2628000)
20+
* .maxLeaseTtl(2628000)
21+
* .description("description of pki");
22+
* }</pre>
23+
* </blockquote>
24+
*/
25+
public class MountConfig implements Serializable {
26+
private static final long serialVersionUID = 839595627039704093L;
27+
28+
@Getter private Integer defaultLeaseTtl;
29+
@Getter private Integer maxLeaseTtl;
30+
@Getter private String description;
31+
@Getter private Boolean forceNoCache;
32+
@Getter private String pluginName;
33+
private List<String> auditNonHmacRequestKeys;
34+
private List<String> auditNonHmacResponseKeys;
35+
36+
public MountConfig defaultLeaseTtl(final Integer defaultLeaseTtl) {
37+
this.defaultLeaseTtl = defaultLeaseTtl;
38+
return this;
39+
}
40+
41+
public MountConfig maxLeaseTtl(final Integer maxLeaseTtl) {
42+
this.maxLeaseTtl = maxLeaseTtl;
43+
return this;
44+
}
45+
46+
public MountConfig description(final String description) {
47+
this.description = description;
48+
return this;
49+
}
50+
51+
public MountConfig forceNoCache(final Boolean forceNoCache) {
52+
this.forceNoCache = forceNoCache;
53+
return this;
54+
}
55+
56+
public MountConfig pluginName(final String pluginName) {
57+
this.pluginName = pluginName;
58+
return this;
59+
}
60+
61+
public MountConfig auditNonHmacRequestKeys(final List<String> auditNonHmacRequestKeys) {
62+
if (auditNonHmacRequestKeys != null) {
63+
this.auditNonHmacRequestKeys = new ArrayList<>();
64+
this.auditNonHmacRequestKeys.addAll(auditNonHmacRequestKeys);
65+
}
66+
return this;
67+
}
68+
69+
public MountConfig auditNonHmacResponseKeys(final List<String> auditNonHmacResponseKeys) {
70+
if (auditNonHmacResponseKeys != null) {
71+
this.auditNonHmacResponseKeys = new ArrayList<>();
72+
this.auditNonHmacResponseKeys.addAll(auditNonHmacResponseKeys);
73+
}
74+
return this;
75+
}
76+
77+
public List<String> getAuditNonHmacRequestKeys() {
78+
if (auditNonHmacRequestKeys == null) {
79+
return null;
80+
} else {
81+
final List<String> clone = new ArrayList<>();
82+
clone.addAll(auditNonHmacRequestKeys);
83+
return clone;
84+
}
85+
}
86+
87+
public List<String> getAuditNonHmacResponseKeys() {
88+
if (auditNonHmacResponseKeys == null) {
89+
return null;
90+
} else {
91+
final List<String> clone = new ArrayList<>();
92+
clone.addAll(auditNonHmacResponseKeys);
93+
return clone;
94+
}
95+
}
96+
}
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
package com.bettercloud.vault.api.mounts;
2+
3+
import java.io.Serializable;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
import java.util.stream.Collectors;
7+
8+
import com.bettercloud.vault.json.Json;
9+
import com.bettercloud.vault.json.JsonObject;
10+
11+
import lombok.Getter;
12+
13+
/**
14+
* <p>A container for options sent to mounts endpoints on the Secret Engine backend as REST payload. This class is
15+
* meant for use with a builder pattern style. Example usage:</p>
16+
*
17+
* <blockquote>
18+
* <pre>{@code
19+
* final MountPayload payload = new MountPayload()
20+
* .defaultLeaseTtl(TimeToLive.of(30, TimeUnit.MINUTES))
21+
* .maxLeaseTtl(TimeToLive.of(30, TimeUnit.MINUTES))
22+
* .description("description of pki");
23+
* }</pre>
24+
* </blockquote>
25+
*/
26+
public class MountPayload implements Serializable {
27+
private static final long serialVersionUID = 839595627039704093L;
28+
29+
@Getter private TimeToLive defaultLeaseTtl;
30+
@Getter private TimeToLive maxLeaseTtl;
31+
@Getter private String description;
32+
@Getter private Boolean forceNoCache;
33+
@Getter private String pluginName;
34+
@Getter private Boolean local;
35+
@Getter private Boolean sealWrap;
36+
private List<String> auditNonHmacRequestKeys;
37+
private List<String> auditNonHmacResponseKeys;
38+
39+
public MountPayload defaultLeaseTtl(final TimeToLive defaultLeaseTtl) {
40+
this.defaultLeaseTtl = defaultLeaseTtl;
41+
return this;
42+
}
43+
44+
public MountPayload maxLeaseTtl(final TimeToLive maxLeaseTtl) {
45+
this.maxLeaseTtl = maxLeaseTtl;
46+
return this;
47+
}
48+
49+
public MountPayload description(final String description) {
50+
this.description = description;
51+
return this;
52+
}
53+
54+
public MountPayload forceNoCache(final Boolean forceNoCache) {
55+
this.forceNoCache = forceNoCache;
56+
return this;
57+
}
58+
59+
public MountPayload pluginName(final String pluginName) {
60+
this.pluginName = pluginName;
61+
return this;
62+
}
63+
64+
public MountPayload local(final Boolean local) {
65+
this.local = local;
66+
return this;
67+
}
68+
69+
public MountPayload sealWrap(final Boolean sealWrap) {
70+
this.sealWrap = sealWrap;
71+
return this;
72+
}
73+
74+
public MountPayload auditNonHmacRequestKeys(final List<String> auditNonHmacRequestKeys) {
75+
if (auditNonHmacRequestKeys != null) {
76+
this.auditNonHmacRequestKeys = new ArrayList<>();
77+
this.auditNonHmacRequestKeys.addAll(auditNonHmacRequestKeys);
78+
}
79+
return this;
80+
}
81+
82+
public MountPayload auditNonHmacResponseKeys(final List<String> auditNonHmacResponseKeys) {
83+
if (auditNonHmacResponseKeys != null) {
84+
this.auditNonHmacResponseKeys = new ArrayList<>();
85+
this.auditNonHmacResponseKeys.addAll(auditNonHmacResponseKeys);
86+
}
87+
return this;
88+
}
89+
90+
public List<String> getAuditNonHmacRequestKeys() {
91+
if (auditNonHmacRequestKeys == null) {
92+
return null;
93+
} else {
94+
final List<String> clone = new ArrayList<>();
95+
clone.addAll(auditNonHmacRequestKeys);
96+
return clone;
97+
}
98+
}
99+
100+
public List<String> getAuditNonHmacResponseKeys() {
101+
if (auditNonHmacResponseKeys == null) {
102+
return null;
103+
} else {
104+
final List<String> clone = new ArrayList<>();
105+
clone.addAll(auditNonHmacResponseKeys);
106+
return clone;
107+
}
108+
}
109+
110+
public JsonObject toEnableJson(MountType type) {
111+
final JsonObject jsonObject = Json.object();
112+
113+
jsonObject.addIfNotNull("type", type.value());
114+
jsonObject.addIfNotNull("description", this.description);
115+
jsonObject.addIfNotNull("config", this.toConfigJson());
116+
jsonObject.addIfNotNull("plugin_name", this.pluginName);
117+
jsonObject.addIfNotNull("local", this.local);
118+
jsonObject.addIfNotNull("seal_wrap", this.sealWrap);
119+
120+
return jsonObject;
121+
}
122+
123+
public JsonObject toTuneJson() {
124+
final JsonObject jsonObject = Json.object();
125+
126+
if (this.defaultLeaseTtl != null) {
127+
jsonObject.addIfNotNull("default_lease_ttl", this.defaultLeaseTtl.toString());
128+
}
129+
130+
if (this.maxLeaseTtl != null) {
131+
jsonObject.addIfNotNull("max_lease_ttl", this.maxLeaseTtl.toString());
132+
}
133+
134+
jsonObject.addIfNotNull("description", this.description);
135+
136+
if (this.auditNonHmacRequestKeys != null && this.auditNonHmacRequestKeys.size() > 0) {
137+
jsonObject.addIfNotNull("audit_non_hmac_request_keys", this.auditNonHmacRequestKeys.stream().collect(Collectors.joining(",")));
138+
}
139+
140+
if (this.auditNonHmacResponseKeys != null && this.auditNonHmacResponseKeys.size() > 0) {
141+
jsonObject.addIfNotNull("audit_non_hmac_response_keys", this.auditNonHmacResponseKeys.stream().collect(Collectors.joining(",")));
142+
}
143+
144+
return jsonObject;
145+
}
146+
147+
private JsonObject toConfigJson() {
148+
final JsonObject jsonObject = toTuneJson();
149+
150+
jsonObject.addIfNotNull("force_no_cache", this.forceNoCache);
151+
jsonObject.addIfNotNull("plugin_name", this.pluginName);
152+
153+
if (jsonObject.isEmpty()) {
154+
return null;
155+
}
156+
157+
return jsonObject;
158+
}
159+
}

0 commit comments

Comments
 (0)