Skip to content

Commit

Permalink
chore(fips): update endpoint overwrite method (#435)
Browse files Browse the repository at this point in the history
(cherry picked from commit 27ef646)
  • Loading branch information
yitingb authored and junfuchen99 committed Aug 9, 2024
1 parent 7e0dc50 commit 2c8bece
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion benchmark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<dependency>
<groupId>com.aws.greengrass</groupId>
<artifactId>nucleus</artifactId>
<version>2.6.0-SNAPSHOT</version>
<version>2.13.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.aws.greengrass</groupId>
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>2.17.81</version>
<version>2.20.138</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -73,13 +73,13 @@
<dependency>
<groupId>com.aws.greengrass</groupId>
<artifactId>nucleus</artifactId>
<version>2.6.0-SNAPSHOT</version>
<version>2.13.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.aws.greengrass</groupId>
<artifactId>nucleus</artifactId>
<version>2.6.0-SNAPSHOT</version>
<version>2.13.0-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.aws.greengrass.clientdevices.auth.iot.NetworkStateFake;
import com.aws.greengrass.dependency.State;
import com.aws.greengrass.lifecyclemanager.Kernel;
import com.aws.greengrass.mqttclient.MqttRequestException;
import com.aws.greengrass.mqttclient.spool.SpoolerStoreException;
import com.aws.greengrass.testcommons.testutilities.GGExtension;

Expand All @@ -46,6 +47,7 @@
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;

Expand Down Expand Up @@ -172,7 +174,8 @@ void GIVEN_clientDevice_WHEN_verifyingItsIdentity_THEN_pemStored(ExtensionContex
@Test
void GIVEN_clientConnectsWhileOnline_WHEN_offline_THEN_clientCanConnect(ExtensionContext context) throws Exception {
ignoreExceptionOfType(context, NoSuchFileException.class);

ignoreExceptionOfType(context, MqttRequestException.class);
ignoreExceptionOfType(context, ExecutionException.class);
// Given
network.goOnline();

Expand All @@ -198,7 +201,8 @@ void GIVEN_clientConnectsWhileOnline_WHEN_offline_THEN_clientCanConnect(Extensio
void GIVEN_clientConnectsWhileOnline_WHEN_offlineAndTtlExpired_THEN_clientCanNotConnect(ExtensionContext context)
throws Exception {
ignoreExceptionOfType(context, NoSuchFileException.class);

ignoreExceptionOfType(context, MqttRequestException.class);
ignoreExceptionOfType(context, ExecutionException.class);
// Given
network.goOnline();
Instant now = Instant.now();
Expand Down Expand Up @@ -230,6 +234,8 @@ void GIVEN_clientConnectsWhileOnline_WHEN_offlineAndTtlExpired_THEN_clientCanNot
void GIVEN_clientConnectsWhileOnline_WHEN_offlineAndCertificateRevoked_THEN_backOnlineAndClientRejected(
ExtensionContext context) throws Exception {
ignoreExceptionOfType(context, NoSuchFileException.class);
ignoreExceptionOfType(context, MqttRequestException.class);
ignoreExceptionOfType(context, ExecutionException.class);
// Given
network.goOnline();

Expand Down Expand Up @@ -260,6 +266,8 @@ void GIVEN_clientConnectsWhileOnline_WHEN_offlineAndCertificateRevoked_THEN_back
void GIVEN_clientConnectsWhileOnline_WHEN_offlineAndCertDetachedFromThing_THEN_backOnlineAndClientRejected(
ExtensionContext context) throws Exception {
ignoreExceptionOfType(context, NoSuchFileException.class);
ignoreExceptionOfType(context, MqttRequestException.class);
ignoreExceptionOfType(context, ExecutionException.class);
// Given
network.goOnline();

Expand Down Expand Up @@ -291,6 +299,8 @@ void GIVEN_clientConnectsWhileOnline_WHEN_storedPemIsCorrupted_THEN_clientCanSti
ExtensionContext context) throws Exception {
ignoreExceptionOfType(context, NoSuchFileException.class);
ignoreExceptionOfType(context, InvalidCertificateException.class);
ignoreExceptionOfType(context, MqttRequestException.class);
ignoreExceptionOfType(context, ExecutionException.class);
// Given
network.goOnline();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@
import software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.core.retry.RetryPolicy;
import software.amazon.awssdk.endpoints.Endpoint;
import software.amazon.awssdk.http.apache.ApacheHttpClient;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.greengrassv2data.GreengrassV2DataClient;
import software.amazon.awssdk.services.greengrassv2data.GreengrassV2DataClientBuilder;
import software.amazon.awssdk.services.greengrassv2data.endpoints.GreengrassV2DataEndpointParams;
import software.amazon.awssdk.services.greengrassv2data.endpoints.GreengrassV2DataEndpointProvider;

import java.net.URI;
import java.util.concurrent.CompletableFuture;
import javax.inject.Inject;

/**
Expand Down Expand Up @@ -51,14 +55,23 @@ public GreengrassV2DataClient getClient() throws DeviceConfigurationException {
String ggServiceEndpoint = ClientConfigurationUtils.getGreengrassServiceEndpoint(deviceConfiguration);
ApacheHttpClient.Builder httpClient = ClientConfigurationUtils.getConfiguredClientBuilder(deviceConfiguration);

GreengrassV2DataEndpointProvider endpointProvider = new GreengrassV2DataEndpointProvider() {
@Override
public CompletableFuture<Endpoint> resolveEndpoint(GreengrassV2DataEndpointParams endpointParams) {
return CompletableFuture.supplyAsync(() -> Endpoint.builder()
.url(URI.create(ggServiceEndpoint))
.build());
}
};

GreengrassV2DataClientBuilder clientBuilder =
GreengrassV2DataClient.builder().credentialsProvider(AnonymousCredentialsProvider.create())
.endpointProvider(endpointProvider)
.httpClientBuilder(httpClient.useIdleConnectionReaper(false))
.overrideConfiguration(ClientOverrideConfiguration.builder()
.retryPolicy(RetryPolicy.none()).build());

clientBuilder.region(Region.of(awsRegion));
clientBuilder.endpointOverride(URI.create(ggServiceEndpoint));
return clientBuilder.build();
}

Expand Down

0 comments on commit 2c8bece

Please sign in to comment.