-
Notifications
You must be signed in to change notification settings - Fork 11
/
view.go
69 lines (58 loc) · 2.02 KB
/
view.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package view
import (
"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/machinescommon"
"github.com/OctopusDeploy/cli/pkg/output"
"github.com/OctopusDeploy/cli/pkg/usage"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines"
"github.com/spf13/cobra"
)
func NewCmdView(f factory.Factory) *cobra.Command {
flags := shared.NewViewFlags()
cmd := &cobra.Command{
Args: usage.ExactArgs(1),
Use: "view {<name> | <id>}",
Short: "View a SSH deployment target",
Long: "View a SSH deployment target in Octopus Deploy",
Example: heredoc.Docf(`
$ %[1]s deployment-target ssh view 'linux-web-server'
$ %[1]s deployment-target ssh view Machines-100
`, constants.ExecutableName),
RunE: func(c *cobra.Command, args []string) error {
opts := shared.NewViewOptions(flags, cmd.NewDependencies(f, c), args)
return ViewRun(opts)
},
}
machinescommon.RegisterWebFlag(cmd, flags.WebFlags)
return cmd
}
func ViewRun(opts *shared.ViewOptions) error {
return shared.ViewRun(opts, contributeEndpoint, "SSH")
}
func contributeEndpoint(opts *shared.ViewOptions, targetEndpoint machines.IEndpoint) ([]*output.DataRow, error) {
data := []*output.DataRow{}
endpoint := targetEndpoint.(*machines.SSHEndpoint)
data = append(data, output.NewDataRow("URI", endpoint.URI.String()))
data = append(data, output.NewDataRow("Runtime architecture", getRuntimeArchitecture(endpoint)))
accountRows, err := shared.ContributeAccount(opts, endpoint.AccountID)
if err != nil {
return nil, err
}
data = append(data, accountRows...)
proxy, err := shared.ContributeProxy(opts, endpoint.ProxyID)
data = append(data, proxy...)
if err != nil {
return nil, err
}
return data, nil
}
func getRuntimeArchitecture(endpoint *machines.SSHEndpoint) string {
if endpoint.DotNetCorePlatform == "" {
return "Mono"
}
return endpoint.DotNetCorePlatform
}