1// Package cloudbilling provides access to the Google Cloud Billing API. 2// 3// See https://cloud.google.com/billing/ 4// 5// Usage example: 6// 7// import "google.golang.org/api/cloudbilling/v1" 8// ... 9// cloudbillingService, err := cloudbilling.New(oauthHttpClient) 10package cloudbilling // import "google.golang.org/api/cloudbilling/v1" 11 12import ( 13 "bytes" 14 "encoding/json" 15 "errors" 16 "fmt" 17 context "golang.org/x/net/context" 18 ctxhttp "golang.org/x/net/context/ctxhttp" 19 gensupport "google.golang.org/api/gensupport" 20 googleapi "google.golang.org/api/googleapi" 21 "io" 22 "net/http" 23 "net/url" 24 "strconv" 25 "strings" 26) 27 28// Always reference these packages, just in case the auto-generated code 29// below doesn't. 30var _ = bytes.NewBuffer 31var _ = strconv.Itoa 32var _ = fmt.Sprintf 33var _ = json.NewDecoder 34var _ = io.Copy 35var _ = url.Parse 36var _ = gensupport.MarshalJSON 37var _ = googleapi.Version 38var _ = errors.New 39var _ = strings.Replace 40var _ = context.Canceled 41var _ = ctxhttp.Do 42 43const apiId = "cloudbilling:v1" 44const apiName = "cloudbilling" 45const apiVersion = "v1" 46const basePath = "https://cloudbilling.googleapis.com/" 47 48// OAuth2 scopes used by this API. 49const ( 50 // View and manage your data across Google Cloud Platform services 51 CloudPlatformScope = "https://www.googleapis.com/auth/cloud-platform" 52) 53 54func New(client *http.Client) (*Service, error) { 55 if client == nil { 56 return nil, errors.New("client is nil") 57 } 58 s := &Service{client: client, BasePath: basePath} 59 s.BillingAccounts = NewBillingAccountsService(s) 60 s.Projects = NewProjectsService(s) 61 return s, nil 62} 63 64type Service struct { 65 client *http.Client 66 BasePath string // API endpoint base URL 67 UserAgent string // optional additional User-Agent fragment 68 69 BillingAccounts *BillingAccountsService 70 71 Projects *ProjectsService 72} 73 74func (s *Service) userAgent() string { 75 if s.UserAgent == "" { 76 return googleapi.UserAgent 77 } 78 return googleapi.UserAgent + " " + s.UserAgent 79} 80 81func NewBillingAccountsService(s *Service) *BillingAccountsService { 82 rs := &BillingAccountsService{s: s} 83 rs.Projects = NewBillingAccountsProjectsService(s) 84 return rs 85} 86 87type BillingAccountsService struct { 88 s *Service 89 90 Projects *BillingAccountsProjectsService 91} 92 93func NewBillingAccountsProjectsService(s *Service) *BillingAccountsProjectsService { 94 rs := &BillingAccountsProjectsService{s: s} 95 return rs 96} 97 98type BillingAccountsProjectsService struct { 99 s *Service 100} 101 102func NewProjectsService(s *Service) *ProjectsService { 103 rs := &ProjectsService{s: s} 104 return rs 105} 106 107type ProjectsService struct { 108 s *Service 109} 110 111// BillingAccount: A billing account in [Google Developers 112// Console](https://console.developers.google.com/). You can assign a 113// billing account to one or more projects. 114type BillingAccount struct { 115 // DisplayName: The display name given to the billing account, such as 116 // `My Billing Account`. This name is displayed in the Google Developers 117 // Console. 118 DisplayName string `json:"displayName,omitempty"` 119 120 // Name: The resource name of the billing account. The resource name has 121 // the form `billingAccounts/{billing_account_id}`. For example, 122 // `billingAccounts/012345-567890-ABCDEF` would be the resource name for 123 // billing account `012345-567890-ABCDEF`. 124 Name string `json:"name,omitempty"` 125 126 // Open: True if the billing account is open, and will therefore be 127 // charged for any usage on associated projects. False if the billing 128 // account is closed, and therefore projects associated with it will be 129 // unable to use paid services. 130 Open bool `json:"open,omitempty"` 131 132 // ServerResponse contains the HTTP response code and headers from the 133 // server. 134 googleapi.ServerResponse `json:"-"` 135 136 // ForceSendFields is a list of field names (e.g. "DisplayName") to 137 // unconditionally include in API requests. By default, fields with 138 // empty values are omitted from API requests. However, any non-pointer, 139 // non-interface field appearing in ForceSendFields will be sent to the 140 // server regardless of whether the field is empty or not. This may be 141 // used to include empty fields in Patch requests. 142 ForceSendFields []string `json:"-"` 143} 144 145func (s *BillingAccount) MarshalJSON() ([]byte, error) { 146 type noMethod BillingAccount 147 raw := noMethod(*s) 148 return gensupport.MarshalJSON(raw, s.ForceSendFields) 149} 150 151// ListBillingAccountsResponse: Response message for 152// `ListBillingAccounts`. 153type ListBillingAccountsResponse struct { 154 // BillingAccounts: A list of billing accounts. 155 BillingAccounts []*BillingAccount `json:"billingAccounts,omitempty"` 156 157 // NextPageToken: A token to retrieve the next page of results. To 158 // retrieve the next page, call `ListBillingAccounts` again with the 159 // `page_token` field set to this value. This field is empty if there 160 // are no more results to retrieve. 161 NextPageToken string `json:"nextPageToken,omitempty"` 162 163 // ServerResponse contains the HTTP response code and headers from the 164 // server. 165 googleapi.ServerResponse `json:"-"` 166 167 // ForceSendFields is a list of field names (e.g. "BillingAccounts") to 168 // unconditionally include in API requests. By default, fields with 169 // empty values are omitted from API requests. However, any non-pointer, 170 // non-interface field appearing in ForceSendFields will be sent to the 171 // server regardless of whether the field is empty or not. This may be 172 // used to include empty fields in Patch requests. 173 ForceSendFields []string `json:"-"` 174} 175 176func (s *ListBillingAccountsResponse) MarshalJSON() ([]byte, error) { 177 type noMethod ListBillingAccountsResponse 178 raw := noMethod(*s) 179 return gensupport.MarshalJSON(raw, s.ForceSendFields) 180} 181 182// ListProjectBillingInfoResponse: Request message for 183// `ListProjectBillingInfoResponse`. 184type ListProjectBillingInfoResponse struct { 185 // NextPageToken: A token to retrieve the next page of results. To 186 // retrieve the next page, call `ListProjectBillingInfo` again with the 187 // `page_token` field set to this value. This field is empty if there 188 // are no more results to retrieve. 189 NextPageToken string `json:"nextPageToken,omitempty"` 190 191 // ProjectBillingInfo: A list of `ProjectBillingInfo` resources 192 // representing the projects associated with the billing account. 193 ProjectBillingInfo []*ProjectBillingInfo `json:"projectBillingInfo,omitempty"` 194 195 // ServerResponse contains the HTTP response code and headers from the 196 // server. 197 googleapi.ServerResponse `json:"-"` 198 199 // ForceSendFields is a list of field names (e.g. "NextPageToken") to 200 // unconditionally include in API requests. By default, fields with 201 // empty values are omitted from API requests. However, any non-pointer, 202 // non-interface field appearing in ForceSendFields will be sent to the 203 // server regardless of whether the field is empty or not. This may be 204 // used to include empty fields in Patch requests. 205 ForceSendFields []string `json:"-"` 206} 207 208func (s *ListProjectBillingInfoResponse) MarshalJSON() ([]byte, error) { 209 type noMethod ListProjectBillingInfoResponse 210 raw := noMethod(*s) 211 return gensupport.MarshalJSON(raw, s.ForceSendFields) 212} 213 214// ProjectBillingInfo: Encapsulation of billing information for a 215// Developers Console project. A project has at most one associated 216// billing account at a time (but a billing account can be assigned to 217// multiple projects). 218type ProjectBillingInfo struct { 219 // BillingAccountName: The resource name of the billing account 220 // associated with the project, if any. For example, 221 // `billingAccounts/012345-567890-ABCDEF`. 222 BillingAccountName string `json:"billingAccountName,omitempty"` 223 224 // BillingEnabled: True if the project is associated with an open 225 // billing account, to which usage on the project is charged. False if 226 // the project is associated with a closed billing account, or no 227 // billing account at all, and therefore cannot use paid services. This 228 // field is read-only. 229 BillingEnabled bool `json:"billingEnabled,omitempty"` 230 231 // Name: The resource name for the `ProjectBillingInfo`; has the form 232 // `projects/{project_id}/billingInfo`. For example, the resource name 233 // for the billing information for project `tokyo-rain-123` would be 234 // `projects/tokyo-rain-123/billingInfo`. This field is read-only. 235 Name string `json:"name,omitempty"` 236 237 // ProjectId: The ID of the project that this `ProjectBillingInfo` 238 // represents, such as `tokyo-rain-123`. This is a convenience field so 239 // that you don't need to parse the `name` field to obtain a project ID. 240 // This field is read-only. 241 ProjectId string `json:"projectId,omitempty"` 242 243 // ServerResponse contains the HTTP response code and headers from the 244 // server. 245 googleapi.ServerResponse `json:"-"` 246 247 // ForceSendFields is a list of field names (e.g. "BillingAccountName") 248 // to unconditionally include in API requests. By default, fields with 249 // empty values are omitted from API requests. However, any non-pointer, 250 // non-interface field appearing in ForceSendFields will be sent to the 251 // server regardless of whether the field is empty or not. This may be 252 // used to include empty fields in Patch requests. 253 ForceSendFields []string `json:"-"` 254} 255 256func (s *ProjectBillingInfo) MarshalJSON() ([]byte, error) { 257 type noMethod ProjectBillingInfo 258 raw := noMethod(*s) 259 return gensupport.MarshalJSON(raw, s.ForceSendFields) 260} 261 262// method id "cloudbilling.billingAccounts.get": 263 264type BillingAccountsGetCall struct { 265 s *Service 266 name string 267 urlParams_ gensupport.URLParams 268 ifNoneMatch_ string 269 ctx_ context.Context 270} 271 272// Get: Gets information about a billing account. The current 273// authenticated user must be an [owner of the billing 274// account](https://support.google.com/cloud/answer/4430947). 275func (r *BillingAccountsService) Get(name string) *BillingAccountsGetCall { 276 c := &BillingAccountsGetCall{s: r.s, urlParams_: make(gensupport.URLParams)} 277 c.name = name 278 return c 279} 280 281// Fields allows partial responses to be retrieved. See 282// https://developers.google.com/gdata/docs/2.0/basics#PartialResponse 283// for more information. 284func (c *BillingAccountsGetCall) Fields(s ...googleapi.Field) *BillingAccountsGetCall { 285 c.urlParams_.Set("fields", googleapi.CombineFields(s)) 286 return c 287} 288 289// IfNoneMatch sets the optional parameter which makes the operation 290// fail if the object's ETag matches the given value. This is useful for 291// getting updates only after the object has changed since the last 292// request. Use googleapi.IsNotModified to check whether the response 293// error from Do is the result of In-None-Match. 294func (c *BillingAccountsGetCall) IfNoneMatch(entityTag string) *BillingAccountsGetCall { 295 c.ifNoneMatch_ = entityTag 296 return c 297} 298 299// Context sets the context to be used in this call's Do method. Any 300// pending HTTP request will be aborted if the provided context is 301// canceled. 302func (c *BillingAccountsGetCall) Context(ctx context.Context) *BillingAccountsGetCall { 303 c.ctx_ = ctx 304 return c 305} 306 307func (c *BillingAccountsGetCall) doRequest(alt string) (*http.Response, error) { 308 var body io.Reader = nil 309 c.urlParams_.Set("alt", alt) 310 urls := googleapi.ResolveRelative(c.s.BasePath, "v1/{+name}") 311 urls += "?" + c.urlParams_.Encode() 312 req, _ := http.NewRequest("GET", urls, body) 313 googleapi.Expand(req.URL, map[string]string{ 314 "name": c.name, 315 }) 316 req.Header.Set("User-Agent", c.s.userAgent()) 317 if c.ifNoneMatch_ != "" { 318 req.Header.Set("If-None-Match", c.ifNoneMatch_) 319 } 320 if c.ctx_ != nil { 321 return ctxhttp.Do(c.ctx_, c.s.client, req) 322 } 323 return c.s.client.Do(req) 324} 325 326// Do executes the "cloudbilling.billingAccounts.get" call. 327// Exactly one of *BillingAccount or error will be non-nil. Any non-2xx 328// status code is an error. Response headers are in either 329// *BillingAccount.ServerResponse.Header or (if a response was returned 330// at all) in error.(*googleapi.Error).Header. Use 331// googleapi.IsNotModified to check whether the returned error was 332// because http.StatusNotModified was returned. 333func (c *BillingAccountsGetCall) Do(opts ...googleapi.CallOption) (*BillingAccount, error) { 334 gensupport.SetOptions(c.urlParams_, opts...) 335 res, err := c.doRequest("json") 336 if res != nil && res.StatusCode == http.StatusNotModified { 337 if res.Body != nil { 338 res.Body.Close() 339 } 340 return nil, &googleapi.Error{ 341 Code: res.StatusCode, 342 Header: res.Header, 343 } 344 } 345 if err != nil { 346 return nil, err 347 } 348 defer googleapi.CloseBody(res) 349 if err := googleapi.CheckResponse(res); err != nil { 350 return nil, err 351 } 352 ret := &BillingAccount{ 353 ServerResponse: googleapi.ServerResponse{ 354 Header: res.Header, 355 HTTPStatusCode: res.StatusCode, 356 }, 357 } 358 if err := json.NewDecoder(res.Body).Decode(&ret); err != nil { 359 return nil, err 360 } 361 return ret, nil 362 // { 363 // "description": "Gets information about a billing account. The current authenticated user must be an [owner of the billing account](https://support.google.com/cloud/answer/4430947).", 364 // "httpMethod": "GET", 365 // "id": "cloudbilling.billingAccounts.get", 366 // "parameterOrder": [ 367 // "name" 368 // ], 369 // "parameters": { 370 // "name": { 371 // "description": "The resource name of the billing account to retrieve. For example, `billingAccounts/012345-567890-ABCDEF`.", 372 // "location": "path", 373 // "pattern": "^billingAccounts/[^/]*$", 374 // "required": true, 375 // "type": "string" 376 // } 377 // }, 378 // "path": "v1/{+name}", 379 // "response": { 380 // "$ref": "BillingAccount" 381 // }, 382 // "scopes": [ 383 // "https://www.googleapis.com/auth/cloud-platform" 384 // ] 385 // } 386 387} 388 389// method id "cloudbilling.billingAccounts.list": 390 391type BillingAccountsListCall struct { 392 s *Service 393 urlParams_ gensupport.URLParams 394 ifNoneMatch_ string 395 ctx_ context.Context 396} 397 398// List: Lists the billing accounts that the current authenticated user 399// [owns](https://support.google.com/cloud/answer/4430947). 400func (r *BillingAccountsService) List() *BillingAccountsListCall { 401 c := &BillingAccountsListCall{s: r.s, urlParams_: make(gensupport.URLParams)} 402 return c 403} 404 405// PageSize sets the optional parameter "pageSize": Requested page size. 406// The maximum page size is 100; this is also the default. 407func (c *BillingAccountsListCall) PageSize(pageSize int64) *BillingAccountsListCall { 408 c.urlParams_.Set("pageSize", fmt.Sprint(pageSize)) 409 return c 410} 411 412// PageToken sets the optional parameter "pageToken": A token 413// identifying a page of results to return. This should be a 414// `next_page_token` value returned from a previous 415// `ListBillingAccounts` call. If unspecified, the first page of results 416// is returned. 417func (c *BillingAccountsListCall) PageToken(pageToken string) *BillingAccountsListCall { 418 c.urlParams_.Set("pageToken", pageToken) 419 return c 420} 421 422// Fields allows partial responses to be retrieved. See 423// https://developers.google.com/gdata/docs/2.0/basics#PartialResponse 424// for more information. 425func (c *BillingAccountsListCall) Fields(s ...googleapi.Field) *BillingAccountsListCall { 426 c.urlParams_.Set("fields", googleapi.CombineFields(s)) 427 return c 428} 429 430// IfNoneMatch sets the optional parameter which makes the operation 431// fail if the object's ETag matches the given value. This is useful for 432// getting updates only after the object has changed since the last 433// request. Use googleapi.IsNotModified to check whether the response 434// error from Do is the result of In-None-Match. 435func (c *BillingAccountsListCall) IfNoneMatch(entityTag string) *BillingAccountsListCall { 436 c.ifNoneMatch_ = entityTag 437 return c 438} 439 440// Context sets the context to be used in this call's Do method. Any 441// pending HTTP request will be aborted if the provided context is 442// canceled. 443func (c *BillingAccountsListCall) Context(ctx context.Context) *BillingAccountsListCall { 444 c.ctx_ = ctx 445 return c 446} 447 448func (c *BillingAccountsListCall) doRequest(alt string) (*http.Response, error) { 449 var body io.Reader = nil 450 c.urlParams_.Set("alt", alt) 451 urls := googleapi.ResolveRelative(c.s.BasePath, "v1/billingAccounts") 452 urls += "?" + c.urlParams_.Encode() 453 req, _ := http.NewRequest("GET", urls, body) 454 googleapi.SetOpaque(req.URL) 455 req.Header.Set("User-Agent", c.s.userAgent()) 456 if c.ifNoneMatch_ != "" { 457 req.Header.Set("If-None-Match", c.ifNoneMatch_) 458 } 459 if c.ctx_ != nil { 460 return ctxhttp.Do(c.ctx_, c.s.client, req) 461 } 462 return c.s.client.Do(req) 463} 464 465// Do executes the "cloudbilling.billingAccounts.list" call. 466// Exactly one of *ListBillingAccountsResponse or error will be non-nil. 467// Any non-2xx status code is an error. Response headers are in either 468// *ListBillingAccountsResponse.ServerResponse.Header or (if a response 469// was returned at all) in error.(*googleapi.Error).Header. Use 470// googleapi.IsNotModified to check whether the returned error was 471// because http.StatusNotModified was returned. 472func (c *BillingAccountsListCall) Do(opts ...googleapi.CallOption) (*ListBillingAccountsResponse, error) { 473 gensupport.SetOptions(c.urlParams_, opts...) 474 res, err := c.doRequest("json") 475 if res != nil && res.StatusCode == http.StatusNotModified { 476 if res.Body != nil { 477 res.Body.Close() 478 } 479 return nil, &googleapi.Error{ 480 Code: res.StatusCode, 481 Header: res.Header, 482 } 483 } 484 if err != nil { 485 return nil, err 486 } 487 defer googleapi.CloseBody(res) 488 if err := googleapi.CheckResponse(res); err != nil { 489 return nil, err 490 } 491 ret := &ListBillingAccountsResponse{ 492 ServerResponse: googleapi.ServerResponse{ 493 Header: res.Header, 494 HTTPStatusCode: res.StatusCode, 495 }, 496 } 497 if err := json.NewDecoder(res.Body).Decode(&ret); err != nil { 498 return nil, err 499 } 500 return ret, nil 501 // { 502 // "description": "Lists the billing accounts that the current authenticated user [owns](https://support.google.com/cloud/answer/4430947).", 503 // "httpMethod": "GET", 504 // "id": "cloudbilling.billingAccounts.list", 505 // "parameters": { 506 // "pageSize": { 507 // "description": "Requested page size. The maximum page size is 100; this is also the default.", 508 // "format": "int32", 509 // "location": "query", 510 // "type": "integer" 511 // }, 512 // "pageToken": { 513 // "description": "A token identifying a page of results to return. This should be a `next_page_token` value returned from a previous `ListBillingAccounts` call. If unspecified, the first page of results is returned.", 514 // "location": "query", 515 // "type": "string" 516 // } 517 // }, 518 // "path": "v1/billingAccounts", 519 // "response": { 520 // "$ref": "ListBillingAccountsResponse" 521 // }, 522 // "scopes": [ 523 // "https://www.googleapis.com/auth/cloud-platform" 524 // ] 525 // } 526 527} 528 529// Pages invokes f for each page of results. 530// A non-nil error returned from f will halt the iteration. 531// The provided context supersedes any context provided to the Context method. 532func (c *BillingAccountsListCall) Pages(ctx context.Context, f func(*ListBillingAccountsResponse) error) error { 533 c.ctx_ = ctx 534 defer c.PageToken(c.urlParams_.Get("pageToken")) // reset paging to original point 535 for { 536 x, err := c.Do() 537 if err != nil { 538 return err 539 } 540 if err := f(x); err != nil { 541 return err 542 } 543 if x.NextPageToken == "" { 544 return nil 545 } 546 c.PageToken(x.NextPageToken) 547 } 548} 549 550// method id "cloudbilling.billingAccounts.projects.list": 551 552type BillingAccountsProjectsListCall struct { 553 s *Service 554 name string 555 urlParams_ gensupport.URLParams 556 ifNoneMatch_ string 557 ctx_ context.Context 558} 559 560// List: Lists the projects associated with a billing account. The 561// current authenticated user must be an [owner of the billing 562// account](https://support.google.com/cloud/answer/4430947). 563func (r *BillingAccountsProjectsService) List(name string) *BillingAccountsProjectsListCall { 564 c := &BillingAccountsProjectsListCall{s: r.s, urlParams_: make(gensupport.URLParams)} 565 c.name = name 566 return c 567} 568 569// PageSize sets the optional parameter "pageSize": Requested page size. 570// The maximum page size is 100; this is also the default. 571func (c *BillingAccountsProjectsListCall) PageSize(pageSize int64) *BillingAccountsProjectsListCall { 572 c.urlParams_.Set("pageSize", fmt.Sprint(pageSize)) 573 return c 574} 575 576// PageToken sets the optional parameter "pageToken": A token 577// identifying a page of results to be returned. This should be a 578// `next_page_token` value returned from a previous 579// `ListProjectBillingInfo` call. If unspecified, the first page of 580// results is returned. 581func (c *BillingAccountsProjectsListCall) PageToken(pageToken string) *BillingAccountsProjectsListCall { 582 c.urlParams_.Set("pageToken", pageToken) 583 return c 584} 585 586// Fields allows partial responses to be retrieved. See 587// https://developers.google.com/gdata/docs/2.0/basics#PartialResponse 588// for more information. 589func (c *BillingAccountsProjectsListCall) Fields(s ...googleapi.Field) *BillingAccountsProjectsListCall { 590 c.urlParams_.Set("fields", googleapi.CombineFields(s)) 591 return c 592} 593 594// IfNoneMatch sets the optional parameter which makes the operation 595// fail if the object's ETag matches the given value. This is useful for 596// getting updates only after the object has changed since the last 597// request. Use googleapi.IsNotModified to check whether the response 598// error from Do is the result of In-None-Match. 599func (c *BillingAccountsProjectsListCall) IfNoneMatch(entityTag string) *BillingAccountsProjectsListCall { 600 c.ifNoneMatch_ = entityTag 601 return c 602} 603 604// Context sets the context to be used in this call's Do method. Any 605// pending HTTP request will be aborted if the provided context is 606// canceled. 607func (c *BillingAccountsProjectsListCall) Context(ctx context.Context) *BillingAccountsProjectsListCall { 608 c.ctx_ = ctx 609 return c 610} 611 612func (c *BillingAccountsProjectsListCall) doRequest(alt string) (*http.Response, error) { 613 var body io.Reader = nil 614 c.urlParams_.Set("alt", alt) 615 urls := googleapi.ResolveRelative(c.s.BasePath, "v1/{+name}/projects") 616 urls += "?" + c.urlParams_.Encode() 617 req, _ := http.NewRequest("GET", urls, body) 618 googleapi.Expand(req.URL, map[string]string{ 619 "name": c.name, 620 }) 621 req.Header.Set("User-Agent", c.s.userAgent()) 622 if c.ifNoneMatch_ != "" { 623 req.Header.Set("If-None-Match", c.ifNoneMatch_) 624 } 625 if c.ctx_ != nil { 626 return ctxhttp.Do(c.ctx_, c.s.client, req) 627 } 628 return c.s.client.Do(req) 629} 630 631// Do executes the "cloudbilling.billingAccounts.projects.list" call. 632// Exactly one of *ListProjectBillingInfoResponse or error will be 633// non-nil. Any non-2xx status code is an error. Response headers are in 634// either *ListProjectBillingInfoResponse.ServerResponse.Header or (if a 635// response was returned at all) in error.(*googleapi.Error).Header. Use 636// googleapi.IsNotModified to check whether the returned error was 637// because http.StatusNotModified was returned. 638func (c *BillingAccountsProjectsListCall) Do(opts ...googleapi.CallOption) (*ListProjectBillingInfoResponse, error) { 639 gensupport.SetOptions(c.urlParams_, opts...) 640 res, err := c.doRequest("json") 641 if res != nil && res.StatusCode == http.StatusNotModified { 642 if res.Body != nil { 643 res.Body.Close() 644 } 645 return nil, &googleapi.Error{ 646 Code: res.StatusCode, 647 Header: res.Header, 648 } 649 } 650 if err != nil { 651 return nil, err 652 } 653 defer googleapi.CloseBody(res) 654 if err := googleapi.CheckResponse(res); err != nil { 655 return nil, err 656 } 657 ret := &ListProjectBillingInfoResponse{ 658 ServerResponse: googleapi.ServerResponse{ 659 Header: res.Header, 660 HTTPStatusCode: res.StatusCode, 661 }, 662 } 663 if err := json.NewDecoder(res.Body).Decode(&ret); err != nil { 664 return nil, err 665 } 666 return ret, nil 667 // { 668 // "description": "Lists the projects associated with a billing account. The current authenticated user must be an [owner of the billing account](https://support.google.com/cloud/answer/4430947).", 669 // "httpMethod": "GET", 670 // "id": "cloudbilling.billingAccounts.projects.list", 671 // "parameterOrder": [ 672 // "name" 673 // ], 674 // "parameters": { 675 // "name": { 676 // "description": "The resource name of the billing account associated with the projects that you want to list. For example, `billingAccounts/012345-567890-ABCDEF`.", 677 // "location": "path", 678 // "pattern": "^billingAccounts/[^/]*$", 679 // "required": true, 680 // "type": "string" 681 // }, 682 // "pageSize": { 683 // "description": "Requested page size. The maximum page size is 100; this is also the default.", 684 // "format": "int32", 685 // "location": "query", 686 // "type": "integer" 687 // }, 688 // "pageToken": { 689 // "description": "A token identifying a page of results to be returned. This should be a `next_page_token` value returned from a previous `ListProjectBillingInfo` call. If unspecified, the first page of results is returned.", 690 // "location": "query", 691 // "type": "string" 692 // } 693 // }, 694 // "path": "v1/{+name}/projects", 695 // "response": { 696 // "$ref": "ListProjectBillingInfoResponse" 697 // }, 698 // "scopes": [ 699 // "https://www.googleapis.com/auth/cloud-platform" 700 // ] 701 // } 702 703} 704 705// Pages invokes f for each page of results. 706// A non-nil error returned from f will halt the iteration. 707// The provided context supersedes any context provided to the Context method. 708func (c *BillingAccountsProjectsListCall) Pages(ctx context.Context, f func(*ListProjectBillingInfoResponse) error) error { 709 c.ctx_ = ctx 710 defer c.PageToken(c.urlParams_.Get("pageToken")) // reset paging to original point 711 for { 712 x, err := c.Do() 713 if err != nil { 714 return err 715 } 716 if err := f(x); err != nil { 717 return err 718 } 719 if x.NextPageToken == "" { 720 return nil 721 } 722 c.PageToken(x.NextPageToken) 723 } 724} 725 726// method id "cloudbilling.projects.getBillingInfo": 727 728type ProjectsGetBillingInfoCall struct { 729 s *Service 730 name string 731 urlParams_ gensupport.URLParams 732 ifNoneMatch_ string 733 ctx_ context.Context 734} 735 736// GetBillingInfo: Gets the billing information for a project. The 737// current authenticated user must have [permission to view the 738// project](https://cloud.google.com/docs/permissions-overview#h.bgs0oxof 739// vnoo ). 740func (r *ProjectsService) GetBillingInfo(name string) *ProjectsGetBillingInfoCall { 741 c := &ProjectsGetBillingInfoCall{s: r.s, urlParams_: make(gensupport.URLParams)} 742 c.name = name 743 return c 744} 745 746// Fields allows partial responses to be retrieved. See 747// https://developers.google.com/gdata/docs/2.0/basics#PartialResponse 748// for more information. 749func (c *ProjectsGetBillingInfoCall) Fields(s ...googleapi.Field) *ProjectsGetBillingInfoCall { 750 c.urlParams_.Set("fields", googleapi.CombineFields(s)) 751 return c 752} 753 754// IfNoneMatch sets the optional parameter which makes the operation 755// fail if the object's ETag matches the given value. This is useful for 756// getting updates only after the object has changed since the last 757// request. Use googleapi.IsNotModified to check whether the response 758// error from Do is the result of In-None-Match. 759func (c *ProjectsGetBillingInfoCall) IfNoneMatch(entityTag string) *ProjectsGetBillingInfoCall { 760 c.ifNoneMatch_ = entityTag 761 return c 762} 763 764// Context sets the context to be used in this call's Do method. Any 765// pending HTTP request will be aborted if the provided context is 766// canceled. 767func (c *ProjectsGetBillingInfoCall) Context(ctx context.Context) *ProjectsGetBillingInfoCall { 768 c.ctx_ = ctx 769 return c 770} 771 772func (c *ProjectsGetBillingInfoCall) doRequest(alt string) (*http.Response, error) { 773 var body io.Reader = nil 774 c.urlParams_.Set("alt", alt) 775 urls := googleapi.ResolveRelative(c.s.BasePath, "v1/{+name}/billingInfo") 776 urls += "?" + c.urlParams_.Encode() 777 req, _ := http.NewRequest("GET", urls, body) 778 googleapi.Expand(req.URL, map[string]string{ 779 "name": c.name, 780 }) 781 req.Header.Set("User-Agent", c.s.userAgent()) 782 if c.ifNoneMatch_ != "" { 783 req.Header.Set("If-None-Match", c.ifNoneMatch_) 784 } 785 if c.ctx_ != nil { 786 return ctxhttp.Do(c.ctx_, c.s.client, req) 787 } 788 return c.s.client.Do(req) 789} 790 791// Do executes the "cloudbilling.projects.getBillingInfo" call. 792// Exactly one of *ProjectBillingInfo or error will be non-nil. Any 793// non-2xx status code is an error. Response headers are in either 794// *ProjectBillingInfo.ServerResponse.Header or (if a response was 795// returned at all) in error.(*googleapi.Error).Header. Use 796// googleapi.IsNotModified to check whether the returned error was 797// because http.StatusNotModified was returned. 798func (c *ProjectsGetBillingInfoCall) Do(opts ...googleapi.CallOption) (*ProjectBillingInfo, error) { 799 gensupport.SetOptions(c.urlParams_, opts...) 800 res, err := c.doRequest("json") 801 if res != nil && res.StatusCode == http.StatusNotModified { 802 if res.Body != nil { 803 res.Body.Close() 804 } 805 return nil, &googleapi.Error{ 806 Code: res.StatusCode, 807 Header: res.Header, 808 } 809 } 810 if err != nil { 811 return nil, err 812 } 813 defer googleapi.CloseBody(res) 814 if err := googleapi.CheckResponse(res); err != nil { 815 return nil, err 816 } 817 ret := &ProjectBillingInfo{ 818 ServerResponse: googleapi.ServerResponse{ 819 Header: res.Header, 820 HTTPStatusCode: res.StatusCode, 821 }, 822 } 823 if err := json.NewDecoder(res.Body).Decode(&ret); err != nil { 824 return nil, err 825 } 826 return ret, nil 827 // { 828 // "description": "Gets the billing information for a project. The current authenticated user must have [permission to view the project](https://cloud.google.com/docs/permissions-overview#h.bgs0oxofvnoo ).", 829 // "httpMethod": "GET", 830 // "id": "cloudbilling.projects.getBillingInfo", 831 // "parameterOrder": [ 832 // "name" 833 // ], 834 // "parameters": { 835 // "name": { 836 // "description": "The resource name of the project for which billing information is retrieved. For example, `projects/tokyo-rain-123`.", 837 // "location": "path", 838 // "pattern": "^projects/[^/]*$", 839 // "required": true, 840 // "type": "string" 841 // } 842 // }, 843 // "path": "v1/{+name}/billingInfo", 844 // "response": { 845 // "$ref": "ProjectBillingInfo" 846 // }, 847 // "scopes": [ 848 // "https://www.googleapis.com/auth/cloud-platform" 849 // ] 850 // } 851 852} 853 854// method id "cloudbilling.projects.updateBillingInfo": 855 856type ProjectsUpdateBillingInfoCall struct { 857 s *Service 858 name string 859 projectbillinginfo *ProjectBillingInfo 860 urlParams_ gensupport.URLParams 861 ctx_ context.Context 862} 863 864// UpdateBillingInfo: Sets or updates the billing account associated 865// with a project. You specify the new billing account by setting the 866// `billing_account_name` in the `ProjectBillingInfo` resource to the 867// resource name of a billing account. Associating a project with an 868// open billing account enables billing on the project and allows 869// charges for resource usage. If the project already had a billing 870// account, this method changes the billing account used for resource 871// usage charges. *Note:* Incurred charges that have not yet been 872// reported in the transaction history of the Google Developers Console 873// may be billed to the new billing account, even if the charge occurred 874// before the new billing account was assigned to the project. The 875// current authenticated user must have ownership privileges for both 876// the 877// [project](https://cloud.google.com/docs/permissions-overview#h.bgs0oxo 878// fvnoo ) and the [billing 879// account](https://support.google.com/cloud/answer/4430947). You can 880// disable billing on the project by setting the `billing_account_name` 881// field to empty. This action disassociates the current billing account 882// from the project. Any billable activity of your in-use services will 883// stop, and your application could stop functioning as expected. Any 884// unbilled charges to date will be billed to the previously associated 885// account. The current authenticated user must be either an owner of 886// the project or an owner of the billing account for the project. Note 887// that associating a project with a *closed* billing account will have 888// much the same effect as disabling billing on the project: any paid 889// resources used by the project will be shut down. Thus, unless you 890// wish to disable billing, you should always call this method with the 891// name of an *open* billing account. 892func (r *ProjectsService) UpdateBillingInfo(name string, projectbillinginfo *ProjectBillingInfo) *ProjectsUpdateBillingInfoCall { 893 c := &ProjectsUpdateBillingInfoCall{s: r.s, urlParams_: make(gensupport.URLParams)} 894 c.name = name 895 c.projectbillinginfo = projectbillinginfo 896 return c 897} 898 899// Fields allows partial responses to be retrieved. See 900// https://developers.google.com/gdata/docs/2.0/basics#PartialResponse 901// for more information. 902func (c *ProjectsUpdateBillingInfoCall) Fields(s ...googleapi.Field) *ProjectsUpdateBillingInfoCall { 903 c.urlParams_.Set("fields", googleapi.CombineFields(s)) 904 return c 905} 906 907// Context sets the context to be used in this call's Do method. Any 908// pending HTTP request will be aborted if the provided context is 909// canceled. 910func (c *ProjectsUpdateBillingInfoCall) Context(ctx context.Context) *ProjectsUpdateBillingInfoCall { 911 c.ctx_ = ctx 912 return c 913} 914 915func (c *ProjectsUpdateBillingInfoCall) doRequest(alt string) (*http.Response, error) { 916 var body io.Reader = nil 917 body, err := googleapi.WithoutDataWrapper.JSONReader(c.projectbillinginfo) 918 if err != nil { 919 return nil, err 920 } 921 ctype := "application/json" 922 c.urlParams_.Set("alt", alt) 923 urls := googleapi.ResolveRelative(c.s.BasePath, "v1/{+name}/billingInfo") 924 urls += "?" + c.urlParams_.Encode() 925 req, _ := http.NewRequest("PUT", urls, body) 926 googleapi.Expand(req.URL, map[string]string{ 927 "name": c.name, 928 }) 929 req.Header.Set("Content-Type", ctype) 930 req.Header.Set("User-Agent", c.s.userAgent()) 931 if c.ctx_ != nil { 932 return ctxhttp.Do(c.ctx_, c.s.client, req) 933 } 934 return c.s.client.Do(req) 935} 936 937// Do executes the "cloudbilling.projects.updateBillingInfo" call. 938// Exactly one of *ProjectBillingInfo or error will be non-nil. Any 939// non-2xx status code is an error. Response headers are in either 940// *ProjectBillingInfo.ServerResponse.Header or (if a response was 941// returned at all) in error.(*googleapi.Error).Header. Use 942// googleapi.IsNotModified to check whether the returned error was 943// because http.StatusNotModified was returned. 944func (c *ProjectsUpdateBillingInfoCall) Do(opts ...googleapi.CallOption) (*ProjectBillingInfo, error) { 945 gensupport.SetOptions(c.urlParams_, opts...) 946 res, err := c.doRequest("json") 947 if res != nil && res.StatusCode == http.StatusNotModified { 948 if res.Body != nil { 949 res.Body.Close() 950 } 951 return nil, &googleapi.Error{ 952 Code: res.StatusCode, 953 Header: res.Header, 954 } 955 } 956 if err != nil { 957 return nil, err 958 } 959 defer googleapi.CloseBody(res) 960 if err := googleapi.CheckResponse(res); err != nil { 961 return nil, err 962 } 963 ret := &ProjectBillingInfo{ 964 ServerResponse: googleapi.ServerResponse{ 965 Header: res.Header, 966 HTTPStatusCode: res.StatusCode, 967 }, 968 } 969 if err := json.NewDecoder(res.Body).Decode(&ret); err != nil { 970 return nil, err 971 } 972 return ret, nil 973 // { 974 // "description": "Sets or updates the billing account associated with a project. You specify the new billing account by setting the `billing_account_name` in the `ProjectBillingInfo` resource to the resource name of a billing account. Associating a project with an open billing account enables billing on the project and allows charges for resource usage. If the project already had a billing account, this method changes the billing account used for resource usage charges. *Note:* Incurred charges that have not yet been reported in the transaction history of the Google Developers Console may be billed to the new billing account, even if the charge occurred before the new billing account was assigned to the project. The current authenticated user must have ownership privileges for both the [project](https://cloud.google.com/docs/permissions-overview#h.bgs0oxofvnoo ) and the [billing account](https://support.google.com/cloud/answer/4430947). You can disable billing on the project by setting the `billing_account_name` field to empty. This action disassociates the current billing account from the project. Any billable activity of your in-use services will stop, and your application could stop functioning as expected. Any unbilled charges to date will be billed to the previously associated account. The current authenticated user must be either an owner of the project or an owner of the billing account for the project. Note that associating a project with a *closed* billing account will have much the same effect as disabling billing on the project: any paid resources used by the project will be shut down. Thus, unless you wish to disable billing, you should always call this method with the name of an *open* billing account.", 975 // "httpMethod": "PUT", 976 // "id": "cloudbilling.projects.updateBillingInfo", 977 // "parameterOrder": [ 978 // "name" 979 // ], 980 // "parameters": { 981 // "name": { 982 // "description": "The resource name of the project associated with the billing information that you want to update. For example, `projects/tokyo-rain-123`.", 983 // "location": "path", 984 // "pattern": "^projects/[^/]*$", 985 // "required": true, 986 // "type": "string" 987 // } 988 // }, 989 // "path": "v1/{+name}/billingInfo", 990 // "request": { 991 // "$ref": "ProjectBillingInfo" 992 // }, 993 // "response": { 994 // "$ref": "ProjectBillingInfo" 995 // }, 996 // "scopes": [ 997 // "https://www.googleapis.com/auth/cloud-platform" 998 // ] 999 // } 1000 1001} 1002