-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Fix: Regex issue and Keyerror crash #1794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -308,11 +308,16 @@ def _construct_basepath_mappings(self, basepaths, http_api): | |
invalid_regex = r"[^0-9a-zA-Z\/\-\_]+" | ||
if re.search(invalid_regex, path) is not None: | ||
raise InvalidResourceException(self.logical_id, "Invalid Basepath name provided.") | ||
# ignore leading and trailing `/` in the path name | ||
m = re.search(r"[a-zA-Z0-9]+[\-\_]?[a-zA-Z0-9]+", path) | ||
path = m.string[m.start(0) : m.end(0)] | ||
if path is None: | ||
raise InvalidResourceException(self.logical_id, "Invalid Basepath name provided.") | ||
|
||
if path == "/": | ||
path = "" | ||
else: | ||
# ignore leading and trailing `/` in the path name | ||
m = re.search(r"[a-zA-Z0-9]+[\-\_]?[a-zA-Z0-9]+", path) | ||
path = m.string[m.start(0) : m.end(0)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not clear from reading the code what If it's generating a logical ID from an arbitrary string, we should refactor in such a way; it seems to be a fairly generic use-case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point. I am not sure about the reason behind creating logical_id like this. But we can try to understand where we use the logical id further and modify the logic accordingly. I will merge this PR for now and can track this later. |
||
if path is None: | ||
raise InvalidResourceException(self.logical_id, "Invalid Basepath name provided.") | ||
|
||
logical_id = "{}{}{}".format(self.logical_id, re.sub(r"[\-\_]+", "", path), "ApiMapping") | ||
basepath_mapping = ApiGatewayV2ApiMapping(logical_id, attributes=self.passthrough_resource_attributes) | ||
basepath_mapping.DomainName = ref(self.domain.get("ApiDomainName")) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Resources: | ||
SomeHttpApi: | ||
Type: AWS::Serverless::HttpApi | ||
Properties: | ||
DefinitionBody: | ||
paths: | ||
"/{domain}": | ||
any: | ||
responses: {} | ||
"/{domain/}{id}": | ||
any: | ||
responses: {} | ||
openapi: 3.0.1 | ||
Auth: | ||
Authorizers: | ||
OAuth2Authorizer: | ||
AuthorizationScopes: | ||
JwtConfiguration: | ||
audience: | ||
- randomnumber | ||
issuer: https://some/issuer | ||
IdentitySource: "$request.headers.Authorization" | ||
DefaultAuthorizer: OAuth2Authorizer |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Could not find x-amazon-apigateway-any-method in /{domain} within DefinitionBody." | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: since we are just ignoring the leading and trailing
/
, I think we can simplify the code asThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, it does look better, however even with this i won't be able to get rid of the if else as i would still have to check if path is "" before I do re.search. so I don't think it will be that useful.