Skip to content

Commit

Permalink
hvs use 2023-11-28 api
Browse files Browse the repository at this point in the history
  • Loading branch information
keeefer committed Nov 20, 2024
1 parent aa5c178 commit 868356a
Show file tree
Hide file tree
Showing 50 changed files with 705 additions and 812 deletions.
31 changes: 15 additions & 16 deletions internal/commands/vaultsecrets/apps/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"context"
"fmt"

"github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-06-13/client/secret_service"
preview_secret_service "github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-11-28/client/secret_service"
"github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-11-28/models"

"github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-11-28/client/secret_service"
"github.com/hashicorp/hcp/internal/pkg/cmd"
"github.com/hashicorp/hcp/internal/pkg/flagvalue"
"github.com/hashicorp/hcp/internal/pkg/format"
Expand All @@ -23,20 +24,18 @@ type CreateOpts struct {
Output *format.Outputter
IO iostreams.IOStreams

AppName string
Description string
Client secret_service.ClientService
PreviewClient preview_secret_service.ClientService
AppName string
Description string
Client secret_service.ClientService
}

func NewCmdCreate(ctx *cmd.Context, runF func(*CreateOpts) error) *cmd.Command {
opts := &CreateOpts{
Ctx: ctx.ShutdownCtx,
Profile: ctx.Profile,
Output: ctx.Output,
IO: ctx.IO,
Client: secret_service.New(ctx.HCP, nil),
PreviewClient: preview_secret_service.New(ctx.HCP, nil),
Ctx: ctx.ShutdownCtx,
Profile: ctx.Profile,
Output: ctx.Output,
IO: ctx.IO,
Client: secret_service.New(ctx.HCP, nil),
}

cmd := &cmd.Command{
Expand Down Expand Up @@ -88,10 +87,10 @@ func NewCmdCreate(ctx *cmd.Context, runF func(*CreateOpts) error) *cmd.Command {

func createRun(opts *CreateOpts) error {
resp, err := opts.Client.CreateApp(&secret_service.CreateAppParams{
Context: opts.Ctx,
LocationProjectID: opts.Profile.ProjectID,
LocationOrganizationID: opts.Profile.OrganizationID,
Body: secret_service.CreateAppBody{
Context: opts.Ctx,
ProjectID: opts.Profile.ProjectID,
OrganizationID: opts.Profile.OrganizationID,
Body: &models.SecretServiceCreateAppBody{
Name: opts.AppName,
Description: opts.Description,
},
Expand Down
18 changes: 9 additions & 9 deletions internal/commands/vaultsecrets/apps/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-06-13/client/secret_service"
"github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-06-13/models"
mock_secret_service "github.com/hashicorp/hcp/internal/pkg/api/mocks/github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-06-13/client/secret_service"
"github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-11-28/client/secret_service"
"github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-11-28/models"
mock_secret_service "github.com/hashicorp/hcp/internal/pkg/api/mocks/github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-11-28/client/secret_service"
"github.com/hashicorp/hcp/internal/pkg/cmd"
"github.com/hashicorp/hcp/internal/pkg/format"
"github.com/hashicorp/hcp/internal/pkg/iostreams"
Expand Down Expand Up @@ -151,16 +151,16 @@ func TestCreateRun(t *testing.T) {
vs.EXPECT().CreateApp(mock.Anything, mock.Anything).Return(nil, errors.New("missing app name")).Once()
} else {
vs.EXPECT().CreateApp(&secret_service.CreateAppParams{
Context: opts.Ctx,
LocationOrganizationID: "123",
LocationProjectID: "abc",
Body: secret_service.CreateAppBody{
Context: opts.Ctx,
OrganizationID: "123",
ProjectID: "abc",
Body: &models.SecretServiceCreateAppBody{
Name: opts.AppName,
Description: opts.Description,
},
}, nil).Return(&secret_service.CreateAppOK{
Payload: &models.Secrets20230613CreateAppResponse{
App: &models.Secrets20230613App{
Payload: &models.Secrets20231128CreateAppResponse{
App: &models.Secrets20231128App{
Name: opts.AppName,
Description: opts.Description,
},
Expand Down
29 changes: 13 additions & 16 deletions internal/commands/vaultsecrets/apps/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
"context"
"fmt"

"github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-06-13/client/secret_service"
preview_secret_service "github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-11-28/client/secret_service"
"github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-11-28/client/secret_service"
"github.com/hashicorp/hcp/internal/commands/vaultsecrets/apps/helper"
"github.com/hashicorp/hcp/internal/pkg/cmd"
"github.com/hashicorp/hcp/internal/pkg/format"
Expand All @@ -23,19 +22,17 @@ type DeleteOpts struct {
Output *format.Outputter
IO iostreams.IOStreams

AppName string
Client secret_service.ClientService
PreviewClient preview_secret_service.ClientService
AppName string
Client secret_service.ClientService
}

func NewCmdDelete(ctx *cmd.Context, runF func(*DeleteOpts) error) *cmd.Command {
opts := &DeleteOpts{
Ctx: ctx.ShutdownCtx,
Profile: ctx.Profile,
Output: ctx.Output,
IO: ctx.IO,
Client: secret_service.New(ctx.HCP, nil),
PreviewClient: preview_secret_service.New(ctx.HCP, nil),
Ctx: ctx.ShutdownCtx,
Profile: ctx.Profile,
Output: ctx.Output,
IO: ctx.IO,
Client: secret_service.New(ctx.HCP, nil),
}

cmd := &cmd.Command{
Expand Down Expand Up @@ -69,17 +66,17 @@ func NewCmdDelete(ctx *cmd.Context, runF func(*DeleteOpts) error) *cmd.Command {
return deleteRun(opts)
},
}
cmd.Args.Autocomplete = helper.PredictAppName(ctx, cmd, preview_secret_service.New(ctx.HCP, nil))
cmd.Args.Autocomplete = helper.PredictAppName(ctx, cmd, secret_service.New(ctx.HCP, nil))

return cmd
}

func deleteRun(opts *DeleteOpts) error {
_, err := opts.Client.DeleteApp(&secret_service.DeleteAppParams{
Context: opts.Ctx,
LocationOrganizationID: opts.Profile.OrganizationID,
LocationProjectID: opts.Profile.ProjectID,
Name: opts.AppName,
Context: opts.Ctx,
OrganizationID: opts.Profile.OrganizationID,
ProjectID: opts.Profile.ProjectID,
Name: opts.AppName,
}, nil)

if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions internal/commands/vaultsecrets/apps/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-06-13/client/secret_service"
mock_secret_service "github.com/hashicorp/hcp/internal/pkg/api/mocks/github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-06-13/client/secret_service"
"github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-11-28/client/secret_service"
mock_secret_service "github.com/hashicorp/hcp/internal/pkg/api/mocks/github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-11-28/client/secret_service"
"github.com/hashicorp/hcp/internal/pkg/cmd"
"github.com/hashicorp/hcp/internal/pkg/format"
"github.com/hashicorp/hcp/internal/pkg/iostreams"
Expand Down Expand Up @@ -135,10 +135,10 @@ func TestDeleteRun(t *testing.T) {
vs.EXPECT().DeleteApp(mock.Anything, mock.Anything).Return(nil, errors.New(c.ErrMsg)).Once()
} else {
vs.EXPECT().DeleteApp(&secret_service.DeleteAppParams{
LocationOrganizationID: "123",
LocationProjectID: "abc",
Name: opts.AppName,
Context: opts.Ctx,
OrganizationID: "123",
ProjectID: "abc",
Name: opts.AppName,
Context: opts.Ctx,
}, nil).Return(&secret_service.DeleteAppOK{}, nil).Once()
}

Expand Down
27 changes: 3 additions & 24 deletions internal/commands/vaultsecrets/apps/displayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,28 @@
package apps

import (
"github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-06-13/models"
preview_models "github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-11-28/models"
"github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-11-28/models"
"github.com/hashicorp/hcp/internal/pkg/format"
)

type displayer struct {
apps []*models.Secrets20230613App
previewApps []*preview_models.Secrets20231128App
apps []*models.Secrets20231128App

single bool
}

func newDisplayer(single bool, apps ...*models.Secrets20230613App) *displayer {
func newDisplayer(single bool, apps ...*models.Secrets20231128App) *displayer {
return &displayer{
apps: apps,
single: single,
}
}

func newDisplayerPreview(single bool, apps ...*preview_models.Secrets20231128App) *displayer {
return &displayer{
previewApps: apps,
single: single,
}
}

func (d *displayer) DefaultFormat() format.Format {
return format.Table
}

func (d *displayer) Payload() any {
if d.previewApps != nil {
if d.single {
if len(d.previewApps) != 1 {
return nil
}

return d.previewApps[0]
}

return d.previewApps
}

if d.single {
if len(d.apps) != 1 {
return nil
Expand Down
12 changes: 6 additions & 6 deletions internal/commands/vaultsecrets/apps/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
"context"
"fmt"

preview_secret_service "github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-11-28/client/secret_service"
preview_models "github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-11-28/models"
"github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-11-28/client/secret_service"
"github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-11-28/models"
"github.com/hashicorp/hcp/internal/pkg/cmd"
"github.com/posener/complete"
)

// PredictAppName returns a predict function for application names.
func PredictAppName(ctx *cmd.Context, c *cmd.Command, client preview_secret_service.ClientService) complete.PredictFunc {
func PredictAppName(ctx *cmd.Context, c *cmd.Command, client secret_service.ClientService) complete.PredictFunc {
return func(args complete.Args) []string {
// Parse the args
remainingArgs, err := ctx.ParseFlags(c, args.All)
Expand All @@ -40,11 +40,11 @@ func PredictAppName(ctx *cmd.Context, c *cmd.Command, client preview_secret_serv
}
}

func getApps(ctx context.Context, orgID, projectID string, client preview_secret_service.ClientService) ([]*preview_models.Secrets20231128App, error) {
req := preview_secret_service.NewListAppsParamsWithContext(ctx)
func getApps(ctx context.Context, orgID, projectID string, client secret_service.ClientService) ([]*models.Secrets20231128App, error) {
req := secret_service.NewListAppsParamsWithContext(ctx)
req.OrganizationID = orgID
req.ProjectID = projectID
var apps []*preview_models.Secrets20231128App
var apps []*models.Secrets20231128App
for {

resp, err := client.ListApps(req, nil)
Expand Down
23 changes: 10 additions & 13 deletions internal/commands/vaultsecrets/apps/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
"context"
"fmt"

"github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-06-13/client/secret_service"
preview_secret_service "github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-11-28/client/secret_service"
"github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-11-28/client/secret_service"
"github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-11-28/models"
"github.com/hashicorp/hcp/internal/pkg/cmd"
"github.com/hashicorp/hcp/internal/pkg/format"
Expand All @@ -23,18 +22,16 @@ type ListOpts struct {
Output *format.Outputter
IO iostreams.IOStreams

Client secret_service.ClientService
PreviewClient preview_secret_service.ClientService
Client secret_service.ClientService
}

func NewCmdList(ctx *cmd.Context, runF func(*ListOpts) error) *cmd.Command {
opts := &ListOpts{
Ctx: ctx.ShutdownCtx,
Profile: ctx.Profile,
IO: ctx.IO,
Output: ctx.Output,
PreviewClient: preview_secret_service.New(ctx.HCP, nil),
Client: secret_service.New(ctx.HCP, nil),
Ctx: ctx.ShutdownCtx,
Profile: ctx.Profile,
IO: ctx.IO,
Output: ctx.Output,
Client: secret_service.New(ctx.HCP, nil),
}

cmd := &cmd.Command{
Expand Down Expand Up @@ -62,15 +59,15 @@ func NewCmdList(ctx *cmd.Context, runF func(*ListOpts) error) *cmd.Command {
}

func listRun(opts *ListOpts) error {
params := &preview_secret_service.ListAppsParams{
params := &secret_service.ListAppsParams{
Context: opts.Ctx,
ProjectID: opts.Profile.ProjectID,
OrganizationID: opts.Profile.OrganizationID,
}

var apps []*models.Secrets20231128App
for {
resp, err := opts.PreviewClient.ListApps(params, nil)
resp, err := opts.Client.ListApps(params, nil)

if err != nil {
return fmt.Errorf("failed to list apps: %w", err)
Expand All @@ -84,5 +81,5 @@ func listRun(opts *ListOpts) error {
next := resp.Payload.Pagination.NextPageToken
params.PaginationNextPageToken = &next
}
return opts.Output.Display(newDisplayerPreview(false, apps...))
return opts.Output.Display(newDisplayer(false, apps...))
}
Loading

0 comments on commit 868356a

Please sign in to comment.