Skip to content

Commit 4698da7

Browse files
committed
refactor: when cache error is less than 10 tes should be broken
1 parent 732599d commit 4698da7

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/main/java/com/aws/greengrass/tes/TokenExchangeService.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.aws.greengrass.authorization.exceptions.AuthorizationException;
1010
import com.aws.greengrass.config.Topic;
1111
import com.aws.greengrass.config.Topics;
12+
import com.aws.greengrass.config.WhatHappened;
1213
import com.aws.greengrass.dependency.ImplementsService;
1314
import com.aws.greengrass.dependency.State;
1415
import com.aws.greengrass.deployment.DeviceConfiguration;
@@ -87,6 +88,9 @@ public TokenExchangeService(Topics topics,
8788

8889
// Subscribe to cache configuration changes
8990
config.subscribe((why, node) -> {
91+
if (why.equals(WhatHappened.timestampUpdated)) {
92+
return;
93+
}
9094
if (node != null && (node.childOf(PORT_TOPIC)
9195
|| node.childOf(CLOUD_4XX_ERROR_CACHE_TOPIC)
9296
|| node.childOf(CLOUD_5XX_ERROR_CACHE_TOPIC)
@@ -145,6 +149,7 @@ protected void startup() {
145149
.log("Attempting to start server at configured port {}", port);
146150
try {
147151
validateConfig();
152+
validateAllCacheConfigs();
148153
server = new HttpServerImpl(port, credentialRequestHandler);
149154
server.start();
150155
logger.atInfo().log("Started server at port {}", server.getServerPort());
@@ -180,11 +185,22 @@ private void validateConfig() {
180185
}
181186
}
182187

188+
private void validateAllCacheConfigs() {
189+
validateCacheConfig(Coerce.toInt(config.findOrDefault(
190+
CredentialRequestHandler.CLOUD_4XX_ERROR_CACHE_IN_SEC, CONFIGURATION_CONFIG_KEY,
191+
CLOUD_4XX_ERROR_CACHE_TOPIC)), CLOUD_4XX_ERROR_CACHE_TOPIC);
192+
validateCacheConfig(Coerce.toInt(config.findOrDefault(
193+
CredentialRequestHandler.CLOUD_5XX_ERROR_CACHE_IN_SEC, CONFIGURATION_CONFIG_KEY,
194+
CLOUD_5XX_ERROR_CACHE_TOPIC)), CLOUD_5XX_ERROR_CACHE_TOPIC);
195+
validateCacheConfig(Coerce.toInt(config.findOrDefault(
196+
CredentialRequestHandler.UNKNOWN_ERROR_CACHE_IN_SEC, CONFIGURATION_CONFIG_KEY,
197+
UNKNOWN_ERROR_CACHE_TOPIC)), UNKNOWN_ERROR_CACHE_TOPIC);
198+
}
199+
183200
private int validateCacheConfig(int newCacheValue, String topic) {
184201
if (newCacheValue < MINIMUM_ERROR_CACHE_IN_SEC) {
185-
logger.atError().log("Error cache value must be at least {} seconds, setting {} to minimum value {}",
186-
MINIMUM_ERROR_CACHE_IN_SEC, topic, MINIMUM_ERROR_CACHE_IN_SEC);
187-
return MINIMUM_ERROR_CACHE_IN_SEC;
202+
throw new IllegalArgumentException(
203+
"Error cache value for " + topic + " must be at least " + MINIMUM_ERROR_CACHE_IN_SEC + " seconds");
188204
}
189205
return newCacheValue;
190206
}

0 commit comments

Comments
 (0)