Skip to content

Commit e4879f8

Browse files
authored
Update rule set (#599)
1 parent 25ca7a5 commit e4879f8

File tree

1 file changed

+40
-23
lines changed

1 file changed

+40
-23
lines changed

scripts/update_s3_endpoint_resolver_artifacts.py

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import argparse
77
import json
8-
import boto3
98
import requests
109

1110

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

7372

74-
def get_secret_from_secrets_manager(secret_name, region_name):
75-
session = boto3.session.Session()
76-
client = session.client(
77-
service_name='secretsmanager',
78-
region_name=region_name
79-
)
73+
def extract_rule_set(s3_model):
74+
"""
75+
Extract the smithy.rules#endpointRuleSet from the s3_model JSON.
8076
77+
The ruleset is nested at: shapes -> com.amazonaws.s3#AmazonS3 -> traits -> smithy.rules#endpointRuleSet
78+
79+
Args:
80+
s3_model: The full s3-2006-03-01.json model as a dictionary
81+
82+
Returns:
83+
The endpoint ruleset dictionary
84+
85+
Raises:
86+
KeyError: If the expected path doesn't exist in the model
87+
"""
8188
try:
82-
get_secret_value_response = client.get_secret_value(
83-
SecretId=secret_name
84-
)
85-
except Exception as e:
86-
raise e
89+
# Navigate through the nested structure to find the endpoint ruleset
90+
shapes = s3_model.get('shapes', {})
91+
amazon_s3_shape = shapes.get('com.amazonaws.s3#AmazonS3', {})
92+
traits = amazon_s3_shape.get('traits', {})
93+
rule_set = traits.get('smithy.rules#endpointRuleSet', None)
8794

88-
return json.loads(get_secret_value_response['SecretString'])
95+
if rule_set is None:
96+
raise KeyError(
97+
"smithy.rules#endpointRuleSet not found in s3_model")
98+
99+
return rule_set
100+
101+
except KeyError as e:
102+
raise KeyError(
103+
f"Failed to extract endpoint ruleset from s3_model: {e}")
89104

90105

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

101116

102117
if __name__ == '__main__':
103-
argument_parser = argparse.ArgumentParser(description="Endpoint Ruleset Updater")
118+
argument_parser = argparse.ArgumentParser(
119+
description="Endpoint Ruleset Updater")
104120
argument_parser.add_argument("--ruleset", metavar="<Path to ruleset>",
105-
required=False, help="Path to endpoint ruleset json file")
121+
required=False, help="Path to endpoint ruleset json file")
106122
argument_parser.add_argument("--partitions", metavar="<Path to partitions>",
107-
required=False, help="Path to partitions json file")
123+
required=False, help="Path to partitions json file")
108124
parsed_args = argument_parser.parse_args()
109125

110-
git_secret = get_secret_from_secrets_manager("s3/endpoint/resolver/artifacts/git", "us-east-1")
111-
112126
if (parsed_args.ruleset):
113127
with open(parsed_args.ruleset) as f:
114-
rule_set = json.load(f)
128+
rule_set = json.load(f)
115129
else:
116-
rule_set = download_from_git(git_secret['ruleset-url'], git_secret['ruleset-token'])
130+
s3_model = download_from_git(
131+
'https://raw.githubusercontent.com/aws/api-models-aws/refs/heads/main/models/s3/service/2006-03-01/s3-2006-03-01.json')
132+
rule_set = extract_rule_set(s3_model)
117133

118-
if (parsed_args.partitions):
134+
if (parsed_args.partitions):
119135
with open(parsed_args.partitions) as f:
120-
partition = json.load(f)
136+
partition = json.load(f)
121137
else:
122-
partition = download_from_git('https://raw.githubusercontent.com/aws/aws-sdk-cpp/main/tools/code-generation/partitions/partitions.json')
138+
partition = download_from_git(
139+
'https://raw.githubusercontent.com/aws/aws-sdk-cpp/main/tools/code-generation/partitions/partitions.json')
123140

124141
generate_c_file_from_json(
125142
rule_set,

0 commit comments

Comments
 (0)