Files
teleport/tool/tctl/common/saml_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

71 lines
2.3 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"
"fmt"
"github.com/alecthomas/kingpin/v2"
"github.com/gravitational/trace"
"github.com/gravitational/teleport/lib/auth/authclient"
"github.com/gravitational/teleport/lib/service/servicecfg"
)
// implements common.CLICommand interface
type SAMLCommand struct {
config *servicecfg.Config
exportCmd *kingpin.CmdClause
// connectorName is passed as a CLI flag
connectorName string
}
// Initialize allows a caller-defined command to plug itself into CLI
// argument parsing
func (cmd *SAMLCommand) Initialize(app *kingpin.Application, cfg *servicecfg.Config) {
cmd.config = cfg
saml := app.Command("saml", "Operations on SAML auth connectors.")
cmd.exportCmd = saml.Command("export", "Export a SAML signing key in .crt format.")
cmd.exportCmd.Arg("connector_name", "name of the SAML connector to export the key from").Required().StringVar(&cmd.connectorName)
}
// TryRun is executed after the CLI parsing is done. The command must
// determine if selectedCommand belongs to it and return match=true
func (cmd *SAMLCommand) TryRun(ctx context.Context, selectedCommand string, c *authclient.Client) (match bool, err error) {
if selectedCommand == cmd.exportCmd.FullCommand() {
return true, trace.Wrap(cmd.export(ctx, c))
}
return false, nil
}
// export executes 'tctl saml export <connector_name>'
func (cmd *SAMLCommand) export(ctx context.Context, c *authclient.Client) error {
sc, err := c.GetSAMLConnector(ctx, cmd.connectorName, false)
if err != nil {
return trace.Wrap(err)
}
fmt.Println(sc.GetSigningKeyPair().Cert)
return nil
}