Skip to content

Commit ebd6afa

Browse files
committed
add policy delete support
1 parent 28349fc commit ebd6afa

File tree

5 files changed

+290
-116
lines changed

5 files changed

+290
-116
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package releasechannel
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/MakeNowJust/heredoc/v2"
7+
"github.com/ctrlplanedev/cli/internal/api"
8+
"github.com/ctrlplanedev/cli/internal/cliutil"
9+
"github.com/spf13/cobra"
10+
"github.com/spf13/viper"
11+
)
12+
13+
func NewDeletePolicyCmd() *cobra.Command {
14+
var policyId string
15+
var name string
16+
17+
cmd := &cobra.Command{
18+
Use: "policy [flags]",
19+
Short: "Delete a policy",
20+
Long: `Delete a policy by specifying a policy ID.`,
21+
Example: heredoc.Doc(`
22+
$ ctrlc delete policy --policy-id 123e4567-e89b-12d3-a456-426614174000
23+
`),
24+
RunE: func(cmd *cobra.Command, args []string) error {
25+
if policyId == "" && name == "" {
26+
return fmt.Errorf("either --id or --name must be provided")
27+
}
28+
29+
workspace := viper.GetString("workspace")
30+
if name != "" && workspace == "" {
31+
return fmt.Errorf("workspace is required when using --name")
32+
}
33+
34+
apiURL := viper.GetString("url")
35+
apiKey := viper.GetString("api-key")
36+
client, err := api.NewAPIKeyClientWithResponses(apiURL, apiKey)
37+
if err != nil {
38+
return fmt.Errorf("failed to create API client: %w", err)
39+
}
40+
41+
if policyId != "" {
42+
return fmt.Errorf("policy ID is not yet supported")
43+
}
44+
45+
resp, err := client.DeletePolicyByName(cmd.Context(), workspace, name)
46+
if err != nil {
47+
return fmt.Errorf("failed to delete policy: %w", err)
48+
}
49+
50+
return cliutil.HandleResponseOutput(cmd, resp)
51+
},
52+
}
53+
54+
cmd.Flags().StringVar(&policyId, "policy-id", "", "Policy ID")
55+
cmd.Flags().StringVar(&name, "name", "", "Policy name")
56+
cmd.Flags().String("workspace", "", "ID of the workspace")
57+
58+
return cmd
59+
}

go.mod

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
module github.com/ctrlplanedev/cli
22

3-
go 1.23.0
4-
5-
toolchain go1.23.4
3+
go 1.24.2
64

75
require (
86
github.com/MakeNowJust/heredoc/v2 v2.0.1
@@ -30,9 +28,11 @@ require (
3028
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
3129
github.com/charmbracelet/lipgloss v0.10.0 // indirect
3230
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
31+
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 // indirect
3332
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
3433
github.com/fsnotify/fsnotify v1.7.0 // indirect
3534
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
35+
github.com/getkin/kin-openapi v0.127.0 // indirect
3636
github.com/go-logfmt/logfmt v0.6.0 // indirect
3737
github.com/go-logr/logr v1.4.2 // indirect
3838
github.com/go-openapi/jsonpointer v0.21.0 // indirect
@@ -51,6 +51,7 @@ require (
5151
github.com/hashicorp/hcl v1.0.0 // indirect
5252
github.com/hashicorp/jsonapi v1.3.2 // indirect
5353
github.com/inconshreveable/mousetrap v1.1.0 // indirect
54+
github.com/invopop/yaml v0.3.1 // indirect
5455
github.com/josharian/intern v1.0.0 // indirect
5556
github.com/json-iterator/go v1.1.12 // indirect
5657
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
@@ -61,31 +62,38 @@ require (
6162
github.com/mitchellh/mapstructure v1.5.0 // indirect
6263
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
6364
github.com/modern-go/reflect2 v1.0.2 // indirect
65+
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
6466
github.com/muesli/reflow v0.3.0 // indirect
6567
github.com/muesli/termenv v0.15.2 // indirect
6668
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
69+
github.com/oapi-codegen/oapi-codegen/v2 v2.4.1 // indirect
6770
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
71+
github.com/perimeterx/marshmallow v1.1.5 // indirect
6872
github.com/pkg/errors v0.9.1 // indirect
6973
github.com/rivo/uniseg v0.4.7 // indirect
7074
github.com/sagikazarmark/locafero v0.4.0 // indirect
7175
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
7276
github.com/sourcegraph/conc v0.3.0 // indirect
77+
github.com/speakeasy-api/openapi-overlay v0.9.0 // indirect
7378
github.com/spf13/afero v1.11.0 // indirect
7479
github.com/spf13/cast v1.6.0 // indirect
7580
github.com/spf13/pflag v1.0.5 // indirect
7681
github.com/subosito/gotenv v1.6.0 // indirect
7782
github.com/tailscale/hujson v0.0.0-20220506213045-af5ed07155e5 // indirect
83+
github.com/vmware-labs/yaml-jsonpath v0.3.2 // indirect
7884
github.com/x448/float16 v0.8.4 // indirect
7985
go.uber.org/atomic v1.9.0 // indirect
8086
go.uber.org/multierr v1.9.0 // indirect
8187
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
88+
golang.org/x/mod v0.21.0 // indirect
8289
golang.org/x/net v0.30.0 // indirect
8390
golang.org/x/oauth2 v0.23.0 // indirect
8491
golang.org/x/sync v0.8.0 // indirect
8592
golang.org/x/sys v0.26.0 // indirect
8693
golang.org/x/term v0.25.0 // indirect
8794
golang.org/x/text v0.19.0 // indirect
8895
golang.org/x/time v0.7.0 // indirect
96+
golang.org/x/tools v0.26.0 // indirect
8997
google.golang.org/protobuf v1.35.1 // indirect
9098
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
9199
gopkg.in/inf.v0 v0.9.1 // indirect
@@ -98,3 +106,5 @@ require (
98106
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
99107
sigs.k8s.io/yaml v1.4.0 // indirect
100108
)
109+
110+
tool github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen

0 commit comments

Comments
 (0)