-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: deployment-target list feat: deployment-target cloud-region list feat: deployment-target listening-tentacle list feat: deployment-target polling-tentacle list feat: deployment-target azure-web-app list feat: deployment-target ssh list
- Loading branch information
1 parent
a169d2e
commit 4ab66c2
Showing
17 changed files
with
389 additions
and
20 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package list | ||
|
||
import ( | ||
"fmt" | ||
"github.com/MakeNowJust/heredoc/v2" | ||
"github.com/OctopusDeploy/cli/pkg/cmd" | ||
"github.com/OctopusDeploy/cli/pkg/cmd/target/list" | ||
"github.com/OctopusDeploy/cli/pkg/constants" | ||
"github.com/OctopusDeploy/cli/pkg/factory" | ||
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewCmdList(f factory.Factory) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "list", | ||
Short: "List Azure Web App deployment targets in an instance of Octopus Deploy", | ||
Long: "List Azure Web App deployment targets in an instance of Octopus Deploy.", | ||
Example: fmt.Sprintf(heredoc.Doc(` | ||
$ %s deployment-target azure-web-app list | ||
`), constants.ExecutableName), | ||
RunE: func(c *cobra.Command, args []string) error { | ||
dependencies := cmd.NewDependencies(f, c) | ||
options := list.NewListOptions(dependencies, c, machines.MachinesQuery{DeploymentTargetTypes: []string{"AzureWebApp"}}) | ||
return list.ListRun(options) | ||
}, | ||
} | ||
|
||
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
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,30 @@ | ||
package list | ||
|
||
import ( | ||
"fmt" | ||
"github.com/MakeNowJust/heredoc/v2" | ||
"github.com/OctopusDeploy/cli/pkg/cmd" | ||
"github.com/OctopusDeploy/cli/pkg/cmd/target/list" | ||
"github.com/OctopusDeploy/cli/pkg/constants" | ||
"github.com/OctopusDeploy/cli/pkg/factory" | ||
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewCmdList(f factory.Factory) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "list", | ||
Short: "List Cloud Region deployment targets in an instance of Octopus Deploy", | ||
Long: "List Cloud Region deployment targets in an instance of Octopus Deploy.", | ||
Example: fmt.Sprintf(heredoc.Doc(` | ||
$ %s deployment-target cloud-region list | ||
`), constants.ExecutableName), | ||
RunE: func(c *cobra.Command, args []string) error { | ||
dependencies := cmd.NewDependencies(f, c) | ||
options := list.NewListOptions(dependencies, c, machines.MachinesQuery{DeploymentTargetTypes: []string{"CloudRegion"}}) | ||
return list.ListRun(options) | ||
}, | ||
} | ||
|
||
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
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,148 @@ | ||
package list | ||
|
||
import ( | ||
"fmt" | ||
"github.com/MakeNowJust/heredoc/v2" | ||
"github.com/OctopusDeploy/cli/pkg/cmd" | ||
"github.com/OctopusDeploy/cli/pkg/cmd/target/shared" | ||
"github.com/OctopusDeploy/cli/pkg/constants" | ||
"github.com/OctopusDeploy/cli/pkg/factory" | ||
"github.com/OctopusDeploy/cli/pkg/output" | ||
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines" | ||
"github.com/spf13/cobra" | ||
"strings" | ||
) | ||
|
||
type ListOptions struct { | ||
*cobra.Command | ||
*cmd.Dependencies | ||
*shared.GetTargetsOptions | ||
} | ||
|
||
type Entity struct { | ||
Id string `json:"Id"` | ||
Name string `json:"Name"` | ||
} | ||
|
||
func NewListOptions(dependencies *cmd.Dependencies, command *cobra.Command, query machines.MachinesQuery) *ListOptions { | ||
return &ListOptions{ | ||
Command: command, | ||
Dependencies: dependencies, | ||
GetTargetsOptions: shared.NewGetTargetsOptions(dependencies, query), | ||
} | ||
} | ||
|
||
func NewCmdList(f factory.Factory) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "list", | ||
Short: "List deployment targets in an instance of Octopus Deploy", | ||
Long: "List deployment targets in an instance of Octopus Deploy.", | ||
Example: fmt.Sprintf(heredoc.Doc(` | ||
$ %s deployment-target list | ||
`), constants.ExecutableName), | ||
RunE: func(c *cobra.Command, args []string) error { | ||
return ListRun(NewListOptions(cmd.NewDependencies(f, c), c, machines.MachinesQuery{})) | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func ListRun(opts *ListOptions) error { | ||
allTargets, err := opts.GetTargetsCallback() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
type TargetAsJson struct { | ||
Id string `json:"Id"` | ||
Name string `json:"Name"` | ||
Type string `json:"Type"` | ||
Roles []string `json:"Roles"` | ||
Environments []Entity `json:"Environments"` | ||
Tenants []Entity `json:"Tenants"` | ||
TenantTags []string `json:"TenantTags"` | ||
} | ||
|
||
environmentMap, err := GetEnvironmentMap(opts, err) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
tenantMap, err := GetTenantMap(opts, err) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return output.PrintArray(allTargets, opts.Command, output.Mappers[*machines.DeploymentTarget]{ | ||
Json: func(item *machines.DeploymentTarget) any { | ||
environments := resolveEntities(item.EnvironmentIDs, environmentMap) | ||
tenants := resolveEntities(item.TenantIDs, tenantMap) | ||
return TargetAsJson{ | ||
Id: item.GetID(), | ||
Name: item.Name, | ||
Type: shared.CommunicationStyleToDeploymentTargetTypeMap[item.Endpoint.GetCommunicationStyle()], | ||
Roles: item.Roles, | ||
Environments: environments, | ||
Tenants: tenants, | ||
TenantTags: item.TenantTags, | ||
} | ||
}, | ||
Table: output.TableDefinition[*machines.DeploymentTarget]{ | ||
Header: []string{"NAME", "TYPE", "ROLES", "ENVIRONMENTS", "TENANTS", "TAGS"}, | ||
Row: func(item *machines.DeploymentTarget) []string { | ||
environmentNames := resolveValues(item.EnvironmentIDs, environmentMap) | ||
tenantNames := resolveValues(item.TenantIDs, tenantMap) | ||
return []string{output.Bold(item.Name), shared.CommunicationStyleToDescriptionMap[item.Endpoint.GetCommunicationStyle()], formatAsList(item.Roles), formatAsList(environmentNames), formatAsList(tenantNames), formatAsList(item.TenantTags)} | ||
}, | ||
}, | ||
Basic: func(item *machines.DeploymentTarget) string { | ||
return item.Name | ||
}, | ||
}) | ||
} | ||
|
||
func resolveValues(keys []string, lookup map[string]string) []string { | ||
var values []string | ||
for _, key := range keys { | ||
values = append(values, lookup[key]) | ||
} | ||
return values | ||
} | ||
|
||
func resolveEntities(keys []string, lookup map[string]string) []Entity { | ||
var entities []Entity | ||
for _, k := range keys { | ||
entities = append(entities, Entity{Id: k, Name: lookup[k]}) | ||
} | ||
|
||
return entities | ||
} | ||
|
||
func GetEnvironmentMap(opts *ListOptions, err error) (map[string]string, error) { | ||
environmentMap := make(map[string]string) | ||
allEnvs, err := opts.Client.Environments.GetAll() | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, e := range allEnvs { | ||
environmentMap[e.GetID()] = e.GetName() | ||
} | ||
return environmentMap, nil | ||
} | ||
|
||
func GetTenantMap(opts *ListOptions, err error) (map[string]string, error) { | ||
tenantMap := make(map[string]string) | ||
allEnvs, err := opts.Client.Tenants.GetAll() | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, e := range allEnvs { | ||
tenantMap[e.GetID()] = e.Name | ||
} | ||
return tenantMap, nil | ||
} | ||
|
||
func formatAsList(items []string) string { | ||
return strings.Join(items, ",") | ||
} |
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,30 @@ | ||
package list | ||
|
||
import ( | ||
"fmt" | ||
"github.com/MakeNowJust/heredoc/v2" | ||
"github.com/OctopusDeploy/cli/pkg/cmd" | ||
"github.com/OctopusDeploy/cli/pkg/cmd/target/list" | ||
"github.com/OctopusDeploy/cli/pkg/constants" | ||
"github.com/OctopusDeploy/cli/pkg/factory" | ||
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewCmdList(f factory.Factory) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "list", | ||
Short: "List Listening Tentacle deployment targets in an instance of Octopus Deploy", | ||
Long: "List Listening Tentacle deployment targets in an instance of Octopus Deploy.", | ||
Example: fmt.Sprintf(heredoc.Doc(` | ||
$ %s deployment-target listening-tentacle list | ||
`), constants.ExecutableName), | ||
RunE: func(c *cobra.Command, args []string) error { | ||
dependencies := cmd.NewDependencies(f, c) | ||
options := list.NewListOptions(dependencies, c, machines.MachinesQuery{DeploymentTargetTypes: []string{"TentaclePassive"}}) | ||
return list.ListRun(options) | ||
}, | ||
} | ||
|
||
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
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,30 @@ | ||
package list | ||
|
||
import ( | ||
"fmt" | ||
"github.com/MakeNowJust/heredoc/v2" | ||
"github.com/OctopusDeploy/cli/pkg/cmd" | ||
"github.com/OctopusDeploy/cli/pkg/cmd/target/list" | ||
"github.com/OctopusDeploy/cli/pkg/constants" | ||
"github.com/OctopusDeploy/cli/pkg/factory" | ||
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewCmdList(f factory.Factory) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "list", | ||
Short: "List Polling Tentacle deployment targets in an instance of Octopus Deploy", | ||
Long: "List Polling Tentacle deployment targets in an instance of Octopus Deploy.", | ||
Example: fmt.Sprintf(heredoc.Doc(` | ||
$ %s deployment-target polling-tentacle list | ||
`), constants.ExecutableName), | ||
RunE: func(c *cobra.Command, args []string) error { | ||
dependencies := cmd.NewDependencies(f, c) | ||
options := list.NewListOptions(dependencies, c, machines.MachinesQuery{DeploymentTargetTypes: []string{"TentacleActive"}}) | ||
return list.ListRun(options) | ||
}, | ||
} | ||
|
||
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,22 @@ | ||
package polling_tentacle | ||
|
||
import ( | ||
"fmt" | ||
|
||
cmdList "github.com/OctopusDeploy/cli/pkg/cmd/target/polling-tentacle/list" | ||
"github.com/OctopusDeploy/cli/pkg/constants" | ||
"github.com/OctopusDeploy/cli/pkg/factory" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewCmdPollingTentacle(f factory.Factory) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "polling-tentacle <command>", | ||
Short: "Manage polling tentacle deployment targets", | ||
Long: "Work with Octopus Deploy polling tentacle deployment targets.", | ||
Example: fmt.Sprintf("$ %s deployment-target polling-tenatacle list", constants.ExecutableName), | ||
} | ||
|
||
cmd.AddCommand(cmdList.NewCmdList(f)) | ||
return cmd | ||
} |
Oops, something went wrong.