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 #1131

Closed
wants to merge 14 commits into 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
}
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
Comment on lines 12 to +24
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 webhook-related endpoint specifications.

The PR objectives mention webhook functionality and HMAC signature authentication, but the API specification is missing:

  1. Webhook configuration endpoints
  2. HMAC signature header definition (X-Signature)
  3. Webhook event payload schemas

Would you like me to help generate the missing API specifications for the webhook functionality?

Also applies to: 313-321

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
eventWebhookUrl:
additionalProperties: false
description: ""
title: event_webhook_url
type: string
Comment on lines +272 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

Enhance webhook property definitions.

The new webhook properties need more detailed specifications:

  1. Add descriptions explaining the purpose and usage of each property
  2. Add URL format validation for eventWebhookUrl
  3. Define allowed values for eventWebhookEvents using an enum

Apply this diff to enhance the property definitions:

   eventWebhookEvents:
     additionalProperties: false
-    description: ""
+    description: "List of event types that trigger webhook notifications (e.g., document.created, document.removed)"
     items:
-      type: string
+      type: string
+      enum:
+        - document.created
+        - document.removed
     title: event_webhook_events
     type: array
   eventWebhookUrl:
     additionalProperties: false
-    description: ""
+    description: "HTTPS URL that will receive webhook event notifications"
     title: event_webhook_url
     type: string
+    format: uri
+    pattern: "^https://"
📝 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
eventWebhookUrl:
additionalProperties: false
description: ""
title: event_webhook_url
type: string
eventWebhookEvents:
additionalProperties: false
description: "List of event types that trigger webhook notifications (e.g., document.created, document.removed)"
items:
type: string
enum:
- document.created
- document.removed
title: event_webhook_events
type: array
eventWebhookUrl:
additionalProperties: false
description: "HTTPS URL that will receive webhook event notifications"
title: event_webhook_url
type: string
format: uri
pattern: "^https://"

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