Skip to content

Commit

Permalink
wip - cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sbiscigl committed Sep 10, 2024
1 parent 91f7a0c commit fa6e55e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ namespace client
inline virtual std::shared_ptr<Aws::Http::HttpClient> GetHttpClient() { return m_httpClient; }
virtual void DisableRequestProcessing();


virtual ResolveEndpointOutcome ResolveEndpoint(const Aws::Endpoint::EndpointParameters& endpointParameters, EndpointUpdateCallback&& epCallback) const = 0;
virtual SelectAuthSchemeOptionOutcome SelectAuthSchemeOption(const AwsSmithyClientAsyncRequestContext& ctx) const = 0;
virtual SigningOutcome SignRequest(std::shared_ptr<HttpRequest> httpRequest, const AuthSchemeOption& targetAuthSchemeOption) const = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace smithy {
using AwsCredentialSignerT = AwsSignerBase<IdentityT>;
using SigV4AuthSchemeParameters = DefaultAuthSchemeResolverParameters;

//This allows to override the identity resolver
explicit SigV4AuthScheme(std::shared_ptr<AwsCredentialIdentityResolverT> identityResolver,
const Aws::String& serviceName,
const Aws::String& region)
Expand All @@ -38,7 +39,7 @@ namespace smithy {
//delegate constructor
explicit SigV4AuthScheme(const Aws::String& serviceName,
const Aws::String& region)
: SigV4AuthScheme(Aws::MakeShared<DefaultAwsCredentialIdentityResolver>("SigV4AuthScheme"),
: SigV4AuthScheme(Aws::MakeShared<DefaultAwsCredentialIdentityResolver>("SigV4AuthScheme"),
serviceName,
region)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@
#include <aws/core/auth/AWSCredentialsProviderChain.h>

namespace smithy {
constexpr char ALLOC_ID[] = "DefaultAwsCredentialIdentityResolver";
/**
* A smithy SigV4 AWS Credentials resolver wrapper on top of legacy SDK Credentials provider
* TODO: refactor into own signer using smithy design
*/
class DefaultAwsCredentialIdentityResolver : public AwsCredentialIdentityResolver {
protected:

mutable std::shared_ptr<Aws::Auth::AWSCredentialsProviderChain> legacyChain_sp;

public:
using SigV4AuthSchemeParameters = DefaultAuthSchemeResolverParameters;

DefaultAwsCredentialIdentityResolver():
legacyChain_sp{Aws::MakeShared<Aws::Auth::DefaultAWSCredentialsProviderChain>("DefaultAwsCredentialIdentityResolver")}
{
DefaultAwsCredentialIdentityResolver(): legacyChain_sp{Aws::MakeShared<Aws::Auth::DefaultAWSCredentialsProviderChain>(ALLOC_ID)}{

};

DefaultAwsCredentialIdentityResolver(const DefaultAwsCredentialIdentityResolver& other) = delete;
Expand All @@ -34,8 +38,7 @@ namespace smithy {
assert(legacyChain_sp);
};

ResolveIdentityFutureOutcome getIdentity(const IdentityProperties& identityProperties,
const AdditionalParameters& additionalParameters) override
ResolveIdentityFutureOutcome getIdentity(const IdentityProperties& identityProperties, const AdditionalParameters& additionalParameters) override
{
AWS_UNREFERENCED_PARAM(identityProperties);
AWS_UNREFERENCED_PARAM(additionalParameters);
Expand All @@ -45,15 +48,10 @@ namespace smithy {
auto smithyCreds = Aws::MakeUnique<AwsCredentialIdentity>("DefaultAwsCredentialIdentityResolver",
legacyCreds.GetAWSAccessKeyId(),
legacyCreds.GetAWSSecretKey(),
legacyCreds.GetSessionToken().empty() ?
Aws::Crt::Optional<Aws::String>() :
legacyCreds.GetSessionToken(),
legacyCreds.GetSessionToken().empty()? Aws::Crt::Optional<Aws::String>() : legacyCreds.GetSessionToken(),
legacyCreds.GetExpiration());

return {std::move(smithyCreds)};
return ResolveIdentityFutureOutcome(std::move(smithyCreds));
}

protected:
mutable std::shared_ptr<Aws::Auth::AWSCredentialsProviderChain> legacyChain_sp;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace smithy {
* TODO: refactor into own signer using smithy design
*/
class AwsSigV4Signer : public AwsSignerBase<AwsCredentialIdentityBase> {

public:
using SigV4AuthSchemeParameters = DefaultAuthSchemeResolverParameters;
explicit AwsSigV4Signer(const Aws::String& serviceName, const Aws::String& region)
Expand All @@ -41,7 +42,7 @@ namespace smithy {
}();



auto signPayloadIt = properties.find("SignPayload");
bool signPayload = signPayloadIt != properties.end() ? signPayloadIt->second.get<Aws::String>() == "true" : false;

Expand Down
17 changes: 14 additions & 3 deletions tests/aws-cpp-sdk-core-tests/smithy/client/SmithyClientTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,33 +78,38 @@ class MockDeserializer
std::queue<Aws::String> m_responseQueue{};
};


class SmithyClientTest : public Aws::Testing::AwsCppSdkGTestSuite {
protected:


protected:
static const char ALLOCATION_TAG[];
Aws::Client::ClientConfiguration clientConfig;
std::shared_ptr<Aws::Http::HttpClient> httpClient;
std::shared_ptr<Aws::Client::AWSErrorMarshaller> errorMarshaller;
std::shared_ptr<TestEndPointProvider> endPointProvider;
std::shared_ptr<TestCredentialsProviderChain> credsProviderChain;
public:
public:
void SetUp() override{
httpClient = Aws::MakeShared<MockHttpClient>(ALLOCATION_TAG);
errorMarshaller = Aws::MakeShared<Aws::Client::XmlErrorMarshaller>(ALLOCATION_TAG);
credsProviderChain = Aws::MakeShared<TestCredentialsProviderChain>(ALLOCATION_TAG);

//add mock credentials provider for the test to the credentials provider chain
AddCredentialsProvider(Aws::MakeShared<TestCredentialsProvider>("TestCredentialsProviderChain"));

}

void AddCredentialsProvider(const std::shared_ptr<Aws::Auth::AWSCredentialsProvider>& provider)
{
credsProviderChain->AddProvider(provider);
}

};

const char SmithyClientTest::ALLOCATION_TAG[] = "SmithyClientTest";



using MySmithyClientConfig = Aws::Client::ClientConfiguration;
using MyServiceAuthSchemeResolver = smithy::AuthSchemeResolverBase<smithy::DefaultAuthSchemeResolverParameters>; //smithy::SigV4AuthSchemeResolver<>;
static constexpr char MyServiceName[] = "MySuperService";
Expand Down Expand Up @@ -137,6 +142,7 @@ class TestClient : public MySmithyClient
authSchemesMap)
{}


SelectAuthSchemeOptionOutcome SelectAuthSchemeOption(const smithy::client::AwsSmithyClientAsyncRequestContext& ctx) const
{
return MySmithyClient::SelectAuthSchemeOption(ctx);
Expand All @@ -146,6 +152,8 @@ class TestClient : public MySmithyClient
{
return MySmithyClient::SignRequest(httpRequest, targetAuthSchemeOption);
}


};

TEST_F(SmithyClientTest, testSigV4) {
Expand Down Expand Up @@ -195,6 +203,8 @@ TEST_F(SmithyClientTest, testSigV4) {
std::cout<<"Final auth="<<res2.GetResult()->GetAwsAuthorization()<<std::endl;

EXPECT_EQ(res2.GetResult()->GetSigningAccessKey(), "dummyAccessId");


}


Expand Down Expand Up @@ -246,4 +256,5 @@ TEST_F(SmithyClientTest, testSigV4a) {
EXPECT_TRUE(res2.GetResult()->GetSigningAccessKey().empty());

EXPECT_FALSE(res2.GetResult()->GetUri().GetURIString(true).empty());

}
6 changes: 3 additions & 3 deletions tools/scripts/run_code_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
CORE_COMPONENT_TO_MODEL = {"defaults": DEFAULTS_FILE_LOCATION,
"partitions": PARTITIONS_FILE_LOCATION}

DEBUG = True
DEBUG = False

class ServiceModel(object):
def __init__(self, service_id, c2j_model, endpoint_rule_set, endpoint_tests):
Expand Down Expand Up @@ -292,7 +292,6 @@ def generate_single_client(service_name: str,
del kwargs["use_smithy_client"]
kwargs["use-smithy-client"] = ""


if tmp_dir:
output_filename = f"{tmp_dir}/{model_files.c2j_model.replace('.normal.json', '.zip')}"
else:
Expand Down Expand Up @@ -373,7 +372,7 @@ def parse_arguments() -> dict:
"mark operation functions in service client as virtual functions. Always on by default",
action="store_true")
parser.add_argument("--use-smithy-client",
help="TODO",
help="generate clients using smithy base client if supported",
action="store_true")

args = vars(parser.parse_args())
Expand Down Expand Up @@ -443,6 +442,7 @@ def parse_arguments() -> dict:
if args.get(raw_argument):
raw_generator_arguments[raw_argument] = args[raw_argument]
arg_map["raw_generator_arguments"] = raw_generator_arguments

return arg_map


Expand Down

0 comments on commit fa6e55e

Please sign in to comment.