Path: blob/main/dev/gpctl/cmd/public-api-workspaces-ownertoken.go
2496 views
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package cmd56import (7"github.com/gitpod-io/gitpod/common-go/log"8v1 "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1"9"github.com/spf13/cobra"10)1112var publicApiWorkspacesOwnertokenCmd = &cobra.Command{13Use: "ownertoken <workspace-id>",14Short: "Retrieve the owner token for a given workspace ID",15Args: cobra.ExactArgs(1),16Run: func(cmd *cobra.Command, args []string) {17workspaceID := args[0]1819conn, err := newPublicAPIConn()20if err != nil {21log.WithError(err).Fatal()22}2324service := v1.NewWorkspacesServiceClient(conn)2526log.Debugf("Retrieving workspace owner token for %s", workspaceID)27resp, err := service.GetOwnerToken(cmd.Context(), &v1.GetOwnerTokenRequest{WorkspaceId: workspaceID})28if err != nil {29log.WithError(err).Fatalf("failed to retrieve owner token (ID: %s)", workspaceID)30return31}3233tpl := `{{ .Token }}`34err = getOutputFormat(tpl, "{..token}").Print(resp)35if err != nil {36log.Fatal(err)37}38},39}4041func init() {42publicApiWorkspacesCmd.AddCommand(publicApiWorkspacesOwnertokenCmd)43}444546