Skip to content

Commit 1191abd

Browse files
Merge pull request #186 from casz/deprecate/optionalHeader
deprecate `optionalHeader`
2 parents b4533c5 + c1f7b1c commit 1191abd

File tree

14 files changed

+99
-93
lines changed

14 files changed

+99
-93
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ private Map<String, String> collectSecretEngineVersions() {
254254
try {
255255
final RestResponse restResponse = new Rest()//NOPMD
256256
.url(vaultConfig.getAddress() + "/v1/sys/mounts")
257-
.optionalHeader("X-Vault-Token", vaultConfig.getToken())
258-
.optionalHeader("X-Vault-Namespace", this.vaultConfig.getNameSpace())
257+
.header("X-Vault-Token", vaultConfig.getToken())
258+
.header("X-Vault-Namespace", this.vaultConfig.getNameSpace())
259259
.connectTimeoutSeconds(vaultConfig.getOpenTimeout())
260260
.readTimeoutSeconds(vaultConfig.getReadTimeout())
261261
.sslVerification(vaultConfig.getSslConfig().isVerify())

src/main/java/com/bettercloud/vault/api/Auth.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ public AuthResponse createToken(final TokenRequest tokenRequest, final String to
261261
// HTTP request to Vault
262262
final RestResponse restResponse = new Rest()//NOPMD
263263
.url(url)
264-
.optionalHeader("X-Vault-Token", config.getToken())
265-
.optionalHeader("X-Vault-Namespace", this.nameSpace)
264+
.header("X-Vault-Token", config.getToken())
265+
.header("X-Vault-Namespace", this.nameSpace)
266266
.body(requestJson.getBytes(StandardCharsets.UTF_8))
267267
.connectTimeoutSeconds(config.getOpenTimeout())
268268
.readTimeoutSeconds(config.getReadTimeout())
@@ -422,7 +422,7 @@ public AuthResponse loginByAppRole(final String path, final String roleId, final
422422
final String requestJson = Json.object().add("role_id", roleId).add("secret_id", secretId).toString();
423423
final RestResponse restResponse = new Rest()//NOPMD
424424
.url(config.getAddress() + "/v1/auth/" + path + "/login")
425-
.optionalHeader("X-Vault-Namespace", this.nameSpace)
425+
.header("X-Vault-Namespace", this.nameSpace)
426426
.body(requestJson.getBytes(StandardCharsets.UTF_8))
427427
.connectTimeoutSeconds(config.getOpenTimeout())
428428
.readTimeoutSeconds(config.getReadTimeout())
@@ -505,7 +505,7 @@ public AuthResponse loginByUserPass(final String username, final String password
505505
final String requestJson = Json.object().add("password", password).toString();
506506
final RestResponse restResponse = new Rest()//NOPMD
507507
.url(config.getAddress() + "/v1/auth/" + mount + "/login/" + username)
508-
.optionalHeader("X-Vault-Namespace", this.nameSpace)
508+
.header("X-Vault-Namespace", this.nameSpace)
509509
.body(requestJson.getBytes(StandardCharsets.UTF_8))
510510
.connectTimeoutSeconds(config.getOpenTimeout())
511511
.readTimeoutSeconds(config.getReadTimeout())
@@ -628,7 +628,7 @@ public AuthResponse loginByAwsEc2(final String role, final String identity, fina
628628
final RestResponse restResponse = new Rest()//NOPMD
629629
.url(config.getAddress() + "/v1/auth/" + mount + "/login")
630630
.body(requestJson.getBytes(StandardCharsets.UTF_8))
631-
.optionalHeader("X-Vault-Namespace", this.nameSpace)
631+
.header("X-Vault-Namespace", this.nameSpace)
632632
.connectTimeoutSeconds(config.getOpenTimeout())
633633
.readTimeoutSeconds(config.getReadTimeout())
634634
.sslVerification(config.getSslConfig().isVerify())
@@ -703,7 +703,7 @@ public AuthResponse loginByAwsEc2(final String role, final String pkcs7, final S
703703
final String requestJson = request.toString();
704704
final RestResponse restResponse = new Rest()//NOPMD
705705
.url(config.getAddress() + "/v1/auth/" + mount + "/login")
706-
.optionalHeader("X-Vault-Namespace", this.nameSpace)
706+
.header("X-Vault-Namespace", this.nameSpace)
707707
.body(requestJson.getBytes(StandardCharsets.UTF_8))
708708
.connectTimeoutSeconds(config.getOpenTimeout())
709709
.readTimeoutSeconds(config.getReadTimeout())
@@ -782,7 +782,7 @@ public AuthResponse loginByAwsIam(final String role, final String iamRequestUrl,
782782
final String requestJson = request.toString();
783783
final RestResponse restResponse = new Rest()//NOPMD
784784
.url(config.getAddress() + "/v1/auth/" + mount + "/login")
785-
.optionalHeader("X-Vault-Namespace", this.nameSpace)
785+
.header("X-Vault-Namespace", this.nameSpace)
786786
.body(requestJson.getBytes(StandardCharsets.UTF_8))
787787
.connectTimeoutSeconds(config.getOpenTimeout())
788788
.readTimeoutSeconds(config.getReadTimeout())
@@ -867,7 +867,7 @@ public AuthResponse loginByGithub(final String githubToken, final String githubA
867867
final String requestJson = Json.object().add("token", githubToken).toString();
868868
final RestResponse restResponse = new Rest()//NOPMD
869869
.url(config.getAddress() + "/v1/auth/" + mount + "/login")
870-
.optionalHeader("X-Vault-Namespace", this.nameSpace)
870+
.header("X-Vault-Namespace", this.nameSpace)
871871
.body(requestJson.getBytes(StandardCharsets.UTF_8))
872872
.connectTimeoutSeconds(config.getOpenTimeout())
873873
.readTimeoutSeconds(config.getReadTimeout())
@@ -931,7 +931,7 @@ public AuthResponse loginByJwt(final String provider, final String role, final S
931931
final String requestJson = Json.object().add("role", role).add("jwt", jwt).toString();
932932
final RestResponse restResponse = new Rest()
933933
.url(config.getAddress() + "/v1/auth/" + provider + "/login")
934-
.optionalHeader("X-Vault-Namespace", this.nameSpace)
934+
.header("X-Vault-Namespace", this.nameSpace)
935935
.body(requestJson.getBytes(StandardCharsets.UTF_8))
936936
.connectTimeoutSeconds(config.getOpenTimeout())
937937
.readTimeoutSeconds(config.getReadTimeout())
@@ -1071,7 +1071,7 @@ public AuthResponse loginByCert(final String certAuthMount) throws VaultExceptio
10711071
try {
10721072
final RestResponse restResponse = new Rest()//NOPMD
10731073
.url(config.getAddress() + "/v1/auth/" + mount + "/login")
1074-
.optionalHeader("X-Vault-Namespace", this.nameSpace)
1074+
.header("X-Vault-Namespace", this.nameSpace)
10751075
.connectTimeoutSeconds(config.getOpenTimeout())
10761076
.readTimeoutSeconds(config.getReadTimeout())
10771077
.sslVerification(config.getSslConfig().isVerify())
@@ -1152,8 +1152,8 @@ public AuthResponse renewSelf(final long increment, final String tokenAuthMount)
11521152
final String requestJson = Json.object().add("increment", increment).toString();
11531153
final RestResponse restResponse = new Rest()//NOPMD
11541154
.url(config.getAddress() + "/v1/auth/" + mount + "/renew-self")
1155-
.optionalHeader("X-Vault-Token", config.getToken())
1156-
.optionalHeader("X-Vault-Namespace", this.nameSpace)
1155+
.header("X-Vault-Token", config.getToken())
1156+
.header("X-Vault-Namespace", this.nameSpace)
11571157
.body(increment < 0 ? null : requestJson.getBytes(StandardCharsets.UTF_8))
11581158
.connectTimeoutSeconds(config.getOpenTimeout())
11591159
.readTimeoutSeconds(config.getReadTimeout())
@@ -1215,8 +1215,8 @@ public LookupResponse lookupSelf(final String tokenAuthMount) throws VaultExcept
12151215
// HTTP request to Vault
12161216
final RestResponse restResponse = new Rest()//NOPMD
12171217
.url(config.getAddress() + "/v1/auth/" + mount + "/lookup-self")
1218-
.optionalHeader("X-Vault-Token", config.getToken())
1219-
.optionalHeader("X-Vault-Namespace", this.nameSpace)
1218+
.header("X-Vault-Token", config.getToken())
1219+
.header("X-Vault-Namespace", this.nameSpace)
12201220
.connectTimeoutSeconds(config.getOpenTimeout())
12211221
.readTimeoutSeconds(config.getReadTimeout())
12221222
.sslVerification(config.getSslConfig().isVerify())
@@ -1277,8 +1277,8 @@ public LogicalResponse lookupWrap() throws VaultException {
12771277
// HTTP request to Vault
12781278
final RestResponse restResponse = new Rest()//NOPMD
12791279
.url(config.getAddress() + "/v1/sys/wrapping/lookup")
1280-
.optionalHeader("X-Vault-Token", config.getToken())
1281-
.optionalHeader("X-Vault-Namespace", this.nameSpace)
1280+
.header("X-Vault-Token", config.getToken())
1281+
.header("X-Vault-Namespace", this.nameSpace)
12821282
.connectTimeoutSeconds(config.getOpenTimeout())
12831283
.readTimeoutSeconds(config.getReadTimeout())
12841284
.sslVerification(config.getSslConfig().isVerify())
@@ -1339,8 +1339,8 @@ public void revokeSelf(final String tokenAuthMount) throws VaultException {
13391339
// HTTP request to Vault
13401340
final RestResponse restResponse = new Rest()//NOPMD
13411341
.url(config.getAddress() + "/v1/auth/" + mount + "/revoke-self")
1342-
.optionalHeader("X-Vault-Token", config.getToken())
1343-
.optionalHeader("X-Vault-Namespace", this.nameSpace)
1342+
.header("X-Vault-Token", config.getToken())
1343+
.header("X-Vault-Namespace", this.nameSpace)
13441344
.connectTimeoutSeconds(config.getOpenTimeout())
13451345
.readTimeoutSeconds(config.getReadTimeout())
13461346
.sslVerification(config.getSslConfig().isVerify())
@@ -1440,8 +1440,8 @@ public AuthResponse unwrap(final String wrappedToken) throws VaultException {
14401440
// HTTP request to Vault
14411441
final RestResponse restResponse = new Rest()
14421442
.url(url)
1443-
.optionalHeader("X-Vault-Token", config.getToken())
1444-
.optionalHeader("X-Vault-Namespace", this.nameSpace)
1443+
.header("X-Vault-Token", config.getToken())
1444+
.header("X-Vault-Namespace", this.nameSpace)
14451445
.body(requestJson.getBytes(StandardCharsets.UTF_8))
14461446
.connectTimeoutSeconds(config.getOpenTimeout())
14471447
.readTimeoutSeconds(config.getReadTimeout())

src/main/java/com/bettercloud/vault/api/Debug.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,12 @@ public HealthResponse health(
9191
// Build an HTTP request for Vault
9292
final Rest rest = new Rest()//NOPMD
9393
.url(config.getAddress() + "/v1/" + path)
94+
.header("X-Vault-Token", config.getToken())
95+
.header("X-Vault-Namespace", this.nameSpace)
9496
.connectTimeoutSeconds(config.getOpenTimeout())
9597
.readTimeoutSeconds(config.getReadTimeout())
9698
.sslVerification(config.getSslConfig().isVerify())
9799
.sslContext(config.getSslConfig().getSslContext());
98-
// Add token if present
99-
rest.optionalHeader("X-Vault-Token", config.getToken());
100-
rest.optionalHeader("X-Vault-Namespace", this.nameSpace);
101100
// Add params if present
102101
if (standbyOk != null) rest.parameter("standbyok", standbyOk.toString());
103102
if (activeCode != null) rest.parameter("activecode", activeCode.toString());

src/main/java/com/bettercloud/vault/api/Leases.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public VaultResponse revoke(final String leaseId) throws VaultException {
6262
*/
6363
final RestResponse restResponse = new Rest()//NOPMD
6464
.url(config.getAddress() + "/v1/sys/leases/revoke/" + leaseId)
65-
.optionalHeader("X-Vault-Token", config.getToken())
66-
.optionalHeader("X-Vault-Namespace", this.nameSpace)
65+
.header("X-Vault-Token", config.getToken())
66+
.header("X-Vault-Namespace", this.nameSpace)
6767
.connectTimeoutSeconds(config.getOpenTimeout())
6868
.readTimeoutSeconds(config.getReadTimeout())
6969
.sslVerification(config.getSslConfig().isVerify())
@@ -117,8 +117,8 @@ public VaultResponse revokePrefix(final String prefix) throws VaultException {
117117
try {
118118
final RestResponse restResponse = new Rest()//NOPMD
119119
.url(config.getAddress() + "/v1/sys/revoke-prefix/" + prefix)
120-
.optionalHeader("X-Vault-Token", config.getToken())
121-
.optionalHeader("X-Vault-Namespace", this.nameSpace)
120+
.header("X-Vault-Token", config.getToken())
121+
.header("X-Vault-Namespace", this.nameSpace)
122122
.connectTimeoutSeconds(config.getOpenTimeout())
123123
.readTimeoutSeconds(config.getReadTimeout())
124124
.sslVerification(config.getSslConfig().isVerify())
@@ -175,8 +175,8 @@ public VaultResponse revokeForce(final String prefix) throws VaultException {
175175
try {
176176
final RestResponse restResponse = new Rest()//NOPMD
177177
.url(config.getAddress() + "/v1/sys/revoke-force/" + prefix)
178-
.optionalHeader("X-Vault-Token", config.getToken())
179-
.optionalHeader("X-Vault-Namespace", this.nameSpace)
178+
.header("X-Vault-Token", config.getToken())
179+
.header("X-Vault-Namespace", this.nameSpace)
180180
.connectTimeoutSeconds(config.getOpenTimeout())
181181
.readTimeoutSeconds(config.getReadTimeout())
182182
.sslVerification(config.getSslConfig().isVerify())
@@ -238,8 +238,8 @@ public VaultResponse renew(final String leaseId, final long increment) throws Va
238238
final String requestJson = Json.object().add("increment", increment).toString();
239239
final RestResponse restResponse = new Rest()//NOPMD
240240
.url(config.getAddress() + "/v1/sys/renew/" + leaseId)
241-
.optionalHeader("X-Vault-Token", config.getToken())
242-
.optionalHeader("X-Vault-Namespace", this.nameSpace)
241+
.header("X-Vault-Token", config.getToken())
242+
.header("X-Vault-Namespace", this.nameSpace)
243243
.body(increment < 0 ? null : requestJson.getBytes(StandardCharsets.UTF_8))
244244
.connectTimeoutSeconds(config.getOpenTimeout())
245245
.readTimeoutSeconds(config.getReadTimeout())

0 commit comments

Comments
 (0)