Skip to content

Commit

Permalink
Add custom user-agent prefix to Route53 calls
Browse files Browse the repository at this point in the history
This commits adds a prefix to the user-agent header field of the client
that makes requests to AWS Route 53 API. User agent is now prefixed as
in:

User-Agent: dyna53::Route53, ...

This is done to allow explicit identification of (well-behaving, i.e.,
unmodified) Dyna53 traffic if that would be needed at any time from AWS
perspective.

Original idea credits to https://twitter.com/antonbabenko
  • Loading branch information
ahachete committed Nov 27, 2022
1 parent 9769840 commit 2289d20
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,35 @@
package com.ongres.labs.dyna53.route53;


import org.eclipse.microprofile.config.inject.ConfigProperty;
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption;
import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.route53.Route53AsyncClient;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;


@ApplicationScoped
public class Route53AsyncClientProvider {
private static final String DYNA53_ROUTE53_USER_AGENT_PREFIX = "dyna53::Route53";

@ConfigProperty(name = "route53_aws_profile")
String route53AWSProfile;

@Produces
public Route53AsyncClient provideRoute53AsyncClient() {
return Route53AsyncClient.builder()
.credentialsProvider(ProfileCredentialsProvider.create("dyna53"))
// Play nice and provide explicit identification for Dyna53 requests to AWS Route 53 services
.overrideConfiguration(
ClientOverrideConfiguration.builder()
.putAdvancedOption(SdkAdvancedClientOption.USER_AGENT_PREFIX, DYNA53_ROUTE53_USER_AGENT_PREFIX)
.build()
)
.credentialsProvider(ProfileCredentialsProvider.create(route53AWSProfile))
.httpClientBuilder(NettyNioAsyncHttpClient.builder()) // Needed by GraalVM native, reflection issues
.region(Region.AWS_GLOBAL)
.build();
Expand Down

0 comments on commit 2289d20

Please sign in to comment.