in samtranslator/model/api/api_generator.py [0:0]
def _construct_body_s3_dict(self) -> Dict[str, Any]:
"""Constructs the RestApi's `BodyS3Location property`_, from the SAM Api's DefinitionUri property.
:returns: a BodyS3Location dict, containing the S3 Bucket, Key, and Version of the Swagger definition
:rtype: dict
"""
if isinstance(self.definition_uri, dict):
if not self.definition_uri.get("Bucket", None) or not self.definition_uri.get("Key", None):
# DefinitionUri is a dictionary but does not contain Bucket or Key property
raise InvalidResourceException(
self.logical_id, "'DefinitionUri' requires Bucket and Key properties to be specified."
)
s3_pointer = self.definition_uri
else:
# DefinitionUri is a string
_parsed_s3_pointer = parse_s3_uri(self.definition_uri)
if _parsed_s3_pointer is None:
raise InvalidResourceException(
self.logical_id,
"'DefinitionUri' is not a valid S3 Uri of the form "
"'s3://bucket/key' with optional versionId query parameter.",
)
s3_pointer = _parsed_s3_pointer
if isinstance(self.definition_uri, Py27UniStr):
# self.defintion_uri is a Py27UniStr instance if it is defined in the template
# we need to preserve the Py27UniStr type
s3_pointer["Bucket"] = Py27UniStr(s3_pointer["Bucket"])
s3_pointer["Key"] = Py27UniStr(s3_pointer["Key"])
if "Version" in s3_pointer:
s3_pointer["Version"] = Py27UniStr(s3_pointer["Version"])
# Construct body_s3 as py27 dict
body_s3 = Py27Dict()
body_s3["Bucket"] = s3_pointer["Bucket"]
body_s3["Key"] = s3_pointer["Key"]
if "Version" in s3_pointer:
body_s3["Version"] = s3_pointer["Version"]
return body_s3