From ffdba8365f8a24468c3cd16e2150915e84472bf9 Mon Sep 17 00:00:00 2001 From: yitingb <118219519+yitingb@users.noreply.github.com> Date: Wed, 11 Oct 2023 12:25:44 -0500 Subject: [PATCH] fix: s3 regional endpoint cover version upgrade scenario (#1543) --- .../com/aws/greengrass/deployment/DeviceConfiguration.java | 4 ++++ .../java/com/aws/greengrass/util/S3SdkClientFactoryTest.java | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/aws/greengrass/deployment/DeviceConfiguration.java b/src/main/java/com/aws/greengrass/deployment/DeviceConfiguration.java index 865f204c32..938ee02e19 100644 --- a/src/main/java/com/aws/greengrass/deployment/DeviceConfiguration.java +++ b/src/main/java/com/aws/greengrass/deployment/DeviceConfiguration.java @@ -171,6 +171,10 @@ public DeviceConfiguration(Kernel kernel) { handleLoggingConfig(); getComponentStoreMaxSizeBytes().dflt(COMPONENT_STORE_MAX_SIZE_DEFAULT_BYTES); getDeploymentPollingFrequencySeconds().dflt(DEPLOYMENT_POLLING_FREQUENCY_DEFAULT_SECONDS); + if (System.getProperty(S3_ENDPOINT_PROP_NAME) != null + && System.getProperty(S3_ENDPOINT_PROP_NAME).equalsIgnoreCase(S3EndpointType.REGIONAL.name())) { + gets3EndpointType().withValue(S3EndpointType.REGIONAL.name()); + } // reset the cache when device configuration changes onAnyChange((what, node) -> deviceConfigValidateCachedResult.set(null)); } diff --git a/src/test/java/com/aws/greengrass/util/S3SdkClientFactoryTest.java b/src/test/java/com/aws/greengrass/util/S3SdkClientFactoryTest.java index 71c39ba461..b994c01e65 100644 --- a/src/test/java/com/aws/greengrass/util/S3SdkClientFactoryTest.java +++ b/src/test/java/com/aws/greengrass/util/S3SdkClientFactoryTest.java @@ -61,6 +61,7 @@ void clearCache() { if(cachedClient != null) { cachedClient.close(); } + System.clearProperty(S3_ENDPOINT_PROP_NAME); } @Test @@ -110,7 +111,7 @@ void GIVEN_valid_configuration_WHEN_updated_THEN_new_added() throws DeviceConfig @Test void GIVEN_valid_configuration_WHEN_get_client_for_region_THEN_clients_cached() { S3SdkClientFactory factory = new S3SdkClientFactory(deviceConfig, credentialProvider); - + factory.handleRegionUpdate(); try (S3Client client = factory.getClientForRegion(Region.US_WEST_2)) { assertThat("has client", client, is(notNullValue())); assertThat(S3SdkClientFactory.clientCache, hasEntry(is(Region.US_WEST_2), is(client)));