|
9 | 9 | import com.aws.greengrass.authorization.exceptions.AuthorizationException; |
10 | 10 | import com.aws.greengrass.config.Topic; |
11 | 11 | import com.aws.greengrass.config.Topics; |
| 12 | +import com.aws.greengrass.config.WhatHappened; |
12 | 13 | import com.aws.greengrass.dependency.ImplementsService; |
13 | 14 | import com.aws.greengrass.dependency.State; |
14 | 15 | import com.aws.greengrass.deployment.DeviceConfiguration; |
@@ -87,6 +88,9 @@ public TokenExchangeService(Topics topics, |
87 | 88 |
|
88 | 89 | // Subscribe to cache configuration changes |
89 | 90 | config.subscribe((why, node) -> { |
| 91 | + if (why.equals(WhatHappened.timestampUpdated)) { |
| 92 | + return; |
| 93 | + } |
90 | 94 | if (node != null && (node.childOf(PORT_TOPIC) |
91 | 95 | || node.childOf(CLOUD_4XX_ERROR_CACHE_TOPIC) |
92 | 96 | || node.childOf(CLOUD_5XX_ERROR_CACHE_TOPIC) |
@@ -145,6 +149,7 @@ protected void startup() { |
145 | 149 | .log("Attempting to start server at configured port {}", port); |
146 | 150 | try { |
147 | 151 | validateConfig(); |
| 152 | + validateAllCacheConfigs(); |
148 | 153 | server = new HttpServerImpl(port, credentialRequestHandler); |
149 | 154 | server.start(); |
150 | 155 | logger.atInfo().log("Started server at port {}", server.getServerPort()); |
@@ -180,11 +185,22 @@ private void validateConfig() { |
180 | 185 | } |
181 | 186 | } |
182 | 187 |
|
| 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 | + |
183 | 200 | private int validateCacheConfig(int newCacheValue, String topic) { |
184 | 201 | 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"); |
188 | 204 | } |
189 | 205 | return newCacheValue; |
190 | 206 | } |
|
0 commit comments