Skip to content

Commit

Permalink
Add CLI commands to manage auth webhook methods
Browse files Browse the repository at this point in the history
  • Loading branch information
chacha912 committed Nov 26, 2024
1 parent 5431716 commit 3f82724
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions cmd/yorkie/project/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]",
Expand Down Expand Up @@ -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
Expand All @@ -90,6 +128,7 @@ func newUpdateCommand() *cobra.Command {
updatableProjectFields := &types.UpdatableProjectFields{
Name: &newName,
AuthWebhookURL: &newAuthWebhookURL,
AuthWebhookMethods: &newAuthWebhookMethods,
ClientDeactivateThreshold: &newClientDeactivateThreshold,
}

Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 3f82724

Please sign in to comment.