Skip to content

Commit

Permalink
Rename webhook types to webhook events for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
hackerwins committed Feb 20, 2025
1 parent da1fda0 commit 2b86a00
Show file tree
Hide file tree
Showing 28 changed files with 347 additions and 330 deletions.
6 changes: 3 additions & 3 deletions api/converter/from_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func FromProject(pbProject *api.Project) *types.Project {
AuthWebhookURL: pbProject.AuthWebhookUrl,
AuthWebhookMethods: pbProject.AuthWebhookMethods,
EventWebhookURL: pbProject.EventWebhookUrl,
EventWebhookTypes: pbProject.EventWebhookTypes,
EventWebhookEvents: pbProject.EventWebhookEvents,
ClientDeactivateThreshold: pbProject.ClientDeactivateThreshold,
PublicKey: pbProject.PublicKey,
SecretKey: pbProject.SecretKey,
Expand Down Expand Up @@ -927,8 +927,8 @@ func FromUpdatableProjectFields(pbProjectFields *api.UpdatableProjectFields) (*t
if pbProjectFields.EventWebhookUrl != nil {
updatableProjectFields.EventWebhookURL = &pbProjectFields.EventWebhookUrl.Value
}
if pbProjectFields.EventWebhookTypes != nil {
updatableProjectFields.EventWebhookTypes = &pbProjectFields.EventWebhookTypes.Types
if pbProjectFields.EventWebhookEvents != nil {
updatableProjectFields.EventWebhookEvents = &pbProjectFields.EventWebhookEvents.Events
}
if pbProjectFields.ClientDeactivateThreshold != nil {
updatableProjectFields.ClientDeactivateThreshold = &pbProjectFields.ClientDeactivateThreshold.Value
Expand Down
10 changes: 5 additions & 5 deletions api/converter/to_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func ToProject(project *types.Project) *api.Project {
AuthWebhookUrl: project.AuthWebhookURL,
AuthWebhookMethods: project.AuthWebhookMethods,
EventWebhookUrl: project.EventWebhookURL,
EventWebhookTypes: project.EventWebhookTypes,
EventWebhookEvents: project.EventWebhookEvents,
ClientDeactivateThreshold: project.ClientDeactivateThreshold,
PublicKey: project.PublicKey,
SecretKey: project.SecretKey,
Expand Down Expand Up @@ -567,12 +567,12 @@ func ToUpdatableProjectFields(fields *types.UpdatableProjectFields) (*api.Updata
if fields.EventWebhookURL != nil {
pbUpdatableProjectFields.EventWebhookUrl = &wrapperspb.StringValue{Value: *fields.EventWebhookURL}
}
if fields.EventWebhookTypes != nil {
pbUpdatableProjectFields.EventWebhookTypes = &api.UpdatableProjectFields_EventWebhookTypes{
Types: *fields.EventWebhookTypes,
if fields.EventWebhookEvents != nil {
pbUpdatableProjectFields.EventWebhookEvents = &api.UpdatableProjectFields_EventWebhookEvents{
Events: *fields.EventWebhookEvents,
}
} else {
pbUpdatableProjectFields.EventWebhookTypes = nil
pbUpdatableProjectFields.EventWebhookEvents = nil
}
if fields.ClientDeactivateThreshold != nil {
pbUpdatableProjectFields.ClientDeactivateThreshold = &wrapperspb.StringValue{
Expand Down
27 changes: 14 additions & 13 deletions api/docs/yorkie/v1/admin.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1463,10 +1463,11 @@ components:
type: object
yorkie.v1.Operation.Select:
additionalProperties: false
description: "NOTE(hackerwins): Select Operation is not used in the current
version.\r\n In the previous version, it was used to represent selection of
Text.\r\n However, it has been replaced by Presence now. It is retained for
backward\r\n compatibility purposes."
description: |-
NOTE(hackerwins): Select Operation is not used in the current version.
In the previous version, it was used to represent selection of Text.
However, it has been replaced by Presence now. It is retained for backward
compatibility purposes.
properties:
executedAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
Expand Down Expand Up @@ -1825,12 +1826,12 @@ components:
description: ""
title: created_at
type: object
eventWebhookTypes:
eventWebhookEvents:
additionalProperties: false
description: ""
items:
type: string
title: event_webhook_types
title: event_webhook_events
type: array
eventWebhookUrl:
additionalProperties: false
Expand Down Expand Up @@ -2143,11 +2144,11 @@ components:
description: ""
title: client_deactivate_threshold
type: object
eventWebhookTypes:
$ref: '#/components/schemas/yorkie.v1.UpdatableProjectFields.EventWebhookTypes'
eventWebhookEvents:
$ref: '#/components/schemas/yorkie.v1.UpdatableProjectFields.EventWebhookEvents'
additionalProperties: false
description: ""
title: event_webhook_types
title: event_webhook_events
type: object
eventWebhookUrl:
$ref: '#/components/schemas/google.protobuf.StringValue'
Expand Down Expand Up @@ -2176,18 +2177,18 @@ components:
type: array
title: AuthWebhookMethods
type: object
yorkie.v1.UpdatableProjectFields.EventWebhookTypes:
yorkie.v1.UpdatableProjectFields.EventWebhookEvents:
additionalProperties: false
description: ""
properties:
types:
events:
additionalProperties: false
description: ""
items:
type: string
title: types
title: events
type: array
title: EventWebhookTypes
title: EventWebhookEvents
type: object
yorkie.v1.UpdateProjectRequest:
additionalProperties: false
Expand Down
4 changes: 2 additions & 2 deletions api/docs/yorkie/v1/cluster.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,12 @@ components:
description: ""
title: created_at
type: object
eventWebhookTypes:
eventWebhookEvents:
additionalProperties: false
description: ""
items:
type: string
title: event_webhook_types
title: event_webhook_events
type: array
eventWebhookUrl:
additionalProperties: false
Expand Down
38 changes: 21 additions & 17 deletions api/docs/yorkie/v1/resources.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,9 @@ components:
type: object
yorkie.v1.ChangePack:
additionalProperties: false
description: "ChangePack is a message that contains all changes that occurred
in a document.\r\n It is used to synchronize changes between clients and servers."
description: |-
ChangePack is a message that contains all changes that occurred in a document.
It is used to synchronize changes between clients and servers.
properties:
changes:
additionalProperties: false
Expand Down Expand Up @@ -971,10 +972,11 @@ components:
type: object
yorkie.v1.Operation.Select:
additionalProperties: false
description: "NOTE(hackerwins): Select Operation is not used in the current
version.\r\n In the previous version, it was used to represent selection of
Text.\r\n However, it has been replaced by Presence now. It is retained for
backward\r\n compatibility purposes."
description: |-
NOTE(hackerwins): Select Operation is not used in the current version.
In the previous version, it was used to represent selection of Text.
However, it has been replaced by Presence now. It is retained for backward
compatibility purposes.
properties:
executedAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
Expand Down Expand Up @@ -1333,12 +1335,12 @@ components:
description: ""
title: created_at
type: object
eventWebhookTypes:
eventWebhookEvents:
additionalProperties: false
description: ""
items:
type: string
title: event_webhook_types
title: event_webhook_events
type: array
eventWebhookUrl:
additionalProperties: false
Expand Down Expand Up @@ -1410,8 +1412,10 @@ components:
type: object
yorkie.v1.Snapshot:
additionalProperties: false
description: "///////////////////////////////////////\r\n Messages for Snapshot
\ //\r\n///////////////////////////////////////"
description: |-
///////////////////////////////////////
Messages for Snapshot //
///////////////////////////////////////
properties:
presences:
additionalProperties: false
Expand Down Expand Up @@ -1695,11 +1699,11 @@ components:
description: ""
title: client_deactivate_threshold
type: object
eventWebhookTypes:
$ref: '#/components/schemas/yorkie.v1.UpdatableProjectFields.EventWebhookTypes'
eventWebhookEvents:
$ref: '#/components/schemas/yorkie.v1.UpdatableProjectFields.EventWebhookEvents'
additionalProperties: false
description: ""
title: event_webhook_types
title: event_webhook_events
type: object
eventWebhookUrl:
$ref: '#/components/schemas/google.protobuf.StringValue'
Expand Down Expand Up @@ -1728,18 +1732,18 @@ components:
type: array
title: AuthWebhookMethods
type: object
yorkie.v1.UpdatableProjectFields.EventWebhookTypes:
yorkie.v1.UpdatableProjectFields.EventWebhookEvents:
additionalProperties: false
description: ""
properties:
types:
events:
additionalProperties: false
description: ""
items:
type: string
title: types
title: events
type: array
title: EventWebhookTypes
title: EventWebhookEvents
type: object
yorkie.v1.User:
additionalProperties: false
Expand Down
14 changes: 8 additions & 6 deletions api/docs/yorkie/v1/yorkie.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,9 @@ components:
type: object
yorkie.v1.ChangePack:
additionalProperties: false
description: "ChangePack is a message that contains all changes that occurred
in a document.\r\n It is used to synchronize changes between clients and servers."
description: |-
ChangePack is a message that contains all changes that occurred in a document.
It is used to synchronize changes between clients and servers.
properties:
changes:
additionalProperties: false
Expand Down Expand Up @@ -976,10 +977,11 @@ components:
type: object
yorkie.v1.Operation.Select:
additionalProperties: false
description: "NOTE(hackerwins): Select Operation is not used in the current
version.\r\n In the previous version, it was used to represent selection of
Text.\r\n However, it has been replaced by Presence now. It is retained for
backward\r\n compatibility purposes."
description: |-
NOTE(hackerwins): Select Operation is not used in the current version.
In the previous version, it was used to represent selection of Text.
However, it has been replaced by Presence now. It is retained for backward
compatibility purposes.
properties:
executedAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
Expand Down
10 changes: 5 additions & 5 deletions api/types/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ type Project struct {
// EventWebhookURL is the url of the event webhook.
EventWebhookURL string `json:"event_webhook_url"`

// EventWebhookTypes is the types that send the event webhook.
EventWebhookTypes []string `json:"event_webhook_types"`
// EventWebhookEvents are the events that event webhook will be triggered.
EventWebhookEvents []string `json:"event_webhook_events"`

// ClientDeactivateThreshold is the time after which clients in
// specific project are considered deactivate for housekeeping.
Expand Down Expand Up @@ -80,17 +80,17 @@ func (p *Project) RequireAuth(method Method) bool {
return false
}

// RequireEventWebhook returns whether the given method requires to send event webhook.
// RequireEventWebhook returns whether the given type requires to send event webhook.
func (p *Project) RequireEventWebhook(eventType EventWebhookType) bool {
if len(p.EventWebhookURL) == 0 {
return false
}

if len(p.EventWebhookTypes) == 0 {
if len(p.EventWebhookEvents) == 0 {
return false
}

for _, t := range p.EventWebhookTypes {
for _, t := range p.EventWebhookEvents {
if EventWebhookType(t) == eventType {
return true
}
Expand Down
8 changes: 4 additions & 4 deletions api/types/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ func TestProjectInfo(t *testing.T) {
// 1. Specify which event types to allow
validWebhookURL := "ValidWebhookURL"
info := &types.Project{
EventWebhookURL: validWebhookURL,
EventWebhookTypes: []string{string(types.DocRootChanged)},
EventWebhookURL: validWebhookURL,
EventWebhookEvents: []string{string(types.DocRootChanged)},
}
assert.True(t, info.RequireEventWebhook(types.DocRootChanged))

// 2. No event types specified
info2 := &types.Project{
EventWebhookURL: validWebhookURL,
EventWebhookTypes: []string{},
EventWebhookURL: validWebhookURL,
EventWebhookEvents: []string{},
}
assert.False(t, info2.RequireEventWebhook(types.DocRootChanged))

Expand Down
6 changes: 3 additions & 3 deletions api/types/updatable_project_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ type UpdatableProjectFields struct {
// EventWebhookURL is the URL of the event webhook.
EventWebhookURL *string `bson:"event_webhook_url,omitempty" validate:"omitempty,url|emptystring"`

// EventWebhookTypes is the types of events that trigger the webhook.
EventWebhookTypes *[]string `bson:"event_webhook_types,omitempty" validate:"omitempty,invalid_webhook_event"`
// EventWebhookEvents is the events that trigger the webhook.
EventWebhookEvents *[]string `bson:"event_webhook_events,omitempty" validate:"omitempty,invalid_webhook_event"`

// ClientDeactivateThreshold is the time after which clients in specific project are considered deactivate.
ClientDeactivateThreshold *string `bson:"client_deactivate_threshold,omitempty" validate:"omitempty,min=2,duration"`
Expand All @@ -56,7 +56,7 @@ func (i *UpdatableProjectFields) Validate() error {
i.AuthWebhookMethods == nil &&
i.ClientDeactivateThreshold == nil &&
i.EventWebhookURL == nil &&
i.EventWebhookTypes == nil {
i.EventWebhookEvents == nil {
return ErrEmptyProjectFields
}

Expand Down
10 changes: 5 additions & 5 deletions api/types/updatable_project_fields_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestUpdatableProjectFields(t *testing.T) {
string(types.WatchDocuments),
}
newEventWebhookURL := "http://localhost:4000"
newEventWebhookTypes := []string{
newEventWebhookEvents := []string{
string(types.DocRootChanged),
}
newClientDeactivateThreshold := "1h"
Expand All @@ -44,7 +44,7 @@ func TestUpdatableProjectFields(t *testing.T) {
AuthWebhookURL: &newAuthWebhookURL,
AuthWebhookMethods: &newAuthWebhookMethods,
EventWebhookURL: &newEventWebhookURL,
EventWebhookTypes: &newEventWebhookTypes,
EventWebhookEvents: &newEventWebhookEvents,
ClientDeactivateThreshold: &newClientDeactivateThreshold,
}
assert.NoError(t, fields.Validate())
Expand All @@ -69,15 +69,15 @@ func TestUpdatableProjectFields(t *testing.T) {
newAuthWebhookMethods = []string{
"InvalidMethods",
}
// invalid EventWebhookTypes
newEventWebhookTypes = []string{
// invalid EventWebhookEvents
newEventWebhookEvents = []string{
"DocChanged",
}
fields = &types.UpdatableProjectFields{
Name: &newName,
AuthWebhookURL: &newAuthWebhookURL,
AuthWebhookMethods: &newAuthWebhookMethods,
EventWebhookTypes: &newEventWebhookTypes,
EventWebhookEvents: &newEventWebhookEvents,
ClientDeactivateThreshold: &newClientDeactivateThreshold,
}
assert.ErrorAs(t, fields.Validate(), &formErr)
Expand Down
5 changes: 2 additions & 3 deletions api/yorkie/v1/admin.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions api/yorkie/v1/cluster.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2b86a00

Please sign in to comment.