Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v10] Ensure tctl windows_desktops ls produces expected output #19015

Merged
merged 3 commits into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
51 changes: 16 additions & 35 deletions tool/tctl/common/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ func (c *windowsDesktopServiceCollection) writeText(w io.Writer) error {

type windowsDesktopCollection struct {
desktops []types.WindowsDesktop
verbose bool
}

func (c *windowsDesktopCollection) resources() (r []types.Resource) {
Expand All @@ -754,22 +755,28 @@ func (c *windowsDesktopCollection) resources() (r []types.Resource) {
}

func (c *windowsDesktopCollection) writeText(w io.Writer) error {
t := asciitable.MakeTable([]string{"UUID", "Address"})
for _, desktop := range c.desktops {
t.AddRow([]string{desktop.GetName(), desktop.GetAddr()})
var rows [][]string
for _, d := range c.desktops {
labels := stripInternalTeleportLabels(c.verbose, d.GetAllLabels())
rows = append(rows, []string{d.GetName(), d.GetAddr(), d.GetDomain(), labels})
}
headers := []string{"Name", "Address", "AD Domain", "Labels"}
var t asciitable.Table
if c.verbose {
t = asciitable.MakeTable(headers, rows...)
} else {
t = asciitable.MakeTableWithTruncatedColumn(headers, rows, "Labels")
}
_, err := t.AsBuffer().WriteTo(w)
return trace.Wrap(err)
}

type windowsDesktopAndService struct {
desktop types.WindowsDesktop
service types.WindowsDesktopService
func (c *windowsDesktopCollection) writeYAML(w io.Writer) error {
return utils.WriteYAML(w, c.desktops)
}

type windowsDesktopAndServiceCollection struct {
desktops []windowsDesktopAndService
verbose bool
func (c *windowsDesktopCollection) writeJSON(w io.Writer) error {
return utils.WriteJSON(w, c.desktops)
}

func stripInternalTeleportLabels(verbose bool, labels map[string]string) string {
Expand All @@ -784,32 +791,6 @@ func stripInternalTeleportLabels(verbose bool, labels map[string]string) string
return types.LabelsAsString(labels, nil)
}

func (c *windowsDesktopAndServiceCollection) writeText(w io.Writer) error {
var rows [][]string
for _, d := range c.desktops {
labels := stripInternalTeleportLabels(c.verbose, d.desktop.GetAllLabels())
rows = append(rows, []string{d.service.GetHostname(), d.desktop.GetAddr(),
d.desktop.GetDomain(), labels, d.service.GetTeleportVersion()})
}
headers := []string{"Host", "Address", "AD Domain", "Labels", "Version"}
var t asciitable.Table
if c.verbose {
t = asciitable.MakeTable(headers, rows...)
} else {
t = asciitable.MakeTableWithTruncatedColumn(headers, rows, "Labels")
}
_, err := t.AsBuffer().WriteTo(w)
return trace.Wrap(err)
}

func (c *windowsDesktopAndServiceCollection) writeYAML(w io.Writer) error {
return utils.WriteYAML(w, c.desktops)
}

func (c *windowsDesktopAndServiceCollection) writeJSON(w io.Writer) error {
return utils.WriteJSON(w, c.desktops)
}

type tokenCollection struct {
tokens []types.ProvisionToken
}
Expand Down
12 changes: 2 additions & 10 deletions tool/tctl/common/desktop_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,10 @@ func (c *DesktopCommand) ListDesktop(ctx context.Context, client auth.ClientI) e
if err != nil {
return trace.Wrap(err)
}
coll := windowsDesktopAndServiceCollection{
desktops: []windowsDesktopAndService{},
coll := windowsDesktopCollection{
desktops: desktops,
verbose: c.verbose,
}
for _, desktop := range desktops {
ds, err := client.GetWindowsDesktopService(ctx, desktop.GetHostID())
if err != nil {
return trace.Wrap(err)
}
coll.desktops = append(coll.desktops,
windowsDesktopAndService{desktop: desktop, service: ds})
}
switch c.format {
case teleport.Text:
return trace.Wrap(coll.writeText(os.Stdout))
Expand Down