From eb893e1c7a54589cfdbd2c36d68d402e78b35cb6 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 21 Feb 2024 13:47:03 -0800 Subject: [PATCH] Actions: Add partial implementation of list action cmd --- .../commands/waypoint/actionconfig/delete.go | 2 - .../commands/waypoint/actionconfig/list.go | 44 +++++++++++++++++-- .../commands/waypoint/actionconfig/show.go | 12 +++-- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/internal/commands/waypoint/actionconfig/delete.go b/internal/commands/waypoint/actionconfig/delete.go index 2ad3eed1..feb1ca7d 100644 --- a/internal/commands/waypoint/actionconfig/delete.go +++ b/internal/commands/waypoint/actionconfig/delete.go @@ -13,8 +13,6 @@ type DeleteOpts struct { opts.WaypointOpts Name string - // We intentionally don't support ID for delete yet. - Id string } func NewCmdDelete(ctx *cmd.Context) *cmd.Command { diff --git a/internal/commands/waypoint/actionconfig/list.go b/internal/commands/waypoint/actionconfig/list.go index 4aef9464..994dfafc 100644 --- a/internal/commands/waypoint/actionconfig/list.go +++ b/internal/commands/waypoint/actionconfig/list.go @@ -1,18 +1,56 @@ package actionconfig -import "github.com/hashicorp/hcp/internal/pkg/cmd" +import ( + "fmt" + + "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/client/waypoint_service" + "github.com/hashicorp/hcp/internal/commands/waypoint/opts" + "github.com/hashicorp/hcp/internal/pkg/cmd" +) + +type ListOpts struct { + opts.WaypointOpts +} func NewCmdList(ctx *cmd.Context) *cmd.Command { + opts := &ListOpts{ + WaypointOpts: opts.New(ctx), + } + cmd := &cmd.Command{ Name: "list", ShortHelp: "List all known action configurations.", LongHelp: "List all known action configuration.", - RunF: listActionConfig, + RunF: func(c *cmd.Command, args []string) error { + return listActionConfig(c, args, opts) + }, + PersistentPreRun: func(c *cmd.Command, args []string) error { + return cmd.RequireOrgAndProject(ctx) + }, } return cmd } -func listActionConfig(c *cmd.Command, args []string) error { +func listActionConfig(c *cmd.Command, args []string, opts *ListOpts) error { + ns, err := opts.Namespace() + if err != nil { + return err + } + + resp, err := opts.WS.WaypointServiceListActionConfigs(&waypoint_service.WaypointServiceListActionConfigsParams{ + NamespaceID: ns.ID, + Context: opts.Ctx, + }, nil) + if err != nil { + fmt.Fprintf(opts.IO.Err(), "Error listing action configs: %s", err) + return err + } + + respPayload := resp.GetPayload() + if len(respPayload.ActionConfigs) > 0 { + // Print them + } + return nil } diff --git a/internal/commands/waypoint/actionconfig/show.go b/internal/commands/waypoint/actionconfig/show.go index 66d25bc8..e7dc09f1 100644 --- a/internal/commands/waypoint/actionconfig/show.go +++ b/internal/commands/waypoint/actionconfig/show.go @@ -13,8 +13,6 @@ type ShowOpts struct { opts.WaypointOpts Name string - // We intentionally don't support ID for delete yet. - Id string } func NewCmdShow(ctx *cmd.Context) *cmd.Command { @@ -55,7 +53,7 @@ func showActionConfig(c *cmd.Command, args []string, opts *ShowOpts) error { // Make action name a string pointer actionName := &opts.Name - resp, err := opts.WS.WaypointServiceGetActionConfig(&waypoint_service.WaypointServiceGetActionConfigParams{ + _, err = opts.WS.WaypointServiceGetActionConfig(&waypoint_service.WaypointServiceGetActionConfigParams{ NamespaceID: ns.ID, Context: opts.Ctx, ActionName: actionName, @@ -65,10 +63,10 @@ func showActionConfig(c *cmd.Command, args []string, opts *ShowOpts) error { return err } - respPayload := resp.GetPayload() - actionCfg := respPayload.ActionConfig - latestRun := respPayload.LatestRun - totalRuns := respPayload.TotalRuns + // respPayload := resp.GetPayload() + // actionCfg := respPayload.ActionConfig + // latestRun := respPayload.LatestRun + // totalRuns := respPayload.TotalRuns // TODO(briancain): add a displayer.go