diff --git a/pkg/cmd/worker/list/list.go b/pkg/cmd/worker/list/list.go index e17ffe8c..cc6d15cc 100644 --- a/pkg/cmd/worker/list/list.go +++ b/pkg/cmd/worker/list/list.go @@ -5,6 +5,7 @@ import ( "github.com/OctopusDeploy/cli/pkg/cmd" "github.com/OctopusDeploy/cli/pkg/cmd/model" "github.com/OctopusDeploy/cli/pkg/cmd/worker/shared" + ssh "github.com/OctopusDeploy/cli/pkg/cmd/worker/ssh/view" "github.com/OctopusDeploy/cli/pkg/constants" "github.com/OctopusDeploy/cli/pkg/factory" "github.com/OctopusDeploy/cli/pkg/machinescommon" @@ -55,6 +56,11 @@ func ListRun(opts *ListOptions) error { HealthStatus string `json:"HealthStatus"` StatusSummary string `json:"StatusSummary"` WorkerPools []model.Entity `json:"WorkerPools"` + URI string `json:"URI"` + Version string `json:"Version,omitempty"` + Runtime string `json:"Runtime,omitempty"` + Account *model.Entity `json:"Account,omitempty"` + Proxy string `json:"Proxy"` } workerPoolMap, err := GetWorkerPoolMap(opts) @@ -72,6 +78,11 @@ func ListRun(opts *ListOptions) error { HealthStatus: item.HealthStatus, StatusSummary: item.StatusSummary, WorkerPools: resolveEntities(item.WorkerPoolIDs, workerPoolMap), + URI: getEndpointUri(item.Endpoint), + Version: getVersion(item.Endpoint), + Runtime: getRuntimeArchitecture(item.Endpoint), + Account: getAccount(opts, item.Endpoint), + Proxy: getProxy(opts, item.Endpoint), } }, Table: output.TableDefinition[*machines.Worker]{ @@ -104,6 +115,83 @@ func resolveEntities(keys []string, lookup map[string]string) []model.Entity { return entities } +func getEndpointUri(end machines.IEndpoint) string { + endpointUri := "" + switch end.GetCommunicationStyle() { + case "TentaclePassive": + endpoint := end.(*machines.ListeningTentacleEndpoint) + endpointUri = endpoint.URI.String() + case "TentacleActive": + endpoint := end.(*machines.PollingTentacleEndpoint) + endpointUri = endpoint.URI.String() + case "Ssh": + endpoint := end.(*machines.SSHEndpoint) + endpointUri = endpoint.URI.String() + } + return endpointUri +} + +func getVersion(end machines.IEndpoint) string { + tentacleVersion := "" + switch end.GetCommunicationStyle() { + case "TentaclePassive": + endpoint := end.(*machines.ListeningTentacleEndpoint) + tentacleVersion = endpoint.TentacleVersionDetails.Version + case "TentacleActive": + endpoint := end.(*machines.PollingTentacleEndpoint) + tentacleVersion = endpoint.TentacleVersionDetails.Version + } + return tentacleVersion +} + +func getRuntimeArchitecture(end machines.IEndpoint) string { + switch end.GetCommunicationStyle() { + case "Ssh": + endpoint := end.(*machines.SSHEndpoint) + return ssh.GetRuntimeArchitecture(endpoint) + } + return "" +} + +func getAccount(opts *ListOptions, end machines.IEndpoint) *model.Entity { + accountId := "" + switch end.GetCommunicationStyle() { + case "Ssh": + endpoint := end.(*machines.SSHEndpoint) + accountId = endpoint.AccountID + } + if accountId != "" { + account, err := opts.Client.Accounts.GetByID(accountId) + if err != nil { + return nil + } + entity := &model.Entity{Id: account.GetID(), Name: account.GetName()} + return entity + } + return nil +} + +func getProxy(opts *ListOptions, end machines.IEndpoint) string { + proxyId := "" + switch end.GetCommunicationStyle() { + case "TentaclePassive": + endpoint := end.(*machines.ListeningTentacleEndpoint) + proxyId = endpoint.ProxyID + case "Ssh": + endpoint := end.(*machines.SSHEndpoint) + proxyId = endpoint.ProxyID + } + + if proxyId != "" { + proxy, err := opts.Client.Proxies.GetById(proxyId) + if err != nil { + return "None" + } + return proxy.GetName() + } + return "None" +} + func GetWorkerPoolMap(opts *ListOptions) (map[string]string, error) { workerPoolMap := make(map[string]string) allEnvs, err := opts.Client.WorkerPools.GetAll() diff --git a/pkg/cmd/worker/ssh/view/view.go b/pkg/cmd/worker/ssh/view/view.go index 7f67eebc..46418dc6 100644 --- a/pkg/cmd/worker/ssh/view/view.go +++ b/pkg/cmd/worker/ssh/view/view.go @@ -44,7 +44,7 @@ func contributeEndpoint(opts *shared.ViewOptions, workerEndpoint machines.IEndpo endpoint := workerEndpoint.(*machines.SSHEndpoint) data = append(data, output.NewDataRow("URI", endpoint.URI.String())) - data = append(data, output.NewDataRow("Runtime architecture", getRuntimeArchitecture(endpoint))) + data = append(data, output.NewDataRow("Runtime architecture", GetRuntimeArchitecture(endpoint))) accountRows, err := shared.ContributeAccount(opts, endpoint.AccountID) if err != nil { return nil, err @@ -60,7 +60,7 @@ func contributeEndpoint(opts *shared.ViewOptions, workerEndpoint machines.IEndpo return data, nil } -func getRuntimeArchitecture(endpoint *machines.SSHEndpoint) string { +func GetRuntimeArchitecture(endpoint *machines.SSHEndpoint) string { if endpoint.DotNetCorePlatform == "" { return "Mono" }