Skip to content

Commit

Permalink
al2 compilaiton fix, pr comment address
Browse files Browse the repository at this point in the history
  • Loading branch information
sbera87 committed Dec 15, 2024
1 parent cbc6b8f commit a99e702
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ namespace Aws
}
SmithyEventStreamEncoder<smithy::AwsCredentialIdentityBase> m_evtEncoder;
};
} // namespace Event
} // namespace Event
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,57 @@

namespace smithy
{
static const char AWS_SMITHY_CLIENT_SIGNING_TAG[] = "AwsClientRequestSigning";
//4 Minutes
static const std::chrono::milliseconds TIME_DIFF_MAX = std::chrono::minutes(4);
//-4 Minutes
static const std::chrono::milliseconds TIME_DIFF_MIN = std::chrono::minutes(-4);
static const char AWS_SMITHY_CLIENT_SIGNING_TAG[] = "AwsClientRequestSigning";
//4 Minutes
static const std::chrono::milliseconds TIME_DIFF_MAX = std::chrono::minutes(4);
//-4 Minutes
static const std::chrono::milliseconds TIME_DIFF_MIN = std::chrono::minutes(-4);


struct EventStreamSignerVisitor
{
explicit EventStreamSignerVisitor(std::shared_ptr<Aws::Utils::Event::SmithyEventEncoderStream> evSp,
const AuthSchemeOption& targetAuthSchemeOption)
: m_eventEncoderStreamSp(evSp), m_targetAuthSchemeOption(targetAuthSchemeOption) {}
template <typename AuthSchemeAlternativeT>
void operator()(AuthSchemeAlternativeT&) {}
std::shared_ptr<Aws::Utils::Event::SmithyEventEncoderStream> m_eventEncoderStreamSp;
const AuthSchemeOption& m_targetAuthSchemeOption;
};



template <>
void EventStreamSignerVisitor::operator()(smithy::SigV4AuthScheme& authScheme) {
// Auth Scheme Variant alternative contains the requested auth option
assert(strcmp(authScheme.schemeId, m_targetAuthSchemeOption.schemeId) == 0);
using IdentityT = smithy::SigV4AuthScheme::IdentityT;
using IdentityResolver = IdentityResolverBase<IdentityT>;
using Signer = AwsSignerBase<IdentityT>;
std::shared_ptr<Signer> signer = authScheme.signer(m_targetAuthSchemeOption.isEventStreaming);
if (!signer) {
AWS_LOGSTREAM_ERROR(AWS_SMITHY_CLIENT_SIGNING_TAG, "Failed to adjust signing clock skew. Signer is null.");
return;
}

std::shared_ptr<IdentityResolver> identityResolver = authScheme.identityResolver();
if (!identityResolver) {
AWS_LOGSTREAM_ERROR(AWS_SMITHY_CLIENT_SIGNING_TAG, "Failed to find identityResolver.");

return;
}

auto identityResult =
identityResolver->getIdentity(m_targetAuthSchemeOption.identityProperties(), m_targetAuthSchemeOption.identityProperties());

if (!identityResult.IsSuccess()) {
AWS_LOGSTREAM_ERROR(AWS_SMITHY_CLIENT_SIGNING_TAG, "Failed to resolve identity");
return;
}

// typecast to streaming type as we know this visitor is for smithy types
m_eventEncoderStreamSp->SetSigner(signer, std::move(identityResult.GetResultWithOwnership()));
}

template <typename AuthSchemesVariantT>
class AwsClientRequestSigning
Expand Down Expand Up @@ -209,49 +255,5 @@ namespace smithy
}
}
};

struct EventStreamSignerVisitor {
explicit EventStreamSignerVisitor(std::shared_ptr<Aws::Utils::Event::SmithyEventEncoderStream> evSp,
const AuthSchemeOption& targetAuthSchemeOption)
: m_eventEncoderStreamSp(evSp), m_targetAuthSchemeOption(targetAuthSchemeOption) {}

std::shared_ptr<Aws::Utils::Event::SmithyEventEncoderStream> m_eventEncoderStreamSp;
const AuthSchemeOption& m_targetAuthSchemeOption;

template <typename AuthSchemeAlternativeT>
void operator()(AuthSchemeAlternativeT&) {}

template <>
void operator()<smithy::SigV4AuthScheme>(smithy::SigV4AuthScheme& authScheme) {
// Auth Scheme Variant alternative contains the requested auth option
assert(strcmp(authScheme.schemeId, m_targetAuthSchemeOption.schemeId) == 0);
using IdentityT = smithy::SigV4AuthScheme::IdentityT;
using IdentityResolver = IdentityResolverBase<IdentityT>;
using Signer = AwsSignerBase<IdentityT>;
std::shared_ptr<Signer> signer = authScheme.signer(m_targetAuthSchemeOption.isEventStreaming);
if (!signer) {
AWS_LOGSTREAM_ERROR(AWS_SMITHY_CLIENT_SIGNING_TAG, "Failed to adjust signing clock skew. Signer is null.");
return;
}

std::shared_ptr<IdentityResolver> identityResolver = authScheme.identityResolver();
if (!identityResolver) {
AWS_LOGSTREAM_ERROR(AWS_SMITHY_CLIENT_SIGNING_TAG, "Failed to find identityResolver.");

return;
}

auto identityResult =
identityResolver->getIdentity(m_targetAuthSchemeOption.identityProperties(), m_targetAuthSchemeOption.identityProperties());

if (!identityResult.IsSuccess()) {
AWS_LOGSTREAM_ERROR(AWS_SMITHY_CLIENT_SIGNING_TAG, "Failed to resolve identity");
return;
}

// typecast to streaming type as we know this visitor is for smithy types
m_eventEncoderStreamSp->SetSigner(signer, std::move(identityResult.GetResultWithOwnership()));
}
};
};
} // namespace smithy
} // namespace smithy
14 changes: 9 additions & 5 deletions tools/scripts/run_code_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _build_service_model_with_endpoints(models_dir: str, endpoint_rules_dir: str
endpoint_tests=endpoint_tests_filename)


def collect_available_models(models_dir: str, endpoint_rules_dir: str, legacy_mapped_services: Set[str]) -> dict:
def collect_available_models(models_dir: str, endpoint_rules_dir: str, legacy_mapped_services: Set[str], smithy_supported_clients: Set[str]) -> dict:
"""Return a dict of <service_name, model_file_name> with all available c2j models in a models_dir
:param models_dir: path to the directory with c2j models
Expand Down Expand Up @@ -156,7 +156,7 @@ def collect_available_models(models_dir: str, endpoint_rules_dir: str, legacy_ma
if ("protocol" in model["metadata"] and
(model["metadata"]["protocol"] == "json" or model["metadata"]["protocol"] == "rest-json")):
if key not in SMITHY_EXCLUSION_CLIENTS:
SMITHY_SUPPORTED_CLIENTS.add(key)
smithy_supported_clients.add(key)

else:
print("service Id not found in model file:", model_file_date[0], " Skipping.")
Expand Down Expand Up @@ -563,6 +563,9 @@ def main():
with open(os.path.abspath(SMITHY_TO_C2J_MAP_FILE), 'r') as file:
smithy_c2j_data = json.load(file)
c2j_smithy_data = {value: key for key, value in smithy_c2j_data.items()}


smithy_supported_clients = SMITHY_SUPPORTED_CLIENTS.copy()

with ProcessPoolExecutor(max_workers=max_workers) as executor:
build_generator_future = None
Expand All @@ -575,7 +578,8 @@ def main():

available_models = collect_available_models(args["path_to_api_definitions"],
args["path_to_endpoint_rules"],
set(c2j_smithy_data.keys()))
set(c2j_smithy_data.keys()),
smithy_supported_clients)
if args.get("list_all"):
model_list = available_models.keys()
print(model_list)
Expand All @@ -600,7 +604,7 @@ def main():
pending = set()
done = set()
if DEBUG:
print(f"Smithy supported clients: {SMITHY_SUPPORTED_CLIENTS}")
print(f"Smithy supported clients: {smithy_supported_clients}")
print(f"Running code generator, up to {max_workers} processes in parallel")
sys.stdout.flush()
for core_component in ["defaults", "partitions"]:
Expand Down Expand Up @@ -628,7 +632,7 @@ def main():
args["path_to_generator"],
args["output_location"],
None,
(service in SMITHY_SUPPORTED_CLIENTS),
(service in smithy_supported_clients),
args["raw_generator_arguments"])
pending.add(task)

Expand Down

0 comments on commit a99e702

Please sign in to comment.