blob: 2ed64c9b992a62c3318aa38cb701926cca89d1f0 [file] [log] [blame]
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Code generated by protoc-gen-go_gapic. DO NOT EDIT.
package resourcemanager
import (
"context"
"fmt"
"math"
"net/url"
"time"
"cloud.google.com/go/longrunning"
lroauto "cloud.google.com/go/longrunning/autogen"
gax "github.com/googleapis/gax-go/v2"
"google.golang.org/api/iterator"
"google.golang.org/api/option"
"google.golang.org/api/option/internaloption"
gtransport "google.golang.org/api/transport/grpc"
resourcemanagerpb "google.golang.org/genproto/googleapis/cloud/resourcemanager/v3"
iampb "google.golang.org/genproto/googleapis/iam/v1"
longrunningpb "google.golang.org/genproto/googleapis/longrunning"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/protobuf/proto"
)
var newProjectsClientHook clientHook
// ProjectsCallOptions contains the retry settings for each method of ProjectsClient.
type ProjectsCallOptions struct {
GetProject []gax.CallOption
ListProjects []gax.CallOption
SearchProjects []gax.CallOption
CreateProject []gax.CallOption
UpdateProject []gax.CallOption
MoveProject []gax.CallOption
DeleteProject []gax.CallOption
UndeleteProject []gax.CallOption
GetIamPolicy []gax.CallOption
SetIamPolicy []gax.CallOption
TestIamPermissions []gax.CallOption
}
func defaultProjectsGRPCClientOptions() []option.ClientOption {
return []option.ClientOption{
internaloption.WithDefaultEndpoint("cloudresourcemanager.googleapis.com:443"),
internaloption.WithDefaultMTLSEndpoint("cloudresourcemanager.mtls.googleapis.com:443"),
internaloption.WithDefaultAudience("https://cloudresourcemanager.googleapis.com/"),
internaloption.WithDefaultScopes(DefaultAuthScopes()...),
internaloption.EnableJwtWithScope(),
option.WithGRPCDialOption(grpc.WithDisableServiceConfig()),
option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
grpc.MaxCallRecvMsgSize(math.MaxInt32))),
}
}
func defaultProjectsCallOptions() *ProjectsCallOptions {
return &ProjectsCallOptions{
GetProject: []gax.CallOption{
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.Unavailable,
}, gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.30,
})
}),
},
ListProjects: []gax.CallOption{
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.Unavailable,
}, gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.30,
})
}),
},
SearchProjects: []gax.CallOption{},
CreateProject: []gax.CallOption{},
UpdateProject: []gax.CallOption{},
MoveProject: []gax.CallOption{},
DeleteProject: []gax.CallOption{},
UndeleteProject: []gax.CallOption{},
GetIamPolicy: []gax.CallOption{
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.Unavailable,
}, gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.30,
})
}),
},
SetIamPolicy: []gax.CallOption{},
TestIamPermissions: []gax.CallOption{},
}
}
// internalProjectsClient is an interface that defines the methods availaible from Cloud Resource Manager API.
type internalProjectsClient interface {
Close() error
setGoogleClientInfo(...string)
Connection() *grpc.ClientConn
GetProject(context.Context, *resourcemanagerpb.GetProjectRequest, ...gax.CallOption) (*resourcemanagerpb.Project, error)
ListProjects(context.Context, *resourcemanagerpb.ListProjectsRequest, ...gax.CallOption) *ProjectIterator
SearchProjects(context.Context, *resourcemanagerpb.SearchProjectsRequest, ...gax.CallOption) *ProjectIterator
CreateProject(context.Context, *resourcemanagerpb.CreateProjectRequest, ...gax.CallOption) (*CreateProjectOperation, error)
CreateProjectOperation(name string) *CreateProjectOperation
UpdateProject(context.Context, *resourcemanagerpb.UpdateProjectRequest, ...gax.CallOption) (*UpdateProjectOperation, error)
UpdateProjectOperation(name string) *UpdateProjectOperation
MoveProject(context.Context, *resourcemanagerpb.MoveProjectRequest, ...gax.CallOption) (*MoveProjectOperation, error)
MoveProjectOperation(name string) *MoveProjectOperation
DeleteProject(context.Context, *resourcemanagerpb.DeleteProjectRequest, ...gax.CallOption) (*DeleteProjectOperation, error)
DeleteProjectOperation(name string) *DeleteProjectOperation
UndeleteProject(context.Context, *resourcemanagerpb.UndeleteProjectRequest, ...gax.CallOption) (*UndeleteProjectOperation, error)
UndeleteProjectOperation(name string) *UndeleteProjectOperation
GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)
}
// ProjectsClient is a client for interacting with Cloud Resource Manager API.
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
//
// Manages Google Cloud Projects.
type ProjectsClient struct {
// The internal transport-dependent client.
internalClient internalProjectsClient
// The call options for this service.
CallOptions *ProjectsCallOptions
// LROClient is used internally to handle long-running operations.
// It is exposed so that its CallOptions can be modified if required.
// Users should not Close this client.
LROClient *lroauto.OperationsClient
}
// Wrapper methods routed to the internal client.
// Close closes the connection to the API service. The user should invoke this when
// the client is no longer required.
func (c *ProjectsClient) Close() error {
return c.internalClient.Close()
}
// setGoogleClientInfo sets the name and version of the application in
// the `x-goog-api-client` header passed on each request. Intended for
// use by Google-written clients.
func (c *ProjectsClient) setGoogleClientInfo(keyval ...string) {
c.internalClient.setGoogleClientInfo(keyval...)
}
// Connection returns a connection to the API service.
//
// Deprecated.
func (c *ProjectsClient) Connection() *grpc.ClientConn {
return c.internalClient.Connection()
}
// GetProject retrieves the project identified by the specified name (for example,
// projects/415104041262).
//
// The caller must have resourcemanager.projects.get permission
// for this project.
func (c *ProjectsClient) GetProject(ctx context.Context, req *resourcemanagerpb.GetProjectRequest, opts ...gax.CallOption) (*resourcemanagerpb.Project, error) {
return c.internalClient.GetProject(ctx, req, opts...)
}
// ListProjects lists projects that are direct children of the specified folder or
// organization resource. list() provides a strongly consistent view of the
// projects underneath the specified parent resource. list() returns
// projects sorted based upon the (ascending) lexical ordering of their
// display_name. The caller must have resourcemanager.projects.list
// permission on the identified parent.
func (c *ProjectsClient) ListProjects(ctx context.Context, req *resourcemanagerpb.ListProjectsRequest, opts ...gax.CallOption) *ProjectIterator {
return c.internalClient.ListProjects(ctx, req, opts...)
}
// SearchProjects search for projects that the caller has both resourcemanager.projects.get
// permission on, and also satisfy the specified query.
//
// This method returns projects in an unspecified order.
//
// This method is eventually consistent with project mutations; this means
// that a newly created project may not appear in the results or recent
// updates to an existing project may not be reflected in the results. To
// retrieve the latest state of a project, use the
// GetProject method.
func (c *ProjectsClient) SearchProjects(ctx context.Context, req *resourcemanagerpb.SearchProjectsRequest, opts ...gax.CallOption) *ProjectIterator {
return c.internalClient.SearchProjects(ctx, req, opts...)
}
// CreateProject request that a new project be created. The result is an Operation which
// can be used to track the creation process. This process usually takes a few
// seconds, but can sometimes take much longer. The tracking Operation is
// automatically deleted after a few hours, so there is no need to call
// DeleteOperation.
func (c *ProjectsClient) CreateProject(ctx context.Context, req *resourcemanagerpb.CreateProjectRequest, opts ...gax.CallOption) (*CreateProjectOperation, error) {
return c.internalClient.CreateProject(ctx, req, opts...)
}
// CreateProjectOperation returns a new CreateProjectOperation from a given name.
// The name must be that of a previously created CreateProjectOperation, possibly from a different process.
func (c *ProjectsClient) CreateProjectOperation(name string) *CreateProjectOperation {
return c.internalClient.CreateProjectOperation(name)
}
// UpdateProject updates the display_name and labels of the project identified by the
// specified name (for example, projects/415104041262). Deleting all
// labels requires an update mask for labels field.
//
// The caller must have resourcemanager.projects.update permission for this
// project.
func (c *ProjectsClient) UpdateProject(ctx context.Context, req *resourcemanagerpb.UpdateProjectRequest, opts ...gax.CallOption) (*UpdateProjectOperation, error) {
return c.internalClient.UpdateProject(ctx, req, opts...)
}
// UpdateProjectOperation returns a new UpdateProjectOperation from a given name.
// The name must be that of a previously created UpdateProjectOperation, possibly from a different process.
func (c *ProjectsClient) UpdateProjectOperation(name string) *UpdateProjectOperation {
return c.internalClient.UpdateProjectOperation(name)
}
// MoveProject move a project to another place in your resource hierarchy, under a new
// resource parent.
//
// Returns an operation which can be used to track the process of the project
// move workflow.
// Upon success, the Operation.response field will be populated with the
// moved project.
//
// The caller must have resourcemanager.projects.update permission on the
// project and have resourcemanager.projects.move permission on the
// project’s current and proposed new parent.
func (c *ProjectsClient) MoveProject(ctx context.Context, req *resourcemanagerpb.MoveProjectRequest, opts ...gax.CallOption) (*MoveProjectOperation, error) {
return c.internalClient.MoveProject(ctx, req, opts...)
}
// MoveProjectOperation returns a new MoveProjectOperation from a given name.
// The name must be that of a previously created MoveProjectOperation, possibly from a different process.
func (c *ProjectsClient) MoveProjectOperation(name string) *MoveProjectOperation {
return c.internalClient.MoveProjectOperation(name)
}
// DeleteProject marks the project identified by the specified
// name (for example, projects/415104041262) for deletion.
//
// This method will only affect the project if it has a lifecycle state of
// [ACTIVE][google.cloud.resourcemanager.v3.Project.State.ACTIVE (at http://google.cloud.resourcemanager.v3.Project.State.ACTIVE)].
//
// This method changes the Project’s lifecycle state from
// [ACTIVE][google.cloud.resourcemanager.v3.Project.State.ACTIVE (at http://google.cloud.resourcemanager.v3.Project.State.ACTIVE)]
// to DELETE_REQUESTED.
// The deletion starts at an unspecified time,
// at which point the Project is no longer accessible.
//
// Until the deletion completes, you can check the lifecycle state
// checked by retrieving the project with [GetProject]
// [google.cloud.resourcemanager.v3.Projects.GetProject],
// and the project remains visible to [ListProjects]
// [google.cloud.resourcemanager.v3.Projects.ListProjects].
// However, you cannot update the project.
//
// After the deletion completes, the project is not retrievable by
// the [GetProject]
// [google.cloud.resourcemanager.v3.Projects.GetProject],
// [ListProjects]
// [google.cloud.resourcemanager.v3.Projects.ListProjects], and
// SearchProjects
// methods.
//
// This method behaves idempotently, such that deleting a DELETE_REQUESTED
// project will not cause an error, but also won’t do anything.
//
// The caller must have resourcemanager.projects.delete permissions for this
// project.
func (c *ProjectsClient) DeleteProject(ctx context.Context, req *resourcemanagerpb.DeleteProjectRequest, opts ...gax.CallOption) (*DeleteProjectOperation, error) {
return c.internalClient.DeleteProject(ctx, req, opts...)
}
// DeleteProjectOperation returns a new DeleteProjectOperation from a given name.
// The name must be that of a previously created DeleteProjectOperation, possibly from a different process.
func (c *ProjectsClient) DeleteProjectOperation(name string) *DeleteProjectOperation {
return c.internalClient.DeleteProjectOperation(name)
}
// UndeleteProject restores the project identified by the specified
// name (for example, projects/415104041262).
// You can only use this method for a project that has a lifecycle state of
// [DELETE_REQUESTED]
// [Projects.State.DELETE_REQUESTED].
// After deletion starts, the project cannot be restored.
//
// The caller must have resourcemanager.projects.undelete permission for
// this project.
func (c *ProjectsClient) UndeleteProject(ctx context.Context, req *resourcemanagerpb.UndeleteProjectRequest, opts ...gax.CallOption) (*UndeleteProjectOperation, error) {
return c.internalClient.UndeleteProject(ctx, req, opts...)
}
// UndeleteProjectOperation returns a new UndeleteProjectOperation from a given name.
// The name must be that of a previously created UndeleteProjectOperation, possibly from a different process.
func (c *ProjectsClient) UndeleteProjectOperation(name string) *UndeleteProjectOperation {
return c.internalClient.UndeleteProjectOperation(name)
}
// GetIamPolicy returns the IAM access control policy for the specified project.
// Permission is denied if the policy or the resource do not exist.
func (c *ProjectsClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
return c.internalClient.GetIamPolicy(ctx, req, opts...)
}
// SetIamPolicy sets the IAM access control policy for the specified project.
//
// CAUTION: This method will replace the existing policy, and cannot be used
// to append additional IAM settings.
//
// Note: Removing service accounts from policies or changing their roles can
// render services completely inoperable. It is important to understand how
// the service account is being used before removing or updating its roles.
//
// The following constraints apply when using setIamPolicy():
//
// Project does not support allUsers and allAuthenticatedUsers as
// members in a Binding of a Policy.
//
// The owner role can be granted to a user, serviceAccount, or a group
// that is part of an organization. For example,
// group@myownpersonaldomain.com (at mailto:group@myownpersonaldomain.com) could be added as an owner to a project in
// the myownpersonaldomain.com (at http://myownpersonaldomain.com) organization, but not the examplepetstore.com (at http://examplepetstore.com)
// organization.
//
// Service accounts can be made owners of a project directly
// without any restrictions. However, to be added as an owner, a user must be
// invited using the Cloud Platform console and must accept the invitation.
//
// A user cannot be granted the owner role using setIamPolicy(). The user
// must be granted the owner role using the Cloud Platform Console and must
// explicitly accept the invitation.
//
// Invitations to grant the owner role cannot be sent using
// setIamPolicy();
// they must be sent only using the Cloud Platform Console.
//
// Membership changes that leave the project without any owners that have
// accepted the Terms of Service (ToS) will be rejected.
//
// If the project is not part of an organization, there must be at least
// one owner who has accepted the Terms of Service (ToS) agreement in the
// policy. Calling setIamPolicy() to remove the last ToS-accepted owner
// from the policy will fail. This restriction also applies to legacy
// projects that no longer have owners who have accepted the ToS. Edits to
// IAM policies will be rejected until the lack of a ToS-accepting owner is
// rectified.
//
// Calling this method requires enabling the App Engine Admin API.
func (c *ProjectsClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
return c.internalClient.SetIamPolicy(ctx, req, opts...)
}
// TestIamPermissions returns permissions that a caller has on the specified project.
func (c *ProjectsClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
return c.internalClient.TestIamPermissions(ctx, req, opts...)
}
// projectsGRPCClient is a client for interacting with Cloud Resource Manager API over gRPC transport.
//
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
type projectsGRPCClient struct {
// Connection pool of gRPC connections to the service.
connPool gtransport.ConnPool
// flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE
disableDeadlines bool
// Points back to the CallOptions field of the containing ProjectsClient
CallOptions **ProjectsCallOptions
// The gRPC API client.
projectsClient resourcemanagerpb.ProjectsClient
// LROClient is used internally to handle long-running operations.
// It is exposed so that its CallOptions can be modified if required.
// Users should not Close this client.
LROClient **lroauto.OperationsClient
// The x-goog-* metadata to be sent with each request.
xGoogMetadata metadata.MD
}
// NewProjectsClient creates a new projects client based on gRPC.
// The returned client must be Closed when it is done being used to clean up its underlying connections.
//
// Manages Google Cloud Projects.
func NewProjectsClient(ctx context.Context, opts ...option.ClientOption) (*ProjectsClient, error) {
clientOpts := defaultProjectsGRPCClientOptions()
if newProjectsClientHook != nil {
hookOpts, err := newProjectsClientHook(ctx, clientHookParams{})
if err != nil {
return nil, err
}
clientOpts = append(clientOpts, hookOpts...)
}
disableDeadlines, err := checkDisableDeadlines()
if err != nil {
return nil, err
}
connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
if err != nil {
return nil, err
}
client := ProjectsClient{CallOptions: defaultProjectsCallOptions()}
c := &projectsGRPCClient{
connPool: connPool,
disableDeadlines: disableDeadlines,
projectsClient: resourcemanagerpb.NewProjectsClient(connPool),
CallOptions: &client.CallOptions,
}
c.setGoogleClientInfo()
client.internalClient = c
client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
if err != nil {
// This error "should not happen", since we are just reusing old connection pool
// and never actually need to dial.
// If this does happen, we could leak connp. However, we cannot close conn:
// If the user invoked the constructor with option.WithGRPCConn,
// we would close a connection that's still in use.
// TODO: investigate error conditions.
return nil, err
}
c.LROClient = &client.LROClient
return &client, nil
}
// Connection returns a connection to the API service.
//
// Deprecated.
func (c *projectsGRPCClient) Connection() *grpc.ClientConn {
return c.connPool.Conn()
}
// setGoogleClientInfo sets the name and version of the application in
// the `x-goog-api-client` header passed on each request. Intended for
// use by Google-written clients.
func (c *projectsGRPCClient) setGoogleClientInfo(keyval ...string) {
kv := append([]string{"gl-go", versionGo()}, keyval...)
kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
}
// Close closes the connection to the API service. The user should invoke this when
// the client is no longer required.
func (c *projectsGRPCClient) Close() error {
return c.connPool.Close()
}
func (c *projectsGRPCClient) GetProject(ctx context.Context, req *resourcemanagerpb.GetProjectRequest, opts ...gax.CallOption) (*resourcemanagerpb.Project, error) {
if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond)
defer cancel()
ctx = cctx
}
md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
ctx = insertMetadata(ctx, c.xGoogMetadata, md)
opts = append((*c.CallOptions).GetProject[0:len((*c.CallOptions).GetProject):len((*c.CallOptions).GetProject)], opts...)
var resp *resourcemanagerpb.Project
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = c.projectsClient.GetProject(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
func (c *projectsGRPCClient) ListProjects(ctx context.Context, req *resourcemanagerpb.ListProjectsRequest, opts ...gax.CallOption) *ProjectIterator {
ctx = insertMetadata(ctx, c.xGoogMetadata)
opts = append((*c.CallOptions).ListProjects[0:len((*c.CallOptions).ListProjects):len((*c.CallOptions).ListProjects)], opts...)
it := &ProjectIterator{}
req = proto.Clone(req).(*resourcemanagerpb.ListProjectsRequest)
it.InternalFetch = func(pageSize int, pageToken string) ([]*resourcemanagerpb.Project, string, error) {
resp := &resourcemanagerpb.ListProjectsResponse{}
if pageToken != "" {
req.PageToken = pageToken
}
if pageSize > math.MaxInt32 {
req.PageSize = math.MaxInt32
} else if pageSize != 0 {
req.PageSize = int32(pageSize)
}
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = c.projectsClient.ListProjects(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, "", err
}
it.Response = resp
return resp.GetProjects(), resp.GetNextPageToken(), nil
}
fetch := func(pageSize int, pageToken string) (string, error) {
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
if err != nil {
return "", err
}
it.items = append(it.items, items...)
return nextPageToken, nil
}
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
it.pageInfo.MaxSize = int(req.GetPageSize())
it.pageInfo.Token = req.GetPageToken()
return it
}
func (c *projectsGRPCClient) SearchProjects(ctx context.Context, req *resourcemanagerpb.SearchProjectsRequest, opts ...gax.CallOption) *ProjectIterator {
ctx = insertMetadata(ctx, c.xGoogMetadata)
opts = append((*c.CallOptions).SearchProjects[0:len((*c.CallOptions).SearchProjects):len((*c.CallOptions).SearchProjects)], opts...)
it := &ProjectIterator{}
req = proto.Clone(req).(*resourcemanagerpb.SearchProjectsRequest)
it.InternalFetch = func(pageSize int, pageToken string) ([]*resourcemanagerpb.Project, string, error) {
resp := &resourcemanagerpb.SearchProjectsResponse{}
if pageToken != "" {
req.PageToken = pageToken
}
if pageSize > math.MaxInt32 {
req.PageSize = math.MaxInt32
} else if pageSize != 0 {
req.PageSize = int32(pageSize)
}
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = c.projectsClient.SearchProjects(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, "", err
}
it.Response = resp
return resp.GetProjects(), resp.GetNextPageToken(), nil
}
fetch := func(pageSize int, pageToken string) (string, error) {
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
if err != nil {
return "", err
}
it.items = append(it.items, items...)
return nextPageToken, nil
}
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
it.pageInfo.MaxSize = int(req.GetPageSize())
it.pageInfo.Token = req.GetPageToken()
return it
}
func (c *projectsGRPCClient) CreateProject(ctx context.Context, req *resourcemanagerpb.CreateProjectRequest, opts ...gax.CallOption) (*CreateProjectOperation, error) {
if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond)
defer cancel()
ctx = cctx
}
ctx = insertMetadata(ctx, c.xGoogMetadata)
opts = append((*c.CallOptions).CreateProject[0:len((*c.CallOptions).CreateProject):len((*c.CallOptions).CreateProject)], opts...)
var resp *longrunningpb.Operation
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = c.projectsClient.CreateProject(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, err
}
return &CreateProjectOperation{
lro: longrunning.InternalNewOperation(*c.LROClient, resp),
}, nil
}
func (c *projectsGRPCClient) UpdateProject(ctx context.Context, req *resourcemanagerpb.UpdateProjectRequest, opts ...gax.CallOption) (*UpdateProjectOperation, error) {
if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond)
defer cancel()
ctx = cctx
}
md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "project.name", url.QueryEscape(req.GetProject().GetName())))
ctx = insertMetadata(ctx, c.xGoogMetadata, md)
opts = append((*c.CallOptions).UpdateProject[0:len((*c.CallOptions).UpdateProject):len((*c.CallOptions).UpdateProject)], opts...)
var resp *longrunningpb.Operation
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = c.projectsClient.UpdateProject(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, err
}
return &UpdateProjectOperation{
lro: longrunning.InternalNewOperation(*c.LROClient, resp),
}, nil
}
func (c *projectsGRPCClient) MoveProject(ctx context.Context, req *resourcemanagerpb.MoveProjectRequest, opts ...gax.CallOption) (*MoveProjectOperation, error) {
if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond)
defer cancel()
ctx = cctx
}
md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
ctx = insertMetadata(ctx, c.xGoogMetadata, md)
opts = append((*c.CallOptions).MoveProject[0:len((*c.CallOptions).MoveProject):len((*c.CallOptions).MoveProject)], opts...)
var resp *longrunningpb.Operation
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = c.projectsClient.MoveProject(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, err
}
return &MoveProjectOperation{
lro: longrunning.InternalNewOperation(*c.LROClient, resp),
}, nil
}
func (c *projectsGRPCClient) DeleteProject(ctx context.Context, req *resourcemanagerpb.DeleteProjectRequest, opts ...gax.CallOption) (*DeleteProjectOperation, error) {
if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond)
defer cancel()
ctx = cctx
}
md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
ctx = insertMetadata(ctx, c.xGoogMetadata, md)
opts = append((*c.CallOptions).DeleteProject[0:len((*c.CallOptions).DeleteProject):len((*c.CallOptions).DeleteProject)], opts...)
var resp *longrunningpb.Operation
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = c.projectsClient.DeleteProject(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, err
}
return &DeleteProjectOperation{
lro: longrunning.InternalNewOperation(*c.LROClient, resp),
}, nil
}
func (c *projectsGRPCClient) UndeleteProject(ctx context.Context, req *resourcemanagerpb.UndeleteProjectRequest, opts ...gax.CallOption) (*UndeleteProjectOperation, error) {
if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond)
defer cancel()
ctx = cctx
}
md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
ctx = insertMetadata(ctx, c.xGoogMetadata, md)
opts = append((*c.CallOptions).UndeleteProject[0:len((*c.CallOptions).UndeleteProject):len((*c.CallOptions).UndeleteProject)], opts...)
var resp *longrunningpb.Operation
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = c.projectsClient.UndeleteProject(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, err
}
return &UndeleteProjectOperation{
lro: longrunning.InternalNewOperation(*c.LROClient, resp),
}, nil
}
func (c *projectsGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond)
defer cancel()
ctx = cctx
}
md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource())))
ctx = insertMetadata(ctx, c.xGoogMetadata, md)
opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
var resp *iampb.Policy
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = c.projectsClient.GetIamPolicy(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
func (c *projectsGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond)
defer cancel()
ctx = cctx
}
md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource())))
ctx = insertMetadata(ctx, c.xGoogMetadata, md)
opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
var resp *iampb.Policy
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = c.projectsClient.SetIamPolicy(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
func (c *projectsGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource())))
ctx = insertMetadata(ctx, c.xGoogMetadata, md)
opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
var resp *iampb.TestIamPermissionsResponse
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = c.projectsClient.TestIamPermissions(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
// CreateProjectOperation manages a long-running operation from CreateProject.
type CreateProjectOperation struct {
lro *longrunning.Operation
}
// CreateProjectOperation returns a new CreateProjectOperation from a given name.
// The name must be that of a previously created CreateProjectOperation, possibly from a different process.
func (c *projectsGRPCClient) CreateProjectOperation(name string) *CreateProjectOperation {
return &CreateProjectOperation{
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
}
}
// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
//
// See documentation of Poll for error-handling information.
func (op *CreateProjectOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*resourcemanagerpb.Project, error) {
var resp resourcemanagerpb.Project
if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
return nil, err
}
return &resp, nil
}
// Poll fetches the latest state of the long-running operation.
//
// Poll also fetches the latest metadata, which can be retrieved by Metadata.
//
// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
// the operation has completed with failure, the error is returned and op.Done will return true.
// If Poll succeeds and the operation has completed successfully,
// op.Done will return true, and the response of the operation is returned.
// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
func (op *CreateProjectOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*resourcemanagerpb.Project, error) {
var resp resourcemanagerpb.Project
if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
return nil, err
}
if !op.Done() {
return nil, nil
}
return &resp, nil
}
// Metadata returns metadata associated with the long-running operation.
// Metadata itself does not contact the server, but Poll does.
// To get the latest metadata, call this method after a successful call to Poll.
// If the metadata is not available, the returned metadata and error are both nil.
func (op *CreateProjectOperation) Metadata() (*resourcemanagerpb.CreateProjectMetadata, error) {
var meta resourcemanagerpb.CreateProjectMetadata
if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
return nil, nil
} else if err != nil {
return nil, err
}
return &meta, nil
}
// Done reports whether the long-running operation has completed.
func (op *CreateProjectOperation) Done() bool {
return op.lro.Done()
}
// Name returns the name of the long-running operation.
// The name is assigned by the server and is unique within the service from which the operation is created.
func (op *CreateProjectOperation) Name() string {
return op.lro.Name()
}
// DeleteProjectOperation manages a long-running operation from DeleteProject.
type DeleteProjectOperation struct {
lro *longrunning.Operation
}
// DeleteProjectOperation returns a new DeleteProjectOperation from a given name.
// The name must be that of a previously created DeleteProjectOperation, possibly from a different process.
func (c *projectsGRPCClient) DeleteProjectOperation(name string) *DeleteProjectOperation {
return &DeleteProjectOperation{
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
}
}
// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
//
// See documentation of Poll for error-handling information.
func (op *DeleteProjectOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*resourcemanagerpb.Project, error) {
var resp resourcemanagerpb.Project
if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
return nil, err
}
return &resp, nil
}
// Poll fetches the latest state of the long-running operation.
//
// Poll also fetches the latest metadata, which can be retrieved by Metadata.
//
// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
// the operation has completed with failure, the error is returned and op.Done will return true.
// If Poll succeeds and the operation has completed successfully,
// op.Done will return true, and the response of the operation is returned.
// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
func (op *DeleteProjectOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*resourcemanagerpb.Project, error) {
var resp resourcemanagerpb.Project
if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
return nil, err
}
if !op.Done() {
return nil, nil
}
return &resp, nil
}
// Metadata returns metadata associated with the long-running operation.
// Metadata itself does not contact the server, but Poll does.
// To get the latest metadata, call this method after a successful call to Poll.
// If the metadata is not available, the returned metadata and error are both nil.
func (op *DeleteProjectOperation) Metadata() (*resourcemanagerpb.DeleteProjectMetadata, error) {
var meta resourcemanagerpb.DeleteProjectMetadata
if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
return nil, nil
} else if err != nil {
return nil, err
}
return &meta, nil
}
// Done reports whether the long-running operation has completed.
func (op *DeleteProjectOperation) Done() bool {
return op.lro.Done()
}
// Name returns the name of the long-running operation.
// The name is assigned by the server and is unique within the service from which the operation is created.
func (op *DeleteProjectOperation) Name() string {
return op.lro.Name()
}
// MoveProjectOperation manages a long-running operation from MoveProject.
type MoveProjectOperation struct {
lro *longrunning.Operation
}
// MoveProjectOperation returns a new MoveProjectOperation from a given name.
// The name must be that of a previously created MoveProjectOperation, possibly from a different process.
func (c *projectsGRPCClient) MoveProjectOperation(name string) *MoveProjectOperation {
return &MoveProjectOperation{
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
}
}
// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
//
// See documentation of Poll for error-handling information.
func (op *MoveProjectOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*resourcemanagerpb.Project, error) {
var resp resourcemanagerpb.Project
if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
return nil, err
}
return &resp, nil
}
// Poll fetches the latest state of the long-running operation.
//
// Poll also fetches the latest metadata, which can be retrieved by Metadata.
//
// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
// the operation has completed with failure, the error is returned and op.Done will return true.
// If Poll succeeds and the operation has completed successfully,
// op.Done will return true, and the response of the operation is returned.
// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
func (op *MoveProjectOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*resourcemanagerpb.Project, error) {
var resp resourcemanagerpb.Project
if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
return nil, err
}
if !op.Done() {
return nil, nil
}
return &resp, nil
}
// Metadata returns metadata associated with the long-running operation.
// Metadata itself does not contact the server, but Poll does.
// To get the latest metadata, call this method after a successful call to Poll.
// If the metadata is not available, the returned metadata and error are both nil.
func (op *MoveProjectOperation) Metadata() (*resourcemanagerpb.MoveProjectMetadata, error) {
var meta resourcemanagerpb.MoveProjectMetadata
if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
return nil, nil
} else if err != nil {
return nil, err
}
return &meta, nil
}
// Done reports whether the long-running operation has completed.
func (op *MoveProjectOperation) Done() bool {
return op.lro.Done()
}
// Name returns the name of the long-running operation.
// The name is assigned by the server and is unique within the service from which the operation is created.
func (op *MoveProjectOperation) Name() string {
return op.lro.Name()
}
// UndeleteProjectOperation manages a long-running operation from UndeleteProject.
type UndeleteProjectOperation struct {
lro *longrunning.Operation
}
// UndeleteProjectOperation returns a new UndeleteProjectOperation from a given name.
// The name must be that of a previously created UndeleteProjectOperation, possibly from a different process.
func (c *projectsGRPCClient) UndeleteProjectOperation(name string) *UndeleteProjectOperation {
return &UndeleteProjectOperation{
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
}
}
// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
//
// See documentation of Poll for error-handling information.
func (op *UndeleteProjectOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*resourcemanagerpb.Project, error) {
var resp resourcemanagerpb.Project
if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
return nil, err
}
return &resp, nil
}
// Poll fetches the latest state of the long-running operation.
//
// Poll also fetches the latest metadata, which can be retrieved by Metadata.
//
// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
// the operation has completed with failure, the error is returned and op.Done will return true.
// If Poll succeeds and the operation has completed successfully,
// op.Done will return true, and the response of the operation is returned.
// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
func (op *UndeleteProjectOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*resourcemanagerpb.Project, error) {
var resp resourcemanagerpb.Project
if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
return nil, err
}
if !op.Done() {
return nil, nil
}
return &resp, nil
}
// Metadata returns metadata associated with the long-running operation.
// Metadata itself does not contact the server, but Poll does.
// To get the latest metadata, call this method after a successful call to Poll.
// If the metadata is not available, the returned metadata and error are both nil.
func (op *UndeleteProjectOperation) Metadata() (*resourcemanagerpb.UndeleteProjectMetadata, error) {
var meta resourcemanagerpb.UndeleteProjectMetadata
if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
return nil, nil
} else if err != nil {
return nil, err
}
return &meta, nil
}
// Done reports whether the long-running operation has completed.
func (op *UndeleteProjectOperation) Done() bool {
return op.lro.Done()
}
// Name returns the name of the long-running operation.
// The name is assigned by the server and is unique within the service from which the operation is created.
func (op *UndeleteProjectOperation) Name() string {
return op.lro.Name()
}
// UpdateProjectOperation manages a long-running operation from UpdateProject.
type UpdateProjectOperation struct {
lro *longrunning.Operation
}
// UpdateProjectOperation returns a new UpdateProjectOperation from a given name.
// The name must be that of a previously created UpdateProjectOperation, possibly from a different process.
func (c *projectsGRPCClient) UpdateProjectOperation(name string) *UpdateProjectOperation {
return &UpdateProjectOperation{
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
}
}
// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
//
// See documentation of Poll for error-handling information.
func (op *UpdateProjectOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*resourcemanagerpb.Project, error) {
var resp resourcemanagerpb.Project
if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
return nil, err
}
return &resp, nil
}
// Poll fetches the latest state of the long-running operation.
//
// Poll also fetches the latest metadata, which can be retrieved by Metadata.
//
// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
// the operation has completed with failure, the error is returned and op.Done will return true.
// If Poll succeeds and the operation has completed successfully,
// op.Done will return true, and the response of the operation is returned.
// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
func (op *UpdateProjectOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*resourcemanagerpb.Project, error) {
var resp resourcemanagerpb.Project
if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
return nil, err
}
if !op.Done() {
return nil, nil
}
return &resp, nil
}
// Metadata returns metadata associated with the long-running operation.
// Metadata itself does not contact the server, but Poll does.
// To get the latest metadata, call this method after a successful call to Poll.
// If the metadata is not available, the returned metadata and error are both nil.
func (op *UpdateProjectOperation) Metadata() (*resourcemanagerpb.UpdateProjectMetadata, error) {
var meta resourcemanagerpb.UpdateProjectMetadata
if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
return nil, nil
} else if err != nil {
return nil, err
}
return &meta, nil
}
// Done reports whether the long-running operation has completed.
func (op *UpdateProjectOperation) Done() bool {
return op.lro.Done()
}
// Name returns the name of the long-running operation.
// The name is assigned by the server and is unique within the service from which the operation is created.
func (op *UpdateProjectOperation) Name() string {
return op.lro.Name()
}
// ProjectIterator manages a stream of *resourcemanagerpb.Project.
type ProjectIterator struct {
items []*resourcemanagerpb.Project
pageInfo *iterator.PageInfo
nextFunc func() error
// Response is the raw response for the current page.
// It must be cast to the RPC response type.
// Calling Next() or InternalFetch() updates this value.
Response interface{}
// InternalFetch is for use by the Google Cloud Libraries only.
// It is not part of the stable interface of this package.
//
// InternalFetch returns results from a single call to the underlying RPC.
// The number of results is no greater than pageSize.
// If there are no more results, nextPageToken is empty and err is nil.
InternalFetch func(pageSize int, pageToken string) (results []*resourcemanagerpb.Project, nextPageToken string, err error)
}
// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
func (it *ProjectIterator) PageInfo() *iterator.PageInfo {
return it.pageInfo
}
// Next returns the next result. Its second return value is iterator.Done if there are no more
// results. Once Next returns Done, all subsequent calls will return Done.
func (it *ProjectIterator) Next() (*resourcemanagerpb.Project, error) {
var item *resourcemanagerpb.Project
if err := it.nextFunc(); err != nil {
return item, err
}
item = it.items[0]
it.items = it.items[1:]
return item, nil
}
func (it *ProjectIterator) bufLen() int {
return len(it.items)
}
func (it *ProjectIterator) takeBuf() interface{} {
b := it.items
it.items = nil
return b
}