Skip to content

Commit

Permalink
Refactor workload identity commands
Browse files Browse the repository at this point in the history
  • Loading branch information
vapopov committed Dec 17, 2024
1 parent 8d8f135 commit ecbbbf5
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions tool/tctl/common/workload_identity_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/gravitational/teleport/lib/auth/authclient"
"github.com/gravitational/teleport/lib/service/servicecfg"
"github.com/gravitational/teleport/lib/utils"
commonclient "github.com/gravitational/teleport/tool/tctl/common/client"
)

// WorkloadIdentityCommand is a group of commands pertaining to Teleport
Expand Down Expand Up @@ -84,17 +85,25 @@ func (c *WorkloadIdentityCommand) Initialize(

// TryRun attempts to run subcommands.
func (c *WorkloadIdentityCommand) TryRun(
ctx context.Context, cmd string, client *authclient.Client,
ctx context.Context, cmd string, clientFunc commonclient.InitFunc,
) (match bool, err error) {
var commandFunc func(ctx context.Context, client *authclient.Client) error
switch cmd {
case c.listCmd.FullCommand():
err = c.ListWorkloadIdentities(ctx, client)
commandFunc = c.ListWorkloadIdentities
case c.rmCmd.FullCommand():
err = c.DeleteWorkloadIdentity(ctx, client)
commandFunc = c.DeleteWorkloadIdentity
default:
return false, nil
}

client, closeFn, err := clientFunc(ctx)
if err != nil {
return false, trace.Wrap(err)
}
err = commandFunc(ctx, client)
closeFn(ctx)

return true, trace.Wrap(err)
}

Expand Down

0 comments on commit ecbbbf5

Please sign in to comment.