-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from hashicorp/WAYP-2309-waypoint-applications…
…-cli `hcp waypoint applications` CLI
- Loading branch information
Showing
38 changed files
with
881 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:feature | ||
waypoint: Add `waypoint applications` CLI for managing HCP Waypoint applications. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ands/waypoint/add-on/add_on_definition.go → .../add-ons/definitions/add_on_definition.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package addon | ||
package definitions | ||
|
||
import ( | ||
"github.com/hashicorp/hcp/internal/commands/waypoint/opts" | ||
|
2 changes: 1 addition & 1 deletion
2
...ypoint/add-on/add_on_definition_create.go → ...ds/waypoint/add-ons/definitions/create.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package addon | ||
package definitions | ||
|
||
import ( | ||
"fmt" | ||
|
2 changes: 1 addition & 1 deletion
2
...t/add-on/add_on_definition_create_test.go → ...ypoint/add-ons/definitions/create_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package addon | ||
package definitions | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
...ypoint/add-on/add_on_definition_delete.go → ...ds/waypoint/add-ons/definitions/delete.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package addon | ||
package definitions | ||
|
||
import ( | ||
"fmt" | ||
|
2 changes: 1 addition & 1 deletion
2
...t/add-on/add_on_definition_delete_test.go → ...ypoint/add-ons/definitions/delete_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package addon | ||
package definitions | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
...waypoint/add-on/add_on_definition_list.go → ...ands/waypoint/add-ons/definitions/list.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...int/add-on/add_on_definition_list_test.go → ...waypoint/add-ons/definitions/list_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package addon | ||
package definitions | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
...waypoint/add-on/add_on_definition_read.go → ...ands/waypoint/add-ons/definitions/read.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...int/add-on/add_on_definition_read_test.go → ...waypoint/add-ons/definitions/read_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package addon | ||
package definitions | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
...ypoint/add-on/add_on_definition_update.go → ...ds/waypoint/add-ons/definitions/update.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package addon | ||
package definitions | ||
|
||
import ( | ||
"fmt" | ||
|
2 changes: 1 addition & 1 deletion
2
...t/add-on/add_on_definition_update_test.go → ...ypoint/add-ons/definitions/update_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package addon | ||
package definitions | ||
|
||
import ( | ||
"context" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package applications | ||
|
||
import ( | ||
"github.com/hashicorp/hcp/internal/commands/waypoint/opts" | ||
"github.com/hashicorp/hcp/internal/pkg/cmd" | ||
"github.com/hashicorp/hcp/internal/pkg/heredoc" | ||
) | ||
|
||
type ApplicationOpts struct { | ||
opts.WaypointOpts | ||
|
||
Name string | ||
TemplateName string | ||
ActionConfigNames []string | ||
ReadmeMarkdownFile string | ||
|
||
testFunc func(c *cmd.Command, args []string) error | ||
} | ||
|
||
func NewCmdApplications(ctx *cmd.Context) *cmd.Command { | ||
opts := &ApplicationOpts{ | ||
WaypointOpts: opts.New(ctx), | ||
} | ||
|
||
cmd := &cmd.Command{ | ||
Name: "applications", | ||
ShortHelp: "Manage HCP Waypoint applications.", | ||
LongHelp: heredoc.New(ctx.IO).Must(` | ||
The {{ template "mdCodeOrBold" "hcp waypoint applications" }} command group lets you manage | ||
HCP Waypoint applications. | ||
`), | ||
} | ||
|
||
cmd.AddChild(NewCmdApplicationsCreate(ctx, opts)) | ||
cmd.AddChild(NewCmdApplicationsDestroy(ctx, opts)) | ||
cmd.AddChild(NewCmdApplicationsList(ctx, opts)) | ||
cmd.AddChild(NewCmdApplicationsRead(ctx, opts)) | ||
cmd.AddChild(NewCmdApplicationsUpdate(ctx, opts)) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package applications | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/client/waypoint_service" | ||
"github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/models" | ||
"github.com/hashicorp/hcp/internal/pkg/cmd" | ||
"github.com/hashicorp/hcp/internal/pkg/flagvalue" | ||
"github.com/hashicorp/hcp/internal/pkg/heredoc" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func NewCmdApplicationsCreate(ctx *cmd.Context, opts *ApplicationOpts) *cmd.Command { | ||
cmd := &cmd.Command{ | ||
Name: "create", | ||
ShortHelp: "Create a new HCP Waypoint application.", | ||
LongHelp: heredoc.New(ctx.IO).Must(` | ||
The {{ template "mdCodeOrBold" "hcp waypoint applications create" }} command lets you create | ||
a new HCP Waypoint application. | ||
`), | ||
Examples: []cmd.Example{ | ||
{ | ||
Preamble: "Create a new HCP Waypoint application:", | ||
Command: heredoc.New(ctx.IO, heredoc.WithPreserveNewlines()).Must(` | ||
$ hcp waypoint application create -n my-application -t my-templates | ||
`), | ||
}, | ||
}, | ||
RunF: func(c *cmd.Command, args []string) error { | ||
if opts.testFunc != nil { | ||
return opts.testFunc(c, args) | ||
} | ||
return applicationCreate(opts) | ||
}, | ||
PersistentPreRun: func(c *cmd.Command, args []string) error { | ||
return cmd.RequireOrgAndProject(ctx) | ||
}, | ||
Flags: cmd.Flags{ | ||
Local: []*cmd.Flag{ | ||
{ | ||
Name: "name", | ||
Shorthand: "n", | ||
DisplayValue: "NAME", | ||
Description: "The name of the application.", | ||
Value: flagvalue.Simple("", &opts.Name), | ||
Required: true, | ||
}, | ||
{ | ||
Name: "templates-name", | ||
Shorthand: "t", | ||
DisplayValue: "TEMPLATE_NAME", | ||
Description: "The name of the templates to use for the application.", | ||
Value: flagvalue.Simple("", &opts.TemplateName), | ||
Required: true, | ||
}, | ||
{ | ||
Name: "action-config-name", | ||
DisplayValue: "ACTION_CONFIG_NAME", | ||
Description: "The name of the action configuration to be added to the application.", | ||
Value: flagvalue.SimpleSlice(nil, &opts.ActionConfigNames), | ||
Required: false, | ||
Repeatable: true, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func applicationCreate(opts *ApplicationOpts) error { | ||
ns, err := opts.Namespace() | ||
if err != nil { | ||
return errors.Wrap(err, "unable to access HCP project") | ||
} | ||
|
||
actionConfigs := make([]*models.HashicorpCloudWaypointActionCfgRef, len(opts.ActionConfigNames)) | ||
for i, name := range opts.ActionConfigNames { | ||
actionConfigs[i] = &models.HashicorpCloudWaypointActionCfgRef{ | ||
Name: name, | ||
} | ||
} | ||
|
||
_, err = opts.WS.WaypointServiceCreateApplicationFromTemplate( | ||
&waypoint_service.WaypointServiceCreateApplicationFromTemplateParams{ | ||
NamespaceID: ns.ID, | ||
Context: opts.Ctx, | ||
Body: &models.HashicorpCloudWaypointWaypointServiceCreateApplicationFromTemplateBody{ | ||
Name: opts.Name, | ||
ApplicationTemplate: &models.HashicorpCloudWaypointRefApplicationTemplate{ | ||
Name: opts.TemplateName, | ||
}, | ||
ActionCfgRefs: actionConfigs, | ||
}, | ||
}, nil) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to create application %q", opts.Name) | ||
} | ||
|
||
fmt.Fprintf(opts.IO.Err(), "Application %q created.", opts.Name) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package applications | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/go-openapi/runtime/client" | ||
"github.com/hashicorp/hcp/internal/pkg/cmd" | ||
"github.com/hashicorp/hcp/internal/pkg/format" | ||
"github.com/hashicorp/hcp/internal/pkg/iostreams" | ||
"github.com/hashicorp/hcp/internal/pkg/profile" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNewCmdCreateApplication(t *testing.T) { | ||
t.Parallel() | ||
|
||
cases := []struct { | ||
Name string | ||
Args []string | ||
Profile func(t *testing.T) *profile.Profile | ||
Error string | ||
Expect *ApplicationOpts | ||
}{ | ||
{ | ||
Name: "No Org", | ||
Profile: profile.TestProfile, | ||
Args: []string{}, | ||
Error: "Organization ID must be configured", | ||
}, | ||
{ | ||
Name: "No Name", | ||
Profile: profile.TestProfile, | ||
Args: []string{"-t", "templates-name"}, | ||
Error: "The name of the application is required", | ||
}, | ||
{ | ||
Name: "No Template Name", | ||
Profile: profile.TestProfile, | ||
Args: []string{"-n", "app-name"}, | ||
Error: "The name of the templates to use for the application is required", | ||
}, | ||
{ | ||
Name: "Happy", | ||
Profile: profile.TestProfile, | ||
Args: []string{"-n", "app-name", "-t", "templates-name"}, | ||
Expect: &ApplicationOpts{ | ||
Name: "app-name", | ||
TemplateName: "templates-name", | ||
}, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
c := c | ||
|
||
t.Run(c.Name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
r := require.New(t) | ||
|
||
// Create a context. | ||
io := iostreams.Test() | ||
ctx := &cmd.Context{ | ||
IO: io, | ||
Profile: c.Profile(t), | ||
Output: format.New(io), | ||
HCP: &client.Runtime{}, | ||
ShutdownCtx: context.Background(), | ||
} | ||
|
||
var appOpts ApplicationOpts | ||
appOpts.testFunc = func(c *cmd.Command, args []string) error { | ||
return nil | ||
} | ||
cmd := NewCmdApplicationsCreate(ctx, &appOpts) | ||
cmd.SetIO(io) | ||
|
||
cmd.Run(c.Args) | ||
|
||
if c.Expect != nil { | ||
r.Equal(c.Expect.Name, appOpts.Name) | ||
r.Equal(c.Expect.TemplateName, appOpts.TemplateName) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.