Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 40 additions & 23 deletions scripts/update_s3_endpoint_resolver_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import argparse
import json
import boto3
import requests


Expand Down Expand Up @@ -71,21 +70,37 @@ def generate_c_file_from_json(json_content, c_file_name, c_struct_name):
print(f"An error occurred: {e}")


def get_secret_from_secrets_manager(secret_name, region_name):
session = boto3.session.Session()
client = session.client(
service_name='secretsmanager',
region_name=region_name
)
def extract_rule_set(s3_model):
"""
Extract the smithy.rules#endpointRuleSet from the s3_model JSON.

The ruleset is nested at: shapes -> com.amazonaws.s3#AmazonS3 -> traits -> smithy.rules#endpointRuleSet

Args:
s3_model: The full s3-2006-03-01.json model as a dictionary

Returns:
The endpoint ruleset dictionary

Raises:
KeyError: If the expected path doesn't exist in the model
"""
try:
get_secret_value_response = client.get_secret_value(
SecretId=secret_name
)
except Exception as e:
raise e
# Navigate through the nested structure to find the endpoint ruleset
shapes = s3_model.get('shapes', {})
amazon_s3_shape = shapes.get('com.amazonaws.s3#AmazonS3', {})
traits = amazon_s3_shape.get('traits', {})
rule_set = traits.get('smithy.rules#endpointRuleSet', None)

return json.loads(get_secret_value_response['SecretString'])
if rule_set is None:
raise KeyError(
"smithy.rules#endpointRuleSet not found in s3_model")

return rule_set

except KeyError as e:
raise KeyError(
f"Failed to extract endpoint ruleset from s3_model: {e}")


def download_from_git(url, token=None):
Expand All @@ -100,26 +115,28 @@ def download_from_git(url, token=None):


if __name__ == '__main__':
argument_parser = argparse.ArgumentParser(description="Endpoint Ruleset Updater")
argument_parser = argparse.ArgumentParser(
description="Endpoint Ruleset Updater")
argument_parser.add_argument("--ruleset", metavar="<Path to ruleset>",
required=False, help="Path to endpoint ruleset json file")
required=False, help="Path to endpoint ruleset json file")
argument_parser.add_argument("--partitions", metavar="<Path to partitions>",
required=False, help="Path to partitions json file")
required=False, help="Path to partitions json file")
parsed_args = argument_parser.parse_args()

git_secret = get_secret_from_secrets_manager("s3/endpoint/resolver/artifacts/git", "us-east-1")

if (parsed_args.ruleset):
with open(parsed_args.ruleset) as f:
rule_set = json.load(f)
rule_set = json.load(f)
else:
rule_set = download_from_git(git_secret['ruleset-url'], git_secret['ruleset-token'])
s3_model = download_from_git(
'https://raw.githubusercontent.com/aws/api-models-aws/refs/heads/main/models/s3/service/2006-03-01/s3-2006-03-01.json')
rule_set = extract_rule_set(s3_model)

if (parsed_args.partitions):
if (parsed_args.partitions):
with open(parsed_args.partitions) as f:
partition = json.load(f)
partition = json.load(f)
else:
partition = download_from_git('https://raw.githubusercontent.com/aws/aws-sdk-cpp/main/tools/code-generation/partitions/partitions.json')
partition = download_from_git(
'https://raw.githubusercontent.com/aws/aws-sdk-cpp/main/tools/code-generation/partitions/partitions.json')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we still using CPP sdk for something specific? I thought we were moving to public models instead of relying on CPP sdk?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only rule set are available from the model, the partition is not.
The baseline partitions.json file will be delivered via a SDK release tool that we are not on. So, we still need to grab it via C++ SDK.


generate_c_file_from_json(
rule_set,
Expand Down