Skip to content

Instantly share code, notes, and snippets.

@dtan4
Last active May 14, 2020 13:06
Show Gist options
  • Save dtan4/a2081e75ff8e4737c872e80fd9e6f9e6 to your computer and use it in GitHub Desktop.
Save dtan4/a2081e75ff8e4737c872e80fd9e6f9e6 to your computer and use it in GitHub Desktop.
package main
import (
"context"
"log"
"time"
"google.golang.org/api/iam/v1"
)
const (
projectID = "***"
serviceAccountIDBase = "foobar"
)
func main() {
ctx := context.Background()
svc, err := iam.NewService(ctx)
if err != nil {
log.Fatal(err)
}
projectName := "projects/" + projectID
for {
log.Println("create")
serviceAccountID := serviceAccountIDBase + time.Now().Format("20060102150405")
r1, err := svc.Projects.ServiceAccounts.Create(projectName, &iam.CreateServiceAccountRequest{
AccountId: serviceAccountID,
}).Do()
if err != nil {
log.Fatal(err)
}
log.Println("created")
name := r1.Name
time.Sleep(1 * time.Second)
log.Println("get")
_, err = svc.Projects.ServiceAccounts.Get(name).Do()
if err != nil {
log.Fatal(err)
}
log.Println("got")
log.Println("delete")
_, err = svc.Projects.ServiceAccounts.Delete(name).Do()
if err != nil {
log.Fatal(err)
}
log.Printf("deleted %q", name)
time.Sleep(1 * time.Second)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment