-
Notifications
You must be signed in to change notification settings - Fork 83
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
Implement deletion protection #367
Implement deletion protection #367
Conversation
spec=ServerlessSpec(cloud="aws", region="us-west-2"), | ||
deletion_protection="enabled" |
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.
This is docstrings code.
if deletion_protection in ["enabled", "disabled"]: | ||
dp = DeletionProtection(deletion_protection) | ||
else: | ||
raise ValueError("deletion_protection must be either 'enabled' or 'disabled'") |
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.
The generated DeletionProtection
class implements a validation, but the error message it emits is very confusing. So I implemented my own check on this here and in the configure method.
if deletion_protection is None: | ||
description = self.describe_index(name=name) | ||
dp = DeletionProtection(description.deletion_protection) |
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.
If the user does not specify a value for deletion_protection
, we call describe_index to look up the current value and pass that value with the other arguments in the configure request. Even though the API doesn't require a value to be passed, manual testing showed the generated code will stupidly plugin the default value of disabled
if none is specified. This is needed to avoid disabling deletion protection when somebody is trying to scale by calling this with replicas
or pod_type
only.
pod_config_args.update(replicas=replicas) | ||
|
||
if pod_config_args != {}: | ||
spec = ConfigureIndexRequestSpec(pod=ConfigureIndexRequestSpecPod(**pod_config_args)) |
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.
I hate the arrangement of this code. Blame the black formatter. I need to update the configs to shorten the line length to something more reasonable.
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.
LGTM, thanks again for flagging the issues around the deletionProtection
enum early. Made it much easier to test things across the other clients. 🎉 🚢
It might warrant a broader discussion at some point as to whether we want to completely replace generated types for things like responses in order to give us more flexibility and control over the interface, but that's probably a pretty big lift.
Problem
Implement deletion protection for python sdk
Solution
DeletionProtection
, seemed extremely poor so I added a custom wrapper classIndexModel
and incorporated it into thedescribe_index
andlist_indexes
actions__init__.py
file.This ended up being a much bigger lift than expected, but as a nice side effect we're no longer exposing generated objects in responses from these various actions. That creates some additional flexibility for future refactoring work.
Type of Change
Test Plan
Describe specific steps for validating this change.