Skip to content

Commit 6cd26a4

Browse files
committed
refactor: move config topic to tes class and rename for better user understanding
1 parent 7a35e70 commit 6cd26a4

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ public class CredentialRequestHandler implements HttpHandler {
7373
public static final int CLOUD_5XX_ERROR_CACHE_IN_SEC = 60;
7474
public static final int UNKNOWN_ERROR_CACHE_IN_SEC = 300;
7575

76-
public static final String CLOUD_4XX_ERROR_CACHE_TOPIC = "cloud4xxErrorCacheInSec";
77-
public static final String CLOUD_5XX_ERROR_CACHE_TOPIC = "cloud5xxErrorCacheInSec";
78-
public static final String UNKNOWN_ERROR_CACHE_TOPIC = "unknownErrorCacheInSec";
79-
8076
private int cloud4xxErrorCacheInSec = CLOUD_4XX_ERROR_CACHE_IN_SEC;
8177
private int cloud5xxErrorCacheInSec = CLOUD_5XX_ERROR_CACHE_IN_SEC;
8278
private int unknownErrorCacheInSec = UNKNOWN_ERROR_CACHE_IN_SEC;

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ public class TokenExchangeService extends GreengrassService implements AwsCreden
4141
private String iotRoleAlias;
4242
private HttpServerImpl server;
4343

44+
public static final String CLOUD_4XX_ERROR_CACHE_TOPIC = "error4xxCredentialRetryInSec";
45+
public static final String CLOUD_5XX_ERROR_CACHE_TOPIC = "error5xxCredentialRetryInSec";
46+
public static final String UNKNOWN_ERROR_CACHE_TOPIC = "errorUnknownCredentialRetryInSec";
47+
private static final int MINIMUM_ERROR_CACHE_IN_SEC = 10;
4448
private int cloud4xxErrorCache;
4549
private int cloud5xxErrorCache;
4650
private int unknownErrorCache;
47-
private static final int MINIMUM_ERROR_CACHE_IN_SEC = 10;
4851

4952
private final AuthorizationHandler authZHandler;
5053
private final CredentialRequestHandler credentialRequestHandler;
@@ -82,35 +85,35 @@ public TokenExchangeService(Topics topics,
8285
this.credentialRequestHandler = credentialRequestHandler;
8386

8487
cloud4xxErrorCache = validateCacheConfig(Coerce.toInt(config.lookup(
85-
CONFIGURATION_CONFIG_KEY, CredentialRequestHandler.CLOUD_4XX_ERROR_CACHE_TOPIC).dflt(
88+
CONFIGURATION_CONFIG_KEY, CLOUD_4XX_ERROR_CACHE_TOPIC).dflt(
8689
CredentialRequestHandler.CLOUD_4XX_ERROR_CACHE_IN_SEC)),
8790
CredentialRequestHandler.CLOUD_4XX_ERROR_CACHE_IN_SEC);
8891
cloud5xxErrorCache = validateCacheConfig(Coerce.toInt(config.lookup(
89-
CONFIGURATION_CONFIG_KEY, CredentialRequestHandler.CLOUD_5XX_ERROR_CACHE_TOPIC).dflt(
92+
CONFIGURATION_CONFIG_KEY, CLOUD_5XX_ERROR_CACHE_TOPIC).dflt(
9093
CredentialRequestHandler.CLOUD_5XX_ERROR_CACHE_IN_SEC)),
9194
CredentialRequestHandler.CLOUD_5XX_ERROR_CACHE_IN_SEC);
9295
unknownErrorCache = validateCacheConfig(Coerce.toInt(config.lookup(
93-
CONFIGURATION_CONFIG_KEY, CredentialRequestHandler.UNKNOWN_ERROR_CACHE_TOPIC).dflt(
96+
CONFIGURATION_CONFIG_KEY, UNKNOWN_ERROR_CACHE_TOPIC).dflt(
9497
CredentialRequestHandler.UNKNOWN_ERROR_CACHE_IN_SEC)),
9598
CredentialRequestHandler.UNKNOWN_ERROR_CACHE_IN_SEC);
9699

97100
credentialRequestHandler.configureCacheSettings(cloud4xxErrorCache, cloud5xxErrorCache, unknownErrorCache);
98101

99102
// Subscribe to cache configuration changes
100103
config.subscribe((why, node) -> {
101-
if (node != null && (node.childOf(CredentialRequestHandler.CLOUD_4XX_ERROR_CACHE_TOPIC)
102-
|| node.childOf(CredentialRequestHandler.CLOUD_5XX_ERROR_CACHE_TOPIC)
103-
|| node.childOf(CredentialRequestHandler.UNKNOWN_ERROR_CACHE_TOPIC))) {
104+
if (node != null && (node.childOf(CLOUD_4XX_ERROR_CACHE_TOPIC)
105+
|| node.childOf(CLOUD_5XX_ERROR_CACHE_TOPIC)
106+
|| node.childOf(UNKNOWN_ERROR_CACHE_TOPIC))) {
104107
logger.atDebug("tes-cache-config-change").kv("node", node).kv("why", why).log();
105108

106109
int newCloud4xxErrorCache = validateCacheConfig(Coerce.toInt(config.lookup(
107-
CONFIGURATION_CONFIG_KEY, CredentialRequestHandler.CLOUD_4XX_ERROR_CACHE_TOPIC).dflt(
110+
CONFIGURATION_CONFIG_KEY, CLOUD_4XX_ERROR_CACHE_TOPIC).dflt(
108111
CredentialRequestHandler.CLOUD_4XX_ERROR_CACHE_IN_SEC)), cloud4xxErrorCache);
109112
int newCloud5xxErrorCache = validateCacheConfig(Coerce.toInt(config.lookup(
110-
CONFIGURATION_CONFIG_KEY, CredentialRequestHandler.CLOUD_5XX_ERROR_CACHE_TOPIC).dflt(
113+
CONFIGURATION_CONFIG_KEY, CLOUD_5XX_ERROR_CACHE_TOPIC).dflt(
111114
CredentialRequestHandler.CLOUD_5XX_ERROR_CACHE_IN_SEC)), cloud5xxErrorCache);
112115
int newUnknownErrorCache = validateCacheConfig(Coerce.toInt(config.lookup(
113-
CONFIGURATION_CONFIG_KEY, CredentialRequestHandler.UNKNOWN_ERROR_CACHE_TOPIC).dflt(
116+
CONFIGURATION_CONFIG_KEY, UNKNOWN_ERROR_CACHE_TOPIC).dflt(
114117
CredentialRequestHandler.UNKNOWN_ERROR_CACHE_IN_SEC)), unknownErrorCache);
115118

116119
if (cloud4xxErrorCache != newCloud4xxErrorCache

src/test/java/com/aws/greengrass/tes/TokenExchangeServiceTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@
4848
import static com.aws.greengrass.lifecyclemanager.GreengrassService.SETENV_CONFIG_NAMESPACE;
4949
import static com.aws.greengrass.lifecyclemanager.Kernel.SERVICE_TYPE_TOPIC_KEY;
5050
import static com.aws.greengrass.lifecyclemanager.KernelCommandLine.MAIN_SERVICE_NAME;
51-
import static com.aws.greengrass.tes.CredentialRequestHandler.CLOUD_4XX_ERROR_CACHE_TOPIC;
52-
import static com.aws.greengrass.tes.CredentialRequestHandler.CLOUD_5XX_ERROR_CACHE_TOPIC;
53-
import static com.aws.greengrass.tes.CredentialRequestHandler.UNKNOWN_ERROR_CACHE_TOPIC;
5451
import static com.aws.greengrass.tes.CredentialRequestHandler.CLOUD_4XX_ERROR_CACHE_IN_SEC;
5552
import static com.aws.greengrass.tes.CredentialRequestHandler.CLOUD_5XX_ERROR_CACHE_IN_SEC;
5653
import static com.aws.greengrass.tes.CredentialRequestHandler.UNKNOWN_ERROR_CACHE_IN_SEC;
5754
import static com.aws.greengrass.tes.TokenExchangeService.ACTIVE_PORT_TOPIC;
55+
import static com.aws.greengrass.tes.TokenExchangeService.CLOUD_4XX_ERROR_CACHE_TOPIC;
56+
import static com.aws.greengrass.tes.TokenExchangeService.CLOUD_5XX_ERROR_CACHE_TOPIC;
5857
import static com.aws.greengrass.tes.TokenExchangeService.PORT_TOPIC;
5958
import static com.aws.greengrass.tes.TokenExchangeService.TES_URI_ENV_VARIABLE_NAME;
6059
import static com.aws.greengrass.tes.TokenExchangeService.TOKEN_EXCHANGE_SERVICE_TOPICS;
60+
import static com.aws.greengrass.tes.TokenExchangeService.UNKNOWN_ERROR_CACHE_TOPIC;
6161
import static com.aws.greengrass.testcommons.testutilities.ExceptionLogProtector.ignoreExceptionUltimateCauseOfType;
6262
import static org.junit.jupiter.api.Assertions.assertEquals;
6363
import static org.junit.jupiter.api.Assertions.assertTrue;

0 commit comments

Comments
 (0)