Skip to content

Commit 8745817

Browse files
SK-3026 update the name of vaultURL
1 parent c314875 commit 8745817

15 files changed

Lines changed: 526 additions & 89 deletions

File tree

common/src/main/java/com/skyflow/enums/CustomHeaderKey.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.skyflow.enums;
22

33
public enum CustomHeaderKey {
4-
SkyflowAccountID("x-skyflow-account-id"),
4+
SkyflowAccountId("x-skyflow-account-id"),
55
SkyflowAccountName("x-skyflow-account-name"),
6-
RequestIDHeader("x-request-id");
6+
RequestIdHeader("x-request-id");
77

88
private final String value;
99

common/src/test/java/com/skyflow/vault/data/RequestContextTests.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,28 @@ public void testGetHeadersReturnsEmptyMapByDefault() {
3232
@Test
3333
public void testAddHeaderIsReflectedInGetHeaders() {
3434
RequestContext context = new RequestContext("INSERT");
35-
context.addHeader(CustomHeaderKey.SkyflowAccountID, "account-id-value");
35+
context.addHeader(CustomHeaderKey.SkyflowAccountId, "account-id-value");
3636

3737
Map<CustomHeaderKey, String> headers = context.getHeaders();
3838

3939
Assert.assertEquals(1, headers.size());
40-
Assert.assertEquals("account-id-value", headers.get(CustomHeaderKey.SkyflowAccountID));
40+
Assert.assertEquals("account-id-value", headers.get(CustomHeaderKey.SkyflowAccountId));
4141
}
4242

4343
@Test
4444
public void testAddHeaderOverwritesExistingValueForSameKey() {
4545
RequestContext context = new RequestContext("INSERT");
46-
context.addHeader(CustomHeaderKey.SkyflowAccountID, "first-value");
47-
context.addHeader(CustomHeaderKey.SkyflowAccountID, "second-value");
46+
context.addHeader(CustomHeaderKey.SkyflowAccountId, "first-value");
47+
context.addHeader(CustomHeaderKey.SkyflowAccountId, "second-value");
4848

4949
Assert.assertEquals(1, context.getHeaders().size());
50-
Assert.assertEquals("second-value", context.getHeaders().get(CustomHeaderKey.SkyflowAccountID));
50+
Assert.assertEquals("second-value", context.getHeaders().get(CustomHeaderKey.SkyflowAccountId));
5151
}
5252

5353
@Test
5454
public void testAddMultipleDistinctHeaders() {
5555
RequestContext context = new RequestContext("DETOKENIZE");
56-
context.addHeader(CustomHeaderKey.SkyflowAccountID, "account-id-value");
56+
context.addHeader(CustomHeaderKey.SkyflowAccountId, "account-id-value");
5757
context.addHeader(CustomHeaderKey.SkyflowAccountName, "account-name-value");
5858

5959
Assert.assertEquals(2, context.getHeaders().size());
@@ -63,6 +63,6 @@ public void testAddMultipleDistinctHeaders() {
6363
public void testGetHeadersReturnsUnmodifiableMap() {
6464
RequestContext context = new RequestContext("INSERT");
6565

66-
context.getHeaders().put(CustomHeaderKey.RequestIDHeader, "request-id-value");
66+
context.getHeaders().put(CustomHeaderKey.RequestIdHeader, "request-id-value");
6767
}
6868
}

common/src/test/java/com/skyflow/vault/data/RequestInterceptorTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ public class RequestInterceptorTests {
88

99
@Test
1010
public void testInterceptMutatesRequestContext() {
11-
RequestInterceptor interceptor = context -> context.addHeader(CustomHeaderKey.SkyflowAccountID, "account-id-value");
11+
RequestInterceptor interceptor = context -> context.addHeader(CustomHeaderKey.SkyflowAccountId, "account-id-value");
1212
RequestContext context = new RequestContext("INSERT");
1313

1414
interceptor.intercept(context);
1515

16-
Assert.assertEquals("account-id-value", context.getHeaders().get(CustomHeaderKey.SkyflowAccountID));
16+
Assert.assertEquals("account-id-value", context.getHeaders().get(CustomHeaderKey.SkyflowAccountId));
1717
}
1818

1919
@Test

flowvault/src/main/java/com/skyflow/Skyflow.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,17 @@ protected void onVaultConfigAdded(VaultConfig vaultConfig) throws SkyflowExcepti
7272

7373
@Override
7474
protected void onVaultConfigUpdated(VaultConfig updatedConfig) throws SkyflowException {
75-
VaultController updated = new VaultController(updatedConfig, this.skyflowCredentials);
75+
// Update the existing controller in place — replacing it would leave any VaultController
76+
// reference the caller already holds pointing at the previous config.
77+
VaultController updated = this.vaultClientsMap.get(updatedConfig.getVaultId());
78+
if (updated == null) {
79+
updated = new VaultController(updatedConfig, this.skyflowCredentials);
80+
this.vaultClientsMap.put(updatedConfig.getVaultId(), updated);
81+
} else {
82+
updated.setVaultConfig(updatedConfig);
83+
}
7684
updated.setCommonHttpConfig(this.timeout, this.connectTimeout, this.readTimeout,
7785
this.writeTimeout, this.maxRetries);
78-
this.vaultClientsMap.put(updatedConfig.getVaultId(), updated);
7986
}
8087

8188
@Override
@@ -110,7 +117,7 @@ public SkyflowClientBuilder updateVaultConfig(VaultConfig vaultConfig) throws Sk
110117

111118
/**
112119
* BaseSkyflow.mergeVaultConfig() only carries env, clusterId and credentials across, so the
113-
* flowvault-specific fields on an incoming update — vaultURL and the HTTP settings — would
120+
* flowvault-specific fields on an incoming update — vaultUrl and the HTTP settings — would
114121
* be dropped silently. Apply them to the merged config the new controller is holding. A null
115122
* on the incoming config means "leave as is", matching how the base class merges every
116123
* other field.
@@ -137,11 +144,11 @@ private void carryVaultOverrides(VaultConfig incoming) throws SkyflowException {
137144
}
138145
// The HTTP settings above are resolved lazily on the next request, but the URL is
139146
// resolved once in the VaultClient constructor — which already ran with the old value.
140-
if (incoming.getVaultURL() != null) {
141-
merged.setVaultURL(incoming.getVaultURL());
147+
if (incoming.getVaultUrl() != null) {
148+
merged.setVaultUrl(incoming.getVaultUrl());
142149
VaultController controller = this.vaultClientsMap.get(incoming.getVaultId());
143150
if (controller != null) {
144-
controller.refreshVaultURL();
151+
controller.refreshVaultUrl();
145152
}
146153
}
147154
}

flowvault/src/main/java/com/skyflow/VaultClient.java

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected VaultClient(VaultConfig vaultConfig, Credentials credentials) throws S
3434
super(vaultConfig, credentials);
3535
this.apiClientBuilder = new ApiClientBuilder();
3636
this.apiClient = null;
37-
updateVaultURL();
37+
updateVaultUrl();
3838
}
3939

4040
/**
@@ -89,30 +89,43 @@ protected synchronized void setBearerToken() throws SkyflowException {
8989
}
9090
}
9191

92+
/**
93+
* Adopts an updated config in place, so a VaultController reference the caller already holds
94+
* keeps working instead of silently serving the previous config. Discards the cached HTTP and
95+
* API clients; the bearer token is re-resolved by setBearerToken, which drops it when the
96+
* effective credentials changed.
97+
*/
98+
protected void setVaultConfig(VaultConfig vaultConfig) throws SkyflowException {
99+
this.vaultConfig = vaultConfig;
100+
this.sharedHttpClient = null;
101+
this.apiClient = null;
102+
updateVaultUrl();
103+
}
104+
92105
/**
93106
* Re-resolves the vault URL from the current config. The constructor resolves it once, so a
94-
* vaultURL supplied later through updateVaultConfig would otherwise never take effect.
107+
* vaultUrl supplied later through updateVaultConfig would otherwise never take effect.
95108
*/
96-
protected void refreshVaultURL() throws SkyflowException {
97-
updateVaultURL();
109+
protected void refreshVaultUrl() throws SkyflowException {
110+
updateVaultUrl();
98111
}
99112

100-
private void updateVaultURL() throws SkyflowException {
101-
// Fetch vaultURL from ENV
102-
String vaultURL = Utils.getEnvVaultURL();
113+
private void updateVaultUrl() throws SkyflowException {
114+
// Fetch vaultUrl from ENV
115+
String vaultUrl = Utils.getEnvVaultUrl();
103116

104-
// If vaultURL from ENV is null or empty, fetch vaultURL from vault config
105-
if (vaultURL == null || vaultURL.isEmpty()) {
106-
vaultURL = this.vaultConfig.getVaultURL();
117+
// If vaultUrl from ENV is null or empty, fetch vaultUrl from vault config
118+
if (vaultUrl == null || vaultUrl.isEmpty()) {
119+
vaultUrl = this.vaultConfig.getVaultUrl();
107120
}
108121

109-
// If vaultURL from vault config is also null or empty, construct vaultURL from clusterId passed in vault config
110-
if (vaultURL == null || vaultURL.isEmpty()) {
111-
vaultURL = Utils.getVaultURL(this.vaultConfig.getClusterId(), this.vaultConfig.getEnv());
122+
// If vaultUrl from vault config is also null or empty, construct vaultUrl from clusterId passed in vault config
123+
if (vaultUrl == null || vaultUrl.isEmpty()) {
124+
vaultUrl = Utils.getVaultUrl(this.vaultConfig.getClusterId(), this.vaultConfig.getEnv());
112125
}
113-
this.apiClientBuilder.url(vaultURL);
114-
if (!vaultURL.equals(this.currentVaultURL)) {
115-
this.currentVaultURL = vaultURL;
126+
this.apiClientBuilder.url(vaultUrl);
127+
if (!vaultUrl.equals(this.currentVaultURL)) {
128+
this.currentVaultURL = vaultUrl;
116129
this.apiClient = null;
117130
}
118131
}

flowvault/src/main/java/com/skyflow/config/VaultConfig.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515
public class VaultConfig extends BaseVaultConfig {
1616

17-
private String vaultURL;
17+
private String vaultUrl;
1818
// HTTP timeout & retry config (vault-level overrides). null => inherit client-wide default, then SDK default.
1919
private Integer timeout; // overall call timeout, in seconds
2020
private Integer connectTimeout; // per-attempt connection-establishment timeout, in seconds
@@ -24,20 +24,20 @@ public class VaultConfig extends BaseVaultConfig {
2424

2525
public VaultConfig() {
2626
super();
27-
this.vaultURL = null;
27+
this.vaultUrl = null;
2828
this.timeout = null;
2929
this.connectTimeout = null;
3030
this.readTimeout = null;
3131
this.writeTimeout = null;
3232
this.maxRetries = null;
3333
}
3434

35-
public String getVaultURL() {
36-
return vaultURL;
35+
public String getVaultUrl() {
36+
return vaultUrl;
3737
}
3838

39-
public void setVaultURL(String vaultURL) {
40-
this.vaultURL = vaultURL;
39+
public void setVaultUrl(String vaultUrl) {
40+
this.vaultUrl = vaultUrl;
4141
}
4242

4343
public Integer getTimeout() {

flowvault/src/main/java/com/skyflow/utils/Utils.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@
5555

5656
public final class Utils extends BaseUtils {
5757

58-
public static String getVaultURL(String clusterId, Env env) {
59-
return getVaultURL(clusterId, env, Constants.VAULT_DOMAIN);
58+
public static String getVaultUrl(String clusterId, Env env) {
59+
// The 3-arg overload is inherited from common's BaseUtils, which keeps the older
60+
// getVaultURL spelling (shared with v2), so it is qualified rather than renamed here.
61+
return BaseUtils.getVaultURL(clusterId, env, Constants.VAULT_DOMAIN);
6062
}
6163

6264
public static JsonObject getMetrics() {
@@ -67,27 +69,27 @@ public static JsonObject getMetrics() {
6769
}
6870

6971

70-
public static String getEnvVaultURL() throws SkyflowException {
72+
public static String getEnvVaultUrl() throws SkyflowException {
7173
try {
72-
String vaultURL = System.getenv("VAULT_URL");
73-
if (vaultURL == null) {
74+
String vaultUrl = System.getenv("VAULT_URL");
75+
if (vaultUrl == null) {
7476
Dotenv dotenv = Dotenv.load();
75-
vaultURL = dotenv.get("VAULT_URL");
77+
vaultUrl = dotenv.get("VAULT_URL");
7678
}
77-
if (vaultURL != null && vaultURL.trim().isEmpty()) {
79+
if (vaultUrl != null && vaultUrl.trim().isEmpty()) {
7880
LogUtil.printErrorLog(ErrorLogs.EMPTY_VAULT_URL.getLog());
7981
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyVaultUrl.getMessage());
80-
} else if (vaultURL != null && !isValidURL(vaultURL)) {
82+
} else if (vaultUrl != null && !isValidUrl(vaultUrl)) {
8183
LogUtil.printErrorLog(ErrorLogs.INVALID_VAULT_URL_FORMAT.getLog());
8284
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidVaultUrlFormat.getMessage());
8385
}
84-
return vaultURL;
86+
return vaultUrl;
8587
} catch (DotenvException e) {
8688
return null;
8789
}
8890
}
8991

90-
public static boolean isValidURL(String url) {
92+
public static boolean isValidUrl(String url) {
9193
URL parsedUrl;
9294
try {
9395
parsedUrl = new URL(url);

flowvault/src/main/java/com/skyflow/utils/validations/Validations.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public static void validateCredentials(Credentials credentials) throws SkyflowEx
119119
public static void validateVaultConfiguration(VaultConfig vaultConfig) throws SkyflowException {
120120
String vaultId = vaultConfig.getVaultId();
121121
String clusterId = vaultConfig.getClusterId();
122-
String vaultURL = vaultConfig.getVaultURL();
122+
String vaultUrl = vaultConfig.getVaultUrl();
123123
Credentials credentials = vaultConfig.getCredentials();
124124

125125
if (vaultId == null) {
@@ -132,15 +132,15 @@ public static void validateVaultConfiguration(VaultConfig vaultConfig) throws Sk
132132
validateCredentials(credentials);
133133
}
134134

135-
if (vaultURL != null) {
136-
if (vaultURL.trim().isEmpty()) {
135+
if (vaultUrl != null) {
136+
if (vaultUrl.trim().isEmpty()) {
137137
LogUtil.printErrorLog(ErrorLogs.EMPTY_VAULT_URL.getLog());
138138
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyVaultUrl.getMessage());
139-
} else if (!Utils.isValidURL(vaultURL)) {
139+
} else if (!Utils.isValidUrl(vaultUrl)) {
140140
LogUtil.printErrorLog(ErrorLogs.INVALID_VAULT_URL_FORMAT.getLog());
141141
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidVaultUrlFormat.getMessage());
142142
}
143-
} else if (Utils.getEnvVaultURL() == null) {
143+
} else if (Utils.getEnvVaultUrl() == null) {
144144
if (clusterId == null) {
145145
LogUtil.printErrorLog(ErrorLogs.EITHER_VAULT_URL_OR_CLUSTER_ID_REQUIRED.getLog());
146146
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EitherVaultUrlOrClusterIdRequired.getMessage());

0 commit comments

Comments
 (0)