Skip to content
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

Introduce project event webhook #1113

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
8 changes: 8 additions & 0 deletions api/converter/from_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ func FromProject(pbProject *api.Project) *types.Project {
Name: pbProject.Name,
AuthWebhookURL: pbProject.AuthWebhookUrl,
AuthWebhookMethods: pbProject.AuthWebhookMethods,
EventWebhookURL: pbProject.EventWebhookUrl,
EventWebhookEvents: pbProject.EventWebhookEvents,
ClientDeactivateThreshold: pbProject.ClientDeactivateThreshold,
PublicKey: pbProject.PublicKey,
SecretKey: pbProject.SecretKey,
Expand Down Expand Up @@ -921,6 +923,12 @@ func FromUpdatableProjectFields(pbProjectFields *api.UpdatableProjectFields) (*t
if pbProjectFields.AuthWebhookMethods != nil {
updatableProjectFields.AuthWebhookMethods = &pbProjectFields.AuthWebhookMethods.Methods
}
if pbProjectFields.EventWebhookUrl != nil {
updatableProjectFields.EventWebhookURL = &pbProjectFields.EventWebhookUrl.Value
}
if pbProjectFields.EventWebhookEvents != nil {
updatableProjectFields.EventWebhookEvents = &pbProjectFields.EventWebhookEvents.Events
}
Comment on lines +926 to +931
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add null pointer check before dereferencing.

The code directly dereferences Value and Events fields without checking if EventWebhookUrl or EventWebhookEvents is nil, which could lead to a panic.

        if pbProjectFields.EventWebhookUrl != nil {
+               if pbProjectFields.EventWebhookUrl.Value != "" {
+                       if _, err := url.Parse(pbProjectFields.EventWebhookUrl.Value); err == nil {
                                updatableProjectFields.EventWebhookURL = &pbProjectFields.EventWebhookUrl.Value
+                       }
+               }
        }
        if pbProjectFields.EventWebhookEvents != nil {
+               if len(pbProjectFields.EventWebhookEvents.Events) > 0 {
                        updatableProjectFields.EventWebhookEvents = &pbProjectFields.EventWebhookEvents.Events
+               }
        }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if pbProjectFields.EventWebhookUrl != nil {
updatableProjectFields.EventWebhookURL = &pbProjectFields.EventWebhookUrl.Value
}
if pbProjectFields.EventWebhookEvents != nil {
updatableProjectFields.EventWebhookEvents = &pbProjectFields.EventWebhookEvents.Events
}
if pbProjectFields.EventWebhookUrl != nil {
if pbProjectFields.EventWebhookUrl.Value != "" {
if _, err := url.Parse(pbProjectFields.EventWebhookUrl.Value); err == nil {
updatableProjectFields.EventWebhookURL = &pbProjectFields.EventWebhookUrl.Value
}
}
}
if pbProjectFields.EventWebhookEvents != nil {
if len(pbProjectFields.EventWebhookEvents.Events) > 0 {
updatableProjectFields.EventWebhookEvents = &pbProjectFields.EventWebhookEvents.Events
}
}

if pbProjectFields.ClientDeactivateThreshold != nil {
updatableProjectFields.ClientDeactivateThreshold = &pbProjectFields.ClientDeactivateThreshold.Value
}
Expand Down
13 changes: 13 additions & 0 deletions api/converter/to_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,19 @@ func ToUpdatableProjectFields(fields *types.UpdatableProjectFields) (*api.Updata
} else {
pbUpdatableProjectFields.AuthWebhookMethods = nil
}
if fields.EventWebhookURL != nil {
pbUpdatableProjectFields.EventWebhookUrl = &wrapperspb.StringValue{
Value: *fields.EventWebhookURL,
}
}
if fields.EventWebhookEvents != nil {
pbUpdatableProjectFields.EventWebhookEvents = &api.UpdatableProjectFields_EventWebhookEvents{
Events: *fields.EventWebhookEvents,
}
} else {
pbUpdatableProjectFields.EventWebhookEvents = nil
}

if fields.ClientDeactivateThreshold != nil {
pbUpdatableProjectFields.ClientDeactivateThreshold = &wrapperspb.StringValue{
Value: *fields.ClientDeactivateThreshold,
Expand Down
657 changes: 346 additions & 311 deletions api/docs/yorkie/v1/admin.openapi.yaml

Large diffs are not rendered by default.

97 changes: 54 additions & 43 deletions api/docs/yorkie/v1/cluster.openapi.yaml
Original file line number Diff line number Diff line change
@@ -1,82 +1,81 @@
openapi: 3.1.0
info:
description:
Yorkie is an open source document store for building collaborative
description: Yorkie is an open source document store for building collaborative
editing applications.
title: Yorkie
version: v0.5.8
servers:
- description: Production server
url: https://api.yorkie.dev
- description: Local server
url: http://localhost:8080
- description: Production server
url: https://api.yorkie.dev
- description: Local server
url: http://localhost:8080
paths:
/yorkie.v1.ClusterService/DetachDocument:
post:
description: ""
requestBody:
$ref: "#/components/requestBodies/yorkie.v1.ClusterService.DetachDocument.yorkie.v1.ClusterServiceDetachDocumentRequest"
$ref: '#/components/requestBodies/yorkie.v1.ClusterService.DetachDocument.yorkie.v1.ClusterServiceDetachDocumentRequest'
responses:
"200":
$ref: "#/components/responses/yorkie.v1.ClusterService.DetachDocument.yorkie.v1.ClusterServiceDetachDocumentResponse"
$ref: '#/components/responses/yorkie.v1.ClusterService.DetachDocument.yorkie.v1.ClusterServiceDetachDocumentResponse'
default:
$ref: "#/components/responses/connect.error"
$ref: '#/components/responses/connect.error'
tags:
- yorkie.v1.ClusterService
- yorkie.v1.ClusterService
components:
requestBodies:
yorkie.v1.ClusterService.DetachDocument.yorkie.v1.ClusterServiceDetachDocumentRequest:
content:
application/json:
schema:
$ref: "#/components/schemas/yorkie.v1.ClusterServiceDetachDocumentRequest"
$ref: '#/components/schemas/yorkie.v1.ClusterServiceDetachDocumentRequest'
application/proto:
schema:
$ref: "#/components/schemas/yorkie.v1.ClusterServiceDetachDocumentRequest"
$ref: '#/components/schemas/yorkie.v1.ClusterServiceDetachDocumentRequest'
required: true
responses:
connect.error:
content:
application/json:
schema:
$ref: "#/components/schemas/connect.error"
$ref: '#/components/schemas/connect.error'
application/proto:
schema:
$ref: "#/components/schemas/connect.error"
$ref: '#/components/schemas/connect.error'
description: ""
yorkie.v1.ClusterService.DetachDocument.yorkie.v1.ClusterServiceDetachDocumentResponse:
content:
application/json:
schema:
$ref: "#/components/schemas/yorkie.v1.ClusterServiceDetachDocumentResponse"
$ref: '#/components/schemas/yorkie.v1.ClusterServiceDetachDocumentResponse'
application/proto:
schema:
$ref: "#/components/schemas/yorkie.v1.ClusterServiceDetachDocumentResponse"
$ref: '#/components/schemas/yorkie.v1.ClusterServiceDetachDocumentResponse'
description: ""
schemas:
connect.error:
additionalProperties: false
description: "Error type returned by Connect: https://connectrpc.com/docs/go/errors/#http-representation"
description: 'Error type returned by Connect: https://connectrpc.com/docs/go/errors/#http-representation'
properties:
code:
enum:
- CodeCanceled
- CodeUnknown
- CodeInvalidArgument
- CodeDeadlineExceeded
- CodeNotFound
- CodeAlreadyExists
- CodePermissionDenied
- CodeResourceExhausted
- CodeFailedPrecondition
- CodeAborted
- CodeOutOfRange
- CodeInternal
- CodeUnavailable
- CodeDataLoss
- CodeUnauthenticated
- CodeCanceled
- CodeUnknown
- CodeInvalidArgument
- CodeDeadlineExceeded
- CodeNotFound
- CodeAlreadyExists
- CodePermissionDenied
- CodeResourceExhausted
- CodeFailedPrecondition
- CodeAborted
- CodeOutOfRange
- CodeInternal
- CodeUnavailable
- CodeDataLoss
- CodeUnauthenticated
examples:
- CodeNotFound
- CodeNotFound
type: string
message:
type: string
Expand Down Expand Up @@ -186,13 +185,13 @@ components:
title: client_id
type: string
documentSummary:
$ref: "#/components/schemas/yorkie.v1.DocumentSummary"
$ref: '#/components/schemas/yorkie.v1.DocumentSummary'
additionalProperties: false
description: ""
title: document_summary
type: object
project:
$ref: "#/components/schemas/yorkie.v1.Project"
$ref: '#/components/schemas/yorkie.v1.Project'
additionalProperties: false
description: ""
title: project
Expand All @@ -209,13 +208,13 @@ components:
description: ""
properties:
accessedAt:
$ref: "#/components/schemas/google.protobuf.Timestamp"
$ref: '#/components/schemas/google.protobuf.Timestamp'
additionalProperties: false
description: ""
title: accessed_at
type: object
createdAt:
$ref: "#/components/schemas/google.protobuf.Timestamp"
$ref: '#/components/schemas/google.protobuf.Timestamp'
additionalProperties: false
description: ""
title: created_at
Expand All @@ -236,7 +235,7 @@ components:
title: snapshot
type: string
updatedAt:
$ref: "#/components/schemas/google.protobuf.Timestamp"
$ref: '#/components/schemas/google.protobuf.Timestamp'
additionalProperties: false
description: ""
title: updated_at
Expand Down Expand Up @@ -265,11 +264,23 @@ components:
title: client_deactivate_threshold
type: string
createdAt:
$ref: "#/components/schemas/google.protobuf.Timestamp"
$ref: '#/components/schemas/google.protobuf.Timestamp'
additionalProperties: false
description: ""
title: created_at
type: object
eventWebhookEvents:
additionalProperties: false
description: ""
items:
type: string
title: event_webhook_events
type: array
Comment on lines +272 to +278
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add documentation and validation for event webhook events.

The eventWebhookEvents property lacks documentation about supported event types and validation constraints.

Add description and enum validation:

         eventWebhookEvents:
           additionalProperties: false
-          description: ""
+          description: "List of event types that trigger the webhook. Supported values: documentCreated, documentRemoved"
           items:
+            enum:
+              - documentCreated
+              - documentRemoved
             type: string
           title: event_webhook_events
           type: array
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
eventWebhookEvents:
additionalProperties: false
description: ""
items:
type: string
title: event_webhook_events
type: array
eventWebhookEvents:
additionalProperties: false
description: "List of event types that trigger the webhook. Supported values: documentCreated, documentRemoved"
items:
enum:
- documentCreated
- documentRemoved
type: string
title: event_webhook_events
type: array

eventWebhookUrl:
additionalProperties: false
description: ""
title: event_webhook_url
type: string
Comment on lines +279 to +283
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add URL format validation for webhook endpoint.

The eventWebhookUrl property should validate the URL format to prevent configuration errors.

Add format validation:

         eventWebhookUrl:
           additionalProperties: false
-          description: ""
+          description: "HTTPS URL endpoint where webhook events will be delivered"
+          format: uri
+          pattern: "^https://.+"
           title: event_webhook_url
           type: string
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
eventWebhookUrl:
additionalProperties: false
description: ""
title: event_webhook_url
type: string
eventWebhookUrl:
additionalProperties: false
description: "HTTPS URL endpoint where webhook events will be delivered"
format: uri
pattern: "^https://.+"
title: event_webhook_url
type: string

id:
additionalProperties: false
description: ""
Expand All @@ -291,7 +302,7 @@ components:
title: secret_key
type: string
updatedAt:
$ref: "#/components/schemas/google.protobuf.Timestamp"
$ref: '#/components/schemas/google.protobuf.Timestamp'
additionalProperties: false
description: ""
title: updated_at
Expand All @@ -304,7 +315,7 @@ components:
name: Authorization
type: apiKey
security:
- ApiKeyAuth: []
- ApiKeyAuth: []
tags:
- description: ClusterService is a service that provides an API for Cluster.
name: yorkie.v1.ClusterService
- description: ClusterService is a service that provides an API for Cluster.
name: yorkie.v1.ClusterService
Loading
Loading