Files
deploy/cmd/cd-k8s-auth/commands/gcp.go
zeekayandHanzo Dev 1ab6e799c1 cd: the module is github.com/hanzoai/cd, where it is actually hosted
go.mod still declared `module github.com/hanzoai/deploy` after the repo was
renamed. A Go module path is not cosmetic — it is the resolvable location. So
`go get github.com/hanzoai/cd` could not work, and anything importing this
module had to spell a name that no longer exists at that address. The build log
of v3.6.0 is where it surfaced: the compiler was still emitting
github.com/hanzoai/deploy/cmd/cd/commands.

3541 import paths across 690 .go, 19 .proto, 4 .yaml, 3 .sh, 2 .mod, Procfile
and Makefile. Plus the 62 ghcr.io/hanzoai/deploy image references, moved to
ghcr.io/hanzoai/cd to match hanzo.yml's build target — a distinct string from
the module path, replaced separately so neither could clobber the other.

go mod tidy clean, CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./... clean.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-28 21:16:24 -07:00

41 lines
1.2 KiB
Go

package commands
import (
"fmt"
"os"
"github.com/spf13/cobra"
"golang.org/x/oauth2/google"
"github.com/hanzoai/cd/util/errors"
)
// defaultGCPScopes:
// - cloud-platform is the base scope to authenticate to GCP.
// - userinfo.email is used to authenticate to GKE APIs with gserviceaccount
// email instead of numeric uniqueID.
//
// https://github.com/kubernetes/client-go/blob/be758edd136e61a1bffadf1c0235fceb8aee8e9e/plugin/pkg/client/auth/gcp/gcp.go#L59
var defaultGCPScopes = []string{
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/userinfo.email",
}
func newGCPCommand() *cobra.Command {
command := &cobra.Command{
Use: "gcp",
Run: func(c *cobra.Command, _ []string) {
ctx := c.Context()
// Preferred way to retrieve GCP credentials
// https://github.com/golang/oauth2/blob/9780585627b5122c8cc9c6a378ac9861507e7551/google/doc.go#L54-L68
cred, err := google.FindDefaultCredentials(ctx, defaultGCPScopes...)
errors.CheckError(err)
token, err := cred.TokenSource.Token()
errors.CheckError(err)
_, _ = fmt.Fprint(os.Stdout, formatJSON(token.AccessToken, token.Expiry))
},
}
return command
}