Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/MakeNowJust/heredoc/v2 v2.0.1
github.com/OctopusDeploy/go-octodiff v1.0.0
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.108.0
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.108.1
github.com/bmatcuk/doublestar/v4 v4.4.0
github.com/briandowns/spinner v1.19.0
github.com/google/uuid v1.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63n
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w=
github.com/OctopusDeploy/go-octodiff v1.0.0 h1:U+ORg6azniwwYo+O44giOw6TiD5USk8S4VDhOQ0Ven0=
github.com/OctopusDeploy/go-octodiff v1.0.0/go.mod h1:Mze0+EkOWTgTmi8++fyUc6r0aLZT7qD9gX+31t8MmIU=
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.108.0 h1:hUnkq49u3gRiZSisRF9L86gPygKK4qS9LMoO5ADTGKI=
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.108.0/go.mod h1:VkTXDoIPbwGFi5+goo1VSwFNdMVo784cVtJdKIEvfus=
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.108.1 h1:THcIJGQyhhzSx8/b7ibYnyFlwktF8/U+xwXfC373N1U=
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.108.1/go.mod h1:VkTXDoIPbwGFi5+goo1VSwFNdMVo784cVtJdKIEvfus=
github.com/bmatcuk/doublestar/v4 v4.4.0 h1:LmAwNwhjEbYtyVLzjcP/XeVw4nhuScHGkF/XWXnvIic=
github.com/bmatcuk/doublestar/v4 v4.4.0/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
github.com/briandowns/spinner v1.19.0 h1:s8aq38H+Qju89yhp89b4iIiMzMm8YN3p6vGpwyh/a8E=
Expand Down
65 changes: 9 additions & 56 deletions pkg/cmd/target/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,46 +55,32 @@ func ListRun(opts *ListOptions) error {
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 := shared.GetEnvironmentMap(opts.Client)
if err != nil {
return err
}

environmentMap, err := GetEnvironmentMap(opts)
tenantMap, err := shared.GetTenantMap(opts.Client)
if err != nil {
return err
}

tenantMap, err := GetTenantMap(opts)
workerPoolMap, err := shared.GetWorkerPoolMap(opts.Client)
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: machinescommon.CommunicationStyleToDeploymentTargetTypeMap[item.Endpoint.GetCommunicationStyle()],
Roles: item.Roles,
Environments: environments,
Tenants: tenants,
TenantTags: item.TenantTags,
}
return shared.GetDeploymentTargetAsJson(opts.Dependencies, item)
},
Table: output.TableDefinition[*machines.DeploymentTarget]{
Header: []string{"NAME", "TYPE", "ROLES", "ENVIRONMENTS", "TENANTS", "TAGS"},
Header: []string{"NAME", "TYPE", "ROLES", "ENVIRONMENTS", "TENANTS", "TAGS", "DEFAULT WORKER POOL"},
Row: func(item *machines.DeploymentTarget) []string {
environmentNames := resolveValues(item.EnvironmentIDs, environmentMap)
tenantNames := resolveValues(item.TenantIDs, tenantMap)
return []string{output.Bold(item.Name), machinescommon.CommunicationStyleToDescriptionMap[item.Endpoint.GetCommunicationStyle()], output.FormatAsList(item.Roles), output.FormatAsList(environmentNames), output.FormatAsList(tenantNames), output.FormatAsList(item.TenantTags)}
workerPool := shared.ResolveDefaultWorkerPool(item, workerPoolMap, "None")
return []string{output.Bold(item.Name), machinescommon.CommunicationStyleToDescriptionMap[item.Endpoint.GetCommunicationStyle()], output.FormatAsList(item.Roles), output.FormatAsList(environmentNames), output.FormatAsList(tenantNames), output.FormatAsList(item.TenantTags), workerPool}
},
},
Basic: func(item *machines.DeploymentTarget) string {
Expand All @@ -110,36 +96,3 @@ func resolveValues(keys []string, lookup map[string]string) []string {
}
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) (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) (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
}
61 changes: 61 additions & 0 deletions pkg/cmd/target/shared/json.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package shared

import (
"fmt"

"github.com/OctopusDeploy/cli/pkg/cmd"
"github.com/OctopusDeploy/cli/pkg/util"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines"
)

type DeploymentTargetAsJson struct {
Id string `json:"Id"`
Name string `json:"Name"`
HealthStatus string `json:"HealthStatus"`
StatusSummary string `json:"StatusSummary"`
CommunicationStyle string `json:"CommunicationStyle"`
Environments []string `json:"Environments"`
Roles []string `json:"Roles"`
Tenants []string `json:"Tenants"`
TenantTags []string `json:"TenantTags"`
EndpointDetails map[string]string `json:"EndpointDetails"`
WebUrl string `json:"WebUrl"`
}

type DeploymentTargetWithWorkerPool struct {
DeploymentTargetAsJson
DefaultWorkerPool string `json:"DefaultWorkerPool"`
}

func GetDeploymentTargetAsJson(deps *cmd.Dependencies, target *machines.DeploymentTarget) any {
environmentMap, _ := GetEnvironmentMap(deps.Client)
tenantMap, _ := GetTenantMap(deps.Client)

environments := resolveValues(target.EnvironmentIDs, environmentMap)
tenants := resolveValues(target.TenantIDs, tenantMap)

endpointDetails := GetEndpointDetails(target)

targetJson := DeploymentTargetAsJson{
Id: target.GetID(),
Name: target.Name,
HealthStatus: target.HealthStatus,
StatusSummary: target.StatusSummary,
CommunicationStyle: target.Endpoint.GetCommunicationStyle(),
Environments: environments,
Roles: target.Roles,
Tenants: tenants,
TenantTags: target.TenantTags,
EndpointDetails: endpointDetails,
WebUrl: util.GenerateWebURL(deps.Host, target.SpaceID, fmt.Sprintf("infrastructure/machines/%s/settings", target.GetID())),
}

if workerEndpoint, ok := target.Endpoint.(machines.IRunsOnAWorker); ok {
return DeploymentTargetWithWorkerPool{
DeploymentTargetAsJson: targetJson,
DefaultWorkerPool: workerEndpoint.GetDefaultWorkerPoolID(),
}
}

return targetJson
}
48 changes: 47 additions & 1 deletion pkg/cmd/target/shared/target.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package shared

import (
"fmt"
"math"

"github.com/OctopusDeploy/cli/pkg/cmd"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines"
"math"
)

type GetTargetsCallback func() ([]*machines.DeploymentTarget, error)
Expand Down Expand Up @@ -38,3 +40,47 @@ func GetAllTargets(client client.Client, query machines.MachinesQuery) ([]*machi
}
return res.Items, nil
}

func GetEndpointDetails(target *machines.DeploymentTarget) map[string]string {
details := make(map[string]string)

switch target.Endpoint.GetCommunicationStyle() {
case "AzureWebApp":
if endpoint, ok := target.Endpoint.(*machines.AzureWebAppEndpoint); ok {
webApp := endpoint.WebAppName
if endpoint.WebAppSlotName != "" {
webApp = fmt.Sprintf("%s/%s", webApp, endpoint.WebAppSlotName)
}
details["Web App"] = webApp
}
case "Kubernetes":
if endpoint, ok := target.Endpoint.(*machines.KubernetesEndpoint); ok {
details["Authentication Type"] = endpoint.Authentication.GetAuthenticationType()
}
case "Ssh":
if endpoint, ok := target.Endpoint.(*machines.SSHEndpoint); ok {
details["URI"] = endpoint.URI.String()
runtime := "Mono"
if endpoint.DotNetCorePlatform != "" {
runtime = endpoint.DotNetCorePlatform
}
details["Runtime architecture"] = runtime
}
case "TentaclePassive":
if endpoint, ok := target.Endpoint.(*machines.ListeningTentacleEndpoint); ok {
details["URI"] = endpoint.URI.String()
details["Tentacle version"] = endpoint.TentacleVersionDetails.Version
}
case "TentacleActive":
if endpoint, ok := target.Endpoint.(*machines.PollingTentacleEndpoint); ok {
details["URI"] = endpoint.URI.String()
details["Tentacle version"] = endpoint.TentacleVersionDetails.Version
}
case "None":
// Cloud regions typically don't have additional endpoint details
case "OfflineDrop", "StepPackage", "AzureCloudService", "AzureServiceFabricCluster":
// These endpoints don't have specific details we can easily extract
}

return details
}
51 changes: 43 additions & 8 deletions pkg/cmd/target/shared/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package shared

import (
"fmt"

"github.com/OctopusDeploy/cli/pkg/cmd"
"github.com/OctopusDeploy/cli/pkg/machinescommon"
"github.com/OctopusDeploy/cli/pkg/output"
"github.com/OctopusDeploy/cli/pkg/util"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -60,7 +62,7 @@ func ViewRun(opts *ViewOptions, contributeEndpoint ContributeEndpointCallback, d
}
}

environmentMap, err := GetEnvironmentMap(opts)
environmentMap, err := GetEnvironmentMap(opts.Client)
if err != nil {
return err
}
Expand All @@ -70,7 +72,7 @@ func ViewRun(opts *ViewOptions, contributeEndpoint ContributeEndpointCallback, d
data = append(data, output.NewDataRow("Roles", output.FormatAsList(target.Roles)))

if !util.Empty(target.TenantIDs) {
tenantMap, err := GetTenantMap(opts)
tenantMap, err := GetTenantMap(opts.Client)
if err != nil {
return err
}
Expand All @@ -87,13 +89,22 @@ func ViewRun(opts *ViewOptions, contributeEndpoint ContributeEndpointCallback, d
data = append(data, output.NewDataRow("Tenant Tags", "None"))
}

if runsOnAWorker, ok := target.Endpoint.(machines.IRunsOnAWorker); ok {
workerPoolName := "None"
if runsOnAWorker.GetDefaultWorkerPoolID() != "" {
workerPoolMap, _ := GetWorkerPoolMap(opts.Client)
workerPoolName = resolveValues([]string{runsOnAWorker.GetDefaultWorkerPoolID()}, workerPoolMap)[0]
}
data = append(data, output.NewDataRow("Default Worker Pool", workerPoolName))
}

t := output.NewTable(opts.Out)
for _, row := range data {
t.AddRow(row.Name, row.Value)
}
t.Print()
_ = t.Print()

fmt.Fprintf(opts.Out, "\n")
_, _ = fmt.Fprintf(opts.Out, "\n")
machinescommon.DoWebForTargets(target, opts.Dependencies, opts.WebFlags, description)
return nil
}
Expand Down Expand Up @@ -130,9 +141,9 @@ func getHealthStatus(target *machines.DeploymentTarget) string {
}
}

func GetEnvironmentMap(opts *ViewOptions) (map[string]string, error) {
func GetEnvironmentMap(client *client.Client) (map[string]string, error) {
environmentMap := make(map[string]string)
allEnvs, err := opts.Client.Environments.GetAll()
allEnvs, err := client.Environments.GetAll()
if err != nil {
return nil, err
}
Expand All @@ -142,9 +153,21 @@ func GetEnvironmentMap(opts *ViewOptions) (map[string]string, error) {
return environmentMap, nil
}

func GetTenantMap(opts *ViewOptions) (map[string]string, error) {
func GetWorkerPoolMap(client *client.Client) (map[string]string, error) {
workerPoolMap := make(map[string]string)
allWorkerPools, err := client.WorkerPools.GetAll()
if err != nil {
return nil, err
}
for _, wp := range allWorkerPools {
workerPoolMap[wp.ID] = wp.Name
}
return workerPoolMap, nil
}

func GetTenantMap(client *client.Client) (map[string]string, error) {
tenantMap := make(map[string]string)
allEnvs, err := opts.Client.Tenants.GetAll()
allEnvs, err := client.Tenants.GetAll()
if err != nil {
return nil, err
}
Expand All @@ -161,3 +184,15 @@ func resolveValues(keys []string, lookup map[string]string) []string {
}
return values
}

func ResolveDefaultWorkerPool(target *machines.DeploymentTarget, workerPoolMap map[string]string, emptyValue string) string {
if endpoint, ok := target.Endpoint.(machines.IRunsOnAWorker); ok {
if endpoint.GetDefaultWorkerPoolID() != "" {
return resolveValues([]string{endpoint.GetDefaultWorkerPoolID()}, workerPoolMap)[0]
} else {
return emptyValue
}
}

return "N/A"
}
Loading
Loading