Skip to content

Commit 94cb08a

Browse files
committed
chore: replaced switcher.autorefreshtoken with switcher.auth.autorefresh (#393)
* chore: replaced switcher.autorefreshtoken with switcher.auth.autorefresh * chore: replaced switcher.autorefreshtoken with switcher.auth.autorefresh
1 parent 0526062 commit 94cb08a

10 files changed

Lines changed: 43 additions & 19 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ switcher.poolsize=2
145145
| `switcher.environment` || default | Environment name (dev, staging, default) |
146146
| `switcher.local` || false | Enable local-only mode |
147147
| `switcher.check` || false | Validate switcher keys on startup |
148-
| `switcher.autorefreshtoken` || false | Automatically refresh API token before expiration |
148+
| `switcher.auth.autorefresh` || false | Automatically refresh API token before expiration |
149149
| `switcher.relay.restrict` || true | Defines if client will trigger local snapshot relay verification |
150150
| `switcher.snapshot.location` || - | Directory for snapshot files |
151151
| `switcher.snapshot.auto` || false | Auto-load snapshots on startup |

src/main/java/com/switcherapi/client/ContextBuilder.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,12 @@ public ContextBuilder poolConnectionSize(Integer poolSize) {
247247
return this;
248248
}
249249

250-
public ContextBuilder autoRefreshToken(boolean autoRefreshToken) {
251-
switcherProperties.setValue(ContextKey.AUTO_REFRESH_TOKEN, autoRefreshToken);
250+
/**
251+
* @param authAutoRefresh true/false When true, it will enable automatic refresh of authentication token
252+
* @return ContextBuilder
253+
*/
254+
public ContextBuilder authAutoRefresh(boolean authAutoRefresh) {
255+
switcherProperties.setValue(ContextKey.AUTH_AUTO_REFRESH, authAutoRefresh);
252256
return this;
253257
}
254258
}

src/main/java/com/switcherapi/client/SwitcherConfig.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ abstract class SwitcherConfig {
1212

1313
protected boolean local;
1414
protected boolean check;
15-
protected boolean autoRefreshToken;
1615
protected String silent;
1716
protected Integer timeout;
1817
protected Integer regexTimeout;
1918
protected Integer poolSize;
19+
protected AuthConfig auth;
2020
protected RelayConfig relay;
2121
protected SnapshotConfig snapshot;
2222
protected TruststoreConfig truststore;
2323

2424
SwitcherConfig() {
25+
this.auth = new AuthConfig();
2526
this.relay = new RelayConfig();
2627
this.snapshot = new SnapshotConfig();
2728
this.truststore = new TruststoreConfig();
@@ -40,11 +41,14 @@ protected void updateSwitcherConfig(SwitcherProperties properties) {
4041
setEnvironment(properties.getValue(ContextKey.ENVIRONMENT));
4142
setLocal(properties.getBoolean(ContextKey.LOCAL_MODE));
4243
setCheck(properties.getBoolean(ContextKey.CHECK_SWITCHERS));
43-
setAutoRefreshToken(properties.getBoolean(ContextKey.AUTO_REFRESH_TOKEN));
4444
setSilent(properties.getValue(ContextKey.SILENT_MODE));
4545
setTimeout(properties.getInt(ContextKey.TIMEOUT_MS));
4646
setPoolSize(properties.getInt(ContextKey.POOL_CONNECTION_SIZE));
4747

48+
AuthConfig authConfig = new AuthConfig();
49+
authConfig.setAutoRefresh(properties.getBoolean(ContextKey.AUTH_AUTO_REFRESH));
50+
setAuth(authConfig);
51+
4852
RelayConfig relayConfig = new RelayConfig();
4953
relayConfig.setRestrict(properties.getBoolean(ContextKey.RESTRICT_RELAY));
5054
setRelay(relayConfig);
@@ -108,8 +112,8 @@ public void setCheck(boolean check) {
108112
this.check = check;
109113
}
110114

111-
public void setAutoRefreshToken(boolean autoRefreshToken) {
112-
this.autoRefreshToken = autoRefreshToken;
115+
public void setAuth(AuthConfig auth) {
116+
this.auth = auth;
113117
}
114118

115119
public void setSilent(String silent) {
@@ -139,6 +143,18 @@ public void setTruststore(TruststoreConfig truststore) {
139143
this.truststore = truststore;
140144
}
141145

146+
public static class AuthConfig {
147+
private boolean autoRefresh;
148+
149+
public boolean isAutoRefresh() {
150+
return autoRefresh;
151+
}
152+
153+
public void setAutoRefresh(boolean autoRefresh) {
154+
this.autoRefresh = autoRefresh;
155+
}
156+
}
157+
142158
public static class RelayConfig {
143159
private boolean restrict;
144160

src/main/java/com/switcherapi/client/SwitcherContextBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ protected void configureClient() {
113113
.silentMode(silent)
114114
.regexTimeout(regexTimeout)
115115
.timeoutMs(timeout)
116-
.autoRefreshToken(autoRefreshToken)
116+
.authAutoRefresh(auth.isAutoRefresh())
117117
.poolConnectionSize(poolSize)
118118
.snapshotLocation(snapshot.getLocation())
119119
.snapshotAutoLoad(snapshot.isAuto())

src/main/java/com/switcherapi/client/SwitcherPropertiesImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ private void initDefaults() {
3030
setValue(ContextKey.LOCAL_MODE, false);
3131
setValue(ContextKey.CHECK_SWITCHERS, false);
3232
setValue(ContextKey.RESTRICT_RELAY, true);
33-
setValue(ContextKey.AUTO_REFRESH_TOKEN, false);
33+
setValue(ContextKey.AUTH_AUTO_REFRESH, false);
3434
}
3535

3636
@Override
@@ -50,7 +50,7 @@ public void loadFromProperties(Properties prop) {
5050
setValue(ContextKey.LOCAL_MODE, getBoolDefault(resolveProperties(ContextKey.LOCAL_MODE.getParam(), prop), false));
5151
setValue(ContextKey.CHECK_SWITCHERS, getBoolDefault(resolveProperties(ContextKey.CHECK_SWITCHERS.getParam(), prop), false));
5252
setValue(ContextKey.RESTRICT_RELAY, getBoolDefault(resolveProperties(ContextKey.RESTRICT_RELAY.getParam(), prop), true));
53-
setValue(ContextKey.AUTO_REFRESH_TOKEN, getBoolDefault(resolveProperties(ContextKey.AUTO_REFRESH_TOKEN.getParam(), prop), false));
53+
setValue(ContextKey.AUTH_AUTO_REFRESH, getBoolDefault(resolveProperties(ContextKey.AUTH_AUTO_REFRESH.getParam(), prop), false));
5454
setValue(ContextKey.REGEX_TIMEOUT, getIntDefault(resolveProperties(ContextKey.REGEX_TIMEOUT.getParam(), prop), DEFAULT_REGEX_TIMEOUT));
5555
setValue(ContextKey.TRUSTSTORE_PATH, resolveProperties(ContextKey.TRUSTSTORE_PATH.getParam(), prop));
5656
setValue(ContextKey.TRUSTSTORE_PASSWORD, resolveProperties(ContextKey.TRUSTSTORE_PASSWORD.getParam(), prop));

src/main/java/com/switcherapi/client/model/ContextKey.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public enum ContextKey {
114114
/**
115115
* (boolean) Enables automatic refresh of authentication token (default is false)
116116
*/
117-
AUTO_REFRESH_TOKEN("switcher.autorefreshtoken");
117+
AUTH_AUTO_REFRESH("switcher.auth.autorefresh");
118118

119119
private final String param;
120120

src/main/java/com/switcherapi/client/service/remote/ClientRemoteService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ private void scheduleNextAuth() {
170170
}
171171

172172
private boolean isAutoRefreshable() {
173-
return switcherProperties.getBoolean(ContextKey.AUTO_REFRESH_TOKEN) &&
173+
return switcherProperties.getBoolean(ContextKey.AUTH_AUTO_REFRESH) &&
174174
(Objects.isNull(refreshFuture) || refreshFuture.isDone());
175175
}
176176

src/test/java/com/switcherapi/client/SwitcherConfigTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ void shouldInitializeClientFromSwitcherConfig_Minimal() {
3838

3939
private <T extends SwitcherConfig> T buildSwitcherClientConfig(T classConfig, String component,
4040
String domain) {
41+
SwitcherConfig.AuthConfig auth = new SwitcherConfig.AuthConfig();
42+
auth.setAutoRefresh(false);
43+
4144
SwitcherConfig.RelayConfig relay = new SwitcherConfig.RelayConfig();
4245
relay.setRestrict(false);
4346

@@ -62,6 +65,7 @@ private <T extends SwitcherConfig> T buildSwitcherClientConfig(T classConfig, St
6265
classConfig.setTimeout(3000);
6366
classConfig.setRegexTimeout(1000);
6467
classConfig.setPoolSize(2);
68+
classConfig.setAuth(auth);
6569
classConfig.setRelay(relay);
6670
classConfig.setSnapshot(snapshot);
6771
classConfig.setTruststore(truststore);

src/test/java/com/switcherapi/client/SwitcherRemoteAutoRefreshTokenTest.java renamed to src/test/java/com/switcherapi/client/SwitcherRemoteAuthAutoRefreshTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import static org.junit.jupiter.api.Assertions.assertThrows;
1515
import static org.junit.jupiter.api.Assertions.assertTrue;
1616

17-
class SwitcherRemoteAutoRefreshTokenTest extends MockWebServerHelper {
17+
class SwitcherRemoteAuthAutoRefreshTest extends MockWebServerHelper {
1818

1919
@BeforeEach
2020
void setup() throws IOException {
@@ -40,7 +40,7 @@ void shouldAutoRefreshAuthToken() {
4040
givenResponse(generateCriteriaResponse("true", false));
4141

4242
//when
43-
givenAutoRefreshToken(true);
43+
givenAuthAutoRefresh(true);
4444

4545
//test
4646
SwitcherRequest switcher = SwitchersBase.getSwitcher(SwitchersBase.USECASE11);
@@ -58,7 +58,7 @@ void shouldNotAutoRefreshAuthTokenWhenDisabled() {
5858
givenResponse(generateCriteriaResponse("true", false));
5959

6060
//when
61-
givenAutoRefreshToken(false);
61+
givenAuthAutoRefresh(false);
6262

6363
//test
6464
SwitcherRequest switcher = SwitchersBase.getSwitcher(SwitchersBase.USECASE11);
@@ -75,7 +75,7 @@ void shouldNotAutoRefreshAuthTokenWhenAuthFails() {
7575
givenResponse(generateStatusResponse("500"));
7676

7777
//when
78-
givenAutoRefreshToken(true);
78+
givenAuthAutoRefresh(true);
7979

8080
//test
8181
SwitcherRequest switcher = SwitchersBase.getSwitcher(SwitchersBase.USECASE11);
@@ -84,14 +84,14 @@ void shouldNotAutoRefreshAuthTokenWhenAuthFails() {
8484
assertThrows(SwitcherRemoteException.class, switcher::isItOn);
8585
}
8686

87-
private void givenAutoRefreshToken(boolean enabled) {
87+
private void givenAuthAutoRefresh(boolean enabled) {
8888
SwitchersBase.configure(ContextBuilder.builder(true)
8989
.context(SwitchersBase.class.getName())
9090
.url(String.format("http://localhost:%s", mockBackEnd.getPort()))
9191
.domain("domain")
9292
.apiKey("apiKey")
9393
.component("component")
94-
.autoRefreshToken(enabled));
94+
.authAutoRefresh(enabled));
9595

9696
SwitchersBase.initializeClient();
9797
}

src/test/java/com/switcherapi/playground/Features.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ protected void configureClient() {
1717
.apiKey(System.getenv("switcher.api.key"))
1818
.component(System.getenv("switcher.component"))
1919
.domain(System.getenv("switcher.domain"))
20-
.autoRefreshToken(true));
20+
.authAutoRefresh(true));
2121

2222
initializeClient();
2323
}

0 commit comments

Comments
 (0)