From 3f827248bafd21c2b64b5cde746f7929c9f5bc12 Mon Sep 17 00:00:00 2001 From: Yourim Cha Date: Wed, 27 Nov 2024 01:44:06 +0900 Subject: [PATCH] Add CLI commands to manage auth webhook methods --- cmd/yorkie/project/update.go | 51 ++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/cmd/yorkie/project/update.go b/cmd/yorkie/project/update.go index 9684e3900..6f0aee096 100644 --- a/cmd/yorkie/project/update.go +++ b/cmd/yorkie/project/update.go @@ -35,10 +35,23 @@ import ( var ( flagAuthWebhookURL string + flagAuthWebhookMethodsAdd []string + flagAuthWebhookMethodsRm []string flagName string flagClientDeactivateThreshold string ) +var allAuthWebhookMethods = []string{ + string(types.ActivateClient), + string(types.DeactivateClient), + string(types.AttachDocument), + string(types.DetachDocument), + string(types.RemoveDocument), + string(types.PushPull), + string(types.WatchDocuments), + string(types.Broadcast), +} + func newUpdateCommand() *cobra.Command { return &cobra.Command{ Use: "update [name]", @@ -82,6 +95,31 @@ func newUpdateCommand() *cobra.Command { newAuthWebhookURL = flagAuthWebhookURL } + methods := make(map[string]struct{}) + for _, m := range project.AuthWebhookMethods { + methods[m] = struct{}{} + } + for _, m := range flagAuthWebhookMethodsRm { + if m == "ALL" { + methods = make(map[string]struct{}) + } else { + delete(methods, m) + } + } + for _, m := range flagAuthWebhookMethodsAdd { + if m == "ALL" { + for _, m := range allAuthWebhookMethods { + methods[m] = struct{}{} + } + } else { + methods[m] = struct{}{} + } + } + newAuthWebhookMethods := make([]string, 0, len(methods)) + for m := range methods { + newAuthWebhookMethods = append(newAuthWebhookMethods, m) + } + newClientDeactivateThreshold := project.ClientDeactivateThreshold if flagClientDeactivateThreshold != "" { newClientDeactivateThreshold = flagClientDeactivateThreshold @@ -90,6 +128,7 @@ func newUpdateCommand() *cobra.Command { updatableProjectFields := &types.UpdatableProjectFields{ Name: &newName, AuthWebhookURL: &newAuthWebhookURL, + AuthWebhookMethods: &newAuthWebhookMethods, ClientDeactivateThreshold: &newClientDeactivateThreshold, } @@ -154,6 +193,18 @@ func init() { "", "authorization-webhook update url", ) + cmd.Flags().StringArrayVar( + &flagAuthWebhookMethodsAdd, + "auth-webhook-method-add", + []string{}, + "authorization-webhook methods to add ('ALL' for all methods)", + ) + cmd.Flags().StringArrayVar( + &flagAuthWebhookMethodsRm, + "auth-webhook-method-rm", + []string{}, + "authorization-webhook methods to remove ('ALL' for all methods)", + ) cmd.Flags().StringVar( &flagClientDeactivateThreshold, "client-deactivate-threshold",