Skip to content

Modern Docker Management, Designed for Everyone

feat(cli): add vulnerabilities, activities, and webhooks commands with e2e coverage

Kyle Mendellf4f9df0e8f13
diff --git a/cli/internal/types/endpoints.go b/cli/internal/types/endpoints.go
index c96a91a7c..845639b28 100644
--- a/cli/internal/types/endpoints.go
+++ b/cli/internal/types/endpoints.go
@@ -455,6 +455,63 @@ func BackupsS3DestinationInUse(id string) string {
return pathf("/api/backups/s3/%s/in-use", id)
}
+// Vulnerability endpoints
+
+func ImageVulnerabilitiesScan(envID, imageID string) string {
+ return pathf("/api/environments/%s/images/%s/vulnerabilities/scan", envID, imageID)
+}
+func ImageVulnerabilities(envID, imageID string) string {
+ return pathf("/api/environments/%s/images/%s/vulnerabilities", envID, imageID)
+}
+func ImageVulnerabilitiesSummary(envID, imageID string) string {
+ return pathf("/api/environments/%s/images/%s/vulnerabilities/summary", envID, imageID)
+}
+func ImageVulnerabilitiesList(envID, imageID string) string {
+ return pathf("/api/environments/%s/images/%s/vulnerabilities/list", envID, imageID)
+}
+func ImagesVulnerabilitiesSummaries(envID string) string {
+ return pathf("/api/environments/%s/images/vulnerabilities/summaries", envID)
+}
+func VulnerabilitiesScannerStatus(envID string) string {
+ return pathf("/api/environments/%s/vulnerabilities/scanner-status", envID)
+}
+func VulnerabilitiesSummary(envID string) string {
+ return pathf("/api/environments/%s/vulnerabilities/summary", envID)
+}
+func VulnerabilitiesAll(envID string) string {
+ return pathf("/api/environments/%s/vulnerabilities/all", envID)
+}
+func VulnerabilitiesIgnored(envID string) string {
+ return pathf("/api/environments/%s/vulnerabilities/ignored", envID)
+}
+func VulnerabilitiesIgnore(envID string) string {
+ return pathf("/api/environments/%s/vulnerabilities/ignore", envID)
+}
+func VulnerabilityIgnore(envID, ignoreID string) string {
+ return pathf("/api/environments/%s/vulnerabilities/ignore/%s", envID, ignoreID)
+}
+
+// Activity endpoints
+
+func Activities(envID string) string { return pathf("/api/environments/%s/activities", envID) }
+func Activity(envID, activityID string) string {
+ return pathf("/api/environments/%s/activities/%s", envID, activityID)
+}
+func ActivityCancel(envID, activityID string) string {
+ return pathf("/api/environments/%s/activities/%s/cancel", envID, activityID)
+}
+func ActivitiesHistory(envID string) string {
+ return pathf("/api/environments/%s/activities/history", envID)
+}
+
+// Webhook endpoints
+
+func Webhooks(envID string) string { return pathf("/api/environments/%s/webhooks", envID) }
+func Webhook(envID, webhookID string) string {
+ return pathf("/api/environments/%s/webhooks/%s", envID, webhookID)
+}
+func WebhookTrigger(token string) string { return pathf("/api/webhooks/trigger/%s", token) }
+
// GitOps sync endpoints
func GitOpsSyncs(envID string) string { return pathf("/api/environments/%s/gitops-syncs", envID) }
diff --git a/cli/pkg/activities/cmd.go b/cli/pkg/activities/cmd.go
new file mode 100644
index 000000000..eec963a2f
--- /dev/null
+++ b/cli/pkg/activities/cmd.go
@@ -0,0 +1,340 @@
+// Package activities implements the `arcane activities` command group for
+// tracking background operations (the web UI's activity center).
+package activities
+
+import (
+ "encoding/json"
+ "fmt"
+ "net/url"
+ "strconv"
+ "time"
+
+ "emperror.dev/errors"
+
+ "github.com/getarcaneapp/arcane/cli/v2/internal/cmdutil"
+ "github.com/getarcaneapp/arcane/cli/v2/internal/output"
+ "github.com/getarcaneapp/arcane/cli/v2/internal/types"
+ activitytypes "github.com/getarcaneapp/arcane/types/v2/activity"
+ "github.com/getarcaneapp/arcane/types/v2/base"
+ "github.com/spf13/cobra"
+)
+
+var (
+ limitFlag int
+ startFlag int
+ allFlag bool
+ forceFlag bool
+ jsonOutput bool
+ statusFlag string
+ typeFlag string
+ resourceTypeFlag string
+ messagesFlag int
+)
+
+// ActivitiesCmd is the parent command for background activity operations.
+var ActivitiesCmd = &cobra.Command{
+ Use: "activities",
+ Aliases: []string{"activity", "act"},
+ Short: "Track background activities",
+}
+
+var listCmd = &cobra.Command{
+ Use: "list",
+ Aliases: []string{"ls"},
+ Short: "List background activities",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := cmdutil.ClientFromCommand(cmd)
+ if err != nil {
+ return err
+ }
+
+ path, err := cmdutil.ApplyPaginationParams(cmd, types.Activities(c.EnvID()), cmdutil.ListParams{
+ Resource: "activities",
+ Limit: limitFlag,
+ FallbackDefault: 50,
+ Start: startFlag,
+ All: allFlag,
+ })
+ if err != nil {
+ return errors.WrapIf(err, "failed to build pagination query")
+ }
+
+ query := url.Values{}
+ if statusFlag != "" {
+ query.Set("status", statusFlag)
+ }
+ if typeFlag != "" {
+ query.Set("type", typeFlag)
+ }
+ if resourceTypeFlag != "" {
+ query.Set("resourceType", resourceTypeFlag)
+ }
+ if len(query) > 0 {
+ path = cmdutil.AppendQuery(path, query)
+ }
+
+ resp, err := c.Get(cmd.Context(), path)
+ if err != nil {
+ return errors.WrapIf(err, "failed to list activities")
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ body, err := cmdutil.ReadJSONBody(resp)
+ if err != nil {
+ return errors.WrapIf(err, "failed to list activities")
+ }
+
+ if jsonOutput {
+ return cmdutil.PrintRawJSON(body)
+ }
+
+ var result base.Paginated[activitytypes.Activity]
+ if err := json.Unmarshal(body, &result); err != nil {
+ return errors.WrapIf(err, "failed to parse response")
+ }
+
+ headers := []string{"ID", "TYPE", "STATUS", "RESOURCE", "STARTED", "PROGRESS", "MESSAGE"}
+ rows := make([][]string, len(result.Data))
+ for i, item := range result.Data {
+ rows[i] = []string{
+ item.ID,
+ string(item.Type),
+ string(item.Status),
+ activityResource(item),
+ item.StartedAt.Format(time.RFC3339),
+ activityProgress(item),
+ activityMessage(item),
+ }
+ }
+
+ output.Table(headers, rows)
+ output.Showing(len(result.Data), result.Pagination.TotalItems, "activities")
+ return nil
+ },
+}
+
+var getCmd = &cobra.Command{
+ Use: "get <activity-id>",
+ Short: "Get background activity details",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := cmdutil.ClientFromCommand(cmd)
+ if err != nil {
+ return err
+ }
+
+ path := cmdutil.AppendQuery(
+ types.Activity(c.EnvID(), args[0]),
+ url.Values{"limit": []string{strconv.Itoa(messagesFlag)}},
+ )
+ resp, err := c.Get(cmd.Context(), path)
+ if err != nil {
+ return errors.WrapIf(err, "failed to get activity")
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ body, err := cmdutil.ReadJSONBody(resp)
+ if err != nil {
+ return errors.WrapIf(err, "failed to get activity")
+ }
+
+ if jsonOutput {
+ return cmdutil.PrintRawJSON(body)
+ }
+
+ var result base.ApiResponse[activitytypes.Detail]
+ if err := json.Unmarshal(body, &result); err != nil {
+ return errors.WrapIf(err, "failed to parse response")
+ }
+
+ item := result.Data.Activity
+ output.Header("Activity Details")
+ output.KeyValue("ID", item.ID)
+ output.KeyValue("Type", string(item.Type))
+ output.KeyValue("Status", string(item.Status))
+ if resource := activityResource(item); resource != "" {
+ output.KeyValue("Resource", resource)
+ }
+ if item.Progress != nil {
+ output.KeyValue("Progress", activityProgress(item))
+ }
+ if item.Step != "" {
+ output.KeyValue("Step", item.Step)
+ }
+ if item.StartedBy != nil {
+ startedBy := item.StartedBy.Username
+ if item.StartedBy.DisplayName != "" {
+ startedBy = item.StartedBy.DisplayName
+ }
+ output.KeyValue("Started By", startedBy)
+ }
+ output.KeyValue("Started", item.StartedAt.Format(time.RFC3339))
+ if item.EndedAt != nil {
+ output.KeyValue("Ended", item.EndedAt.Format(time.RFC3339))
+ }
+ if item.DurationMs != nil {
+ output.KeyValue("Duration", (time.Duration(*item.DurationMs) * time.Millisecond).String())
+ }
+ if item.Error != nil && *item.Error != "" {
+ output.KeyValue("Error", *item.Error)
+ }
+
+ if len(result.Data.Messages) > 0 {
+ output.Header("Messages")
+ for _, msg := range result.Data.Messages {
+ fmt.Printf("%s [%s] %s\n", msg.CreatedAt.Format(time.RFC3339), msg.Level, msg.Message)
+ }
+ }
+ return nil
+ },
+}
+
+var cancelCmd = &cobra.Command{
+ Use: "cancel <activity-id>",
+ Short: "Cancel a running background activity",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ if !forceFlag {
+ confirmed, err := cmdutil.Confirm(cmd, fmt.Sprintf("Are you sure you want to cancel activity %s?", args[0]))
+ if err != nil {
+ return err
+ }
+ if !confirmed {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ }
+
+ c, err := cmdutil.ClientFromCommand(cmd)
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Post(cmd.Context(), types.ActivityCancel(c.EnvID(), args[0]), nil)
+ if err != nil {
+ return errors.WrapIf(err, "failed to cancel activity")
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[activitytypes.Activity]
+ if err := cmdutil.DecodeJSON(resp, &result); err != nil {
+ return errors.WrapIf(err, "failed to cancel activity")
+ }
+
+ if jsonOutput {
+ return cmdutil.PrintJSON(result.Data)
+ }
+
+ output.Success("Cancellation requested for activity %s (status: %s)", result.Data.ID, result.Data.Status)
+ return nil
+ },
+}
+
+var clearCmd = &cobra.Command{
+ Use: "clear",
+ Short: "Clear finished activity history",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ if !forceFlag {
+ confirmed, err := cmdutil.Confirm(cmd, "Are you sure you want to clear the finished activity history?")
+ if err != nil {
+ return err
+ }
+ if !confirmed {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ }
+
+ c, err := cmdutil.ClientFromCommand(cmd)
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Delete(cmd.Context(), types.ActivitiesHistory(c.EnvID()))
+ if err != nil {
+ return errors.WrapIf(err, "failed to clear activity history")
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[activitytypes.ClearHistoryResult]
+ if err := cmdutil.DecodeJSON(resp, &result); err != nil {
+ return errors.WrapIf(err, "failed to clear activity history")
+ }
+
+ if jsonOutput {
+ return cmdutil.PrintJSON(result.Data)
+ }
+
+ output.Success("Cleared %d finished activities", result.Data.Deleted)
+ return nil
+ },
+}
+
+func init() {
+ ActivitiesCmd.AddCommand(listCmd)
+ ActivitiesCmd.AddCommand(getCmd)
+ ActivitiesCmd.AddCommand(cancelCmd)
+ ActivitiesCmd.AddCommand(clearCmd)
+
+ // List command flags
+ listCmd.Flags().IntVarP(&limitFlag, "limit", "n", 50, "Number of activities to show")
+ listCmd.Flags().IntVar(&startFlag, "start", 0, cmdutil.StartFlagUsage)
+ listCmd.Flags().BoolVarP(&allFlag, "all", "a", false, cmdutil.AllFlagUsage)
+ listCmd.Flags().StringVar(&statusFlag, "status", "", "Filter by status (queued, running, success, failed, cancelled)")
+ listCmd.Flags().StringVar(&typeFlag, "type", "", "Filter by activity type (e.g. image_pull, project_deploy)")
+ listCmd.Flags().StringVar(&resourceTypeFlag, "resource-type", "", "Filter by resource type")
+ listCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ // Get command flags
+ getCmd.Flags().IntVar(&messagesFlag, "messages", 500, "Maximum output messages to return")
+ getCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ // Cancel command flags
+ cancelCmd.Flags().BoolVarP(&forceFlag, "force", "f", false, "Cancel without confirmation")
+ cancelCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ // Clear command flags
+ clearCmd.Flags().BoolVarP(&forceFlag, "force", "f", false, "Clear without confirmation")
+ clearCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+}
+
+func activityResource(item activitytypes.Activity) string {
+ name := ""
+ if item.ResourceName != nil {
+ name = *item.ResourceName
+ }
+ if name == "" && item.ResourceID != nil {
+ name = *item.ResourceID
+ }
+ if item.ResourceType != nil && *item.ResourceType != "" {
+ if name == "" {
+ return *item.ResourceType
+ }
+ return fmt.Sprintf("%s/%s", *item.ResourceType, name)
+ }
+ return name
+}
+
+func activityProgress(item activitytypes.Activity) string {
+ if item.Progress == nil {
+ return "-"
+ }
+ return strconv.Itoa(*item.Progress) + "%"
+}
+
+func activityMessage(item activitytypes.Activity) string {
+ if item.LatestMessage != "" {
+ return item.LatestMessage
+ }
+ if item.Step != "" {
+ return item.Step
+ }
+ if item.Error != nil {
+ return *item.Error
+ }
+ return ""
+}
diff --git a/cli/pkg/admin/federatedcredentials/cmd.go b/cli/pkg/admin/federatedcredentials/cmd.go
index 0b1ed7750..1f9cf48c0 100644
--- a/cli/pkg/admin/federatedcredentials/cmd.go
+++ b/cli/pkg/admin/federatedcredentials/cmd.go
@@ -18,14 +18,11 @@ import (
)
var (
- limitFlag int
- startFlag int
- allFlag bool
- forceFlag bool
- jsonOutput bool
-)
-
-var (
+ limitFlag int
+ startFlag int
+ allFlag bool
+ forceFlag bool
+ jsonOutput bool
createName string
createDescription string
createDisabled bool
@@ -38,9 +35,6 @@ var (
createEnvironment string
createTokenTTL int
createExpiresAt string
-)
-
-var (
updateName string
updateDescription string
updateEnabled bool
diff --git a/cli/pkg/images/extra.go b/cli/pkg/images/extra.go
index fd9d44bc9..5f0fb807e 100644
--- a/cli/pkg/images/extra.go
+++ b/cli/pkg/images/extra.go
@@ -264,6 +264,23 @@ var (
attestationsPlatform string
attestationsPredicateType string
attestationsStatement bool
+ buildTags []string
+ buildDockerfile string
+ buildInlineFile string
+ buildArgs []string
+ buildTarget string
+ buildPlatforms []string
+ buildNetwork string
+ buildProvider string
+ buildNoCache bool
+ buildPull bool
+ buildPush bool
+ buildLoad bool
+ buildsLimit int
+ buildsStart int
+ buildsAll bool
+ buildsStatus string
+ buildsProvider string
)
var imagesAttestationsCmd = &cobra.Command{
@@ -349,21 +366,6 @@ var imagesAttestationsCmd = &cobra.Command{
},
}
-var (
- buildTags []string
- buildDockerfile string
- buildInlineFile string
- buildArgs []string
- buildTarget string
- buildPlatforms []string
- buildNetwork string
- buildProvider string
- buildNoCache bool
- buildPull bool
- buildPush bool
- buildLoad bool
-)
-
var imagesBuildCmd = &cobra.Command{
Use: "build <context-dir|git-url>",
Short: "Build an image with BuildKit on the server",
@@ -502,14 +504,6 @@ func streamBuildOutput(body io.Reader) error {
return nil
}
-var (
- buildsLimit int
- buildsStart int
- buildsAll bool
- buildsStatus string
- buildsProvider string
-)
-
var imagesBuildsCmd = &cobra.Command{
Use: "builds",
Short: "List image build history",
diff --git a/cli/pkg/root.go b/cli/pkg/root.go
index cefd3f4dc..3d6bad787 100644
--- a/cli/pkg/root.go
+++ b/cli/pkg/root.go
@@ -48,6 +48,7 @@ import (
"github.com/getarcaneapp/arcane/cli/v2/internal/output"
"github.com/getarcaneapp/arcane/cli/v2/internal/runstate"
runtimectx "github.com/getarcaneapp/arcane/cli/v2/internal/runtime"
+ "github.com/getarcaneapp/arcane/cli/v2/pkg/activities"
"github.com/getarcaneapp/arcane/cli/v2/pkg/admin"
"github.com/getarcaneapp/arcane/cli/v2/pkg/auth"
"github.com/getarcaneapp/arcane/cli/v2/pkg/backups"
@@ -72,6 +73,8 @@ import (
"github.com/getarcaneapp/arcane/cli/v2/pkg/variables"
"github.com/getarcaneapp/arcane/cli/v2/pkg/version"
"github.com/getarcaneapp/arcane/cli/v2/pkg/volumes"
+ "github.com/getarcaneapp/arcane/cli/v2/pkg/vulnerabilities"
+ "github.com/getarcaneapp/arcane/cli/v2/pkg/webhooks"
"github.com/spf13/cobra"
)
@@ -274,6 +277,9 @@ func init() {
rootCmd.AddCommand(gitops.GitopsCmd)
rootCmd.AddCommand(backups.BackupsCmd)
rootCmd.AddCommand(variables.VariablesCmd)
+ rootCmd.AddCommand(vulnerabilities.VulnerabilitiesCmd)
+ rootCmd.AddCommand(activities.ActivitiesCmd)
+ rootCmd.AddCommand(webhooks.WebhooksCmd)
instrumentCommandTreeInternal(rootCmd)
}
diff --git a/cli/pkg/variables/cmd.go b/cli/pkg/variables/cmd.go
index 66062b8fb..b956830ff 100644
--- a/cli/pkg/variables/cmd.go
+++ b/cli/pkg/variables/cmd.go
@@ -19,24 +19,19 @@ import (
)
var (
- jsonOutput bool
- forceFlag bool
-)
-
-var (
- createKey string
- createValue string
- createSecret bool
- createAllEnvs bool
- createEnvIDs []string
-)
-
-var (
- updateKey string
- updateValue string
- updateSecret bool
- updateAllEnvs bool
- updateEnvIDs []string
+ jsonOutput bool
+ forceFlag bool
+ createKey string
+ createValue string
+ createSecret bool
+ createAllEnvs bool
+ createEnvIDs []string
+ updateKey string
+ updateValue string
+ updateSecret bool
+ updateAllEnvs bool
+ updateEnvIDs []string
+ syncStatusFlag bool
)
// VariablesCmd is the parent command for global variable operations.
@@ -279,8 +274,6 @@ var deleteCmd = &cobra.Command{
},
}
-var syncStatusFlag bool
-
var syncCmd = &cobra.Command{
Use: "sync",
Short: "Sync global variables to every environment (--status shows the last sync result per environment)",
diff --git a/cli/pkg/volumes/backup.go b/cli/pkg/volumes/backup.go
index 46bf9cabe..1803826f4 100644
--- a/cli/pkg/volumes/backup.go
+++ b/cli/pkg/volumes/backup.go
@@ -30,18 +30,15 @@ var (
backupUploadS3Destination string
restorePaths []string
restoreArchiveFile string
-)
-
-var (
- policyEnabled bool
- policySchedule string
- policyRetention int
- policyStopContainers bool
- policyLocal bool
- policyS3 bool
- policyS3Destination string
- policyID string
- policyFile string
+ policyEnabled bool
+ policySchedule string
+ policyRetention int
+ policyStopContainers bool
+ policyLocal bool
+ policyS3 bool
+ policyS3Destination string
+ policyID string
+ policyFile string
)
// backupsListResponse mirrors the backend's paginated volume backup response,
diff --git a/cli/pkg/vulnerabilities/cmd.go b/cli/pkg/vulnerabilities/cmd.go
new file mode 100644
index 000000000..cb1bf01b2
--- /dev/null
+++ b/cli/pkg/vulnerabilities/cmd.go
@@ -0,0 +1,671 @@
+// Package vulnerabilities provides CLI commands for image vulnerability
+// scanning on Arcane servers.
+//
+// This package implements the "arcane vulnerabilities" command group, which
+// includes subcommands for checking scanner status, viewing environment-wide
+// summaries, listing vulnerabilities, scanning images, and managing ignore
+// records.
+package vulnerabilities
+
+import (
+ "context"
+ "encoding/json"
+ "fmt"
+ "io"
+ "net/http"
+ "net/url"
+ "strings"
+ "time"
+
+ "emperror.dev/errors"
+
+ "github.com/getarcaneapp/arcane/cli/v2/internal/client"
+ "github.com/getarcaneapp/arcane/cli/v2/internal/cmdutil"
+ "github.com/getarcaneapp/arcane/cli/v2/internal/output"
+ "github.com/getarcaneapp/arcane/cli/v2/internal/types"
+ "github.com/getarcaneapp/arcane/types/v2/base"
+ "github.com/getarcaneapp/arcane/types/v2/image"
+ "github.com/getarcaneapp/arcane/types/v2/vulnerability"
+ "github.com/spf13/cobra"
+)
+
+var (
+ jsonOutput bool
+ limitFlag int
+ startFlag int
+ allFlag bool
+ forceFlag bool
+ severityFlag string
+ imageFlag string
+ summaryFlag bool
+
+ ignoreImageFlag string
+ ignorePkgFlag string
+ ignoreVersionFlag string
+ ignoreReasonFlag string
+)
+
+// VulnerabilitiesCmd is the parent command for vulnerability operations
+var VulnerabilitiesCmd = &cobra.Command{
+ Use: "vulnerabilities",
+ Aliases: []string{"vulns", "vuln", "cve"},
+ Short: "Manage image vulnerability scans",
+}
+
+var statusCmd = &cobra.Command{
+ Use: "status",
+ Short: "Show vulnerability scanner status",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := cmdutil.ClientFromCommand(cmd)
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Get(cmd.Context(), types.VulnerabilitiesScannerStatus(c.EnvID()))
+ if err != nil {
+ return errors.WrapIf(err, "failed to get scanner status")
+ }
+ defer func() { _ = resp.Body.Close() }()
+ if err := cmdutil.EnsureSuccessStatus(resp); err != nil {
+ return errors.WrapIf(err, "failed to get scanner status")
+ }
+
+ var result base.ApiResponse[struct {
+ Available bool `json:"available"`
+ Version string `json:"version,omitempty"`
+ }]
+ if err := cmdutil.DecodeJSON(resp, &result); err != nil {
+ return err
+ }
+
+ if jsonOutput {
+ return cmdutil.PrintJSON(result.Data)
+ }
+
+ output.Header("Vulnerability Scanner")
+ output.KeyValue("Available", result.Data.Available)
+ if result.Data.Version != "" {
+ output.KeyValue("Version", result.Data.Version)
+ }
+ return nil
+ },
+}
+
+var summaryCmd = &cobra.Command{
+ Use: "summary",
+ Short: "Show environment-wide vulnerability summary",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := cmdutil.ClientFromCommand(cmd)
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Get(cmd.Context(), types.VulnerabilitiesSummary(c.EnvID()))
+ if err != nil {
+ return errors.WrapIf(err, "failed to get vulnerability summary")
+ }
+ defer func() { _ = resp.Body.Close() }()
+ if err := cmdutil.EnsureSuccessStatus(resp); err != nil {
+ return errors.WrapIf(err, "failed to get vulnerability summary")
+ }
+
+ var result base.ApiResponse[vulnerability.EnvironmentVulnerabilitySummary]
+ if err := cmdutil.DecodeJSON(resp, &result); err != nil {
+ return err
+ }
+
+ if jsonOutput {
+ return cmdutil.PrintJSON(result.Data)
+ }
+
+ output.Header("Vulnerability Summary")
+ output.KeyValue("Total Images", result.Data.TotalImages)
+ output.KeyValue("Scanned Images", result.Data.ScannedImages)
+ printSeveritySummary(result.Data.Summary)
+ return nil
+ },
+}
+
+var listCmd = &cobra.Command{
+ Use: "list",
+ Aliases: []string{"ls"},
+ Short: "List vulnerabilities across all scanned images",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := cmdutil.ClientFromCommand(cmd)
+ if err != nil {
+ return err
+ }
+
+ path, err := cmdutil.ApplyPaginationParams(cmd, types.VulnerabilitiesAll(c.EnvID()), cmdutil.ListParams{
+ Resource: "vulnerabilities",
+ Limit: limitFlag,
+ FallbackDefault: 20,
+ Start: startFlag,
+ All: allFlag,
+ })
+ if err != nil {
+ return errors.WrapIf(err, "failed to build pagination query")
+ }
+
+ query := url.Values{}
+ if severityFlag != "" {
+ query.Set("severity", strings.ToUpper(severityFlag))
+ }
+ if imageFlag != "" {
+ query.Set("imageName", imageFlag)
+ }
+ if len(query) > 0 {
+ path = cmdutil.AppendQuery(path, query)
+ }
+
+ resp, err := c.Get(cmd.Context(), path)
+ if err != nil {
+ return errors.WrapIf(err, "failed to list vulnerabilities")
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ body, err := cmdutil.ReadJSONBody(resp)
+ if err != nil {
+ return errors.WrapIf(err, "failed to list vulnerabilities")
+ }
+
+ if jsonOutput {
+ return cmdutil.PrintRawJSON(body)
+ }
+
+ var result base.Paginated[vulnerability.VulnerabilityWithImage]
+ if err := json.Unmarshal(body, &result); err != nil {
+ return errors.WrapIf(err, "failed to parse response")
+ }
+
+ headers := []string{"CVE ID", "SEVERITY", "IMAGE", "PACKAGE", "VERSION", "FIXED IN"}
+ rows := make([][]string, len(result.Data))
+ for i, item := range result.Data {
+ rows[i] = []string{
+ item.VulnerabilityID,
+ string(item.Severity),
+ item.ImageName,
+ item.PkgName,
+ item.InstalledVersion,
+ orDash(item.FixedVersion),
+ }
+ }
+
+ output.Table(headers, rows)
+ output.Showing(len(result.Data), result.Pagination.TotalItems, "vulnerabilities")
+ return nil
+ },
+}
+
+var scanCmd = &cobra.Command{
+ Use: "scan <image>",
+ Short: "Scan an image for vulnerabilities",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := cmdutil.ClientFromCommand(cmd)
+ if err != nil {
+ return err
+ }
+
+ imageID, err := resolveImageID(cmd.Context(), c, args[0])
+ if err != nil {
+ return err
+ }
+
+ // Scans can take a long time on large images.
+ c.SetTimeout(30 * time.Minute)
+
+ resp, err := c.Post(cmd.Context(), types.ImageVulnerabilitiesScan(c.EnvID(), imageID), nil)
+ if err != nil {
+ return errors.WrapIf(err, "failed to scan image")
+ }
+ defer func() { _ = resp.Body.Close() }()
+ if err := cmdutil.EnsureSuccessStatus(resp); err != nil {
+ return errors.WrapIf(err, "failed to scan image")
+ }
+
+ var result base.ApiResponse[vulnerability.ScanResult]
+ if err := cmdutil.DecodeJSON(resp, &result); err != nil {
+ return err
+ }
+
+ if jsonOutput {
+ return cmdutil.PrintJSON(result.Data)
+ }
+
+ output.Header("Vulnerability Scan")
+ output.KeyValue("Image", result.Data.ImageName)
+ output.KeyValue("Status", string(result.Data.Status))
+ if result.Data.ScanPhase != "" {
+ output.KeyValue("Phase", string(result.Data.ScanPhase))
+ }
+ if result.Data.Error != "" {
+ output.KeyValue("Error", result.Data.Error)
+ }
+ if result.Data.ScannerVersion != "" {
+ output.KeyValue("Scanner", result.Data.ScannerVersion)
+ }
+ printSeveritySummary(result.Data.Summary)
+ return nil
+ },
+}
+
+var imageCmd = &cobra.Command{
+ Use: "image <image>",
+ Short: "List vulnerabilities for an image",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := cmdutil.ClientFromCommand(cmd)
+ if err != nil {
+ return err
+ }
+
+ imageID, err := resolveImageID(cmd.Context(), c, args[0])
+ if err != nil {
+ return err
+ }
+
+ if summaryFlag {
+ return runImageSummary(cmd, c, imageID)
+ }
+
+ path, err := cmdutil.ApplyPaginationParams(cmd, types.ImageVulnerabilitiesList(c.EnvID(), imageID), cmdutil.ListParams{
+ Resource: "vulnerabilities",
+ Limit: limitFlag,
+ FallbackDefault: 20,
+ Start: startFlag,
+ All: allFlag,
+ })
+ if err != nil {
+ return errors.WrapIf(err, "failed to build pagination query")
+ }
+
+ if severityFlag != "" {
+ path = cmdutil.AppendQuery(path, url.Values{"severity": []string{strings.ToUpper(severityFlag)}})
+ }
+
+ resp, err := c.Get(cmd.Context(), path)
+ if err != nil {
+ return errors.WrapIf(err, "failed to list image vulnerabilities")
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ body, err := cmdutil.ReadJSONBody(resp)
+ if err != nil {
+ return errors.WrapIf(err, "failed to list image vulnerabilities")
+ }
+
+ if jsonOutput {
+ return cmdutil.PrintRawJSON(body)
+ }
+
+ var result base.Paginated[vulnerability.Vulnerability]
+ if err := json.Unmarshal(body, &result); err != nil {
+ return errors.WrapIf(err, "failed to parse response")
+ }
+
+ headers := []string{"CVE ID", "SEVERITY", "PACKAGE", "VERSION", "FIXED IN"}
+ rows := make([][]string, len(result.Data))
+ for i, item := range result.Data {
+ rows[i] = []string{
+ item.VulnerabilityID,
+ string(item.Severity),
+ item.PkgName,
+ item.InstalledVersion,
+ orDash(item.FixedVersion),
+ }
+ }
+
+ output.Table(headers, rows)
+ output.Showing(len(result.Data), result.Pagination.TotalItems, "vulnerabilities")
+ return nil
+ },
+}
+
+func runImageSummary(cmd *cobra.Command, c *client.Client, imageID string) error {
+ resp, err := c.Get(cmd.Context(), types.ImageVulnerabilitiesSummary(c.EnvID(), imageID))
+ if err != nil {
+ return errors.WrapIf(err, "failed to get image vulnerability summary")
+ }
+ defer func() { _ = resp.Body.Close() }()
+ if err := cmdutil.EnsureSuccessStatus(resp); err != nil {
+ return errors.WrapIf(err, "failed to get image vulnerability summary")
+ }
+
+ var result base.ApiResponse[vulnerability.ScanSummary]
+ if err := cmdutil.DecodeJSON(resp, &result); err != nil {
+ return err
+ }
+
+ if jsonOutput {
+ return cmdutil.PrintJSON(result.Data)
+ }
+
+ output.Header("Image Vulnerability Summary")
+ output.KeyValue("Image ID", result.Data.ImageID)
+ output.KeyValue("Status", string(result.Data.Status))
+ output.KeyValue("Scan Time", result.Data.ScanTime.Format(time.RFC3339))
+ if result.Data.ScanPhase != "" {
+ output.KeyValue("Phase", string(result.Data.ScanPhase))
+ }
+ if result.Data.Error != "" {
+ output.KeyValue("Error", result.Data.Error)
+ }
+ printSeveritySummary(result.Data.Summary)
+ return nil
+}
+
+var ignoreCmd = &cobra.Command{
+ Use: "ignore <cve-id>",
+ Short: "Ignore a vulnerability for an image",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := cmdutil.ClientFromCommand(cmd)
+ if err != nil {
+ return err
+ }
+
+ imageID, err := resolveImageID(cmd.Context(), c, ignoreImageFlag)
+ if err != nil {
+ return err
+ }
+
+ payload := vulnerability.IgnorePayload{
+ ImageID: imageID,
+ VulnerabilityID: args[0],
+ PkgName: ignorePkgFlag,
+ InstalledVersion: ignoreVersionFlag,
+ }
+ if ignoreReasonFlag != "" {
+ payload.Reason = &ignoreReasonFlag
+ }
+
+ resp, err := c.Post(cmd.Context(), types.VulnerabilitiesIgnore(c.EnvID()), payload)
+ if err != nil {
+ return errors.WrapIf(err, "failed to ignore vulnerability")
+ }
+ defer func() { _ = resp.Body.Close() }()
+ if err := cmdutil.EnsureSuccessStatus(resp); err != nil {
+ return errors.WrapIf(err, "failed to ignore vulnerability")
+ }
+
+ var result base.ApiResponse[vulnerability.IgnoredVulnerability]
+ if err := cmdutil.DecodeJSON(resp, &result); err != nil {
+ return err
+ }
+
+ if jsonOutput {
+ return cmdutil.PrintJSON(result.Data)
+ }
+
+ output.Success("Vulnerability %s ignored", result.Data.VulnerabilityID)
+ output.KeyValue("Ignore ID", result.Data.ID)
+ return nil
+ },
+}
+
+var ignoredCmd = &cobra.Command{
+ Use: "ignored",
+ Short: "List ignored vulnerabilities",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := cmdutil.ClientFromCommand(cmd)
+ if err != nil {
+ return err
+ }
+
+ path, err := cmdutil.ApplyPaginationParams(cmd, types.VulnerabilitiesIgnored(c.EnvID()), cmdutil.ListParams{
+ Resource: "vulnerabilities",
+ Limit: limitFlag,
+ FallbackDefault: 20,
+ Start: startFlag,
+ All: allFlag,
+ })
+ if err != nil {
+ return errors.WrapIf(err, "failed to build pagination query")
+ }
+
+ resp, err := c.Get(cmd.Context(), path)
+ if err != nil {
+ return errors.WrapIf(err, "failed to list ignored vulnerabilities")
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ body, err := cmdutil.ReadJSONBody(resp)
+ if err != nil {
+ return errors.WrapIf(err, "failed to list ignored vulnerabilities")
+ }
+
+ if jsonOutput {
+ return cmdutil.PrintRawJSON(body)
+ }
+
+ var result base.Paginated[vulnerability.IgnoredVulnerability]
+ if err := json.Unmarshal(body, &result); err != nil {
+ return errors.WrapIf(err, "failed to parse response")
+ }
+
+ headers := []string{"ID", "CVE ID", "IMAGE ID", "PACKAGE", "REASON", "CREATED"}
+ rows := make([][]string, len(result.Data))
+ for i, item := range result.Data {
+ reason := ""
+ if item.Reason != nil {
+ reason = *item.Reason
+ }
+ rows[i] = []string{
+ item.ID,
+ item.VulnerabilityID,
+ shortImageID(item.ImageID),
+ item.PkgName,
+ orDash(reason),
+ item.CreatedAt.Format(time.RFC3339),
+ }
+ }
+
+ output.Table(headers, rows)
+ output.Showing(len(result.Data), result.Pagination.TotalItems, "ignored vulnerabilities")
+ return nil
+ },
+}
+
+var unignoreCmd = &cobra.Command{
+ Use: "unignore <ignore-id>",
+ Short: "Remove a vulnerability ignore record",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ if !forceFlag {
+ confirmed, err := cmdutil.Confirm(cmd, fmt.Sprintf("Are you sure you want to remove ignore record %s?", args[0]))
+ if err != nil {
+ return err
+ }
+ if !confirmed {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ }
+
+ c, err := cmdutil.ClientFromCommand(cmd)
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Delete(cmd.Context(), types.VulnerabilityIgnore(c.EnvID(), args[0]))
+ if err != nil {
+ return errors.WrapIf(err, "failed to remove ignore record")
+ }
+ defer func() { _ = resp.Body.Close() }()
+ if err := cmdutil.EnsureSuccessStatus(resp); err != nil {
+ return errors.WrapIf(err, "failed to remove ignore record")
+ }
+
+ output.Success("Ignore record %s removed", args[0])
+ return nil
+ },
+}
+
+func init() {
+ VulnerabilitiesCmd.AddCommand(statusCmd)
+ VulnerabilitiesCmd.AddCommand(summaryCmd)
+ VulnerabilitiesCmd.AddCommand(listCmd)
+ VulnerabilitiesCmd.AddCommand(scanCmd)
+ VulnerabilitiesCmd.AddCommand(imageCmd)
+ VulnerabilitiesCmd.AddCommand(ignoreCmd)
+ VulnerabilitiesCmd.AddCommand(ignoredCmd)
+ VulnerabilitiesCmd.AddCommand(unignoreCmd)
+
+ statusCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ summaryCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ listCmd.Flags().IntVarP(&limitFlag, "limit", "n", 20, "Number of vulnerabilities to show")
+ listCmd.Flags().IntVar(&startFlag, "start", 0, cmdutil.StartFlagUsage)
+ listCmd.Flags().BoolVarP(&allFlag, "all", "a", false, cmdutil.AllFlagUsage)
+ listCmd.Flags().StringVar(&severityFlag, "severity", "", "Comma-separated severity filter (critical,high,medium,low,unknown)")
+ listCmd.Flags().StringVar(&imageFlag, "image", "", "Filter by image name (substring)")
+ listCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ scanCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ imageCmd.Flags().BoolVar(&summaryFlag, "summary", false, "Show the scan summary instead of the detailed list")
+ imageCmd.Flags().IntVarP(&limitFlag, "limit", "n", 20, "Number of vulnerabilities to show")
+ imageCmd.Flags().IntVar(&startFlag, "start", 0, cmdutil.StartFlagUsage)
+ imageCmd.Flags().BoolVarP(&allFlag, "all", "a", false, cmdutil.AllFlagUsage)
+ imageCmd.Flags().StringVar(&severityFlag, "severity", "", "Comma-separated severity filter (critical,high,medium,low,unknown)")
+ imageCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ ignoreCmd.Flags().StringVar(&ignoreImageFlag, "image", "", "Image containing the vulnerability")
+ ignoreCmd.Flags().StringVar(&ignorePkgFlag, "package", "", "Package name containing the vulnerability")
+ ignoreCmd.Flags().StringVar(&ignoreVersionFlag, "version", "", "Installed version of the vulnerable package")
+ ignoreCmd.Flags().StringVar(&ignoreReasonFlag, "reason", "", "Reason for ignoring this vulnerability")
+ ignoreCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ _ = ignoreCmd.MarkFlagRequired("image")
+ _ = ignoreCmd.MarkFlagRequired("package")
+
+ ignoredCmd.Flags().IntVarP(&limitFlag, "limit", "n", 20, "Number of ignore records to show")
+ ignoredCmd.Flags().IntVar(&startFlag, "start", 0, cmdutil.StartFlagUsage)
+ ignoredCmd.Flags().BoolVarP(&allFlag, "all", "a", false, cmdutil.AllFlagUsage)
+ ignoredCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ unignoreCmd.Flags().BoolVarP(&forceFlag, "force", "f", false, "Skip the confirmation prompt")
+}
+
+func printSeveritySummary(s *vulnerability.SeveritySummary) {
+ if s == nil {
+ output.Info("No vulnerability data available")
+ return
+ }
+ output.KeyValue("Critical", s.Critical)
+ output.KeyValue("High", s.High)
+ output.KeyValue("Medium", s.Medium)
+ output.KeyValue("Low", s.Low)
+ output.KeyValue("Unknown", s.Unknown)
+ output.KeyValue("Total", s.Total)
+}
+
+func orDash(value string) string {
+ if value == "" {
+ return "-"
+ }
+ return value
+}
+
+func shortImageID(id string) string {
+ trimmed := strings.TrimPrefix(id, "sha256:")
+ if len(trimmed) > 12 {
+ return trimmed[:12]
+ }
+ return trimmed
+}
+
+// resolveImageID resolves an image name, tag, or (partial) ID to a full image
+// ID. It first tries a direct lookup and falls back to a server-side search.
+func resolveImageID(ctx context.Context, c *client.Client, identifier string) (string, error) {
+ trimmed := strings.TrimSpace(identifier)
+ if trimmed == "" {
+ return "", errors.New("image identifier is required")
+ }
+
+ resp, err := c.Get(ctx, types.Image(c.EnvID(), trimmed))
+ if err != nil {
+ return "", errors.WrapIff(err, "failed to resolve image %q", trimmed)
+ }
+
+ body, err := io.ReadAll(resp.Body)
+ _ = resp.Body.Close()
+ if err != nil {
+ return "", errors.WrapIf(err, "failed to read image response")
+ }
+
+ if resp.StatusCode == http.StatusOK {
+ var result base.ApiResponse[image.DetailSummary]
+ if err := json.Unmarshal(body, &result); err != nil {
+ return "", errors.WrapIf(err, "failed to parse image response")
+ }
+ if result.Data.ID == "" {
+ return "", errors.Errorf("image lookup for %q returned empty ID", trimmed)
+ }
+ return result.Data.ID, nil
+ }
+
+ if resp.StatusCode != http.StatusNotFound {
+ return "", errors.Errorf("failed to resolve image %q (status %d): %s", trimmed, resp.StatusCode, strings.TrimSpace(string(body)))
+ }
+
+ searchPath := fmt.Sprintf("%s?search=%s&limit=%d", types.Images(c.EnvID()), url.QueryEscape(trimmed), cmdutil.ShowAllLimit)
+ searchResp, err := c.Get(ctx, searchPath)
+ if err != nil {
+ return "", errors.WrapIf(err, "failed to search images")
+ }
+
+ searchBody, err := cmdutil.ReadJSONBody(searchResp)
+ _ = searchResp.Body.Close()
+ if err != nil {
+ return "", errors.WrapIf(err, "failed to search images")
+ }
+
+ var result base.Paginated[image.Summary]
+ if err := json.Unmarshal(searchBody, &result); err != nil {
+ return "", errors.WrapIf(err, "failed to parse images response")
+ }
+
+ identifierLower := strings.ToLower(trimmed)
+ matches := make([]image.Summary, 0)
+ for _, item := range result.Data {
+ if imageMatches(item, trimmed, identifierLower) {
+ matches = append(matches, item)
+ }
+ }
+
+ switch len(matches) {
+ case 1:
+ return matches[0].ID, nil
+ case 0:
+ return "", errors.Errorf("image %q not found; use the image ID or run `arcane images list`", trimmed)
+ default:
+ return "", errors.Errorf("multiple images match %q; use the image ID or run `arcane images list`", trimmed)
+ }
+}
+
+func imageMatches(item image.Summary, trimmed, identifierLower string) bool {
+ idLower := strings.ToLower(item.ID)
+ if idLower == identifierLower || (len(identifierLower) >= 4 && strings.HasPrefix(idLower, identifierLower)) {
+ return true
+ }
+ for _, tag := range item.RepoTags {
+ if strings.EqualFold(tag, trimmed) || strings.Contains(strings.ToLower(tag), identifierLower) {
+ return true
+ }
+ }
+ for _, digest := range item.RepoDigests {
+ if strings.EqualFold(digest, trimmed) || strings.Contains(strings.ToLower(digest), identifierLower) {
+ return true
+ }
+ }
+ return false
+}
diff --git a/cli/pkg/webhooks/cmd.go b/cli/pkg/webhooks/cmd.go
new file mode 100644
index 000000000..cba546a8f
--- /dev/null
+++ b/cli/pkg/webhooks/cmd.go
@@ -0,0 +1,292 @@
+// Package webhooks implements the `arcane webhooks` command group for
+// per-environment inbound webhooks that trigger actions.
+package webhooks
+
+import (
+ "encoding/json"
+ "fmt"
+ "net/http"
+ "time"
+
+ "emperror.dev/errors"
+
+ "github.com/getarcaneapp/arcane/cli/v2/internal/cmdutil"
+ "github.com/getarcaneapp/arcane/cli/v2/internal/output"
+ "github.com/getarcaneapp/arcane/cli/v2/internal/types"
+ "github.com/getarcaneapp/arcane/types/v2/base"
+ "github.com/getarcaneapp/arcane/types/v2/webhook"
+ "github.com/spf13/cobra"
+)
+
+var (
+ forceFlag bool
+ jsonOutput bool
+ createName string
+ createTarget string
+ createAction string
+ createTargetID string
+ updateEnabled bool
+)
+
+// WebhooksCmd is the parent command for webhook operations.
+var WebhooksCmd = &cobra.Command{
+ Use: "webhooks",
+ Aliases: []string{"webhook", "wh"},
+ Short: "Manage inbound webhooks",
+}
+
+var listCmd = &cobra.Command{
+ Use: "list",
+ Aliases: []string{"ls"},
+ Short: "List webhooks",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := cmdutil.ClientFromCommand(cmd)
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Get(cmd.Context(), types.Webhooks(c.EnvID()))
+ if err != nil {
+ return errors.WrapIf(err, "failed to list webhooks")
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ body, err := cmdutil.ReadJSONBody(resp)
+ if err != nil {
+ return errors.WrapIf(err, "failed to list webhooks")
+ }
+
+ if jsonOutput {
+ return cmdutil.PrintRawJSON(body)
+ }
+
+ var result base.ApiResponse[[]webhook.Summary]
+ if err := json.Unmarshal(body, &result); err != nil {
+ return errors.WrapIf(err, "failed to parse response")
+ }
+
+ headers := []string{"ID", "NAME", "ACTION", "TARGET", "TOKEN", "ENABLED", "LAST TRIGGERED"}
+ rows := make([][]string, len(result.Data))
+ for i, item := range result.Data {
+ enabled := "No"
+ if item.Enabled {
+ enabled = "Yes"
+ }
+ lastTriggered := "-"
+ if item.LastTriggeredAt != nil {
+ lastTriggered = item.LastTriggeredAt.Format(time.RFC3339)
+ }
+ rows[i] = []string{
+ item.ID,
+ item.Name,
+ item.ActionType,
+ webhookTarget(item),
+ item.TokenPrefix,
+ enabled,
+ lastTriggered,
+ }
+ }
+
+ output.Table(headers, rows)
+ output.Showing(len(result.Data), int64(len(result.Data)), "webhooks")
+ return nil
+ },
+}
+
+var createCmd = &cobra.Command{
+ Use: "create",
+ Short: "Create a webhook",
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := cmdutil.ClientFromCommand(cmd)
+ if err != nil {
+ return err
+ }
+
+ req := webhook.CreateInput{
+ Name: createName,
+ TargetType: createTarget,
+ ActionType: createAction,
+ TargetID: createTargetID,
+ }
+
+ resp, err := c.Post(cmd.Context(), types.Webhooks(c.EnvID()), req)
+ if err != nil {
+ return errors.WrapIf(err, "failed to create webhook")
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ var result base.ApiResponse[webhook.Created]
+ if err := cmdutil.DecodeJSON(resp, &result); err != nil {
+ return errors.WrapIf(err, "failed to create webhook")
+ }
+
+ if jsonOutput {
+ return cmdutil.PrintJSON(result.Data)
+ }
+
+ output.Success("Webhook %s created successfully", result.Data.Name)
+ output.KeyValue("ID", result.Data.ID)
+ output.KeyValue("Target Type", result.Data.TargetType)
+ output.KeyValue("Action", result.Data.ActionType)
+ if result.Data.TargetID != "" {
+ output.KeyValue("Target ID", result.Data.TargetID)
+ }
+ if result.Data.Token != "" {
+ output.Warning("Store this token securely — it will not be shown again")
+ output.KeyValue("Token", result.Data.Token)
+ }
+ return nil
+ },
+}
+
+var updateCmd = &cobra.Command{
+ Use: "update <webhook-id>",
+ Short: "Update a webhook",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ if !cmd.Flags().Changed("enabled") {
+ return errors.New("no fields to update: specify --enabled")
+ }
+
+ c, err := cmdutil.ClientFromCommand(cmd)
+ if err != nil {
+ return err
+ }
+
+ req := webhook.UpdateInput{Enabled: updateEnabled}
+ resp, err := c.Request(cmd.Context(), http.MethodPatch, types.Webhook(c.EnvID(), args[0]), req)
+ if err != nil {
+ return errors.WrapIf(err, "failed to update webhook")
+ }
+ defer func() { _ = resp.Body.Close() }()
+ if err := cmdutil.EnsureSuccessStatus(resp); err != nil {
+ return errors.WrapIf(err, "failed to update webhook")
+ }
+
+ if jsonOutput {
+ return cmdutil.PrintJSON(map[string]bool{"enabled": updateEnabled})
+ }
+
+ state := "disabled"
+ if updateEnabled {
+ state = "enabled"
+ }
+ output.Success("Webhook %s %s", args[0], state)
+ return nil
+ },
+}
+
+var deleteCmd = &cobra.Command{
+ Use: "delete <webhook-id>",
+ Aliases: []string{"rm", "remove"},
+ Short: "Delete a webhook",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ if !forceFlag {
+ confirmed, err := cmdutil.Confirm(cmd, fmt.Sprintf("Are you sure you want to delete webhook %s?", args[0]))
+ if err != nil {
+ return err
+ }
+ if !confirmed {
+ fmt.Println("Cancelled")
+ return nil
+ }
+ }
+
+ c, err := cmdutil.ClientFromCommand(cmd)
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Delete(cmd.Context(), types.Webhook(c.EnvID(), args[0]))
+ if err != nil {
+ return errors.WrapIf(err, "failed to delete webhook")
+ }
+ defer func() { _ = resp.Body.Close() }()
+ if err := cmdutil.EnsureSuccessStatus(resp); err != nil {
+ return errors.WrapIf(err, "failed to delete webhook")
+ }
+
+ output.Success("Webhook %s deleted successfully", args[0])
+ return nil
+ },
+}
+
+var triggerCmd = &cobra.Command{
+ Use: "trigger <token>",
+ Short: "Trigger a webhook by token",
+ Long: "Trigger a webhook by its token. The token is the sole authentication mechanism; no login is required. The server accepts the trigger and runs the action in the background.",
+ Args: cobra.ExactArgs(1),
+ SilenceUsage: true,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ c, err := cmdutil.UnauthClientFromCommand(cmd)
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Post(cmd.Context(), types.WebhookTrigger(args[0]), nil)
+ if err != nil {
+ return errors.WrapIf(err, "failed to trigger webhook")
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ body, err := cmdutil.ReadJSONBody(resp)
+ if err != nil {
+ return errors.WrapIf(err, "failed to trigger webhook")
+ }
+
+ if jsonOutput {
+ return cmdutil.PrintRawJSON(body)
+ }
+
+ output.Success("Webhook trigger accepted; the action is running in the background")
+ return nil
+ },
+}
+
+func init() {
+ WebhooksCmd.AddCommand(listCmd)
+ WebhooksCmd.AddCommand(createCmd)
+ WebhooksCmd.AddCommand(updateCmd)
+ WebhooksCmd.AddCommand(deleteCmd)
+ WebhooksCmd.AddCommand(triggerCmd)
+
+ // List command flags
+ listCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ // Create command flags
+ createCmd.Flags().StringVar(&createName, "name", "", "Webhook name")
+ createCmd.Flags().StringVar(&createTarget, "target", "", "Target type: container, project, updater, or gitops")
+ createCmd.Flags().StringVar(&createAction, "action", "", "Action to run: update, start, stop, restart, redeploy, up, down, run, or sync")
+ createCmd.Flags().StringVar(&createTargetID, "target-id", "", "Container ID, project ID, or GitOps sync ID to target (not needed for updater webhooks)")
+ createCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+ _ = createCmd.MarkFlagRequired("name")
+ _ = createCmd.MarkFlagRequired("target")
+ _ = createCmd.MarkFlagRequired("action")
+
+ // Update command flags
+ updateCmd.Flags().BoolVar(&updateEnabled, "enabled", true, "Whether the webhook is active")
+ updateCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ // Delete command flags
+ deleteCmd.Flags().BoolVarP(&forceFlag, "force", "f", false, "Delete without confirmation")
+ deleteCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+
+ // Trigger command flags
+ triggerCmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
+}
+
+func webhookTarget(item webhook.Summary) string {
+ name := item.TargetName
+ if name == "" {
+ name = item.TargetID
+ }
+ if name == "" {
+ return item.TargetType
+ }
+ return fmt.Sprintf("%s/%s", item.TargetType, name)
+}
diff --git a/tests/spec/cli.spec.ts b/tests/spec/cli.spec.ts
index e499f4327..7f14512af 100644
--- a/tests/spec/cli.spec.ts
+++ b/tests/spec/cli.spec.ts
@@ -103,6 +103,12 @@ function expectPaginated(value: unknown): void {
);
}
+// The command must exit 0 and print parseable JSON; the payload shape (array,
+// object, or null on empty) is the command's own concern.
+function expectJsonValue(value: unknown): void {
+ expect(value === null || typeof value === 'object' || Array.isArray(value)).toBe(true);
+}
+
const readOnlyJsonSmokeCommands: JsonSmokeCommand[] = [
{
name: 'images list',
@@ -211,10 +217,12 @@ const readOnlyJsonSmokeCommands: JsonSmokeCommand[] = [
}
},
{
- name: 'templates variables',
- args: ['templates', 'variables', '--json'],
+ name: 'variables list',
+ args: ['variables', 'list', '--json'],
expectation: (value) => {
- expect(value === null || Array.isArray(value)).toBe(true);
+ const envelope = value as { success?: boolean; data?: unknown };
+ expect(envelope.success).toBe(true);
+ expect(envelope.data === null || Array.isArray(envelope.data)).toBe(true);
}
},
{
@@ -228,8 +236,8 @@ const readOnlyJsonSmokeCommands: JsonSmokeCommand[] = [
expectation: expectPaginated
},
{
- name: 'admin events list-env',
- args: ['admin', 'events', 'list-env', '--limit', '5', '--json'],
+ name: 'admin events list --environment',
+ args: ['admin', 'events', 'list', '--environment', '--limit', '5', '--json'],
expectation: expectPaginated
},
{
@@ -238,6 +246,86 @@ const readOnlyJsonSmokeCommands: JsonSmokeCommand[] = [
expectation: (value) => {
expect(value).toEqual(expect.any(Array));
}
+ },
+ {
+ name: 'containers counts',
+ args: ['containers', 'counts', '--json'],
+ expectation: expectJsonValue
+ },
+ {
+ name: 'images updates summary',
+ args: ['images', 'updates', 'summary', '--json'],
+ expectation: expectJsonValue
+ },
+ {
+ name: 'system info',
+ args: ['system', 'info', '--json'],
+ expectation: expectJsonValue
+ },
+ {
+ name: 'projects tags',
+ args: ['projects', 'tags', '--json'],
+ expectation: expectJsonValue
+ },
+ {
+ name: 'jobs list',
+ args: ['jobs', 'list', '--json'],
+ expectation: expectJsonValue
+ },
+ {
+ name: 'registries usage',
+ args: ['registries', 'usage', '--json'],
+ expectation: expectJsonValue
+ },
+ {
+ name: 'admin events stats',
+ args: ['admin', 'events', 'stats', '--json'],
+ expectation: expectJsonValue
+ },
+ {
+ name: 'admin federated list',
+ args: ['admin', 'federated', 'list', '--json'],
+ expectation: expectJsonValue
+ },
+ {
+ name: 'auth keys list',
+ args: ['auth', 'keys', 'list', '--json'],
+ expectation: expectJsonValue
+ },
+ {
+ name: 'backups list',
+ args: ['backups', 'list', '--json'],
+ expectation: expectJsonValue
+ },
+ {
+ name: 'backups policies',
+ args: ['backups', 'policies', '--json'],
+ expectation: expectJsonValue
+ },
+ {
+ name: 'backups s3 list',
+ args: ['backups', 's3', 'list', '--json'],
+ expectation: expectJsonValue
+ },
+ {
+ name: 'activities list',
+ args: ['activities', 'list', '--json'],
+ expectation: expectJsonValue
+ },
+ {
+ name: 'webhooks list',
+ args: ['webhooks', 'list', '--json'],
+ expectation: expectJsonValue
+ },
+ {
+ name: 'vulnerabilities status',
+ args: ['vulnerabilities', 'status', '--json'],
+ expectation: expectJsonValue
+ },
+ {
+ name: 'vulnerabilities ignored',
+ args: ['vulnerabilities', 'ignored', '--json'],
+ expectation: expectJsonValue
}
];