mirror of
https://github.com/gravitational/teleport.git
synced 2026-11-03 07:40:28 +08:00
* check if proxy requested already has an active profile that is not expired before relogging the user in maintain cert reissue use site name make client for currently logged in proxy simplify if remove cert reissue simplify and add test revert comment explicitly save profile add initial commands add better output * review comments * Update tool/tctl/common/proxy_command.go Co-authored-by: Nic Klaassen <nic@goteleport.com> * Update tool/tctl/common/proxy_command.go Co-authored-by: Nic Klaassen <nic@goteleport.com> * remove stdout redirect for now * lint Co-authored-by: Nic Klaassen <nic@goteleport.com>
78 lines
2.1 KiB
Go
78 lines
2.1 KiB
Go
// Copyright 2022 Gravitational, Inc
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package common
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
|
|
"github.com/gravitational/teleport"
|
|
"github.com/gravitational/teleport/lib/auth"
|
|
"github.com/gravitational/teleport/lib/service"
|
|
|
|
"github.com/gravitational/kingpin"
|
|
"github.com/gravitational/trace"
|
|
)
|
|
|
|
// ProxyCommand returns information about connected proxies
|
|
type ProxyCommand struct {
|
|
config *service.Config
|
|
lsCmd *kingpin.CmdClause
|
|
|
|
format string
|
|
}
|
|
|
|
// Initialize creates the proxy command and subcommands
|
|
func (p *ProxyCommand) Initialize(app *kingpin.Application, config *service.Config) {
|
|
p.config = config
|
|
|
|
authCommand := app.Command("proxy", "Operations with information for cluster proxies").Hidden()
|
|
p.lsCmd = authCommand.Command("ls", "List connected auth servers")
|
|
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 auth.ClientI) error {
|
|
proxies, err := clusterAPI.GetProxies()
|
|
if err != nil {
|
|
return trace.Wrap(err)
|
|
}
|
|
|
|
sc := &serverCollection{proxies, false}
|
|
|
|
switch p.format {
|
|
case teleport.Text:
|
|
return sc.writeText(os.Stdout)
|
|
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 auth.ClientI) (match bool, err error) {
|
|
switch cmd {
|
|
case p.lsCmd.FullCommand():
|
|
err = p.ListProxies(ctx, client)
|
|
default:
|
|
return false, nil
|
|
}
|
|
return true, trace.Wrap(err)
|
|
}
|