in gcloud/cloudbilling.go [115:167]
func (c *Client) ProjectListWithBilling(p []*cloudresourcemanager.Project) ([]ProjectWithBilling, error) {
res := []ProjectWithBilling{}
svc, err := c.getCloudbillingService()
if err != nil {
return res, err
}
projs, _ := c.ProjectListWithBillingEnabled()
// if err != nil {
// return res, err
// }
var wg sync.WaitGroup
wg.Add(len(p))
for _, v := range p {
go func(p *cloudresourcemanager.Project) {
defer wg.Done()
if _, ok := projs[p.ProjectId]; ok {
pwb := ProjectWithBilling{Name: p.Name, ID: p.ProjectId, BillingEnabled: true}
res = append(res, pwb)
return
}
// Getting random quota errors when somebody had too many projects.
// sleeping randoming for a second fixed it.
// I don't think these requests can be fixed by batching.
sleepRandom()
if p.LifecycleState == "ACTIVE" && p.Name != "" {
proj := fmt.Sprintf("projects/%s", p.ProjectId)
tmp, err := svc.Projects.GetBillingInfo(proj).Do()
if err != nil {
if strings.Contains(err.Error(), "The caller does not have permission") {
// fmt.Printf("project: %+v\n", p)
return
}
fmt.Printf("error getting billing information: %s\n", err)
return
}
pwb := ProjectWithBilling{Name: p.Name, ID: p.ProjectId, BillingEnabled: tmp.BillingEnabled}
res = append(res, pwb)
return
}
}(v)
}
wg.Wait()
return res, nil
}