Skip to content

Commit

Permalink
Add account id to the built-in endpoint parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyRyabinin committed Aug 13, 2024
1 parent f142890 commit 4b77004
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#pragma once
#include <aws/dynamodb/DynamoDB_EXPORTS.h>
#include <aws/core/client/GenericClientConfiguration.h>
#include <aws/dynamodb/DynamoDBClientConfiguration.h>
#include <aws/core/endpoint/DefaultEndpointProvider.h>
#include <aws/core/endpoint/EndpointParameter.h>
#include <aws/core/utils/memory/stl/AWSString.h>
Expand All @@ -20,13 +20,13 @@ namespace DynamoDB
{
namespace Endpoint
{
using DynamoDBClientConfiguration = Aws::DynamoDB::DynamoDBClientConfiguration;
using EndpointParameters = Aws::Endpoint::EndpointParameters;
using Aws::Endpoint::EndpointProviderBase;
using Aws::Endpoint::DefaultEndpointProvider;

using DynamoDBClientContextParameters = Aws::Endpoint::ClientContextParameters;

using DynamoDBClientConfiguration = Aws::Client::GenericClientConfiguration;
using DynamoDBBuiltInParameters = Aws::Endpoint::BuiltInParameters;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#pragma once
#include <aws/timestream-query/TimestreamQuery_EXPORTS.h>
#include <aws/core/client/GenericClientConfiguration.h>
#include <aws/timestream-query/TimestreamQueryClientConfiguration.h>
#include <aws/core/endpoint/DefaultEndpointProvider.h>
#include <aws/core/endpoint/EndpointParameter.h>
#include <aws/core/utils/memory/stl/AWSString.h>
Expand All @@ -20,13 +20,13 @@ namespace TimestreamQuery
{
namespace Endpoint
{
using TimestreamQueryClientConfiguration = Aws::TimestreamQuery::TimestreamQueryClientConfiguration;
using EndpointParameters = Aws::Endpoint::EndpointParameters;
using Aws::Endpoint::EndpointProviderBase;
using Aws::Endpoint::DefaultEndpointProvider;

using TimestreamQueryClientContextParameters = Aws::Endpoint::ClientContextParameters;

using TimestreamQueryClientConfiguration = Aws::Client::GenericClientConfiguration;
using TimestreamQueryBuiltInParameters = Aws::Endpoint::BuiltInParameters;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#pragma once
#include <aws/timestream-write/TimestreamWrite_EXPORTS.h>
#include <aws/core/client/GenericClientConfiguration.h>
#include <aws/timestream-write/TimestreamWriteClientConfiguration.h>
#include <aws/core/endpoint/DefaultEndpointProvider.h>
#include <aws/core/endpoint/EndpointParameter.h>
#include <aws/core/utils/memory/stl/AWSString.h>
Expand All @@ -20,13 +20,13 @@ namespace TimestreamWrite
{
namespace Endpoint
{
using TimestreamWriteClientConfiguration = Aws::TimestreamWrite::TimestreamWriteClientConfiguration;
using EndpointParameters = Aws::Endpoint::EndpointParameters;
using Aws::Endpoint::EndpointProviderBase;
using Aws::Endpoint::DefaultEndpointProvider;

using TimestreamWriteClientContextParameters = Aws::Endpoint::ClientContextParameters;

using TimestreamWriteClientConfiguration = Aws::Client::GenericClientConfiguration;
using TimestreamWriteBuiltInParameters = Aws::Endpoint::BuiltInParameters;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package com.amazonaws.util.awsclientgenerator.domainmodels.c2j;

import com.amazonaws.util.awsclientgenerator.domainmodels.codegeneration.ClientContextParams;
import com.amazonaws.util.awsclientgenerator.domainmodels.codegeneration.EndpointRuleSetModel;
import com.amazonaws.util.awsclientgenerator.domainmodels.endpoints.EndpointTests;
import lombok.Data;

Expand All @@ -19,7 +20,8 @@ public class C2jServiceModel {
Map<String, C2jShape> shapes;
Map<String, C2jOperation> operations;
String serviceName;
String endpointRules;
String endpointRules; // as a blob
EndpointRuleSetModel endpointRuleSetModel;
EndpointTests endpointTests;
ClientContextParams clientContextParams;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

package com.amazonaws.util.awsclientgenerator.domainmodels.codegeneration;

import lombok.Data;

import java.util.List;
import java.util.Map;

@Data
public class EndpointRuleSetModel {
@Data
public static class Parameter {
@Data
public static class Deprecated {
private String message;
private String since;

}

private String type; // required in schema
private String builtIn;
private boolean required;
private String documentation;
private Deprecated deprecated;

}

private String version;
private String serviceId;
private Map<String, Parameter> parameters;
// private List<Rule> rules; // ignored by this SDK code gen at the moment
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ public boolean hasOnlyBearerAuth() {
return operations.values().parallelStream().allMatch(operation -> operation.getSignerName().equals("Aws::Auth::BEARER_SIGNER"));
}

public boolean hasServiceSpecificClientConfig() {
return metadata.getServiceId().equalsIgnoreCase("S3") ||
metadata.getServiceId().equalsIgnoreCase("S3-CRT") ||
metadata.getServiceId().equalsIgnoreCase("S3 Control") ||
metadata.isHasEndpointDiscoveryTrait() ||
endpointRuleSetModel.getParameters().containsKey("AccountId") || endpointRuleSetModel.getParameters().containsKey("AccountIdEndpointMode");
}

public boolean hasServiceSpecificEndpointProvider() {
return metadata.getServiceId().equalsIgnoreCase("S3") ||
metadata.getServiceId().equalsIgnoreCase("S3-CRT") ||
metadata.getServiceId().equalsIgnoreCase("S3 Control") ||
endpointRuleSetModel.getParameters().containsKey("AccountId") || endpointRuleSetModel.getParameters().containsKey("AccountIdEndpointMode");
}

public Operation getOperationForRequestShapeName(String requestShapeName) {
for (Map.Entry<String, Operation> opEntry : operations.entrySet()) {
Operation op = opEntry.getValue();
Expand All @@ -71,7 +86,8 @@ public Operation getOperationForRequestShapeName(String requestShapeName) {
return null;
}

String endpointRules;
String endpointRules; // as a blob
EndpointRuleSetModel endpointRuleSetModel;
EndpointTests endpointTests;
ClientContextParams clientContextParams;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package com.amazonaws.util.awsclientgenerator.generators;

import com.amazonaws.util.awsclientgenerator.domainmodels.c2j.C2jServiceModel;
import com.amazonaws.util.awsclientgenerator.domainmodels.codegeneration.EndpointRuleSetModel;
import com.amazonaws.util.awsclientgenerator.domainmodels.codegeneration.PartitionsModel;
import com.amazonaws.util.awsclientgenerator.domainmodels.defaults.BaseOption;
import com.amazonaws.util.awsclientgenerator.domainmodels.defaults.BaseOptionModifier;
Expand Down Expand Up @@ -42,6 +43,8 @@ public ByteArrayOutputStream generateServiceSourceFromJson(String rawJson, Strin
C2jServiceModel c2jServiceModel = gson.fromJson(rawJson, C2jServiceModel.class);
c2jServiceModel.setServiceName(serviceName);
c2jServiceModel.setEndpointRules(endpointRuleSet);
EndpointRuleSetModel endpointRuleSetBom = parseEndpointRuleSet(endpointRuleSet);
c2jServiceModel.setEndpointRuleSetModel(endpointRuleSetBom);
if (endpointRulesTests != null) {
EndpointTests endpointTestsModel = gson.fromJson(endpointRulesTests, EndpointTests.class);
c2jServiceModel.setEndpointTests(endpointTestsModel);
Expand Down Expand Up @@ -127,6 +130,18 @@ public PartitionsModel parsePartitions(final String rawJson) {
return gson.fromJson(rawJson, PartitionsModel.class);
}

/**
* Parse rawJson into a structured EndpointRuleSet object
*
* @param rawJson the raw json representation of the partitions object.
* @return a parsed object of partitions.
*/
public EndpointRuleSetModel parseEndpointRuleSet(final String rawJson) {
Gson gson = new Gson();
return gson.fromJson(rawJson, EndpointRuleSetModel.class);
}


/**
* A function to generate C++ source for service client tests
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@ public SdkFileEntry[] generateSourceFiles(ServiceModel serviceModel) throws Exce
fileList.add(generateEndpointProviderHeaderFile(serviceModel));
fileList.add(generateEndpointProviderSourceFile(serviceModel));

if (serviceModel.getMetadata().getServiceId().equalsIgnoreCase("S3") ||
serviceModel.getMetadata().getServiceId().equalsIgnoreCase("S3-CRT") ||
serviceModel.getMetadata().getServiceId().equalsIgnoreCase("S3 Control") ||
serviceModel.getMetadata().isHasEndpointDiscoveryTrait()) {
if (serviceModel.hasServiceSpecificClientConfig()) {
fileList.add(generateServiceClientConfigurationHeaderFile(serviceModel));
fileList.add(generateServiceClientConfigurationSourceFile(serviceModel));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public ServiceModel convert() {
shortenedRules += "\0";
serviceModel.setEndpointRules(shortenedRules);
}
serviceModel.setEndpointRuleSetModel(c2jServiceModel.getEndpointRuleSetModel());
serviceModel.setEndpointTests(c2jServiceModel.getEndpointTests());
serviceModel.setClientContextParams(c2jServiceModel.getClientContextParams());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ namespace ${rootNamespace}
*/
Aws::Crt::Optional<bool>& enableEndpointDiscovery;

#end
#if($serviceModel.endpointRuleSetModel.parameters.containsKey("AccountId"))
/**
* $serviceModel.endpointRuleSetModel.parameters["AccountId"].documentation
*/
Aws::String accountId;
#end
#if($serviceModel.endpointRuleSetModel.parameters.containsKey("AccountIdEndpointMode"))
/**
* $serviceModel.endpointRuleSetModel.parameters["AccountIdEndpointMode"].documentation
*/
Aws::String accountIdEndpointMode = "preferred";
#end
private:
void Load${serviceNamespace}SpecificConfig(const Aws::String& profileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ void ${metadata.classNamePrefix}ClientConfiguration::Load${serviceNamespace}Spec
enableEndpointDiscovery = IsEndpointDiscoveryEnabled(this->endpointOverride, inputProfileName);
}
#end
#if($serviceModel.endpointRuleSetModel.parameters.containsKey("AccountId"))
// accountId is intentionally not set here: AWS_ACCOUNT_ID env variable may not match the provided credentials.
// it must be set by an auth provider / identity resolver or by an SDK user.
#end
#if($serviceModel.endpointRuleSetModel.parameters.containsKey("AccountIdEndpointMode"))
static const char AWS_ACCOUNT_ID_ENDPOINT_MODE_ENVIRONMENT_VARIABLE[] = "AWS_ACCOUNT_ID_ENDPOINT_MODE";
static const char AWS_ACCOUNT_ID_ENDPOINT_MODE_CONFIG_FILE_OPTION[] = "account_id_endpoint_mode";
accountIdEndpointMode = ClientConfiguration::LoadConfigFromEnvOrProfile(AWS_ACCOUNT_ID_ENDPOINT_MODE_ENVIRONMENT_VARIABLE,
inputProfileName,
AWS_ACCOUNT_ID_ENDPOINT_MODE_CONFIG_FILE_OPTION,
{"required", "disabled", "preferred"}, /* allowed values */
"preferred" /* default value */);
#end
}

${metadata.classNamePrefix}ClientConfiguration::${metadata.classNamePrefix}ClientConfiguration(const Client::ClientConfigurationInitValues &configuration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#set($externMacro = "AWS_${metadata.classNamePrefix.toUpperCase()}_EXTERN")
#pragma once
\#include <aws/${metadata.projectName}/${metadata.classNamePrefix}_EXPORTS.h>
#if($serviceModel.metadata.serviceId == "S3" || $serviceModel.metadata.serviceId == "S3 Control")
#if($serviceModel.hasServiceSpecificClientConfig())
\#include <aws/${metadata.projectName}/${metadata.classNamePrefix}ClientConfiguration.h>
#else
\#include <aws/core/client/GenericClientConfiguration.h>
Expand All @@ -31,7 +31,7 @@ namespace ${serviceNamespace}
{
namespace Endpoint
{
#if($serviceModel.metadata.serviceId == "S3" || $serviceModel.metadata.serviceId == "S3 Control")
#if($serviceModel.hasServiceSpecificClientConfig())
using ${metadata.classNamePrefix}ClientConfiguration = Aws::${serviceNamespace}::${metadata.classNamePrefix}ClientConfiguration;
#end
using EndpointParameters = Aws::Endpoint::EndpointParameters;
Expand Down Expand Up @@ -65,10 +65,10 @@ public:
using ${epContextClassName} = Aws::Endpoint::ClientContextParameters;
#end

#if($serviceModel.metadata.serviceId != "S3" && $serviceModel.metadata.serviceId != "S3 Control")
#if(!$serviceModel.hasServiceSpecificClientConfig())
using ${metadata.classNamePrefix}ClientConfiguration = Aws::Client::GenericClientConfiguration;
#end
#if($serviceModel.metadata.serviceId == "S3" || $serviceModel.metadata.serviceId == "S3 Control")
#if($serviceModel.hasServiceSpecificEndpointProvider())
class ${exportMacro} ${epBuiltInClassName} : public Aws::Endpoint::BuiltInParameters
{
public:
Expand All @@ -91,7 +91,7 @@ using ${metadata.classNamePrefix}EndpointProviderBase =
using ${metadata.classNamePrefix}DefaultEpProviderBase =
DefaultEndpointProvider<${metadata.classNamePrefix}ClientConfiguration, ${epBuiltInClassName}, ${epContextClassName}>;

#if($serviceModel.metadata.serviceId == "S3" || $serviceModel.metadata.serviceId == "S3 Control" || $serviceModel.clientContextParams)
#if($serviceModel.hasServiceSpecificEndpointProvider() || $serviceModel.clientContextParams)
} // namespace Endpoint
} // namespace ${serviceNamespace}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace ${rootNamespace}
{
#if($serviceModel.metadata.serviceId == "S3" || $serviceModel.metadata.serviceId == "S3 Control" || $serviceModel.clientContextParams)
#if($serviceModel.hasServiceSpecificEndpointProvider() || $serviceModel.clientContextParams)
#ifndef AWS_${metadata.classNamePrefix.toUpperCase()}_EXPORTS // Except for Windows DLL
namespace Endpoint
{
Expand Down Expand Up @@ -54,7 +54,7 @@ namespace Endpoint
}
#end
#end
#if($serviceModel.metadata.serviceId == "S3" || $serviceModel.metadata.serviceId == "S3 Control")
#if($serviceModel.hasServiceSpecificEndpointProvider())
void ${epBuiltInClassName}::SetFromClientConfiguration(const ${metadata.classNamePrefix}ClientConfiguration& config)
{
SetFromClientConfiguration(static_cast<const ${metadata.classNamePrefix}ClientConfiguration::BaseClientConfigClass&>(config));
Expand Down Expand Up @@ -88,6 +88,16 @@ namespace Endpoint
#if($serviceModel.metadata.serviceId == "S3 Control")
static const char* AWS_S3_USE_ARN_REGION = "UseArnRegion";
SetBooleanParameter(AWS_S3_USE_ARN_REGION, config.useArnRegion);
#end
#if($serviceModel.endpointRuleSetModel.parameters.containsKey("AccountId"))
if(!config.accountId.empty()) {
SetStringParameter("AccountId", config.accountId);
}
#end
#if($serviceModel.endpointRuleSetModel.parameters.containsKey("AccountIdEndpointMode"))
if(!config.accountIdEndpointMode.empty()) {
SetStringParameter("AccountIdEndpointMode", config.accountIdEndpointMode);
}
#end
}
#end
Expand Down

0 comments on commit 4b77004

Please sign in to comment.