...

Source file src/cloud.google.com/go/resourcemanager/apiv3/projects_client.go

Documentation: cloud.google.com/go/resourcemanager/apiv3

     1  // Copyright 2024 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     https://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Code generated by protoc-gen-go_gapic. DO NOT EDIT.
    16  
    17  package resourcemanager
    18  
    19  import (
    20  	"bytes"
    21  	"context"
    22  	"fmt"
    23  	"io"
    24  	"math"
    25  	"net/http"
    26  	"net/url"
    27  	"time"
    28  
    29  	iampb "cloud.google.com/go/iam/apiv1/iampb"
    30  	"cloud.google.com/go/longrunning"
    31  	lroauto "cloud.google.com/go/longrunning/autogen"
    32  	longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
    33  	resourcemanagerpb "cloud.google.com/go/resourcemanager/apiv3/resourcemanagerpb"
    34  	gax "github.com/googleapis/gax-go/v2"
    35  	"google.golang.org/api/googleapi"
    36  	"google.golang.org/api/iterator"
    37  	"google.golang.org/api/option"
    38  	"google.golang.org/api/option/internaloption"
    39  	gtransport "google.golang.org/api/transport/grpc"
    40  	httptransport "google.golang.org/api/transport/http"
    41  	"google.golang.org/grpc"
    42  	"google.golang.org/grpc/codes"
    43  	"google.golang.org/protobuf/encoding/protojson"
    44  	"google.golang.org/protobuf/proto"
    45  )
    46  
    47  var newProjectsClientHook clientHook
    48  
    49  // ProjectsCallOptions contains the retry settings for each method of ProjectsClient.
    50  type ProjectsCallOptions struct {
    51  	GetProject         []gax.CallOption
    52  	ListProjects       []gax.CallOption
    53  	SearchProjects     []gax.CallOption
    54  	CreateProject      []gax.CallOption
    55  	UpdateProject      []gax.CallOption
    56  	MoveProject        []gax.CallOption
    57  	DeleteProject      []gax.CallOption
    58  	UndeleteProject    []gax.CallOption
    59  	GetIamPolicy       []gax.CallOption
    60  	SetIamPolicy       []gax.CallOption
    61  	TestIamPermissions []gax.CallOption
    62  	GetOperation       []gax.CallOption
    63  }
    64  
    65  func defaultProjectsGRPCClientOptions() []option.ClientOption {
    66  	return []option.ClientOption{
    67  		internaloption.WithDefaultEndpoint("cloudresourcemanager.googleapis.com:443"),
    68  		internaloption.WithDefaultEndpointTemplate("cloudresourcemanager.UNIVERSE_DOMAIN:443"),
    69  		internaloption.WithDefaultMTLSEndpoint("cloudresourcemanager.mtls.googleapis.com:443"),
    70  		internaloption.WithDefaultUniverseDomain("googleapis.com"),
    71  		internaloption.WithDefaultAudience("https://cloudresourcemanager.googleapis.com/"),
    72  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
    73  		internaloption.EnableJwtWithScope(),
    74  		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
    75  			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
    76  	}
    77  }
    78  
    79  func defaultProjectsCallOptions() *ProjectsCallOptions {
    80  	return &ProjectsCallOptions{
    81  		GetProject: []gax.CallOption{
    82  			gax.WithTimeout(60000 * time.Millisecond),
    83  			gax.WithRetry(func() gax.Retryer {
    84  				return gax.OnCodes([]codes.Code{
    85  					codes.Unavailable,
    86  				}, gax.Backoff{
    87  					Initial:    100 * time.Millisecond,
    88  					Max:        60000 * time.Millisecond,
    89  					Multiplier: 1.30,
    90  				})
    91  			}),
    92  		},
    93  		ListProjects: []gax.CallOption{
    94  			gax.WithTimeout(60000 * time.Millisecond),
    95  			gax.WithRetry(func() gax.Retryer {
    96  				return gax.OnCodes([]codes.Code{
    97  					codes.Unavailable,
    98  				}, gax.Backoff{
    99  					Initial:    100 * time.Millisecond,
   100  					Max:        60000 * time.Millisecond,
   101  					Multiplier: 1.30,
   102  				})
   103  			}),
   104  		},
   105  		SearchProjects: []gax.CallOption{
   106  			gax.WithTimeout(60000 * time.Millisecond),
   107  		},
   108  		CreateProject: []gax.CallOption{
   109  			gax.WithTimeout(60000 * time.Millisecond),
   110  		},
   111  		UpdateProject: []gax.CallOption{
   112  			gax.WithTimeout(60000 * time.Millisecond),
   113  		},
   114  		MoveProject: []gax.CallOption{
   115  			gax.WithTimeout(60000 * time.Millisecond),
   116  		},
   117  		DeleteProject: []gax.CallOption{
   118  			gax.WithTimeout(60000 * time.Millisecond),
   119  		},
   120  		UndeleteProject: []gax.CallOption{
   121  			gax.WithTimeout(60000 * time.Millisecond),
   122  		},
   123  		GetIamPolicy: []gax.CallOption{
   124  			gax.WithTimeout(60000 * time.Millisecond),
   125  			gax.WithRetry(func() gax.Retryer {
   126  				return gax.OnCodes([]codes.Code{
   127  					codes.Unavailable,
   128  				}, gax.Backoff{
   129  					Initial:    100 * time.Millisecond,
   130  					Max:        60000 * time.Millisecond,
   131  					Multiplier: 1.30,
   132  				})
   133  			}),
   134  		},
   135  		SetIamPolicy: []gax.CallOption{
   136  			gax.WithTimeout(60000 * time.Millisecond),
   137  		},
   138  		TestIamPermissions: []gax.CallOption{},
   139  		GetOperation:       []gax.CallOption{},
   140  	}
   141  }
   142  
   143  func defaultProjectsRESTCallOptions() *ProjectsCallOptions {
   144  	return &ProjectsCallOptions{
   145  		GetProject: []gax.CallOption{
   146  			gax.WithTimeout(60000 * time.Millisecond),
   147  			gax.WithRetry(func() gax.Retryer {
   148  				return gax.OnHTTPCodes(gax.Backoff{
   149  					Initial:    100 * time.Millisecond,
   150  					Max:        60000 * time.Millisecond,
   151  					Multiplier: 1.30,
   152  				},
   153  					http.StatusServiceUnavailable)
   154  			}),
   155  		},
   156  		ListProjects: []gax.CallOption{
   157  			gax.WithTimeout(60000 * time.Millisecond),
   158  			gax.WithRetry(func() gax.Retryer {
   159  				return gax.OnHTTPCodes(gax.Backoff{
   160  					Initial:    100 * time.Millisecond,
   161  					Max:        60000 * time.Millisecond,
   162  					Multiplier: 1.30,
   163  				},
   164  					http.StatusServiceUnavailable)
   165  			}),
   166  		},
   167  		SearchProjects: []gax.CallOption{
   168  			gax.WithTimeout(60000 * time.Millisecond),
   169  		},
   170  		CreateProject: []gax.CallOption{
   171  			gax.WithTimeout(60000 * time.Millisecond),
   172  		},
   173  		UpdateProject: []gax.CallOption{
   174  			gax.WithTimeout(60000 * time.Millisecond),
   175  		},
   176  		MoveProject: []gax.CallOption{
   177  			gax.WithTimeout(60000 * time.Millisecond),
   178  		},
   179  		DeleteProject: []gax.CallOption{
   180  			gax.WithTimeout(60000 * time.Millisecond),
   181  		},
   182  		UndeleteProject: []gax.CallOption{
   183  			gax.WithTimeout(60000 * time.Millisecond),
   184  		},
   185  		GetIamPolicy: []gax.CallOption{
   186  			gax.WithTimeout(60000 * time.Millisecond),
   187  			gax.WithRetry(func() gax.Retryer {
   188  				return gax.OnHTTPCodes(gax.Backoff{
   189  					Initial:    100 * time.Millisecond,
   190  					Max:        60000 * time.Millisecond,
   191  					Multiplier: 1.30,
   192  				},
   193  					http.StatusServiceUnavailable)
   194  			}),
   195  		},
   196  		SetIamPolicy: []gax.CallOption{
   197  			gax.WithTimeout(60000 * time.Millisecond),
   198  		},
   199  		TestIamPermissions: []gax.CallOption{},
   200  		GetOperation:       []gax.CallOption{},
   201  	}
   202  }
   203  
   204  // internalProjectsClient is an interface that defines the methods available from Cloud Resource Manager API.
   205  type internalProjectsClient interface {
   206  	Close() error
   207  	setGoogleClientInfo(...string)
   208  	Connection() *grpc.ClientConn
   209  	GetProject(context.Context, *resourcemanagerpb.GetProjectRequest, ...gax.CallOption) (*resourcemanagerpb.Project, error)
   210  	ListProjects(context.Context, *resourcemanagerpb.ListProjectsRequest, ...gax.CallOption) *ProjectIterator
   211  	SearchProjects(context.Context, *resourcemanagerpb.SearchProjectsRequest, ...gax.CallOption) *ProjectIterator
   212  	CreateProject(context.Context, *resourcemanagerpb.CreateProjectRequest, ...gax.CallOption) (*CreateProjectOperation, error)
   213  	CreateProjectOperation(name string) *CreateProjectOperation
   214  	UpdateProject(context.Context, *resourcemanagerpb.UpdateProjectRequest, ...gax.CallOption) (*UpdateProjectOperation, error)
   215  	UpdateProjectOperation(name string) *UpdateProjectOperation
   216  	MoveProject(context.Context, *resourcemanagerpb.MoveProjectRequest, ...gax.CallOption) (*MoveProjectOperation, error)
   217  	MoveProjectOperation(name string) *MoveProjectOperation
   218  	DeleteProject(context.Context, *resourcemanagerpb.DeleteProjectRequest, ...gax.CallOption) (*DeleteProjectOperation, error)
   219  	DeleteProjectOperation(name string) *DeleteProjectOperation
   220  	UndeleteProject(context.Context, *resourcemanagerpb.UndeleteProjectRequest, ...gax.CallOption) (*UndeleteProjectOperation, error)
   221  	UndeleteProjectOperation(name string) *UndeleteProjectOperation
   222  	GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
   223  	SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
   224  	TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)
   225  	GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
   226  }
   227  
   228  // ProjectsClient is a client for interacting with Cloud Resource Manager API.
   229  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   230  //
   231  // Manages Google Cloud Projects.
   232  type ProjectsClient struct {
   233  	// The internal transport-dependent client.
   234  	internalClient internalProjectsClient
   235  
   236  	// The call options for this service.
   237  	CallOptions *ProjectsCallOptions
   238  
   239  	// LROClient is used internally to handle long-running operations.
   240  	// It is exposed so that its CallOptions can be modified if required.
   241  	// Users should not Close this client.
   242  	LROClient *lroauto.OperationsClient
   243  }
   244  
   245  // Wrapper methods routed to the internal client.
   246  
   247  // Close closes the connection to the API service. The user should invoke this when
   248  // the client is no longer required.
   249  func (c *ProjectsClient) Close() error {
   250  	return c.internalClient.Close()
   251  }
   252  
   253  // setGoogleClientInfo sets the name and version of the application in
   254  // the `x-goog-api-client` header passed on each request. Intended for
   255  // use by Google-written clients.
   256  func (c *ProjectsClient) setGoogleClientInfo(keyval ...string) {
   257  	c.internalClient.setGoogleClientInfo(keyval...)
   258  }
   259  
   260  // Connection returns a connection to the API service.
   261  //
   262  // Deprecated: Connections are now pooled so this method does not always
   263  // return the same resource.
   264  func (c *ProjectsClient) Connection() *grpc.ClientConn {
   265  	return c.internalClient.Connection()
   266  }
   267  
   268  // GetProject retrieves the project identified by the specified name (for example,
   269  // projects/415104041262).
   270  //
   271  // The caller must have resourcemanager.projects.get permission
   272  // for this project.
   273  func (c *ProjectsClient) GetProject(ctx context.Context, req *resourcemanagerpb.GetProjectRequest, opts ...gax.CallOption) (*resourcemanagerpb.Project, error) {
   274  	return c.internalClient.GetProject(ctx, req, opts...)
   275  }
   276  
   277  // ListProjects lists projects that are direct children of the specified folder or
   278  // organization resource. list() provides a strongly consistent view of the
   279  // projects underneath the specified parent resource. list() returns
   280  // projects sorted based upon the (ascending) lexical ordering of their
   281  // display_name. The caller must have resourcemanager.projects.list
   282  // permission on the identified parent.
   283  func (c *ProjectsClient) ListProjects(ctx context.Context, req *resourcemanagerpb.ListProjectsRequest, opts ...gax.CallOption) *ProjectIterator {
   284  	return c.internalClient.ListProjects(ctx, req, opts...)
   285  }
   286  
   287  // SearchProjects search for projects that the caller has both resourcemanager.projects.get
   288  // permission on, and also satisfy the specified query.
   289  //
   290  // This method returns projects in an unspecified order.
   291  //
   292  // This method is eventually consistent with project mutations; this means
   293  // that a newly created project may not appear in the results or recent
   294  // updates to an existing project may not be reflected in the results. To
   295  // retrieve the latest state of a project, use the
   296  // GetProject method.
   297  func (c *ProjectsClient) SearchProjects(ctx context.Context, req *resourcemanagerpb.SearchProjectsRequest, opts ...gax.CallOption) *ProjectIterator {
   298  	return c.internalClient.SearchProjects(ctx, req, opts...)
   299  }
   300  
   301  // CreateProject request that a new project be created. The result is an Operation which
   302  // can be used to track the creation process. This process usually takes a few
   303  // seconds, but can sometimes take much longer. The tracking Operation is
   304  // automatically deleted after a few hours, so there is no need to call
   305  // DeleteOperation.
   306  func (c *ProjectsClient) CreateProject(ctx context.Context, req *resourcemanagerpb.CreateProjectRequest, opts ...gax.CallOption) (*CreateProjectOperation, error) {
   307  	return c.internalClient.CreateProject(ctx, req, opts...)
   308  }
   309  
   310  // CreateProjectOperation returns a new CreateProjectOperation from a given name.
   311  // The name must be that of a previously created CreateProjectOperation, possibly from a different process.
   312  func (c *ProjectsClient) CreateProjectOperation(name string) *CreateProjectOperation {
   313  	return c.internalClient.CreateProjectOperation(name)
   314  }
   315  
   316  // UpdateProject updates the display_name and labels of the project identified by the
   317  // specified name (for example, projects/415104041262). Deleting all
   318  // labels requires an update mask for labels field.
   319  //
   320  // The caller must have resourcemanager.projects.update permission for this
   321  // project.
   322  func (c *ProjectsClient) UpdateProject(ctx context.Context, req *resourcemanagerpb.UpdateProjectRequest, opts ...gax.CallOption) (*UpdateProjectOperation, error) {
   323  	return c.internalClient.UpdateProject(ctx, req, opts...)
   324  }
   325  
   326  // UpdateProjectOperation returns a new UpdateProjectOperation from a given name.
   327  // The name must be that of a previously created UpdateProjectOperation, possibly from a different process.
   328  func (c *ProjectsClient) UpdateProjectOperation(name string) *UpdateProjectOperation {
   329  	return c.internalClient.UpdateProjectOperation(name)
   330  }
   331  
   332  // MoveProject move a project to another place in your resource hierarchy, under a new
   333  // resource parent.
   334  //
   335  // Returns an operation which can be used to track the process of the project
   336  // move workflow.
   337  // Upon success, the Operation.response field will be populated with the
   338  // moved project.
   339  //
   340  // The caller must have resourcemanager.projects.move permission on the
   341  // project, on the project’s current and proposed new parent.
   342  //
   343  // If project has no current parent, or it currently does not have an
   344  // associated organization resource, you will also need the
   345  // resourcemanager.projects.setIamPolicy permission in the project.
   346  func (c *ProjectsClient) MoveProject(ctx context.Context, req *resourcemanagerpb.MoveProjectRequest, opts ...gax.CallOption) (*MoveProjectOperation, error) {
   347  	return c.internalClient.MoveProject(ctx, req, opts...)
   348  }
   349  
   350  // MoveProjectOperation returns a new MoveProjectOperation from a given name.
   351  // The name must be that of a previously created MoveProjectOperation, possibly from a different process.
   352  func (c *ProjectsClient) MoveProjectOperation(name string) *MoveProjectOperation {
   353  	return c.internalClient.MoveProjectOperation(name)
   354  }
   355  
   356  // DeleteProject marks the project identified by the specified
   357  // name (for example, projects/415104041262) for deletion.
   358  //
   359  // This method will only affect the project if it has a lifecycle state of
   360  // [ACTIVE][google.cloud.resourcemanager.v3.Project.State.ACTIVE (at http://google.cloud.resourcemanager.v3.Project.State.ACTIVE)].
   361  //
   362  // This method changes the Project’s lifecycle state from
   363  // [ACTIVE][google.cloud.resourcemanager.v3.Project.State.ACTIVE (at http://google.cloud.resourcemanager.v3.Project.State.ACTIVE)]
   364  // to
   365  // DELETE_REQUESTED.
   366  // The deletion starts at an unspecified time,
   367  // at which point the Project is no longer accessible.
   368  //
   369  // Until the deletion completes, you can check the lifecycle state
   370  // checked by retrieving the project with [GetProject]
   371  // [google.cloud.resourcemanager.v3.Projects.GetProject],
   372  // and the project remains visible to [ListProjects]
   373  // [google.cloud.resourcemanager.v3.Projects.ListProjects].
   374  // However, you cannot update the project.
   375  //
   376  // After the deletion completes, the project is not retrievable by
   377  // the  [GetProject]
   378  // [google.cloud.resourcemanager.v3.Projects.GetProject],
   379  // [ListProjects]
   380  // [google.cloud.resourcemanager.v3.Projects.ListProjects], and
   381  // SearchProjects
   382  // methods.
   383  //
   384  // This method behaves idempotently, such that deleting a DELETE_REQUESTED
   385  // project will not cause an error, but also won’t do anything.
   386  //
   387  // The caller must have resourcemanager.projects.delete permissions for this
   388  // project.
   389  func (c *ProjectsClient) DeleteProject(ctx context.Context, req *resourcemanagerpb.DeleteProjectRequest, opts ...gax.CallOption) (*DeleteProjectOperation, error) {
   390  	return c.internalClient.DeleteProject(ctx, req, opts...)
   391  }
   392  
   393  // DeleteProjectOperation returns a new DeleteProjectOperation from a given name.
   394  // The name must be that of a previously created DeleteProjectOperation, possibly from a different process.
   395  func (c *ProjectsClient) DeleteProjectOperation(name string) *DeleteProjectOperation {
   396  	return c.internalClient.DeleteProjectOperation(name)
   397  }
   398  
   399  // UndeleteProject restores the project identified by the specified
   400  // name (for example, projects/415104041262).
   401  // You can only use this method for a project that has a lifecycle state of
   402  // [DELETE_REQUESTED]
   403  // [Projects.State.DELETE_REQUESTED].
   404  // After deletion starts, the project cannot be restored.
   405  //
   406  // The caller must have resourcemanager.projects.undelete permission for
   407  // this project.
   408  func (c *ProjectsClient) UndeleteProject(ctx context.Context, req *resourcemanagerpb.UndeleteProjectRequest, opts ...gax.CallOption) (*UndeleteProjectOperation, error) {
   409  	return c.internalClient.UndeleteProject(ctx, req, opts...)
   410  }
   411  
   412  // UndeleteProjectOperation returns a new UndeleteProjectOperation from a given name.
   413  // The name must be that of a previously created UndeleteProjectOperation, possibly from a different process.
   414  func (c *ProjectsClient) UndeleteProjectOperation(name string) *UndeleteProjectOperation {
   415  	return c.internalClient.UndeleteProjectOperation(name)
   416  }
   417  
   418  // GetIamPolicy returns the IAM access control policy for the specified project, in the
   419  // format projects/{ProjectIdOrNumber} e.g. projects/123.
   420  // Permission is denied if the policy or the resource do not exist.
   421  func (c *ProjectsClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   422  	return c.internalClient.GetIamPolicy(ctx, req, opts...)
   423  }
   424  
   425  // SetIamPolicy sets the IAM access control policy for the specified project, in the
   426  // format projects/{ProjectIdOrNumber} e.g. projects/123.
   427  //
   428  // CAUTION: This method will replace the existing policy, and cannot be used
   429  // to append additional IAM settings.
   430  //
   431  // Note: Removing service accounts from policies or changing their roles can
   432  // render services completely inoperable. It is important to understand how
   433  // the service account is being used before removing or updating its roles.
   434  //
   435  // The following constraints apply when using setIamPolicy():
   436  //
   437  //	Project does not support allUsers and allAuthenticatedUsers as
   438  //	members in a Binding of a Policy.
   439  //
   440  //	The owner role can be granted to a user, serviceAccount, or a group
   441  //	that is part of an organization. For example,
   442  //	group@myownpersonaldomain.com (at mailto:group@myownpersonaldomain.com) could be added as an owner to a project in
   443  //	the myownpersonaldomain.com (at http://myownpersonaldomain.com) organization, but not the examplepetstore.com (at http://examplepetstore.com)
   444  //	organization.
   445  //
   446  //	Service accounts can be made owners of a project directly
   447  //	without any restrictions. However, to be added as an owner, a user must be
   448  //	invited using the Cloud Platform console and must accept the invitation.
   449  //
   450  //	A user cannot be granted the owner role using setIamPolicy(). The user
   451  //	must be granted the owner role using the Cloud Platform Console and must
   452  //	explicitly accept the invitation.
   453  //
   454  //	Invitations to grant the owner role cannot be sent using
   455  //	setIamPolicy();
   456  //	they must be sent only using the Cloud Platform Console.
   457  //
   458  //	If the project is not part of an organization, there must be at least
   459  //	one owner who has accepted the Terms of Service (ToS) agreement in the
   460  //	policy. Calling setIamPolicy() to remove the last ToS-accepted owner
   461  //	from the policy will fail. This restriction also applies to legacy
   462  //	projects that no longer have owners who have accepted the ToS. Edits to
   463  //	IAM policies will be rejected until the lack of a ToS-accepting owner is
   464  //	rectified. If the project is part of an organization, you can remove all
   465  //	owners, potentially making the organization inaccessible.
   466  func (c *ProjectsClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   467  	return c.internalClient.SetIamPolicy(ctx, req, opts...)
   468  }
   469  
   470  // TestIamPermissions returns permissions that a caller has on the specified project, in the
   471  // format projects/{ProjectIdOrNumber} e.g. projects/123…
   472  func (c *ProjectsClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
   473  	return c.internalClient.TestIamPermissions(ctx, req, opts...)
   474  }
   475  
   476  // GetOperation is a utility method from google.longrunning.Operations.
   477  func (c *ProjectsClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   478  	return c.internalClient.GetOperation(ctx, req, opts...)
   479  }
   480  
   481  // projectsGRPCClient is a client for interacting with Cloud Resource Manager API over gRPC transport.
   482  //
   483  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   484  type projectsGRPCClient struct {
   485  	// Connection pool of gRPC connections to the service.
   486  	connPool gtransport.ConnPool
   487  
   488  	// Points back to the CallOptions field of the containing ProjectsClient
   489  	CallOptions **ProjectsCallOptions
   490  
   491  	// The gRPC API client.
   492  	projectsClient resourcemanagerpb.ProjectsClient
   493  
   494  	// LROClient is used internally to handle long-running operations.
   495  	// It is exposed so that its CallOptions can be modified if required.
   496  	// Users should not Close this client.
   497  	LROClient **lroauto.OperationsClient
   498  
   499  	operationsClient longrunningpb.OperationsClient
   500  
   501  	// The x-goog-* metadata to be sent with each request.
   502  	xGoogHeaders []string
   503  }
   504  
   505  // NewProjectsClient creates a new projects client based on gRPC.
   506  // The returned client must be Closed when it is done being used to clean up its underlying connections.
   507  //
   508  // Manages Google Cloud Projects.
   509  func NewProjectsClient(ctx context.Context, opts ...option.ClientOption) (*ProjectsClient, error) {
   510  	clientOpts := defaultProjectsGRPCClientOptions()
   511  	if newProjectsClientHook != nil {
   512  		hookOpts, err := newProjectsClientHook(ctx, clientHookParams{})
   513  		if err != nil {
   514  			return nil, err
   515  		}
   516  		clientOpts = append(clientOpts, hookOpts...)
   517  	}
   518  
   519  	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
   520  	if err != nil {
   521  		return nil, err
   522  	}
   523  	client := ProjectsClient{CallOptions: defaultProjectsCallOptions()}
   524  
   525  	c := &projectsGRPCClient{
   526  		connPool:         connPool,
   527  		projectsClient:   resourcemanagerpb.NewProjectsClient(connPool),
   528  		CallOptions:      &client.CallOptions,
   529  		operationsClient: longrunningpb.NewOperationsClient(connPool),
   530  	}
   531  	c.setGoogleClientInfo()
   532  
   533  	client.internalClient = c
   534  
   535  	client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
   536  	if err != nil {
   537  		// This error "should not happen", since we are just reusing old connection pool
   538  		// and never actually need to dial.
   539  		// If this does happen, we could leak connp. However, we cannot close conn:
   540  		// If the user invoked the constructor with option.WithGRPCConn,
   541  		// we would close a connection that's still in use.
   542  		// TODO: investigate error conditions.
   543  		return nil, err
   544  	}
   545  	c.LROClient = &client.LROClient
   546  	return &client, nil
   547  }
   548  
   549  // Connection returns a connection to the API service.
   550  //
   551  // Deprecated: Connections are now pooled so this method does not always
   552  // return the same resource.
   553  func (c *projectsGRPCClient) Connection() *grpc.ClientConn {
   554  	return c.connPool.Conn()
   555  }
   556  
   557  // setGoogleClientInfo sets the name and version of the application in
   558  // the `x-goog-api-client` header passed on each request. Intended for
   559  // use by Google-written clients.
   560  func (c *projectsGRPCClient) setGoogleClientInfo(keyval ...string) {
   561  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   562  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version)
   563  	c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
   564  }
   565  
   566  // Close closes the connection to the API service. The user should invoke this when
   567  // the client is no longer required.
   568  func (c *projectsGRPCClient) Close() error {
   569  	return c.connPool.Close()
   570  }
   571  
   572  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   573  type projectsRESTClient struct {
   574  	// The http endpoint to connect to.
   575  	endpoint string
   576  
   577  	// The http client.
   578  	httpClient *http.Client
   579  
   580  	// LROClient is used internally to handle long-running operations.
   581  	// It is exposed so that its CallOptions can be modified if required.
   582  	// Users should not Close this client.
   583  	LROClient **lroauto.OperationsClient
   584  
   585  	// The x-goog-* headers to be sent with each request.
   586  	xGoogHeaders []string
   587  
   588  	// Points back to the CallOptions field of the containing ProjectsClient
   589  	CallOptions **ProjectsCallOptions
   590  }
   591  
   592  // NewProjectsRESTClient creates a new projects rest client.
   593  //
   594  // Manages Google Cloud Projects.
   595  func NewProjectsRESTClient(ctx context.Context, opts ...option.ClientOption) (*ProjectsClient, error) {
   596  	clientOpts := append(defaultProjectsRESTClientOptions(), opts...)
   597  	httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
   598  	if err != nil {
   599  		return nil, err
   600  	}
   601  
   602  	callOpts := defaultProjectsRESTCallOptions()
   603  	c := &projectsRESTClient{
   604  		endpoint:    endpoint,
   605  		httpClient:  httpClient,
   606  		CallOptions: &callOpts,
   607  	}
   608  	c.setGoogleClientInfo()
   609  
   610  	lroOpts := []option.ClientOption{
   611  		option.WithHTTPClient(httpClient),
   612  		option.WithEndpoint(endpoint),
   613  	}
   614  	opClient, err := lroauto.NewOperationsRESTClient(ctx, lroOpts...)
   615  	if err != nil {
   616  		return nil, err
   617  	}
   618  	c.LROClient = &opClient
   619  
   620  	return &ProjectsClient{internalClient: c, CallOptions: callOpts}, nil
   621  }
   622  
   623  func defaultProjectsRESTClientOptions() []option.ClientOption {
   624  	return []option.ClientOption{
   625  		internaloption.WithDefaultEndpoint("https://cloudresourcemanager.googleapis.com"),
   626  		internaloption.WithDefaultEndpointTemplate("https://cloudresourcemanager.UNIVERSE_DOMAIN"),
   627  		internaloption.WithDefaultMTLSEndpoint("https://cloudresourcemanager.mtls.googleapis.com"),
   628  		internaloption.WithDefaultUniverseDomain("googleapis.com"),
   629  		internaloption.WithDefaultAudience("https://cloudresourcemanager.googleapis.com/"),
   630  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
   631  	}
   632  }
   633  
   634  // setGoogleClientInfo sets the name and version of the application in
   635  // the `x-goog-api-client` header passed on each request. Intended for
   636  // use by Google-written clients.
   637  func (c *projectsRESTClient) setGoogleClientInfo(keyval ...string) {
   638  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   639  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN")
   640  	c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
   641  }
   642  
   643  // Close closes the connection to the API service. The user should invoke this when
   644  // the client is no longer required.
   645  func (c *projectsRESTClient) Close() error {
   646  	// Replace httpClient with nil to force cleanup.
   647  	c.httpClient = nil
   648  	return nil
   649  }
   650  
   651  // Connection returns a connection to the API service.
   652  //
   653  // Deprecated: This method always returns nil.
   654  func (c *projectsRESTClient) Connection() *grpc.ClientConn {
   655  	return nil
   656  }
   657  func (c *projectsGRPCClient) GetProject(ctx context.Context, req *resourcemanagerpb.GetProjectRequest, opts ...gax.CallOption) (*resourcemanagerpb.Project, error) {
   658  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   659  
   660  	hds = append(c.xGoogHeaders, hds...)
   661  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   662  	opts = append((*c.CallOptions).GetProject[0:len((*c.CallOptions).GetProject):len((*c.CallOptions).GetProject)], opts...)
   663  	var resp *resourcemanagerpb.Project
   664  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   665  		var err error
   666  		resp, err = c.projectsClient.GetProject(ctx, req, settings.GRPC...)
   667  		return err
   668  	}, opts...)
   669  	if err != nil {
   670  		return nil, err
   671  	}
   672  	return resp, nil
   673  }
   674  
   675  func (c *projectsGRPCClient) ListProjects(ctx context.Context, req *resourcemanagerpb.ListProjectsRequest, opts ...gax.CallOption) *ProjectIterator {
   676  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
   677  	opts = append((*c.CallOptions).ListProjects[0:len((*c.CallOptions).ListProjects):len((*c.CallOptions).ListProjects)], opts...)
   678  	it := &ProjectIterator{}
   679  	req = proto.Clone(req).(*resourcemanagerpb.ListProjectsRequest)
   680  	it.InternalFetch = func(pageSize int, pageToken string) ([]*resourcemanagerpb.Project, string, error) {
   681  		resp := &resourcemanagerpb.ListProjectsResponse{}
   682  		if pageToken != "" {
   683  			req.PageToken = pageToken
   684  		}
   685  		if pageSize > math.MaxInt32 {
   686  			req.PageSize = math.MaxInt32
   687  		} else if pageSize != 0 {
   688  			req.PageSize = int32(pageSize)
   689  		}
   690  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   691  			var err error
   692  			resp, err = c.projectsClient.ListProjects(ctx, req, settings.GRPC...)
   693  			return err
   694  		}, opts...)
   695  		if err != nil {
   696  			return nil, "", err
   697  		}
   698  
   699  		it.Response = resp
   700  		return resp.GetProjects(), resp.GetNextPageToken(), nil
   701  	}
   702  	fetch := func(pageSize int, pageToken string) (string, error) {
   703  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   704  		if err != nil {
   705  			return "", err
   706  		}
   707  		it.items = append(it.items, items...)
   708  		return nextPageToken, nil
   709  	}
   710  
   711  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   712  	it.pageInfo.MaxSize = int(req.GetPageSize())
   713  	it.pageInfo.Token = req.GetPageToken()
   714  
   715  	return it
   716  }
   717  
   718  func (c *projectsGRPCClient) SearchProjects(ctx context.Context, req *resourcemanagerpb.SearchProjectsRequest, opts ...gax.CallOption) *ProjectIterator {
   719  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
   720  	opts = append((*c.CallOptions).SearchProjects[0:len((*c.CallOptions).SearchProjects):len((*c.CallOptions).SearchProjects)], opts...)
   721  	it := &ProjectIterator{}
   722  	req = proto.Clone(req).(*resourcemanagerpb.SearchProjectsRequest)
   723  	it.InternalFetch = func(pageSize int, pageToken string) ([]*resourcemanagerpb.Project, string, error) {
   724  		resp := &resourcemanagerpb.SearchProjectsResponse{}
   725  		if pageToken != "" {
   726  			req.PageToken = pageToken
   727  		}
   728  		if pageSize > math.MaxInt32 {
   729  			req.PageSize = math.MaxInt32
   730  		} else if pageSize != 0 {
   731  			req.PageSize = int32(pageSize)
   732  		}
   733  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   734  			var err error
   735  			resp, err = c.projectsClient.SearchProjects(ctx, req, settings.GRPC...)
   736  			return err
   737  		}, opts...)
   738  		if err != nil {
   739  			return nil, "", err
   740  		}
   741  
   742  		it.Response = resp
   743  		return resp.GetProjects(), resp.GetNextPageToken(), nil
   744  	}
   745  	fetch := func(pageSize int, pageToken string) (string, error) {
   746  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   747  		if err != nil {
   748  			return "", err
   749  		}
   750  		it.items = append(it.items, items...)
   751  		return nextPageToken, nil
   752  	}
   753  
   754  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   755  	it.pageInfo.MaxSize = int(req.GetPageSize())
   756  	it.pageInfo.Token = req.GetPageToken()
   757  
   758  	return it
   759  }
   760  
   761  func (c *projectsGRPCClient) CreateProject(ctx context.Context, req *resourcemanagerpb.CreateProjectRequest, opts ...gax.CallOption) (*CreateProjectOperation, error) {
   762  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
   763  	opts = append((*c.CallOptions).CreateProject[0:len((*c.CallOptions).CreateProject):len((*c.CallOptions).CreateProject)], opts...)
   764  	var resp *longrunningpb.Operation
   765  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   766  		var err error
   767  		resp, err = c.projectsClient.CreateProject(ctx, req, settings.GRPC...)
   768  		return err
   769  	}, opts...)
   770  	if err != nil {
   771  		return nil, err
   772  	}
   773  	return &CreateProjectOperation{
   774  		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
   775  	}, nil
   776  }
   777  
   778  func (c *projectsGRPCClient) UpdateProject(ctx context.Context, req *resourcemanagerpb.UpdateProjectRequest, opts ...gax.CallOption) (*UpdateProjectOperation, error) {
   779  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "project.name", url.QueryEscape(req.GetProject().GetName()))}
   780  
   781  	hds = append(c.xGoogHeaders, hds...)
   782  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   783  	opts = append((*c.CallOptions).UpdateProject[0:len((*c.CallOptions).UpdateProject):len((*c.CallOptions).UpdateProject)], opts...)
   784  	var resp *longrunningpb.Operation
   785  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   786  		var err error
   787  		resp, err = c.projectsClient.UpdateProject(ctx, req, settings.GRPC...)
   788  		return err
   789  	}, opts...)
   790  	if err != nil {
   791  		return nil, err
   792  	}
   793  	return &UpdateProjectOperation{
   794  		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
   795  	}, nil
   796  }
   797  
   798  func (c *projectsGRPCClient) MoveProject(ctx context.Context, req *resourcemanagerpb.MoveProjectRequest, opts ...gax.CallOption) (*MoveProjectOperation, error) {
   799  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   800  
   801  	hds = append(c.xGoogHeaders, hds...)
   802  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   803  	opts = append((*c.CallOptions).MoveProject[0:len((*c.CallOptions).MoveProject):len((*c.CallOptions).MoveProject)], opts...)
   804  	var resp *longrunningpb.Operation
   805  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   806  		var err error
   807  		resp, err = c.projectsClient.MoveProject(ctx, req, settings.GRPC...)
   808  		return err
   809  	}, opts...)
   810  	if err != nil {
   811  		return nil, err
   812  	}
   813  	return &MoveProjectOperation{
   814  		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
   815  	}, nil
   816  }
   817  
   818  func (c *projectsGRPCClient) DeleteProject(ctx context.Context, req *resourcemanagerpb.DeleteProjectRequest, opts ...gax.CallOption) (*DeleteProjectOperation, error) {
   819  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   820  
   821  	hds = append(c.xGoogHeaders, hds...)
   822  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   823  	opts = append((*c.CallOptions).DeleteProject[0:len((*c.CallOptions).DeleteProject):len((*c.CallOptions).DeleteProject)], opts...)
   824  	var resp *longrunningpb.Operation
   825  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   826  		var err error
   827  		resp, err = c.projectsClient.DeleteProject(ctx, req, settings.GRPC...)
   828  		return err
   829  	}, opts...)
   830  	if err != nil {
   831  		return nil, err
   832  	}
   833  	return &DeleteProjectOperation{
   834  		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
   835  	}, nil
   836  }
   837  
   838  func (c *projectsGRPCClient) UndeleteProject(ctx context.Context, req *resourcemanagerpb.UndeleteProjectRequest, opts ...gax.CallOption) (*UndeleteProjectOperation, error) {
   839  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   840  
   841  	hds = append(c.xGoogHeaders, hds...)
   842  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   843  	opts = append((*c.CallOptions).UndeleteProject[0:len((*c.CallOptions).UndeleteProject):len((*c.CallOptions).UndeleteProject)], opts...)
   844  	var resp *longrunningpb.Operation
   845  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   846  		var err error
   847  		resp, err = c.projectsClient.UndeleteProject(ctx, req, settings.GRPC...)
   848  		return err
   849  	}, opts...)
   850  	if err != nil {
   851  		return nil, err
   852  	}
   853  	return &UndeleteProjectOperation{
   854  		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
   855  	}, nil
   856  }
   857  
   858  func (c *projectsGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   859  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   860  
   861  	hds = append(c.xGoogHeaders, hds...)
   862  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   863  	opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
   864  	var resp *iampb.Policy
   865  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   866  		var err error
   867  		resp, err = c.projectsClient.GetIamPolicy(ctx, req, settings.GRPC...)
   868  		return err
   869  	}, opts...)
   870  	if err != nil {
   871  		return nil, err
   872  	}
   873  	return resp, nil
   874  }
   875  
   876  func (c *projectsGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   877  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   878  
   879  	hds = append(c.xGoogHeaders, hds...)
   880  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   881  	opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
   882  	var resp *iampb.Policy
   883  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   884  		var err error
   885  		resp, err = c.projectsClient.SetIamPolicy(ctx, req, settings.GRPC...)
   886  		return err
   887  	}, opts...)
   888  	if err != nil {
   889  		return nil, err
   890  	}
   891  	return resp, nil
   892  }
   893  
   894  func (c *projectsGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
   895  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   896  
   897  	hds = append(c.xGoogHeaders, hds...)
   898  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   899  	opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
   900  	var resp *iampb.TestIamPermissionsResponse
   901  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   902  		var err error
   903  		resp, err = c.projectsClient.TestIamPermissions(ctx, req, settings.GRPC...)
   904  		return err
   905  	}, opts...)
   906  	if err != nil {
   907  		return nil, err
   908  	}
   909  	return resp, nil
   910  }
   911  
   912  func (c *projectsGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   913  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   914  
   915  	hds = append(c.xGoogHeaders, hds...)
   916  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   917  	opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
   918  	var resp *longrunningpb.Operation
   919  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   920  		var err error
   921  		resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...)
   922  		return err
   923  	}, opts...)
   924  	if err != nil {
   925  		return nil, err
   926  	}
   927  	return resp, nil
   928  }
   929  
   930  // GetProject retrieves the project identified by the specified name (for example,
   931  // projects/415104041262).
   932  //
   933  // The caller must have resourcemanager.projects.get permission
   934  // for this project.
   935  func (c *projectsRESTClient) GetProject(ctx context.Context, req *resourcemanagerpb.GetProjectRequest, opts ...gax.CallOption) (*resourcemanagerpb.Project, error) {
   936  	baseUrl, err := url.Parse(c.endpoint)
   937  	if err != nil {
   938  		return nil, err
   939  	}
   940  	baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetName())
   941  
   942  	params := url.Values{}
   943  	params.Add("$alt", "json;enum-encoding=int")
   944  
   945  	baseUrl.RawQuery = params.Encode()
   946  
   947  	// Build HTTP headers from client and context metadata.
   948  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   949  
   950  	hds = append(c.xGoogHeaders, hds...)
   951  	hds = append(hds, "Content-Type", "application/json")
   952  	headers := gax.BuildHeaders(ctx, hds...)
   953  	opts = append((*c.CallOptions).GetProject[0:len((*c.CallOptions).GetProject):len((*c.CallOptions).GetProject)], opts...)
   954  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   955  	resp := &resourcemanagerpb.Project{}
   956  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   957  		if settings.Path != "" {
   958  			baseUrl.Path = settings.Path
   959  		}
   960  		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
   961  		if err != nil {
   962  			return err
   963  		}
   964  		httpReq = httpReq.WithContext(ctx)
   965  		httpReq.Header = headers
   966  
   967  		httpRsp, err := c.httpClient.Do(httpReq)
   968  		if err != nil {
   969  			return err
   970  		}
   971  		defer httpRsp.Body.Close()
   972  
   973  		if err = googleapi.CheckResponse(httpRsp); err != nil {
   974  			return err
   975  		}
   976  
   977  		buf, err := io.ReadAll(httpRsp.Body)
   978  		if err != nil {
   979  			return err
   980  		}
   981  
   982  		if err := unm.Unmarshal(buf, resp); err != nil {
   983  			return err
   984  		}
   985  
   986  		return nil
   987  	}, opts...)
   988  	if e != nil {
   989  		return nil, e
   990  	}
   991  	return resp, nil
   992  }
   993  
   994  // ListProjects lists projects that are direct children of the specified folder or
   995  // organization resource. list() provides a strongly consistent view of the
   996  // projects underneath the specified parent resource. list() returns
   997  // projects sorted based upon the (ascending) lexical ordering of their
   998  // display_name. The caller must have resourcemanager.projects.list
   999  // permission on the identified parent.
  1000  func (c *projectsRESTClient) ListProjects(ctx context.Context, req *resourcemanagerpb.ListProjectsRequest, opts ...gax.CallOption) *ProjectIterator {
  1001  	it := &ProjectIterator{}
  1002  	req = proto.Clone(req).(*resourcemanagerpb.ListProjectsRequest)
  1003  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1004  	it.InternalFetch = func(pageSize int, pageToken string) ([]*resourcemanagerpb.Project, string, error) {
  1005  		resp := &resourcemanagerpb.ListProjectsResponse{}
  1006  		if pageToken != "" {
  1007  			req.PageToken = pageToken
  1008  		}
  1009  		if pageSize > math.MaxInt32 {
  1010  			req.PageSize = math.MaxInt32
  1011  		} else if pageSize != 0 {
  1012  			req.PageSize = int32(pageSize)
  1013  		}
  1014  		baseUrl, err := url.Parse(c.endpoint)
  1015  		if err != nil {
  1016  			return nil, "", err
  1017  		}
  1018  		baseUrl.Path += fmt.Sprintf("/v3/projects")
  1019  
  1020  		params := url.Values{}
  1021  		params.Add("$alt", "json;enum-encoding=int")
  1022  		if req.GetPageSize() != 0 {
  1023  			params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
  1024  		}
  1025  		if req.GetPageToken() != "" {
  1026  			params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
  1027  		}
  1028  		params.Add("parent", fmt.Sprintf("%v", req.GetParent()))
  1029  		if req.GetShowDeleted() {
  1030  			params.Add("showDeleted", fmt.Sprintf("%v", req.GetShowDeleted()))
  1031  		}
  1032  
  1033  		baseUrl.RawQuery = params.Encode()
  1034  
  1035  		// Build HTTP headers from client and context metadata.
  1036  		hds := append(c.xGoogHeaders, "Content-Type", "application/json")
  1037  		headers := gax.BuildHeaders(ctx, hds...)
  1038  		e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1039  			if settings.Path != "" {
  1040  				baseUrl.Path = settings.Path
  1041  			}
  1042  			httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  1043  			if err != nil {
  1044  				return err
  1045  			}
  1046  			httpReq.Header = headers
  1047  
  1048  			httpRsp, err := c.httpClient.Do(httpReq)
  1049  			if err != nil {
  1050  				return err
  1051  			}
  1052  			defer httpRsp.Body.Close()
  1053  
  1054  			if err = googleapi.CheckResponse(httpRsp); err != nil {
  1055  				return err
  1056  			}
  1057  
  1058  			buf, err := io.ReadAll(httpRsp.Body)
  1059  			if err != nil {
  1060  				return err
  1061  			}
  1062  
  1063  			if err := unm.Unmarshal(buf, resp); err != nil {
  1064  				return err
  1065  			}
  1066  
  1067  			return nil
  1068  		}, opts...)
  1069  		if e != nil {
  1070  			return nil, "", e
  1071  		}
  1072  		it.Response = resp
  1073  		return resp.GetProjects(), resp.GetNextPageToken(), nil
  1074  	}
  1075  
  1076  	fetch := func(pageSize int, pageToken string) (string, error) {
  1077  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  1078  		if err != nil {
  1079  			return "", err
  1080  		}
  1081  		it.items = append(it.items, items...)
  1082  		return nextPageToken, nil
  1083  	}
  1084  
  1085  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  1086  	it.pageInfo.MaxSize = int(req.GetPageSize())
  1087  	it.pageInfo.Token = req.GetPageToken()
  1088  
  1089  	return it
  1090  }
  1091  
  1092  // SearchProjects search for projects that the caller has both resourcemanager.projects.get
  1093  // permission on, and also satisfy the specified query.
  1094  //
  1095  // This method returns projects in an unspecified order.
  1096  //
  1097  // This method is eventually consistent with project mutations; this means
  1098  // that a newly created project may not appear in the results or recent
  1099  // updates to an existing project may not be reflected in the results. To
  1100  // retrieve the latest state of a project, use the
  1101  // GetProject method.
  1102  func (c *projectsRESTClient) SearchProjects(ctx context.Context, req *resourcemanagerpb.SearchProjectsRequest, opts ...gax.CallOption) *ProjectIterator {
  1103  	it := &ProjectIterator{}
  1104  	req = proto.Clone(req).(*resourcemanagerpb.SearchProjectsRequest)
  1105  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1106  	it.InternalFetch = func(pageSize int, pageToken string) ([]*resourcemanagerpb.Project, string, error) {
  1107  		resp := &resourcemanagerpb.SearchProjectsResponse{}
  1108  		if pageToken != "" {
  1109  			req.PageToken = pageToken
  1110  		}
  1111  		if pageSize > math.MaxInt32 {
  1112  			req.PageSize = math.MaxInt32
  1113  		} else if pageSize != 0 {
  1114  			req.PageSize = int32(pageSize)
  1115  		}
  1116  		baseUrl, err := url.Parse(c.endpoint)
  1117  		if err != nil {
  1118  			return nil, "", err
  1119  		}
  1120  		baseUrl.Path += fmt.Sprintf("/v3/projects:search")
  1121  
  1122  		params := url.Values{}
  1123  		params.Add("$alt", "json;enum-encoding=int")
  1124  		if req.GetPageSize() != 0 {
  1125  			params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
  1126  		}
  1127  		if req.GetPageToken() != "" {
  1128  			params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
  1129  		}
  1130  		if req.GetQuery() != "" {
  1131  			params.Add("query", fmt.Sprintf("%v", req.GetQuery()))
  1132  		}
  1133  
  1134  		baseUrl.RawQuery = params.Encode()
  1135  
  1136  		// Build HTTP headers from client and context metadata.
  1137  		hds := append(c.xGoogHeaders, "Content-Type", "application/json")
  1138  		headers := gax.BuildHeaders(ctx, hds...)
  1139  		e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1140  			if settings.Path != "" {
  1141  				baseUrl.Path = settings.Path
  1142  			}
  1143  			httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  1144  			if err != nil {
  1145  				return err
  1146  			}
  1147  			httpReq.Header = headers
  1148  
  1149  			httpRsp, err := c.httpClient.Do(httpReq)
  1150  			if err != nil {
  1151  				return err
  1152  			}
  1153  			defer httpRsp.Body.Close()
  1154  
  1155  			if err = googleapi.CheckResponse(httpRsp); err != nil {
  1156  				return err
  1157  			}
  1158  
  1159  			buf, err := io.ReadAll(httpRsp.Body)
  1160  			if err != nil {
  1161  				return err
  1162  			}
  1163  
  1164  			if err := unm.Unmarshal(buf, resp); err != nil {
  1165  				return err
  1166  			}
  1167  
  1168  			return nil
  1169  		}, opts...)
  1170  		if e != nil {
  1171  			return nil, "", e
  1172  		}
  1173  		it.Response = resp
  1174  		return resp.GetProjects(), resp.GetNextPageToken(), nil
  1175  	}
  1176  
  1177  	fetch := func(pageSize int, pageToken string) (string, error) {
  1178  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  1179  		if err != nil {
  1180  			return "", err
  1181  		}
  1182  		it.items = append(it.items, items...)
  1183  		return nextPageToken, nil
  1184  	}
  1185  
  1186  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  1187  	it.pageInfo.MaxSize = int(req.GetPageSize())
  1188  	it.pageInfo.Token = req.GetPageToken()
  1189  
  1190  	return it
  1191  }
  1192  
  1193  // CreateProject request that a new project be created. The result is an Operation which
  1194  // can be used to track the creation process. This process usually takes a few
  1195  // seconds, but can sometimes take much longer. The tracking Operation is
  1196  // automatically deleted after a few hours, so there is no need to call
  1197  // DeleteOperation.
  1198  func (c *projectsRESTClient) CreateProject(ctx context.Context, req *resourcemanagerpb.CreateProjectRequest, opts ...gax.CallOption) (*CreateProjectOperation, error) {
  1199  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1200  	body := req.GetProject()
  1201  	jsonReq, err := m.Marshal(body)
  1202  	if err != nil {
  1203  		return nil, err
  1204  	}
  1205  
  1206  	baseUrl, err := url.Parse(c.endpoint)
  1207  	if err != nil {
  1208  		return nil, err
  1209  	}
  1210  	baseUrl.Path += fmt.Sprintf("/v3/projects")
  1211  
  1212  	params := url.Values{}
  1213  	params.Add("$alt", "json;enum-encoding=int")
  1214  
  1215  	baseUrl.RawQuery = params.Encode()
  1216  
  1217  	// Build HTTP headers from client and context metadata.
  1218  	hds := append(c.xGoogHeaders, "Content-Type", "application/json")
  1219  	headers := gax.BuildHeaders(ctx, hds...)
  1220  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1221  	resp := &longrunningpb.Operation{}
  1222  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1223  		if settings.Path != "" {
  1224  			baseUrl.Path = settings.Path
  1225  		}
  1226  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1227  		if err != nil {
  1228  			return err
  1229  		}
  1230  		httpReq = httpReq.WithContext(ctx)
  1231  		httpReq.Header = headers
  1232  
  1233  		httpRsp, err := c.httpClient.Do(httpReq)
  1234  		if err != nil {
  1235  			return err
  1236  		}
  1237  		defer httpRsp.Body.Close()
  1238  
  1239  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1240  			return err
  1241  		}
  1242  
  1243  		buf, err := io.ReadAll(httpRsp.Body)
  1244  		if err != nil {
  1245  			return err
  1246  		}
  1247  
  1248  		if err := unm.Unmarshal(buf, resp); err != nil {
  1249  			return err
  1250  		}
  1251  
  1252  		return nil
  1253  	}, opts...)
  1254  	if e != nil {
  1255  		return nil, e
  1256  	}
  1257  
  1258  	override := fmt.Sprintf("/v3/%s", resp.GetName())
  1259  	return &CreateProjectOperation{
  1260  		lro:      longrunning.InternalNewOperation(*c.LROClient, resp),
  1261  		pollPath: override,
  1262  	}, nil
  1263  }
  1264  
  1265  // UpdateProject updates the display_name and labels of the project identified by the
  1266  // specified name (for example, projects/415104041262). Deleting all
  1267  // labels requires an update mask for labels field.
  1268  //
  1269  // The caller must have resourcemanager.projects.update permission for this
  1270  // project.
  1271  func (c *projectsRESTClient) UpdateProject(ctx context.Context, req *resourcemanagerpb.UpdateProjectRequest, opts ...gax.CallOption) (*UpdateProjectOperation, error) {
  1272  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1273  	body := req.GetProject()
  1274  	jsonReq, err := m.Marshal(body)
  1275  	if err != nil {
  1276  		return nil, err
  1277  	}
  1278  
  1279  	baseUrl, err := url.Parse(c.endpoint)
  1280  	if err != nil {
  1281  		return nil, err
  1282  	}
  1283  	baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetProject().GetName())
  1284  
  1285  	params := url.Values{}
  1286  	params.Add("$alt", "json;enum-encoding=int")
  1287  	if req.GetUpdateMask() != nil {
  1288  		updateMask, err := protojson.Marshal(req.GetUpdateMask())
  1289  		if err != nil {
  1290  			return nil, err
  1291  		}
  1292  		params.Add("updateMask", string(updateMask[1:len(updateMask)-1]))
  1293  	}
  1294  
  1295  	baseUrl.RawQuery = params.Encode()
  1296  
  1297  	// Build HTTP headers from client and context metadata.
  1298  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "project.name", url.QueryEscape(req.GetProject().GetName()))}
  1299  
  1300  	hds = append(c.xGoogHeaders, hds...)
  1301  	hds = append(hds, "Content-Type", "application/json")
  1302  	headers := gax.BuildHeaders(ctx, hds...)
  1303  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1304  	resp := &longrunningpb.Operation{}
  1305  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1306  		if settings.Path != "" {
  1307  			baseUrl.Path = settings.Path
  1308  		}
  1309  		httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
  1310  		if err != nil {
  1311  			return err
  1312  		}
  1313  		httpReq = httpReq.WithContext(ctx)
  1314  		httpReq.Header = headers
  1315  
  1316  		httpRsp, err := c.httpClient.Do(httpReq)
  1317  		if err != nil {
  1318  			return err
  1319  		}
  1320  		defer httpRsp.Body.Close()
  1321  
  1322  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1323  			return err
  1324  		}
  1325  
  1326  		buf, err := io.ReadAll(httpRsp.Body)
  1327  		if err != nil {
  1328  			return err
  1329  		}
  1330  
  1331  		if err := unm.Unmarshal(buf, resp); err != nil {
  1332  			return err
  1333  		}
  1334  
  1335  		return nil
  1336  	}, opts...)
  1337  	if e != nil {
  1338  		return nil, e
  1339  	}
  1340  
  1341  	override := fmt.Sprintf("/v3/%s", resp.GetName())
  1342  	return &UpdateProjectOperation{
  1343  		lro:      longrunning.InternalNewOperation(*c.LROClient, resp),
  1344  		pollPath: override,
  1345  	}, nil
  1346  }
  1347  
  1348  // MoveProject move a project to another place in your resource hierarchy, under a new
  1349  // resource parent.
  1350  //
  1351  // Returns an operation which can be used to track the process of the project
  1352  // move workflow.
  1353  // Upon success, the Operation.response field will be populated with the
  1354  // moved project.
  1355  //
  1356  // The caller must have resourcemanager.projects.move permission on the
  1357  // project, on the project’s current and proposed new parent.
  1358  //
  1359  // If project has no current parent, or it currently does not have an
  1360  // associated organization resource, you will also need the
  1361  // resourcemanager.projects.setIamPolicy permission in the project.
  1362  func (c *projectsRESTClient) MoveProject(ctx context.Context, req *resourcemanagerpb.MoveProjectRequest, opts ...gax.CallOption) (*MoveProjectOperation, error) {
  1363  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1364  	jsonReq, err := m.Marshal(req)
  1365  	if err != nil {
  1366  		return nil, err
  1367  	}
  1368  
  1369  	baseUrl, err := url.Parse(c.endpoint)
  1370  	if err != nil {
  1371  		return nil, err
  1372  	}
  1373  	baseUrl.Path += fmt.Sprintf("/v3/%v:move", req.GetName())
  1374  
  1375  	params := url.Values{}
  1376  	params.Add("$alt", "json;enum-encoding=int")
  1377  
  1378  	baseUrl.RawQuery = params.Encode()
  1379  
  1380  	// Build HTTP headers from client and context metadata.
  1381  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1382  
  1383  	hds = append(c.xGoogHeaders, hds...)
  1384  	hds = append(hds, "Content-Type", "application/json")
  1385  	headers := gax.BuildHeaders(ctx, hds...)
  1386  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1387  	resp := &longrunningpb.Operation{}
  1388  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1389  		if settings.Path != "" {
  1390  			baseUrl.Path = settings.Path
  1391  		}
  1392  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1393  		if err != nil {
  1394  			return err
  1395  		}
  1396  		httpReq = httpReq.WithContext(ctx)
  1397  		httpReq.Header = headers
  1398  
  1399  		httpRsp, err := c.httpClient.Do(httpReq)
  1400  		if err != nil {
  1401  			return err
  1402  		}
  1403  		defer httpRsp.Body.Close()
  1404  
  1405  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1406  			return err
  1407  		}
  1408  
  1409  		buf, err := io.ReadAll(httpRsp.Body)
  1410  		if err != nil {
  1411  			return err
  1412  		}
  1413  
  1414  		if err := unm.Unmarshal(buf, resp); err != nil {
  1415  			return err
  1416  		}
  1417  
  1418  		return nil
  1419  	}, opts...)
  1420  	if e != nil {
  1421  		return nil, e
  1422  	}
  1423  
  1424  	override := fmt.Sprintf("/v3/%s", resp.GetName())
  1425  	return &MoveProjectOperation{
  1426  		lro:      longrunning.InternalNewOperation(*c.LROClient, resp),
  1427  		pollPath: override,
  1428  	}, nil
  1429  }
  1430  
  1431  // DeleteProject marks the project identified by the specified
  1432  // name (for example, projects/415104041262) for deletion.
  1433  //
  1434  // This method will only affect the project if it has a lifecycle state of
  1435  // [ACTIVE][google.cloud.resourcemanager.v3.Project.State.ACTIVE (at http://google.cloud.resourcemanager.v3.Project.State.ACTIVE)].
  1436  //
  1437  // This method changes the Project’s lifecycle state from
  1438  // [ACTIVE][google.cloud.resourcemanager.v3.Project.State.ACTIVE (at http://google.cloud.resourcemanager.v3.Project.State.ACTIVE)]
  1439  // to
  1440  // DELETE_REQUESTED.
  1441  // The deletion starts at an unspecified time,
  1442  // at which point the Project is no longer accessible.
  1443  //
  1444  // Until the deletion completes, you can check the lifecycle state
  1445  // checked by retrieving the project with [GetProject]
  1446  // [google.cloud.resourcemanager.v3.Projects.GetProject],
  1447  // and the project remains visible to [ListProjects]
  1448  // [google.cloud.resourcemanager.v3.Projects.ListProjects].
  1449  // However, you cannot update the project.
  1450  //
  1451  // After the deletion completes, the project is not retrievable by
  1452  // the  [GetProject]
  1453  // [google.cloud.resourcemanager.v3.Projects.GetProject],
  1454  // [ListProjects]
  1455  // [google.cloud.resourcemanager.v3.Projects.ListProjects], and
  1456  // SearchProjects
  1457  // methods.
  1458  //
  1459  // This method behaves idempotently, such that deleting a DELETE_REQUESTED
  1460  // project will not cause an error, but also won’t do anything.
  1461  //
  1462  // The caller must have resourcemanager.projects.delete permissions for this
  1463  // project.
  1464  func (c *projectsRESTClient) DeleteProject(ctx context.Context, req *resourcemanagerpb.DeleteProjectRequest, opts ...gax.CallOption) (*DeleteProjectOperation, error) {
  1465  	baseUrl, err := url.Parse(c.endpoint)
  1466  	if err != nil {
  1467  		return nil, err
  1468  	}
  1469  	baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetName())
  1470  
  1471  	params := url.Values{}
  1472  	params.Add("$alt", "json;enum-encoding=int")
  1473  
  1474  	baseUrl.RawQuery = params.Encode()
  1475  
  1476  	// Build HTTP headers from client and context metadata.
  1477  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1478  
  1479  	hds = append(c.xGoogHeaders, hds...)
  1480  	hds = append(hds, "Content-Type", "application/json")
  1481  	headers := gax.BuildHeaders(ctx, hds...)
  1482  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1483  	resp := &longrunningpb.Operation{}
  1484  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1485  		if settings.Path != "" {
  1486  			baseUrl.Path = settings.Path
  1487  		}
  1488  		httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
  1489  		if err != nil {
  1490  			return err
  1491  		}
  1492  		httpReq = httpReq.WithContext(ctx)
  1493  		httpReq.Header = headers
  1494  
  1495  		httpRsp, err := c.httpClient.Do(httpReq)
  1496  		if err != nil {
  1497  			return err
  1498  		}
  1499  		defer httpRsp.Body.Close()
  1500  
  1501  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1502  			return err
  1503  		}
  1504  
  1505  		buf, err := io.ReadAll(httpRsp.Body)
  1506  		if err != nil {
  1507  			return err
  1508  		}
  1509  
  1510  		if err := unm.Unmarshal(buf, resp); err != nil {
  1511  			return err
  1512  		}
  1513  
  1514  		return nil
  1515  	}, opts...)
  1516  	if e != nil {
  1517  		return nil, e
  1518  	}
  1519  
  1520  	override := fmt.Sprintf("/v3/%s", resp.GetName())
  1521  	return &DeleteProjectOperation{
  1522  		lro:      longrunning.InternalNewOperation(*c.LROClient, resp),
  1523  		pollPath: override,
  1524  	}, nil
  1525  }
  1526  
  1527  // UndeleteProject restores the project identified by the specified
  1528  // name (for example, projects/415104041262).
  1529  // You can only use this method for a project that has a lifecycle state of
  1530  // [DELETE_REQUESTED]
  1531  // [Projects.State.DELETE_REQUESTED].
  1532  // After deletion starts, the project cannot be restored.
  1533  //
  1534  // The caller must have resourcemanager.projects.undelete permission for
  1535  // this project.
  1536  func (c *projectsRESTClient) UndeleteProject(ctx context.Context, req *resourcemanagerpb.UndeleteProjectRequest, opts ...gax.CallOption) (*UndeleteProjectOperation, error) {
  1537  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1538  	jsonReq, err := m.Marshal(req)
  1539  	if err != nil {
  1540  		return nil, err
  1541  	}
  1542  
  1543  	baseUrl, err := url.Parse(c.endpoint)
  1544  	if err != nil {
  1545  		return nil, err
  1546  	}
  1547  	baseUrl.Path += fmt.Sprintf("/v3/%v:undelete", req.GetName())
  1548  
  1549  	params := url.Values{}
  1550  	params.Add("$alt", "json;enum-encoding=int")
  1551  
  1552  	baseUrl.RawQuery = params.Encode()
  1553  
  1554  	// Build HTTP headers from client and context metadata.
  1555  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1556  
  1557  	hds = append(c.xGoogHeaders, hds...)
  1558  	hds = append(hds, "Content-Type", "application/json")
  1559  	headers := gax.BuildHeaders(ctx, hds...)
  1560  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1561  	resp := &longrunningpb.Operation{}
  1562  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1563  		if settings.Path != "" {
  1564  			baseUrl.Path = settings.Path
  1565  		}
  1566  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1567  		if err != nil {
  1568  			return err
  1569  		}
  1570  		httpReq = httpReq.WithContext(ctx)
  1571  		httpReq.Header = headers
  1572  
  1573  		httpRsp, err := c.httpClient.Do(httpReq)
  1574  		if err != nil {
  1575  			return err
  1576  		}
  1577  		defer httpRsp.Body.Close()
  1578  
  1579  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1580  			return err
  1581  		}
  1582  
  1583  		buf, err := io.ReadAll(httpRsp.Body)
  1584  		if err != nil {
  1585  			return err
  1586  		}
  1587  
  1588  		if err := unm.Unmarshal(buf, resp); err != nil {
  1589  			return err
  1590  		}
  1591  
  1592  		return nil
  1593  	}, opts...)
  1594  	if e != nil {
  1595  		return nil, e
  1596  	}
  1597  
  1598  	override := fmt.Sprintf("/v3/%s", resp.GetName())
  1599  	return &UndeleteProjectOperation{
  1600  		lro:      longrunning.InternalNewOperation(*c.LROClient, resp),
  1601  		pollPath: override,
  1602  	}, nil
  1603  }
  1604  
  1605  // GetIamPolicy returns the IAM access control policy for the specified project, in the
  1606  // format projects/{ProjectIdOrNumber} e.g. projects/123.
  1607  // Permission is denied if the policy or the resource do not exist.
  1608  func (c *projectsRESTClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
  1609  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1610  	jsonReq, err := m.Marshal(req)
  1611  	if err != nil {
  1612  		return nil, err
  1613  	}
  1614  
  1615  	baseUrl, err := url.Parse(c.endpoint)
  1616  	if err != nil {
  1617  		return nil, err
  1618  	}
  1619  	baseUrl.Path += fmt.Sprintf("/v3/%v:getIamPolicy", req.GetResource())
  1620  
  1621  	params := url.Values{}
  1622  	params.Add("$alt", "json;enum-encoding=int")
  1623  
  1624  	baseUrl.RawQuery = params.Encode()
  1625  
  1626  	// Build HTTP headers from client and context metadata.
  1627  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
  1628  
  1629  	hds = append(c.xGoogHeaders, hds...)
  1630  	hds = append(hds, "Content-Type", "application/json")
  1631  	headers := gax.BuildHeaders(ctx, hds...)
  1632  	opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
  1633  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1634  	resp := &iampb.Policy{}
  1635  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1636  		if settings.Path != "" {
  1637  			baseUrl.Path = settings.Path
  1638  		}
  1639  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1640  		if err != nil {
  1641  			return err
  1642  		}
  1643  		httpReq = httpReq.WithContext(ctx)
  1644  		httpReq.Header = headers
  1645  
  1646  		httpRsp, err := c.httpClient.Do(httpReq)
  1647  		if err != nil {
  1648  			return err
  1649  		}
  1650  		defer httpRsp.Body.Close()
  1651  
  1652  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1653  			return err
  1654  		}
  1655  
  1656  		buf, err := io.ReadAll(httpRsp.Body)
  1657  		if err != nil {
  1658  			return err
  1659  		}
  1660  
  1661  		if err := unm.Unmarshal(buf, resp); err != nil {
  1662  			return err
  1663  		}
  1664  
  1665  		return nil
  1666  	}, opts...)
  1667  	if e != nil {
  1668  		return nil, e
  1669  	}
  1670  	return resp, nil
  1671  }
  1672  
  1673  // SetIamPolicy sets the IAM access control policy for the specified project, in the
  1674  // format projects/{ProjectIdOrNumber} e.g. projects/123.
  1675  //
  1676  // CAUTION: This method will replace the existing policy, and cannot be used
  1677  // to append additional IAM settings.
  1678  //
  1679  // Note: Removing service accounts from policies or changing their roles can
  1680  // render services completely inoperable. It is important to understand how
  1681  // the service account is being used before removing or updating its roles.
  1682  //
  1683  // The following constraints apply when using setIamPolicy():
  1684  //
  1685  //	Project does not support allUsers and allAuthenticatedUsers as
  1686  //	members in a Binding of a Policy.
  1687  //
  1688  //	The owner role can be granted to a user, serviceAccount, or a group
  1689  //	that is part of an organization. For example,
  1690  //	group@myownpersonaldomain.com (at mailto:group@myownpersonaldomain.com) could be added as an owner to a project in
  1691  //	the myownpersonaldomain.com (at http://myownpersonaldomain.com) organization, but not the examplepetstore.com (at http://examplepetstore.com)
  1692  //	organization.
  1693  //
  1694  //	Service accounts can be made owners of a project directly
  1695  //	without any restrictions. However, to be added as an owner, a user must be
  1696  //	invited using the Cloud Platform console and must accept the invitation.
  1697  //
  1698  //	A user cannot be granted the owner role using setIamPolicy(). The user
  1699  //	must be granted the owner role using the Cloud Platform Console and must
  1700  //	explicitly accept the invitation.
  1701  //
  1702  //	Invitations to grant the owner role cannot be sent using
  1703  //	setIamPolicy();
  1704  //	they must be sent only using the Cloud Platform Console.
  1705  //
  1706  //	If the project is not part of an organization, there must be at least
  1707  //	one owner who has accepted the Terms of Service (ToS) agreement in the
  1708  //	policy. Calling setIamPolicy() to remove the last ToS-accepted owner
  1709  //	from the policy will fail. This restriction also applies to legacy
  1710  //	projects that no longer have owners who have accepted the ToS. Edits to
  1711  //	IAM policies will be rejected until the lack of a ToS-accepting owner is
  1712  //	rectified. If the project is part of an organization, you can remove all
  1713  //	owners, potentially making the organization inaccessible.
  1714  func (c *projectsRESTClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
  1715  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1716  	jsonReq, err := m.Marshal(req)
  1717  	if err != nil {
  1718  		return nil, err
  1719  	}
  1720  
  1721  	baseUrl, err := url.Parse(c.endpoint)
  1722  	if err != nil {
  1723  		return nil, err
  1724  	}
  1725  	baseUrl.Path += fmt.Sprintf("/v3/%v:setIamPolicy", req.GetResource())
  1726  
  1727  	params := url.Values{}
  1728  	params.Add("$alt", "json;enum-encoding=int")
  1729  
  1730  	baseUrl.RawQuery = params.Encode()
  1731  
  1732  	// Build HTTP headers from client and context metadata.
  1733  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
  1734  
  1735  	hds = append(c.xGoogHeaders, hds...)
  1736  	hds = append(hds, "Content-Type", "application/json")
  1737  	headers := gax.BuildHeaders(ctx, hds...)
  1738  	opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
  1739  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1740  	resp := &iampb.Policy{}
  1741  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1742  		if settings.Path != "" {
  1743  			baseUrl.Path = settings.Path
  1744  		}
  1745  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1746  		if err != nil {
  1747  			return err
  1748  		}
  1749  		httpReq = httpReq.WithContext(ctx)
  1750  		httpReq.Header = headers
  1751  
  1752  		httpRsp, err := c.httpClient.Do(httpReq)
  1753  		if err != nil {
  1754  			return err
  1755  		}
  1756  		defer httpRsp.Body.Close()
  1757  
  1758  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1759  			return err
  1760  		}
  1761  
  1762  		buf, err := io.ReadAll(httpRsp.Body)
  1763  		if err != nil {
  1764  			return err
  1765  		}
  1766  
  1767  		if err := unm.Unmarshal(buf, resp); err != nil {
  1768  			return err
  1769  		}
  1770  
  1771  		return nil
  1772  	}, opts...)
  1773  	if e != nil {
  1774  		return nil, e
  1775  	}
  1776  	return resp, nil
  1777  }
  1778  
  1779  // TestIamPermissions returns permissions that a caller has on the specified project, in the
  1780  // format projects/{ProjectIdOrNumber} e.g. projects/123…
  1781  func (c *projectsRESTClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
  1782  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1783  	jsonReq, err := m.Marshal(req)
  1784  	if err != nil {
  1785  		return nil, err
  1786  	}
  1787  
  1788  	baseUrl, err := url.Parse(c.endpoint)
  1789  	if err != nil {
  1790  		return nil, err
  1791  	}
  1792  	baseUrl.Path += fmt.Sprintf("/v3/%v:testIamPermissions", req.GetResource())
  1793  
  1794  	params := url.Values{}
  1795  	params.Add("$alt", "json;enum-encoding=int")
  1796  
  1797  	baseUrl.RawQuery = params.Encode()
  1798  
  1799  	// Build HTTP headers from client and context metadata.
  1800  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
  1801  
  1802  	hds = append(c.xGoogHeaders, hds...)
  1803  	hds = append(hds, "Content-Type", "application/json")
  1804  	headers := gax.BuildHeaders(ctx, hds...)
  1805  	opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
  1806  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1807  	resp := &iampb.TestIamPermissionsResponse{}
  1808  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1809  		if settings.Path != "" {
  1810  			baseUrl.Path = settings.Path
  1811  		}
  1812  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1813  		if err != nil {
  1814  			return err
  1815  		}
  1816  		httpReq = httpReq.WithContext(ctx)
  1817  		httpReq.Header = headers
  1818  
  1819  		httpRsp, err := c.httpClient.Do(httpReq)
  1820  		if err != nil {
  1821  			return err
  1822  		}
  1823  		defer httpRsp.Body.Close()
  1824  
  1825  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1826  			return err
  1827  		}
  1828  
  1829  		buf, err := io.ReadAll(httpRsp.Body)
  1830  		if err != nil {
  1831  			return err
  1832  		}
  1833  
  1834  		if err := unm.Unmarshal(buf, resp); err != nil {
  1835  			return err
  1836  		}
  1837  
  1838  		return nil
  1839  	}, opts...)
  1840  	if e != nil {
  1841  		return nil, e
  1842  	}
  1843  	return resp, nil
  1844  }
  1845  
  1846  // GetOperation is a utility method from google.longrunning.Operations.
  1847  func (c *projectsRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
  1848  	baseUrl, err := url.Parse(c.endpoint)
  1849  	if err != nil {
  1850  		return nil, err
  1851  	}
  1852  	baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetName())
  1853  
  1854  	params := url.Values{}
  1855  	params.Add("$alt", "json;enum-encoding=int")
  1856  
  1857  	baseUrl.RawQuery = params.Encode()
  1858  
  1859  	// Build HTTP headers from client and context metadata.
  1860  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1861  
  1862  	hds = append(c.xGoogHeaders, hds...)
  1863  	hds = append(hds, "Content-Type", "application/json")
  1864  	headers := gax.BuildHeaders(ctx, hds...)
  1865  	opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
  1866  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1867  	resp := &longrunningpb.Operation{}
  1868  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1869  		if settings.Path != "" {
  1870  			baseUrl.Path = settings.Path
  1871  		}
  1872  		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  1873  		if err != nil {
  1874  			return err
  1875  		}
  1876  		httpReq = httpReq.WithContext(ctx)
  1877  		httpReq.Header = headers
  1878  
  1879  		httpRsp, err := c.httpClient.Do(httpReq)
  1880  		if err != nil {
  1881  			return err
  1882  		}
  1883  		defer httpRsp.Body.Close()
  1884  
  1885  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1886  			return err
  1887  		}
  1888  
  1889  		buf, err := io.ReadAll(httpRsp.Body)
  1890  		if err != nil {
  1891  			return err
  1892  		}
  1893  
  1894  		if err := unm.Unmarshal(buf, resp); err != nil {
  1895  			return err
  1896  		}
  1897  
  1898  		return nil
  1899  	}, opts...)
  1900  	if e != nil {
  1901  		return nil, e
  1902  	}
  1903  	return resp, nil
  1904  }
  1905  
  1906  // CreateProjectOperation returns a new CreateProjectOperation from a given name.
  1907  // The name must be that of a previously created CreateProjectOperation, possibly from a different process.
  1908  func (c *projectsGRPCClient) CreateProjectOperation(name string) *CreateProjectOperation {
  1909  	return &CreateProjectOperation{
  1910  		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  1911  	}
  1912  }
  1913  
  1914  // CreateProjectOperation returns a new CreateProjectOperation from a given name.
  1915  // The name must be that of a previously created CreateProjectOperation, possibly from a different process.
  1916  func (c *projectsRESTClient) CreateProjectOperation(name string) *CreateProjectOperation {
  1917  	override := fmt.Sprintf("/v3/%s", name)
  1918  	return &CreateProjectOperation{
  1919  		lro:      longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  1920  		pollPath: override,
  1921  	}
  1922  }
  1923  
  1924  // DeleteProjectOperation returns a new DeleteProjectOperation from a given name.
  1925  // The name must be that of a previously created DeleteProjectOperation, possibly from a different process.
  1926  func (c *projectsGRPCClient) DeleteProjectOperation(name string) *DeleteProjectOperation {
  1927  	return &DeleteProjectOperation{
  1928  		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  1929  	}
  1930  }
  1931  
  1932  // DeleteProjectOperation returns a new DeleteProjectOperation from a given name.
  1933  // The name must be that of a previously created DeleteProjectOperation, possibly from a different process.
  1934  func (c *projectsRESTClient) DeleteProjectOperation(name string) *DeleteProjectOperation {
  1935  	override := fmt.Sprintf("/v3/%s", name)
  1936  	return &DeleteProjectOperation{
  1937  		lro:      longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  1938  		pollPath: override,
  1939  	}
  1940  }
  1941  
  1942  // MoveProjectOperation returns a new MoveProjectOperation from a given name.
  1943  // The name must be that of a previously created MoveProjectOperation, possibly from a different process.
  1944  func (c *projectsGRPCClient) MoveProjectOperation(name string) *MoveProjectOperation {
  1945  	return &MoveProjectOperation{
  1946  		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  1947  	}
  1948  }
  1949  
  1950  // MoveProjectOperation returns a new MoveProjectOperation from a given name.
  1951  // The name must be that of a previously created MoveProjectOperation, possibly from a different process.
  1952  func (c *projectsRESTClient) MoveProjectOperation(name string) *MoveProjectOperation {
  1953  	override := fmt.Sprintf("/v3/%s", name)
  1954  	return &MoveProjectOperation{
  1955  		lro:      longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  1956  		pollPath: override,
  1957  	}
  1958  }
  1959  
  1960  // UndeleteProjectOperation returns a new UndeleteProjectOperation from a given name.
  1961  // The name must be that of a previously created UndeleteProjectOperation, possibly from a different process.
  1962  func (c *projectsGRPCClient) UndeleteProjectOperation(name string) *UndeleteProjectOperation {
  1963  	return &UndeleteProjectOperation{
  1964  		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  1965  	}
  1966  }
  1967  
  1968  // UndeleteProjectOperation returns a new UndeleteProjectOperation from a given name.
  1969  // The name must be that of a previously created UndeleteProjectOperation, possibly from a different process.
  1970  func (c *projectsRESTClient) UndeleteProjectOperation(name string) *UndeleteProjectOperation {
  1971  	override := fmt.Sprintf("/v3/%s", name)
  1972  	return &UndeleteProjectOperation{
  1973  		lro:      longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  1974  		pollPath: override,
  1975  	}
  1976  }
  1977  
  1978  // UpdateProjectOperation returns a new UpdateProjectOperation from a given name.
  1979  // The name must be that of a previously created UpdateProjectOperation, possibly from a different process.
  1980  func (c *projectsGRPCClient) UpdateProjectOperation(name string) *UpdateProjectOperation {
  1981  	return &UpdateProjectOperation{
  1982  		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  1983  	}
  1984  }
  1985  
  1986  // UpdateProjectOperation returns a new UpdateProjectOperation from a given name.
  1987  // The name must be that of a previously created UpdateProjectOperation, possibly from a different process.
  1988  func (c *projectsRESTClient) UpdateProjectOperation(name string) *UpdateProjectOperation {
  1989  	override := fmt.Sprintf("/v3/%s", name)
  1990  	return &UpdateProjectOperation{
  1991  		lro:      longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  1992  		pollPath: override,
  1993  	}
  1994  }
  1995  

View as plain text