MCPcopy
hub / github.com/smallstep/cli / hostsAction

Function hostsAction

command/ssh/hosts.go:50–89  ·  view source on GitHub ↗
(ctx *cli.Context)

Source from the content-addressed store, hash-verified

48}
49
50func hostsAction(ctx *cli.Context) error {
51 if err := errs.NumberOfArguments(ctx, 0); err != nil {
52 return err
53 }
54
55 // Prepare retry function
56 retryFunc, err := loginOnUnauthorized(ctx)
57 if err != nil {
58 return err
59 }
60
61 // Initialize CA client with login if needed.
62 client, err := cautils.NewClient(ctx, ca.WithRetryFunc(retryFunc))
63 if err != nil {
64 return err
65 }
66
67 resp, err := client.SSHGetHosts()
68 if err != nil {
69 return err
70 }
71
72 w := new(tabwriter.Writer)
73 // Format in tab-separated columns with a tab stop of 8.
74 w.Init(os.Stdout, 0, 8, 1, '\t', 0)
75
76 fmt.Fprintln(w, "HOSTNAME\tID\tTAGS")
77 for _, h := range resp.Hosts {
78 tags := ""
79 for i, ht := range h.HostTags {
80 if i > 0 {
81 tags += ","
82 }
83 tags += ht.Name + "=" + ht.Value
84 }
85 fmt.Fprintf(w, "%s\t%s\t%s\n", h.Hostname, h.HostID, tags)
86 }
87 w.Flush()
88 return nil
89}

Callers

nothing calls this directly

Calls 3

NewClientFunction · 0.92
loginOnUnauthorizedFunction · 0.85
SSHGetHostsMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…