Skip to content

Commit

Permalink
nsc ingress generate-access-token: add flag to write token to a file.
Browse files Browse the repository at this point in the history
  • Loading branch information
n-g committed Oct 17, 2023
1 parent bb9bfba commit 2150a1c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions internal/cli/cmd/cluster/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ package cluster
import (
"context"
"fmt"
"os"
"strings"

"github.com/spf13/cobra"
"namespacelabs.dev/foundation/internal/cli/fncobra"
"namespacelabs.dev/foundation/internal/console"
"namespacelabs.dev/foundation/internal/fnapi"
"namespacelabs.dev/foundation/internal/fnerrors"
"namespacelabs.dev/foundation/internal/providers/nscloud/api"
)

Expand Down Expand Up @@ -72,13 +74,22 @@ func newGenerateAccessTokenCmd() *cobra.Command {
}

instance := cmd.Flags().String("instance", "", "Limit the access token to this instance.")
outputPath := cmd.Flags().String("output_to", "", "If specified, write the access token to this path.")

cmd.RunE = fncobra.RunE(func(ctx context.Context, args []string) error {
res, err := fnapi.IssueIngressAccessToken(ctx, *instance)
if err != nil {
return err
}

if *outputPath != "" {
if err := os.WriteFile(*outputPath, []byte(res.IngressAccessToken), 0644); err != nil {
return fnerrors.New("failed to write %q: %w", *outputPath, err)
}

return nil
}

fmt.Fprintln(console.Stdout(ctx), res.IngressAccessToken)
return nil
})
Expand Down

0 comments on commit 2150a1c

Please sign in to comment.