-
Notifications
You must be signed in to change notification settings - Fork 97
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
Add UpdateSubscription endpoint #398
Conversation
Codecov Report
@@ Coverage Diff @@
## master #398 +/- ##
==========================================
+ Coverage 61.14% 62.72% +1.57%
==========================================
Files 26 26
Lines 1521 1588 +67
==========================================
+ Hits 930 996 +66
+ Misses 554 550 -4
- Partials 37 42 +5
Continue to review full report at Codecov.
|
libkv/subscription.go
Outdated
return nil, err | ||
} | ||
|
||
// If the subscriptionID changes, it should be a new subscription rather than an update. |
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 think it should be approached differently. validateSubscription
should check if event
, functionId
, path
and method
are the same, if not it should return validation error. If those values are the same we can just update the key in etcd.
This approach causes that in some cases if we will change the subscription ID we will also need to change this logic. There is no need to do that.
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 approach causes that in some cases if we will change the subscription ID we will also need to change this logic
Wouldn't we need a migration of existing subscriptions anyway in that case? Also, if we do change the how the subscriptionID is calculated, wouldn't that be implemented in the generateSubscriptionID
method?
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.
It would, but we should not treat ID as something that contains meaningful ingo. It can be easily achieved by comparing current values with new values, it's just safer and more obvious. It's a bit more confusing the IDs are compared..
subscription/errors.go
Outdated
} | ||
|
||
func (e ErrInvalidSubscriptionUpdate) Error() string { | ||
return fmt.Sprintf("Invalid update. This update would change the SubscriptionID for %q.", e.ID) |
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'm not sure if that's important to user. The more important would be "Path of existing subscription cannot be update." or something.
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, two small requests though.
README.md
Outdated
**Request** | ||
|
||
* `event` - `string` - event name | ||
* `functionId` - `string` - ID of function to receive events |
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.
can you add some info that those fields cannot be updated?
libkv/subscription.go
Outdated
@@ -65,6 +65,48 @@ func (service Service) CreateSubscription(s *subscription.Subscription) (*subscr | |||
return s, nil | |||
} | |||
|
|||
// UpdateSubscription updates subscription. | |||
func (service Service) UpdateSubscription(id subscription.ID, s *subscription.Subscription) (*subscription.Subscription, error) { | |||
err := service.validateSubscription(s) |
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 know that you didn't introduce that but can you remove validateSubscription method from the struct and just make it regular function like validateSubscriptionUpdate
?
|
||
Status code: | ||
|
||
* `200 Created` on success |
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.
404 if subscription not found
application/json: | ||
schema: | ||
$ref: "#/components/schemas/Subscription" | ||
400: |
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.
404 missing
httpapi/httpapi.go
Outdated
if _, ok := err.(*subscription.ErrInvalidSubscriptionUpdate); ok { | ||
w.WriteHeader(http.StatusBadRequest) | ||
} else if _, ok := err.(*subscription.ErrSubscriptionNotFound); ok { | ||
w.WriteHeader(http.StatusBadRequest) |
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.
it should be 404
|
||
httpresp := &httpapi.Response{} | ||
json.Unmarshal(resp.Body.Bytes(), httpresp) | ||
assert.Equal(t, http.StatusBadRequest, resp.Code) |
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.
404
What did you implement:
Adds an
UpdateSubscription
API endpoint in the Config API. For now, this should only be called if updating the CORS config on an HTTP subscription as the rest of the metadata is included in the subscriptionId.How did you implement it:
Most of the implementation is pretty straight-forward. As noted above, we should only allow a Subscription to be updated
if the CORS config is being changed, as the rest of the Subscription data is included in the subscriptionID.in very limited scenarios. If you're changing one of those elements, you're not updating a Subscription but rather creating a new Subscription.To handle this check, I
generate a subscriptionID and compare it against the existing subscriptionID. If they're different, I throw an error. I thought this would be better than explicitly checking for CORS changes or otherwise comparing the update to the existing. It also should work in the future if we add additional metadata to the Subscription object that's not in the subscription ID.make sure certain values haven't changed and throw an error if they do.How can we verify it:
Start the Event Gateway locally, then:
This should succeed and return the full subscription:
This should fail as it would change the subscription ID:
Todos:
Is this ready for review?: YES
Is it a breaking change?: NO