Files
teleport/tool/tctl/common/proxy_command.go
T
rosstimothy e95f3d3ed5 Start using authclient.Client/ClientI/NewClient (#41539)
Consumes the new auth client created in #41460. The changes introduced
were performed with a series of gofmt rewrite rules.

```bash
$ find ./lib/auth -type f -name '*.go' -exec gofmt -w -l -r "ClientI -> authclient.ClientI" {} \;
$ find ./lib/auth -type f -name '*.go' -exec gofmt -w -l -r "Client -> authclient.Client" {} \;
$ find ./lib/auth -type f -name '*.go' -exec gofmt -w -l -r "NewClient -> authclient.NewClientI" {} \;
$ find . -type f -name '*.go' -exec gofmt -w -l -r "auth.ClientI -> authclient.ClientI" {} \;
$ find . -type f -name '*.go' -exec gofmt -w -l -r "auth.Client -> authclient.Client" {} \;
$ find . -type f -name '*.go' -exec gofmt -w -l -r "auth.NewClient -> authclient.NewClient" {} \;
```
2024-05-15 14:09:14 +00:00

84 lines
2.4 KiB
Go

/*
* Teleport
* Copyright (C) 2023 Gravitational, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package common
import (
"context"
"os"
"github.com/alecthomas/kingpin/v2"
"github.com/gravitational/trace"
"github.com/gravitational/teleport"
"github.com/gravitational/teleport/lib/auth/authclient"
"github.com/gravitational/teleport/lib/service/servicecfg"
)
// ProxyCommand returns information about connected proxies
type ProxyCommand struct {
config *servicecfg.Config
lsCmd *kingpin.CmdClause
format string
}
// Initialize creates the proxy command and subcommands
func (p *ProxyCommand) Initialize(app *kingpin.Application, config *servicecfg.Config) {
p.config = config
proxyCommand := app.Command("proxy", "Operations with information for cluster proxies.").Hidden()
p.lsCmd = proxyCommand.Command("ls", "Lists proxies connected to the cluster.")
p.lsCmd.Flag("format", "Output format: 'yaml', 'json' or 'text'").Default(teleport.YAML).StringVar(&p.format)
}
// ListProxies prints currently connected proxies
func (p *ProxyCommand) ListProxies(ctx context.Context, clusterAPI *authclient.Client) error {
proxies, err := clusterAPI.GetProxies()
if err != nil {
return trace.Wrap(err)
}
sc := &serverCollection{proxies}
switch p.format {
case teleport.Text:
// proxies don't have labels.
verbose := false
return sc.writeText(os.Stdout, verbose)
case teleport.YAML:
return writeYAML(sc, os.Stdout)
case teleport.JSON:
return writeJSON(sc, os.Stdout)
}
return nil
}
// TryRun runs the proxy command
func (p *ProxyCommand) TryRun(ctx context.Context, cmd string, client *authclient.Client) (match bool, err error) {
switch cmd {
case p.lsCmd.FullCommand():
err = p.ListProxies(ctx, client)
default:
return false, nil
}
return true, trace.Wrap(err)
}