8000 fix validator and model check during invocation by bentsku · Pull Request #7846 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

fix validator and model check during invocation #7846

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

Merged
merged 8 commits into from
Mar 17, 2023
Merged

fix validator and model check during invocation #7846

merged 8 commits into from
Mar 17, 2023

Conversation

bentsku
Copy link
Contributor
@bentsku bentsku commented Mar 13, 2023

We had a wrong assumption when using a RequestValidator and validating the body of a request. If a method did not have a requestModel set, we would reject the request. However, AWS uses the default Empty model. We now follow the same logic.

We also did not have validation for validators before, and would return an empty response if no validators existed with that ID. Now, in parity with AWS, it raises an exception instead of returning None.
However, that case should not happen because it's not possible to delete an existing RequestValidator if it's used by a Method in AWS. I'll try to implement this behaviour in following PR.

We needed to change the code in invocations.py to reflect the change when checking if a request is valid.

note: created a test_apigateway_common, where we could test "integrations", or how different RestAPI resources work together, on a level above the CRUD one. If you have a better name than "common", I'm all ears 😄

fixes in part #7842

@bentsku bentsku temporarily deployed to localstack-ext-tests March 13, 2023 12:20 — with GitHub Actions Inactive
@github-actions
Copy link
github-actions bot commented Mar 13, 2023

LocalStack integration with Pro

       3 files  ±  0         3 suites  ±0   1h 42m 44s ⏱️ -19s
1 807 tests +11  1 424 ✔️ +10  383 💤 +1  0 ±0 
2 525 runs  +11  1 790 ✔️ +10  735 💤 +1  0 ±0 

Results for commit 680bdbf. ± Comparison against base commit 77aab87.

♻️ This comment has been updated with latest results.

@bentsku bentsku temporarily deployed to localstack-ext-tests March 15, 2023 00:06 — with GitHub Actions Inactive
@bentsku bentsku changed the base branch from master to apigw-parity-work-models March 15, 2023 00:06
@bentsku bentsku changed the title wip: fix validator check during invocation wip: fix validator and model check during invocation Mar 15, 2023
@coveralls
Copy link
coveralls commented Mar 15, 2023

Coverage Status

Changes Unknown when pulling d290bbf on fix/7842 into ** on master**.

@bentsku bentsku force-pushed the apigw-parity-work-models branch from ea9006d to e1f6be5 Compare March 16, 2023 11:11
Base automatically changed from apigw-parity-work-models to master March 16, 2023 13:18
@bentsku bentsku temporarily deployed to localstack-ext-tests March 16, 2023 13:19 — with GitHub Actions Inactive
@bentsku bentsku changed the title wip: fix validator and model check during invocation fix validator and model check during invocation Mar 16, 2023
@bentsku bentsku self-assigned this Mar 16, 2023
@bentsku bentsku added the aws:apigateway Amazon API Gateway label Mar 16, 2023
@bentsku bentsku requested a review from whummer March 16, 2023 14:56
@bentsku bentsku marked this pull request as ready for review March 16, 2023 18:45
@bentsku bentsku requested a review from calvernaz as a code owner March 16, 2023 18:45
Copy link
Member
@whummer whummer left a comment

Choose a reason for hiding this comment

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

Looks great - as usual, kudos for adding more snapshots to our test suite @bentsku ! 🚀 Added a few minor comments/questions, nothing that should block the merge, though.. 👍

try:
model = self.apigateway_client.get_model(
restApiId=self.context.api_id,
modelName=schema_name,
)
except ClientError as e:
# This should not happen, as we validate that we cannot delete a Model if it's used
Copy link
Member

Choose a reason for hiding this comment

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

I'm always a bit wary of "should not happen" comments - should we simply remove the try/except handling in this case, if we think it is not a valid code path?

Copy link
Contributor Author
@bentsku bentsku Mar 17, 2023

Choose a reason for hiding this comment

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

Yes, I think it can happen for now until #7872 is merged. I'd be for letting it be there, I'll mark it with a TODO instead, until we're sure this code path can't happen anymore.

And maybe somehow the API could be deleted at the same time, triggering an exception. I'll rewrite the comment instead, this might happen in weird case and it's better to log the error and refuse the request than getting some 500 error.

@@ -513,6 +513,11 @@ def update_method(
continue

elif path == "/requestValidatorId" and value not in rest_api.validators:
if not value:
# you can remove a requestValidator by passing an empty string as a value
Copy link
Member

Choose a reason for hiding this comment

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

A wonderful demonstration of the weirdness of API GW patch operations! 😄

requestParameters={"method.request.path.test": True},
)

apigateway_client.put_integration(
Copy link
Member

Choose a reason for hiding this comment

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

nit: for simple integrations, we could try leveraging and extending the create_rest_api_with_integration fixture. It currently only supports dynamodb and kinesis integrations, but Lambda would be a great addition.. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense! I need to take a look at it, and how we can customise it. I guess we can always create simple integrations and use update_* afterwards, for example the requestParameters in that case. There are so many parameters possible.
I'll take a good look a those once I'm starting with integrations. This PR was a bit outside my "normal" work for now, as I was fixing the change in logic now that we are raising exceptions for non-existing resources. 😄

@bentsku bentsku temporarily deployed to localstack-ext-tests March 17, 2023 08:13 — with GitHub Actions Inactive
@bentsku bentsku merged commit 92dca7d into master Mar 17, 2023
@bentsku bentsku deleted the fix/7842 branch March 17, 2023 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws:apigateway Amazon API Gateway
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0