Skip to content

Commit

Permalink
Merge 45ef7c9 into ee2134f
Browse files Browse the repository at this point in the history
  • Loading branch information
asib authored Oct 17, 2024
2 parents ee2134f + 45ef7c9 commit 6021e0e
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions internal/command/tokens/revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tokens
import (
"context"
"fmt"
"os"

"github.com/spf13/cobra"
"github.com/superfly/flyctl/internal/command"
Expand All @@ -13,8 +14,8 @@ import (
func newRevoke() *cobra.Command {
const (
short = "Revoke tokens"
long = "used like: 'fly tokens revoke [ids]'"
usage = "revoke"
long = "Revoke one or more tokens."
usage = "revoke [flags] TOKEN TOKEN ..."
)

cmd := command.New(usage, short, long, runRevoke,
Expand All @@ -27,15 +28,28 @@ func newRevoke() *cobra.Command {
func runRevoke(ctx context.Context) (err error) {
apiClient := flyutil.ClientFromContext(ctx)

numRevoked := 0

args := flag.Args(ctx)
if len(args) == 0 {
if flag.GetString(ctx, "access-token") != "" {
return fmt.Errorf("no tokens provided; you passed a token via --access-token, did you mean to pass it as a positional argument?")
} else {
return fmt.Errorf("no tokens provided")
}
}

for _, id := range args {
err := apiClient.RevokeLimitedAccessToken(ctx, id)
if err != nil {
fmt.Printf("Failed to revoke token %s: %s\n", id, err)
fmt.Fprintf(os.Stderr, "failed to revoke token %s: %s\n", id, err)
continue
}
fmt.Printf("Revoked %s\n", id)
numRevoked += 1
}

fmt.Printf("%d tokens revoked\n", numRevoked)

return nil
}

0 comments on commit 6021e0e

Please sign in to comment.