Skip to content

Instantly share code, notes, and snippets.

@droyo
Created March 20, 2020 21:38
Show Gist options
  • Save droyo/b2b95815c02f509df4602fc204f389cd to your computer and use it in GitHub Desktop.
Save droyo/b2b95815c02f509df4602fc204f389cd to your computer and use it in GitHub Desktop.
Fetch iam service account
import (
"context"
"flag"
"log"
"path"
"github.com/kr/pretty"
"google.golang.org/api/iam/v1"
)
var (
serviceAccountName = flag.String("n", "changeme@myproject.iam.gserviceaccount.com", "name of svc account")
)
func main() {
flag.Parse()
ctx := context.Background()
iamsvc, err := iam.NewService(ctx)
if err != nil {
log.Fatal("could not make iam service:", err)
}
svcacc := iam.NewProjectsServiceAccountsService(iamsvc)
call := svcacc.Get(path.Join("projects/-/serviceAccounts/", *serviceAccountName))
acc, err := call.Do()
if err != nil {
log.Fatal("call failed:", err)
}
pretty.Println(acc)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment