...

Source file src/cloud.google.com/go/resourcemanager/apiv3/folders_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 newFoldersClientHook clientHook
    48  
    49  // FoldersCallOptions contains the retry settings for each method of FoldersClient.
    50  type FoldersCallOptions struct {
    51  	GetFolder          []gax.CallOption
    52  	ListFolders        []gax.CallOption
    53  	SearchFolders      []gax.CallOption
    54  	CreateFolder       []gax.CallOption
    55  	UpdateFolder       []gax.CallOption
    56  	MoveFolder         []gax.CallOption
    57  	DeleteFolder       []gax.CallOption
    58  	UndeleteFolder     []gax.CallOption
    59  	GetIamPolicy       []gax.CallOption
    60  	SetIamPolicy       []gax.CallOption
    61  	TestIamPermissions []gax.CallOption
    62  	GetOperation       []gax.CallOption
    63  }
    64  
    65  func defaultFoldersGRPCClientOptions() []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 defaultFoldersCallOptions() *FoldersCallOptions {
    80  	return &FoldersCallOptions{
    81  		GetFolder: []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  		ListFolders: []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  		SearchFolders: []gax.CallOption{
   106  			gax.WithTimeout(60000 * time.Millisecond),
   107  		},
   108  		CreateFolder: []gax.CallOption{
   109  			gax.WithTimeout(60000 * time.Millisecond),
   110  		},
   111  		UpdateFolder: []gax.CallOption{
   112  			gax.WithTimeout(60000 * time.Millisecond),
   113  		},
   114  		MoveFolder: []gax.CallOption{
   115  			gax.WithTimeout(60000 * time.Millisecond),
   116  		},
   117  		DeleteFolder: []gax.CallOption{
   118  			gax.WithTimeout(60000 * time.Millisecond),
   119  		},
   120  		UndeleteFolder: []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 defaultFoldersRESTCallOptions() *FoldersCallOptions {
   144  	return &FoldersCallOptions{
   145  		GetFolder: []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  		ListFolders: []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  		SearchFolders: []gax.CallOption{
   168  			gax.WithTimeout(60000 * time.Millisecond),
   169  		},
   170  		CreateFolder: []gax.CallOption{
   171  			gax.WithTimeout(60000 * time.Millisecond),
   172  		},
   173  		UpdateFolder: []gax.CallOption{
   174  			gax.WithTimeout(60000 * time.Millisecond),
   175  		},
   176  		MoveFolder: []gax.CallOption{
   177  			gax.WithTimeout(60000 * time.Millisecond),
   178  		},
   179  		DeleteFolder: []gax.CallOption{
   180  			gax.WithTimeout(60000 * time.Millisecond),
   181  		},
   182  		UndeleteFolder: []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  // internalFoldersClient is an interface that defines the methods available from Cloud Resource Manager API.
   205  type internalFoldersClient interface {
   206  	Close() error
   207  	setGoogleClientInfo(...string)
   208  	Connection() *grpc.ClientConn
   209  	GetFolder(context.Context, *resourcemanagerpb.GetFolderRequest, ...gax.CallOption) (*resourcemanagerpb.Folder, error)
   210  	ListFolders(context.Context, *resourcemanagerpb.ListFoldersRequest, ...gax.CallOption) *FolderIterator
   211  	SearchFolders(context.Context, *resourcemanagerpb.SearchFoldersRequest, ...gax.CallOption) *FolderIterator
   212  	CreateFolder(context.Context, *resourcemanagerpb.CreateFolderRequest, ...gax.CallOption) (*CreateFolderOperation, error)
   213  	CreateFolderOperation(name string) *CreateFolderOperation
   214  	UpdateFolder(context.Context, *resourcemanagerpb.UpdateFolderRequest, ...gax.CallOption) (*UpdateFolderOperation, error)
   215  	UpdateFolderOperation(name string) *UpdateFolderOperation
   216  	MoveFolder(context.Context, *resourcemanagerpb.MoveFolderRequest, ...gax.CallOption) (*MoveFolderOperation, error)
   217  	MoveFolderOperation(name string) *MoveFolderOperation
   218  	DeleteFolder(context.Context, *resourcemanagerpb.DeleteFolderRequest, ...gax.CallOption) (*DeleteFolderOperation, error)
   219  	DeleteFolderOperation(name string) *DeleteFolderOperation
   220  	UndeleteFolder(context.Context, *resourcemanagerpb.UndeleteFolderRequest, ...gax.CallOption) (*UndeleteFolderOperation, error)
   221  	UndeleteFolderOperation(name string) *UndeleteFolderOperation
   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  // FoldersClient 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 Cloud Platform folder resources.
   232  // Folders can be used to organize the resources under an
   233  // organization and to control the policies applied to groups of resources.
   234  type FoldersClient struct {
   235  	// The internal transport-dependent client.
   236  	internalClient internalFoldersClient
   237  
   238  	// The call options for this service.
   239  	CallOptions *FoldersCallOptions
   240  
   241  	// LROClient is used internally to handle long-running operations.
   242  	// It is exposed so that its CallOptions can be modified if required.
   243  	// Users should not Close this client.
   244  	LROClient *lroauto.OperationsClient
   245  }
   246  
   247  // Wrapper methods routed to the internal client.
   248  
   249  // Close closes the connection to the API service. The user should invoke this when
   250  // the client is no longer required.
   251  func (c *FoldersClient) Close() error {
   252  	return c.internalClient.Close()
   253  }
   254  
   255  // setGoogleClientInfo sets the name and version of the application in
   256  // the `x-goog-api-client` header passed on each request. Intended for
   257  // use by Google-written clients.
   258  func (c *FoldersClient) setGoogleClientInfo(keyval ...string) {
   259  	c.internalClient.setGoogleClientInfo(keyval...)
   260  }
   261  
   262  // Connection returns a connection to the API service.
   263  //
   264  // Deprecated: Connections are now pooled so this method does not always
   265  // return the same resource.
   266  func (c *FoldersClient) Connection() *grpc.ClientConn {
   267  	return c.internalClient.Connection()
   268  }
   269  
   270  // GetFolder retrieves a folder identified by the supplied resource name.
   271  // Valid folder resource names have the format folders/{folder_id}
   272  // (for example, folders/1234).
   273  // The caller must have resourcemanager.folders.get permission on the
   274  // identified folder.
   275  func (c *FoldersClient) GetFolder(ctx context.Context, req *resourcemanagerpb.GetFolderRequest, opts ...gax.CallOption) (*resourcemanagerpb.Folder, error) {
   276  	return c.internalClient.GetFolder(ctx, req, opts...)
   277  }
   278  
   279  // ListFolders lists the folders that are direct descendants of supplied parent resource.
   280  // list() provides a strongly consistent view of the folders underneath
   281  // the specified parent resource.
   282  // list() returns folders sorted based upon the (ascending) lexical ordering
   283  // of their display_name.
   284  // The caller must have resourcemanager.folders.list permission on the
   285  // identified parent.
   286  func (c *FoldersClient) ListFolders(ctx context.Context, req *resourcemanagerpb.ListFoldersRequest, opts ...gax.CallOption) *FolderIterator {
   287  	return c.internalClient.ListFolders(ctx, req, opts...)
   288  }
   289  
   290  // SearchFolders search for folders that match specific filter criteria.
   291  // search() provides an eventually consistent view of the folders a user has
   292  // access to which meet the specified filter criteria.
   293  //
   294  // This will only return folders on which the caller has the
   295  // permission resourcemanager.folders.get.
   296  func (c *FoldersClient) SearchFolders(ctx context.Context, req *resourcemanagerpb.SearchFoldersRequest, opts ...gax.CallOption) *FolderIterator {
   297  	return c.internalClient.SearchFolders(ctx, req, opts...)
   298  }
   299  
   300  // CreateFolder creates a folder in the resource hierarchy.
   301  // Returns an Operation which can be used to track the progress of the
   302  // folder creation workflow.
   303  // Upon success, the Operation.response field will be populated with the
   304  // created Folder.
   305  //
   306  // In order to succeed, the addition of this new folder must not violate
   307  // the folder naming, height, or fanout constraints.
   308  //
   309  //	The folder’s display_name must be distinct from all other folders that
   310  //	share its parent.
   311  //
   312  //	The addition of the folder must not cause the active folder hierarchy
   313  //	to exceed a height of 10. Note, the full active + deleted folder hierarchy
   314  //	is allowed to reach a height of 20; this provides additional headroom when
   315  //	moving folders that contain deleted folders.
   316  //
   317  //	The addition of the folder must not cause the total number of folders
   318  //	under its parent to exceed 300.
   319  //
   320  // If the operation fails due to a folder constraint violation, some errors
   321  // may be returned by the CreateFolder request, with status code
   322  // FAILED_PRECONDITION and an error description. Other folder constraint
   323  // violations will be communicated in the Operation, with the specific
   324  // PreconditionFailure returned in the details list in the Operation.error
   325  // field.
   326  //
   327  // The caller must have resourcemanager.folders.create permission on the
   328  // identified parent.
   329  func (c *FoldersClient) CreateFolder(ctx context.Context, req *resourcemanagerpb.CreateFolderRequest, opts ...gax.CallOption) (*CreateFolderOperation, error) {
   330  	return c.internalClient.CreateFolder(ctx, req, opts...)
   331  }
   332  
   333  // CreateFolderOperation returns a new CreateFolderOperation from a given name.
   334  // The name must be that of a previously created CreateFolderOperation, possibly from a different process.
   335  func (c *FoldersClient) CreateFolderOperation(name string) *CreateFolderOperation {
   336  	return c.internalClient.CreateFolderOperation(name)
   337  }
   338  
   339  // UpdateFolder updates a folder, changing its display_name.
   340  // Changes to the folder display_name will be rejected if they violate
   341  // either the display_name formatting rules or the naming constraints
   342  // described in the
   343  // CreateFolder
   344  // documentation.
   345  //
   346  // The folder’s display_name must start and end with a letter or digit,
   347  // may contain letters, digits, spaces, hyphens and underscores and can be
   348  // between 3 and 30 characters. This is captured by the regular expression:
   349  // [\p{L}\p{N}][\p{L}\p{N}_- ]{1,28}[\p{L}\p{N}].
   350  // The caller must have resourcemanager.folders.update permission on the
   351  // identified folder.
   352  //
   353  // If the update fails due to the unique name constraint then a
   354  // PreconditionFailure explaining this violation will be returned
   355  // in the Status.details field.
   356  func (c *FoldersClient) UpdateFolder(ctx context.Context, req *resourcemanagerpb.UpdateFolderRequest, opts ...gax.CallOption) (*UpdateFolderOperation, error) {
   357  	return c.internalClient.UpdateFolder(ctx, req, opts...)
   358  }
   359  
   360  // UpdateFolderOperation returns a new UpdateFolderOperation from a given name.
   361  // The name must be that of a previously created UpdateFolderOperation, possibly from a different process.
   362  func (c *FoldersClient) UpdateFolderOperation(name string) *UpdateFolderOperation {
   363  	return c.internalClient.UpdateFolderOperation(name)
   364  }
   365  
   366  // MoveFolder moves a folder under a new resource parent.
   367  // Returns an Operation which can be used to track the progress of the
   368  // folder move workflow.
   369  // Upon success, the Operation.response field will be populated with the
   370  // moved folder.
   371  // Upon failure, a FolderOperationError categorizing the failure cause will
   372  // be returned - if the failure occurs synchronously then the
   373  // FolderOperationError will be returned in the Status.details field.
   374  // If it occurs asynchronously, then the FolderOperation will be returned
   375  // in the Operation.error field.
   376  // In addition, the Operation.metadata field will be populated with a
   377  // FolderOperation message as an aid to stateless clients.
   378  // Folder moves will be rejected if they violate either the naming, height,
   379  // or fanout constraints described in the
   380  // CreateFolder
   381  // documentation. The caller must have resourcemanager.folders.move
   382  // permission on the folder’s current and proposed new parent.
   383  func (c *FoldersClient) MoveFolder(ctx context.Context, req *resourcemanagerpb.MoveFolderRequest, opts ...gax.CallOption) (*MoveFolderOperation, error) {
   384  	return c.internalClient.MoveFolder(ctx, req, opts...)
   385  }
   386  
   387  // MoveFolderOperation returns a new MoveFolderOperation from a given name.
   388  // The name must be that of a previously created MoveFolderOperation, possibly from a different process.
   389  func (c *FoldersClient) MoveFolderOperation(name string) *MoveFolderOperation {
   390  	return c.internalClient.MoveFolderOperation(name)
   391  }
   392  
   393  // DeleteFolder requests deletion of a folder. The folder is moved into the
   394  // DELETE_REQUESTED
   395  // state immediately, and is deleted approximately 30 days later. This method
   396  // may only be called on an empty folder, where a folder is empty if it
   397  // doesn’t contain any folders or projects in the
   398  // [ACTIVE][google.cloud.resourcemanager.v3.Folder.State.ACTIVE (at http://google.cloud.resourcemanager.v3.Folder.State.ACTIVE)] state. If
   399  // called on a folder in
   400  // DELETE_REQUESTED
   401  // state the operation will result in a no-op success.
   402  // The caller must have resourcemanager.folders.delete permission on the
   403  // identified folder.
   404  func (c *FoldersClient) DeleteFolder(ctx context.Context, req *resourcemanagerpb.DeleteFolderRequest, opts ...gax.CallOption) (*DeleteFolderOperation, error) {
   405  	return c.internalClient.DeleteFolder(ctx, req, opts...)
   406  }
   407  
   408  // DeleteFolderOperation returns a new DeleteFolderOperation from a given name.
   409  // The name must be that of a previously created DeleteFolderOperation, possibly from a different process.
   410  func (c *FoldersClient) DeleteFolderOperation(name string) *DeleteFolderOperation {
   411  	return c.internalClient.DeleteFolderOperation(name)
   412  }
   413  
   414  // UndeleteFolder cancels the deletion request for a folder. This method may be called on a
   415  // folder in any state. If the folder is in the
   416  // [ACTIVE][google.cloud.resourcemanager.v3.Folder.State.ACTIVE (at http://google.cloud.resourcemanager.v3.Folder.State.ACTIVE)] state the
   417  // result will be a no-op success. In order to succeed, the folder’s parent
   418  // must be in the
   419  // [ACTIVE][google.cloud.resourcemanager.v3.Folder.State.ACTIVE (at http://google.cloud.resourcemanager.v3.Folder.State.ACTIVE)] state. In
   420  // addition, reintroducing the folder into the tree must not violate folder
   421  // naming, height, and fanout constraints described in the
   422  // CreateFolder
   423  // documentation. The caller must have resourcemanager.folders.undelete
   424  // permission on the identified folder.
   425  func (c *FoldersClient) UndeleteFolder(ctx context.Context, req *resourcemanagerpb.UndeleteFolderRequest, opts ...gax.CallOption) (*UndeleteFolderOperation, error) {
   426  	return c.internalClient.UndeleteFolder(ctx, req, opts...)
   427  }
   428  
   429  // UndeleteFolderOperation returns a new UndeleteFolderOperation from a given name.
   430  // The name must be that of a previously created UndeleteFolderOperation, possibly from a different process.
   431  func (c *FoldersClient) UndeleteFolderOperation(name string) *UndeleteFolderOperation {
   432  	return c.internalClient.UndeleteFolderOperation(name)
   433  }
   434  
   435  // GetIamPolicy gets the access control policy for a folder. The returned policy may be
   436  // empty if no such policy or resource exists. The resource field should
   437  // be the folder’s resource name, for example: “folders/1234”.
   438  // The caller must have resourcemanager.folders.getIamPolicy permission
   439  // on the identified folder.
   440  func (c *FoldersClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   441  	return c.internalClient.GetIamPolicy(ctx, req, opts...)
   442  }
   443  
   444  // SetIamPolicy sets the access control policy on a folder, replacing any existing policy.
   445  // The resource field should be the folder’s resource name, for example:
   446  // “folders/1234”.
   447  // The caller must have resourcemanager.folders.setIamPolicy permission
   448  // on the identified folder.
   449  func (c *FoldersClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   450  	return c.internalClient.SetIamPolicy(ctx, req, opts...)
   451  }
   452  
   453  // TestIamPermissions returns permissions that a caller has on the specified folder.
   454  // The resource field should be the folder’s resource name,
   455  // for example: “folders/1234”.
   456  //
   457  // There are no permissions required for making this API call.
   458  func (c *FoldersClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
   459  	return c.internalClient.TestIamPermissions(ctx, req, opts...)
   460  }
   461  
   462  // GetOperation is a utility method from google.longrunning.Operations.
   463  func (c *FoldersClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   464  	return c.internalClient.GetOperation(ctx, req, opts...)
   465  }
   466  
   467  // foldersGRPCClient is a client for interacting with Cloud Resource Manager API over gRPC transport.
   468  //
   469  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   470  type foldersGRPCClient struct {
   471  	// Connection pool of gRPC connections to the service.
   472  	connPool gtransport.ConnPool
   473  
   474  	// Points back to the CallOptions field of the containing FoldersClient
   475  	CallOptions **FoldersCallOptions
   476  
   477  	// The gRPC API client.
   478  	foldersClient resourcemanagerpb.FoldersClient
   479  
   480  	// LROClient is used internally to handle long-running operations.
   481  	// It is exposed so that its CallOptions can be modified if required.
   482  	// Users should not Close this client.
   483  	LROClient **lroauto.OperationsClient
   484  
   485  	operationsClient longrunningpb.OperationsClient
   486  
   487  	// The x-goog-* metadata to be sent with each request.
   488  	xGoogHeaders []string
   489  }
   490  
   491  // NewFoldersClient creates a new folders client based on gRPC.
   492  // The returned client must be Closed when it is done being used to clean up its underlying connections.
   493  //
   494  // Manages Cloud Platform folder resources.
   495  // Folders can be used to organize the resources under an
   496  // organization and to control the policies applied to groups of resources.
   497  func NewFoldersClient(ctx context.Context, opts ...option.ClientOption) (*FoldersClient, error) {
   498  	clientOpts := defaultFoldersGRPCClientOptions()
   499  	if newFoldersClientHook != nil {
   500  		hookOpts, err := newFoldersClientHook(ctx, clientHookParams{})
   501  		if err != nil {
   502  			return nil, err
   503  		}
   504  		clientOpts = append(clientOpts, hookOpts...)
   505  	}
   506  
   507  	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
   508  	if err != nil {
   509  		return nil, err
   510  	}
   511  	client := FoldersClient{CallOptions: defaultFoldersCallOptions()}
   512  
   513  	c := &foldersGRPCClient{
   514  		connPool:         connPool,
   515  		foldersClient:    resourcemanagerpb.NewFoldersClient(connPool),
   516  		CallOptions:      &client.CallOptions,
   517  		operationsClient: longrunningpb.NewOperationsClient(connPool),
   518  	}
   519  	c.setGoogleClientInfo()
   520  
   521  	client.internalClient = c
   522  
   523  	client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
   524  	if err != nil {
   525  		// This error "should not happen", since we are just reusing old connection pool
   526  		// and never actually need to dial.
   527  		// If this does happen, we could leak connp. However, we cannot close conn:
   528  		// If the user invoked the constructor with option.WithGRPCConn,
   529  		// we would close a connection that's still in use.
   530  		// TODO: investigate error conditions.
   531  		return nil, err
   532  	}
   533  	c.LROClient = &client.LROClient
   534  	return &client, nil
   535  }
   536  
   537  // Connection returns a connection to the API service.
   538  //
   539  // Deprecated: Connections are now pooled so this method does not always
   540  // return the same resource.
   541  func (c *foldersGRPCClient) Connection() *grpc.ClientConn {
   542  	return c.connPool.Conn()
   543  }
   544  
   545  // setGoogleClientInfo sets the name and version of the application in
   546  // the `x-goog-api-client` header passed on each request. Intended for
   547  // use by Google-written clients.
   548  func (c *foldersGRPCClient) setGoogleClientInfo(keyval ...string) {
   549  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   550  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version)
   551  	c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
   552  }
   553  
   554  // Close closes the connection to the API service. The user should invoke this when
   555  // the client is no longer required.
   556  func (c *foldersGRPCClient) Close() error {
   557  	return c.connPool.Close()
   558  }
   559  
   560  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   561  type foldersRESTClient struct {
   562  	// The http endpoint to connect to.
   563  	endpoint string
   564  
   565  	// The http client.
   566  	httpClient *http.Client
   567  
   568  	// LROClient is used internally to handle long-running operations.
   569  	// It is exposed so that its CallOptions can be modified if required.
   570  	// Users should not Close this client.
   571  	LROClient **lroauto.OperationsClient
   572  
   573  	// The x-goog-* headers to be sent with each request.
   574  	xGoogHeaders []string
   575  
   576  	// Points back to the CallOptions field of the containing FoldersClient
   577  	CallOptions **FoldersCallOptions
   578  }
   579  
   580  // NewFoldersRESTClient creates a new folders rest client.
   581  //
   582  // Manages Cloud Platform folder resources.
   583  // Folders can be used to organize the resources under an
   584  // organization and to control the policies applied to groups of resources.
   585  func NewFoldersRESTClient(ctx context.Context, opts ...option.ClientOption) (*FoldersClient, error) {
   586  	clientOpts := append(defaultFoldersRESTClientOptions(), opts...)
   587  	httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
   588  	if err != nil {
   589  		return nil, err
   590  	}
   591  
   592  	callOpts := defaultFoldersRESTCallOptions()
   593  	c := &foldersRESTClient{
   594  		endpoint:    endpoint,
   595  		httpClient:  httpClient,
   596  		CallOptions: &callOpts,
   597  	}
   598  	c.setGoogleClientInfo()
   599  
   600  	lroOpts := []option.ClientOption{
   601  		option.WithHTTPClient(httpClient),
   602  		option.WithEndpoint(endpoint),
   603  	}
   604  	opClient, err := lroauto.NewOperationsRESTClient(ctx, lroOpts...)
   605  	if err != nil {
   606  		return nil, err
   607  	}
   608  	c.LROClient = &opClient
   609  
   610  	return &FoldersClient{internalClient: c, CallOptions: callOpts}, nil
   611  }
   612  
   613  func defaultFoldersRESTClientOptions() []option.ClientOption {
   614  	return []option.ClientOption{
   615  		internaloption.WithDefaultEndpoint("https://cloudresourcemanager.googleapis.com"),
   616  		internaloption.WithDefaultEndpointTemplate("https://cloudresourcemanager.UNIVERSE_DOMAIN"),
   617  		internaloption.WithDefaultMTLSEndpoint("https://cloudresourcemanager.mtls.googleapis.com"),
   618  		internaloption.WithDefaultUniverseDomain("googleapis.com"),
   619  		internaloption.WithDefaultAudience("https://cloudresourcemanager.googleapis.com/"),
   620  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
   621  	}
   622  }
   623  
   624  // setGoogleClientInfo sets the name and version of the application in
   625  // the `x-goog-api-client` header passed on each request. Intended for
   626  // use by Google-written clients.
   627  func (c *foldersRESTClient) setGoogleClientInfo(keyval ...string) {
   628  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   629  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN")
   630  	c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
   631  }
   632  
   633  // Close closes the connection to the API service. The user should invoke this when
   634  // the client is no longer required.
   635  func (c *foldersRESTClient) Close() error {
   636  	// Replace httpClient with nil to force cleanup.
   637  	c.httpClient = nil
   638  	return nil
   639  }
   640  
   641  // Connection returns a connection to the API service.
   642  //
   643  // Deprecated: This method always returns nil.
   644  func (c *foldersRESTClient) Connection() *grpc.ClientConn {
   645  	return nil
   646  }
   647  func (c *foldersGRPCClient) GetFolder(ctx context.Context, req *resourcemanagerpb.GetFolderRequest, opts ...gax.CallOption) (*resourcemanagerpb.Folder, error) {
   648  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   649  
   650  	hds = append(c.xGoogHeaders, hds...)
   651  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   652  	opts = append((*c.CallOptions).GetFolder[0:len((*c.CallOptions).GetFolder):len((*c.CallOptions).GetFolder)], opts...)
   653  	var resp *resourcemanagerpb.Folder
   654  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   655  		var err error
   656  		resp, err = c.foldersClient.GetFolder(ctx, req, settings.GRPC...)
   657  		return err
   658  	}, opts...)
   659  	if err != nil {
   660  		return nil, err
   661  	}
   662  	return resp, nil
   663  }
   664  
   665  func (c *foldersGRPCClient) ListFolders(ctx context.Context, req *resourcemanagerpb.ListFoldersRequest, opts ...gax.CallOption) *FolderIterator {
   666  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
   667  	opts = append((*c.CallOptions).ListFolders[0:len((*c.CallOptions).ListFolders):len((*c.CallOptions).ListFolders)], opts...)
   668  	it := &FolderIterator{}
   669  	req = proto.Clone(req).(*resourcemanagerpb.ListFoldersRequest)
   670  	it.InternalFetch = func(pageSize int, pageToken string) ([]*resourcemanagerpb.Folder, string, error) {
   671  		resp := &resourcemanagerpb.ListFoldersResponse{}
   672  		if pageToken != "" {
   673  			req.PageToken = pageToken
   674  		}
   675  		if pageSize > math.MaxInt32 {
   676  			req.PageSize = math.MaxInt32
   677  		} else if pageSize != 0 {
   678  			req.PageSize = int32(pageSize)
   679  		}
   680  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   681  			var err error
   682  			resp, err = c.foldersClient.ListFolders(ctx, req, settings.GRPC...)
   683  			return err
   684  		}, opts...)
   685  		if err != nil {
   686  			return nil, "", err
   687  		}
   688  
   689  		it.Response = resp
   690  		return resp.GetFolders(), resp.GetNextPageToken(), nil
   691  	}
   692  	fetch := func(pageSize int, pageToken string) (string, error) {
   693  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   694  		if err != nil {
   695  			return "", err
   696  		}
   697  		it.items = append(it.items, items...)
   698  		return nextPageToken, nil
   699  	}
   700  
   701  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   702  	it.pageInfo.MaxSize = int(req.GetPageSize())
   703  	it.pageInfo.Token = req.GetPageToken()
   704  
   705  	return it
   706  }
   707  
   708  func (c *foldersGRPCClient) SearchFolders(ctx context.Context, req *resourcemanagerpb.SearchFoldersRequest, opts ...gax.CallOption) *FolderIterator {
   709  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
   710  	opts = append((*c.CallOptions).SearchFolders[0:len((*c.CallOptions).SearchFolders):len((*c.CallOptions).SearchFolders)], opts...)
   711  	it := &FolderIterator{}
   712  	req = proto.Clone(req).(*resourcemanagerpb.SearchFoldersRequest)
   713  	it.InternalFetch = func(pageSize int, pageToken string) ([]*resourcemanagerpb.Folder, string, error) {
   714  		resp := &resourcemanagerpb.SearchFoldersResponse{}
   715  		if pageToken != "" {
   716  			req.PageToken = pageToken
   717  		}
   718  		if pageSize > math.MaxInt32 {
   719  			req.PageSize = math.MaxInt32
   720  		} else if pageSize != 0 {
   721  			req.PageSize = int32(pageSize)
   722  		}
   723  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   724  			var err error
   725  			resp, err = c.foldersClient.SearchFolders(ctx, req, settings.GRPC...)
   726  			return err
   727  		}, opts...)
   728  		if err != nil {
   729  			return nil, "", err
   730  		}
   731  
   732  		it.Response = resp
   733  		return resp.GetFolders(), resp.GetNextPageToken(), nil
   734  	}
   735  	fetch := func(pageSize int, pageToken string) (string, error) {
   736  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   737  		if err != nil {
   738  			return "", err
   739  		}
   740  		it.items = append(it.items, items...)
   741  		return nextPageToken, nil
   742  	}
   743  
   744  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   745  	it.pageInfo.MaxSize = int(req.GetPageSize())
   746  	it.pageInfo.Token = req.GetPageToken()
   747  
   748  	return it
   749  }
   750  
   751  func (c *foldersGRPCClient) CreateFolder(ctx context.Context, req *resourcemanagerpb.CreateFolderRequest, opts ...gax.CallOption) (*CreateFolderOperation, error) {
   752  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
   753  	opts = append((*c.CallOptions).CreateFolder[0:len((*c.CallOptions).CreateFolder):len((*c.CallOptions).CreateFolder)], opts...)
   754  	var resp *longrunningpb.Operation
   755  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   756  		var err error
   757  		resp, err = c.foldersClient.CreateFolder(ctx, req, settings.GRPC...)
   758  		return err
   759  	}, opts...)
   760  	if err != nil {
   761  		return nil, err
   762  	}
   763  	return &CreateFolderOperation{
   764  		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
   765  	}, nil
   766  }
   767  
   768  func (c *foldersGRPCClient) UpdateFolder(ctx context.Context, req *resourcemanagerpb.UpdateFolderRequest, opts ...gax.CallOption) (*UpdateFolderOperation, error) {
   769  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "folder.name", url.QueryEscape(req.GetFolder().GetName()))}
   770  
   771  	hds = append(c.xGoogHeaders, hds...)
   772  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   773  	opts = append((*c.CallOptions).UpdateFolder[0:len((*c.CallOptions).UpdateFolder):len((*c.CallOptions).UpdateFolder)], opts...)
   774  	var resp *longrunningpb.Operation
   775  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   776  		var err error
   777  		resp, err = c.foldersClient.UpdateFolder(ctx, req, settings.GRPC...)
   778  		return err
   779  	}, opts...)
   780  	if err != nil {
   781  		return nil, err
   782  	}
   783  	return &UpdateFolderOperation{
   784  		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
   785  	}, nil
   786  }
   787  
   788  func (c *foldersGRPCClient) MoveFolder(ctx context.Context, req *resourcemanagerpb.MoveFolderRequest, opts ...gax.CallOption) (*MoveFolderOperation, error) {
   789  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   790  
   791  	hds = append(c.xGoogHeaders, hds...)
   792  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   793  	opts = append((*c.CallOptions).MoveFolder[0:len((*c.CallOptions).MoveFolder):len((*c.CallOptions).MoveFolder)], opts...)
   794  	var resp *longrunningpb.Operation
   795  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   796  		var err error
   797  		resp, err = c.foldersClient.MoveFolder(ctx, req, settings.GRPC...)
   798  		return err
   799  	}, opts...)
   800  	if err != nil {
   801  		return nil, err
   802  	}
   803  	return &MoveFolderOperation{
   804  		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
   805  	}, nil
   806  }
   807  
   808  func (c *foldersGRPCClient) DeleteFolder(ctx context.Context, req *resourcemanagerpb.DeleteFolderRequest, opts ...gax.CallOption) (*DeleteFolderOperation, error) {
   809  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   810  
   811  	hds = append(c.xGoogHeaders, hds...)
   812  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   813  	opts = append((*c.CallOptions).DeleteFolder[0:len((*c.CallOptions).DeleteFolder):len((*c.CallOptions).DeleteFolder)], opts...)
   814  	var resp *longrunningpb.Operation
   815  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   816  		var err error
   817  		resp, err = c.foldersClient.DeleteFolder(ctx, req, settings.GRPC...)
   818  		return err
   819  	}, opts...)
   820  	if err != nil {
   821  		return nil, err
   822  	}
   823  	return &DeleteFolderOperation{
   824  		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
   825  	}, nil
   826  }
   827  
   828  func (c *foldersGRPCClient) UndeleteFolder(ctx context.Context, req *resourcemanagerpb.UndeleteFolderRequest, opts ...gax.CallOption) (*UndeleteFolderOperation, error) {
   829  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   830  
   831  	hds = append(c.xGoogHeaders, hds...)
   832  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   833  	opts = append((*c.CallOptions).UndeleteFolder[0:len((*c.CallOptions).UndeleteFolder):len((*c.CallOptions).UndeleteFolder)], opts...)
   834  	var resp *longrunningpb.Operation
   835  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   836  		var err error
   837  		resp, err = c.foldersClient.UndeleteFolder(ctx, req, settings.GRPC...)
   838  		return err
   839  	}, opts...)
   840  	if err != nil {
   841  		return nil, err
   842  	}
   843  	return &UndeleteFolderOperation{
   844  		lro: longrunning.InternalNewOperation(*c.LROClient, resp),
   845  	}, nil
   846  }
   847  
   848  func (c *foldersGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   849  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   850  
   851  	hds = append(c.xGoogHeaders, hds...)
   852  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   853  	opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
   854  	var resp *iampb.Policy
   855  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   856  		var err error
   857  		resp, err = c.foldersClient.GetIamPolicy(ctx, req, settings.GRPC...)
   858  		return err
   859  	}, opts...)
   860  	if err != nil {
   861  		return nil, err
   862  	}
   863  	return resp, nil
   864  }
   865  
   866  func (c *foldersGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   867  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   868  
   869  	hds = append(c.xGoogHeaders, hds...)
   870  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   871  	opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
   872  	var resp *iampb.Policy
   873  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   874  		var err error
   875  		resp, err = c.foldersClient.SetIamPolicy(ctx, req, settings.GRPC...)
   876  		return err
   877  	}, opts...)
   878  	if err != nil {
   879  		return nil, err
   880  	}
   881  	return resp, nil
   882  }
   883  
   884  func (c *foldersGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
   885  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   886  
   887  	hds = append(c.xGoogHeaders, hds...)
   888  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   889  	opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
   890  	var resp *iampb.TestIamPermissionsResponse
   891  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   892  		var err error
   893  		resp, err = c.foldersClient.TestIamPermissions(ctx, req, settings.GRPC...)
   894  		return err
   895  	}, opts...)
   896  	if err != nil {
   897  		return nil, err
   898  	}
   899  	return resp, nil
   900  }
   901  
   902  func (c *foldersGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   903  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   904  
   905  	hds = append(c.xGoogHeaders, hds...)
   906  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   907  	opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
   908  	var resp *longrunningpb.Operation
   909  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   910  		var err error
   911  		resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...)
   912  		return err
   913  	}, opts...)
   914  	if err != nil {
   915  		return nil, err
   916  	}
   917  	return resp, nil
   918  }
   919  
   920  // GetFolder retrieves a folder identified by the supplied resource name.
   921  // Valid folder resource names have the format folders/{folder_id}
   922  // (for example, folders/1234).
   923  // The caller must have resourcemanager.folders.get permission on the
   924  // identified folder.
   925  func (c *foldersRESTClient) GetFolder(ctx context.Context, req *resourcemanagerpb.GetFolderRequest, opts ...gax.CallOption) (*resourcemanagerpb.Folder, error) {
   926  	baseUrl, err := url.Parse(c.endpoint)
   927  	if err != nil {
   928  		return nil, err
   929  	}
   930  	baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetName())
   931  
   932  	params := url.Values{}
   933  	params.Add("$alt", "json;enum-encoding=int")
   934  
   935  	baseUrl.RawQuery = params.Encode()
   936  
   937  	// Build HTTP headers from client and context metadata.
   938  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   939  
   940  	hds = append(c.xGoogHeaders, hds...)
   941  	hds = append(hds, "Content-Type", "application/json")
   942  	headers := gax.BuildHeaders(ctx, hds...)
   943  	opts = append((*c.CallOptions).GetFolder[0:len((*c.CallOptions).GetFolder):len((*c.CallOptions).GetFolder)], opts...)
   944  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   945  	resp := &resourcemanagerpb.Folder{}
   946  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   947  		if settings.Path != "" {
   948  			baseUrl.Path = settings.Path
   949  		}
   950  		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
   951  		if err != nil {
   952  			return err
   953  		}
   954  		httpReq = httpReq.WithContext(ctx)
   955  		httpReq.Header = headers
   956  
   957  		httpRsp, err := c.httpClient.Do(httpReq)
   958  		if err != nil {
   959  			return err
   960  		}
   961  		defer httpRsp.Body.Close()
   962  
   963  		if err = googleapi.CheckResponse(httpRsp); err != nil {
   964  			return err
   965  		}
   966  
   967  		buf, err := io.ReadAll(httpRsp.Body)
   968  		if err != nil {
   969  			return err
   970  		}
   971  
   972  		if err := unm.Unmarshal(buf, resp); err != nil {
   973  			return err
   974  		}
   975  
   976  		return nil
   977  	}, opts...)
   978  	if e != nil {
   979  		return nil, e
   980  	}
   981  	return resp, nil
   982  }
   983  
   984  // ListFolders lists the folders that are direct descendants of supplied parent resource.
   985  // list() provides a strongly consistent view of the folders underneath
   986  // the specified parent resource.
   987  // list() returns folders sorted based upon the (ascending) lexical ordering
   988  // of their display_name.
   989  // The caller must have resourcemanager.folders.list permission on the
   990  // identified parent.
   991  func (c *foldersRESTClient) ListFolders(ctx context.Context, req *resourcemanagerpb.ListFoldersRequest, opts ...gax.CallOption) *FolderIterator {
   992  	it := &FolderIterator{}
   993  	req = proto.Clone(req).(*resourcemanagerpb.ListFoldersRequest)
   994  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   995  	it.InternalFetch = func(pageSize int, pageToken string) ([]*resourcemanagerpb.Folder, string, error) {
   996  		resp := &resourcemanagerpb.ListFoldersResponse{}
   997  		if pageToken != "" {
   998  			req.PageToken = pageToken
   999  		}
  1000  		if pageSize > math.MaxInt32 {
  1001  			req.PageSize = math.MaxInt32
  1002  		} else if pageSize != 0 {
  1003  			req.PageSize = int32(pageSize)
  1004  		}
  1005  		baseUrl, err := url.Parse(c.endpoint)
  1006  		if err != nil {
  1007  			return nil, "", err
  1008  		}
  1009  		baseUrl.Path += fmt.Sprintf("/v3/folders")
  1010  
  1011  		params := url.Values{}
  1012  		params.Add("$alt", "json;enum-encoding=int")
  1013  		if req.GetPageSize() != 0 {
  1014  			params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
  1015  		}
  1016  		if req.GetPageToken() != "" {
  1017  			params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
  1018  		}
  1019  		params.Add("parent", fmt.Sprintf("%v", req.GetParent()))
  1020  		if req.GetShowDeleted() {
  1021  			params.Add("showDeleted", fmt.Sprintf("%v", req.GetShowDeleted()))
  1022  		}
  1023  
  1024  		baseUrl.RawQuery = params.Encode()
  1025  
  1026  		// Build HTTP headers from client and context metadata.
  1027  		hds := append(c.xGoogHeaders, "Content-Type", "application/json")
  1028  		headers := gax.BuildHeaders(ctx, hds...)
  1029  		e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1030  			if settings.Path != "" {
  1031  				baseUrl.Path = settings.Path
  1032  			}
  1033  			httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  1034  			if err != nil {
  1035  				return err
  1036  			}
  1037  			httpReq.Header = headers
  1038  
  1039  			httpRsp, err := c.httpClient.Do(httpReq)
  1040  			if err != nil {
  1041  				return err
  1042  			}
  1043  			defer httpRsp.Body.Close()
  1044  
  1045  			if err = googleapi.CheckResponse(httpRsp); err != nil {
  1046  				return err
  1047  			}
  1048  
  1049  			buf, err := io.ReadAll(httpRsp.Body)
  1050  			if err != nil {
  1051  				return err
  1052  			}
  1053  
  1054  			if err := unm.Unmarshal(buf, resp); err != nil {
  1055  				return err
  1056  			}
  1057  
  1058  			return nil
  1059  		}, opts...)
  1060  		if e != nil {
  1061  			return nil, "", e
  1062  		}
  1063  		it.Response = resp
  1064  		return resp.GetFolders(), resp.GetNextPageToken(), nil
  1065  	}
  1066  
  1067  	fetch := func(pageSize int, pageToken string) (string, error) {
  1068  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  1069  		if err != nil {
  1070  			return "", err
  1071  		}
  1072  		it.items = append(it.items, items...)
  1073  		return nextPageToken, nil
  1074  	}
  1075  
  1076  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  1077  	it.pageInfo.MaxSize = int(req.GetPageSize())
  1078  	it.pageInfo.Token = req.GetPageToken()
  1079  
  1080  	return it
  1081  }
  1082  
  1083  // SearchFolders search for folders that match specific filter criteria.
  1084  // search() provides an eventually consistent view of the folders a user has
  1085  // access to which meet the specified filter criteria.
  1086  //
  1087  // This will only return folders on which the caller has the
  1088  // permission resourcemanager.folders.get.
  1089  func (c *foldersRESTClient) SearchFolders(ctx context.Context, req *resourcemanagerpb.SearchFoldersRequest, opts ...gax.CallOption) *FolderIterator {
  1090  	it := &FolderIterator{}
  1091  	req = proto.Clone(req).(*resourcemanagerpb.SearchFoldersRequest)
  1092  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1093  	it.InternalFetch = func(pageSize int, pageToken string) ([]*resourcemanagerpb.Folder, string, error) {
  1094  		resp := &resourcemanagerpb.SearchFoldersResponse{}
  1095  		if pageToken != "" {
  1096  			req.PageToken = pageToken
  1097  		}
  1098  		if pageSize > math.MaxInt32 {
  1099  			req.PageSize = math.MaxInt32
  1100  		} else if pageSize != 0 {
  1101  			req.PageSize = int32(pageSize)
  1102  		}
  1103  		baseUrl, err := url.Parse(c.endpoint)
  1104  		if err != nil {
  1105  			return nil, "", err
  1106  		}
  1107  		baseUrl.Path += fmt.Sprintf("/v3/folders:search")
  1108  
  1109  		params := url.Values{}
  1110  		params.Add("$alt", "json;enum-encoding=int")
  1111  		if req.GetPageSize() != 0 {
  1112  			params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
  1113  		}
  1114  		if req.GetPageToken() != "" {
  1115  			params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
  1116  		}
  1117  		if req.GetQuery() != "" {
  1118  			params.Add("query", fmt.Sprintf("%v", req.GetQuery()))
  1119  		}
  1120  
  1121  		baseUrl.RawQuery = params.Encode()
  1122  
  1123  		// Build HTTP headers from client and context metadata.
  1124  		hds := append(c.xGoogHeaders, "Content-Type", "application/json")
  1125  		headers := gax.BuildHeaders(ctx, hds...)
  1126  		e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1127  			if settings.Path != "" {
  1128  				baseUrl.Path = settings.Path
  1129  			}
  1130  			httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  1131  			if err != nil {
  1132  				return err
  1133  			}
  1134  			httpReq.Header = headers
  1135  
  1136  			httpRsp, err := c.httpClient.Do(httpReq)
  1137  			if err != nil {
  1138  				return err
  1139  			}
  1140  			defer httpRsp.Body.Close()
  1141  
  1142  			if err = googleapi.CheckResponse(httpRsp); err != nil {
  1143  				return err
  1144  			}
  1145  
  1146  			buf, err := io.ReadAll(httpRsp.Body)
  1147  			if err != nil {
  1148  				return err
  1149  			}
  1150  
  1151  			if err := unm.Unmarshal(buf, resp); err != nil {
  1152  				return err
  1153  			}
  1154  
  1155  			return nil
  1156  		}, opts...)
  1157  		if e != nil {
  1158  			return nil, "", e
  1159  		}
  1160  		it.Response = resp
  1161  		return resp.GetFolders(), resp.GetNextPageToken(), nil
  1162  	}
  1163  
  1164  	fetch := func(pageSize int, pageToken string) (string, error) {
  1165  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  1166  		if err != nil {
  1167  			return "", err
  1168  		}
  1169  		it.items = append(it.items, items...)
  1170  		return nextPageToken, nil
  1171  	}
  1172  
  1173  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  1174  	it.pageInfo.MaxSize = int(req.GetPageSize())
  1175  	it.pageInfo.Token = req.GetPageToken()
  1176  
  1177  	return it
  1178  }
  1179  
  1180  // CreateFolder creates a folder in the resource hierarchy.
  1181  // Returns an Operation which can be used to track the progress of the
  1182  // folder creation workflow.
  1183  // Upon success, the Operation.response field will be populated with the
  1184  // created Folder.
  1185  //
  1186  // In order to succeed, the addition of this new folder must not violate
  1187  // the folder naming, height, or fanout constraints.
  1188  //
  1189  //	The folder’s display_name must be distinct from all other folders that
  1190  //	share its parent.
  1191  //
  1192  //	The addition of the folder must not cause the active folder hierarchy
  1193  //	to exceed a height of 10. Note, the full active + deleted folder hierarchy
  1194  //	is allowed to reach a height of 20; this provides additional headroom when
  1195  //	moving folders that contain deleted folders.
  1196  //
  1197  //	The addition of the folder must not cause the total number of folders
  1198  //	under its parent to exceed 300.
  1199  //
  1200  // If the operation fails due to a folder constraint violation, some errors
  1201  // may be returned by the CreateFolder request, with status code
  1202  // FAILED_PRECONDITION and an error description. Other folder constraint
  1203  // violations will be communicated in the Operation, with the specific
  1204  // PreconditionFailure returned in the details list in the Operation.error
  1205  // field.
  1206  //
  1207  // The caller must have resourcemanager.folders.create permission on the
  1208  // identified parent.
  1209  func (c *foldersRESTClient) CreateFolder(ctx context.Context, req *resourcemanagerpb.CreateFolderRequest, opts ...gax.CallOption) (*CreateFolderOperation, error) {
  1210  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1211  	body := req.GetFolder()
  1212  	jsonReq, err := m.Marshal(body)
  1213  	if err != nil {
  1214  		return nil, err
  1215  	}
  1216  
  1217  	baseUrl, err := url.Parse(c.endpoint)
  1218  	if err != nil {
  1219  		return nil, err
  1220  	}
  1221  	baseUrl.Path += fmt.Sprintf("/v3/folders")
  1222  
  1223  	params := url.Values{}
  1224  	params.Add("$alt", "json;enum-encoding=int")
  1225  
  1226  	baseUrl.RawQuery = params.Encode()
  1227  
  1228  	// Build HTTP headers from client and context metadata.
  1229  	hds := append(c.xGoogHeaders, "Content-Type", "application/json")
  1230  	headers := gax.BuildHeaders(ctx, hds...)
  1231  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1232  	resp := &longrunningpb.Operation{}
  1233  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1234  		if settings.Path != "" {
  1235  			baseUrl.Path = settings.Path
  1236  		}
  1237  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1238  		if err != nil {
  1239  			return err
  1240  		}
  1241  		httpReq = httpReq.WithContext(ctx)
  1242  		httpReq.Header = headers
  1243  
  1244  		httpRsp, err := c.httpClient.Do(httpReq)
  1245  		if err != nil {
  1246  			return err
  1247  		}
  1248  		defer httpRsp.Body.Close()
  1249  
  1250  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1251  			return err
  1252  		}
  1253  
  1254  		buf, err := io.ReadAll(httpRsp.Body)
  1255  		if err != nil {
  1256  			return err
  1257  		}
  1258  
  1259  		if err := unm.Unmarshal(buf, resp); err != nil {
  1260  			return err
  1261  		}
  1262  
  1263  		return nil
  1264  	}, opts...)
  1265  	if e != nil {
  1266  		return nil, e
  1267  	}
  1268  
  1269  	override := fmt.Sprintf("/v3/%s", resp.GetName())
  1270  	return &CreateFolderOperation{
  1271  		lro:      longrunning.InternalNewOperation(*c.LROClient, resp),
  1272  		pollPath: override,
  1273  	}, nil
  1274  }
  1275  
  1276  // UpdateFolder updates a folder, changing its display_name.
  1277  // Changes to the folder display_name will be rejected if they violate
  1278  // either the display_name formatting rules or the naming constraints
  1279  // described in the
  1280  // CreateFolder
  1281  // documentation.
  1282  //
  1283  // The folder’s display_name must start and end with a letter or digit,
  1284  // may contain letters, digits, spaces, hyphens and underscores and can be
  1285  // between 3 and 30 characters. This is captured by the regular expression:
  1286  // [\p{L}\p{N}][\p{L}\p{N}_- ]{1,28}[\p{L}\p{N}].
  1287  // The caller must have resourcemanager.folders.update permission on the
  1288  // identified folder.
  1289  //
  1290  // If the update fails due to the unique name constraint then a
  1291  // PreconditionFailure explaining this violation will be returned
  1292  // in the Status.details field.
  1293  func (c *foldersRESTClient) UpdateFolder(ctx context.Context, req *resourcemanagerpb.UpdateFolderRequest, opts ...gax.CallOption) (*UpdateFolderOperation, error) {
  1294  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1295  	body := req.GetFolder()
  1296  	jsonReq, err := m.Marshal(body)
  1297  	if err != nil {
  1298  		return nil, err
  1299  	}
  1300  
  1301  	baseUrl, err := url.Parse(c.endpoint)
  1302  	if err != nil {
  1303  		return nil, err
  1304  	}
  1305  	baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetFolder().GetName())
  1306  
  1307  	params := url.Values{}
  1308  	params.Add("$alt", "json;enum-encoding=int")
  1309  	if req.GetUpdateMask() != nil {
  1310  		updateMask, err := protojson.Marshal(req.GetUpdateMask())
  1311  		if err != nil {
  1312  			return nil, err
  1313  		}
  1314  		params.Add("updateMask", string(updateMask[1:len(updateMask)-1]))
  1315  	}
  1316  
  1317  	baseUrl.RawQuery = params.Encode()
  1318  
  1319  	// Build HTTP headers from client and context metadata.
  1320  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "folder.name", url.QueryEscape(req.GetFolder().GetName()))}
  1321  
  1322  	hds = append(c.xGoogHeaders, hds...)
  1323  	hds = append(hds, "Content-Type", "application/json")
  1324  	headers := gax.BuildHeaders(ctx, hds...)
  1325  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1326  	resp := &longrunningpb.Operation{}
  1327  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1328  		if settings.Path != "" {
  1329  			baseUrl.Path = settings.Path
  1330  		}
  1331  		httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
  1332  		if err != nil {
  1333  			return err
  1334  		}
  1335  		httpReq = httpReq.WithContext(ctx)
  1336  		httpReq.Header = headers
  1337  
  1338  		httpRsp, err := c.httpClient.Do(httpReq)
  1339  		if err != nil {
  1340  			return err
  1341  		}
  1342  		defer httpRsp.Body.Close()
  1343  
  1344  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1345  			return err
  1346  		}
  1347  
  1348  		buf, err := io.ReadAll(httpRsp.Body)
  1349  		if err != nil {
  1350  			return err
  1351  		}
  1352  
  1353  		if err := unm.Unmarshal(buf, resp); err != nil {
  1354  			return err
  1355  		}
  1356  
  1357  		return nil
  1358  	}, opts...)
  1359  	if e != nil {
  1360  		return nil, e
  1361  	}
  1362  
  1363  	override := fmt.Sprintf("/v3/%s", resp.GetName())
  1364  	return &UpdateFolderOperation{
  1365  		lro:      longrunning.InternalNewOperation(*c.LROClient, resp),
  1366  		pollPath: override,
  1367  	}, nil
  1368  }
  1369  
  1370  // MoveFolder moves a folder under a new resource parent.
  1371  // Returns an Operation which can be used to track the progress of the
  1372  // folder move workflow.
  1373  // Upon success, the Operation.response field will be populated with the
  1374  // moved folder.
  1375  // Upon failure, a FolderOperationError categorizing the failure cause will
  1376  // be returned - if the failure occurs synchronously then the
  1377  // FolderOperationError will be returned in the Status.details field.
  1378  // If it occurs asynchronously, then the FolderOperation will be returned
  1379  // in the Operation.error field.
  1380  // In addition, the Operation.metadata field will be populated with a
  1381  // FolderOperation message as an aid to stateless clients.
  1382  // Folder moves will be rejected if they violate either the naming, height,
  1383  // or fanout constraints described in the
  1384  // CreateFolder
  1385  // documentation. The caller must have resourcemanager.folders.move
  1386  // permission on the folder’s current and proposed new parent.
  1387  func (c *foldersRESTClient) MoveFolder(ctx context.Context, req *resourcemanagerpb.MoveFolderRequest, opts ...gax.CallOption) (*MoveFolderOperation, error) {
  1388  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1389  	jsonReq, err := m.Marshal(req)
  1390  	if err != nil {
  1391  		return nil, err
  1392  	}
  1393  
  1394  	baseUrl, err := url.Parse(c.endpoint)
  1395  	if err != nil {
  1396  		return nil, err
  1397  	}
  1398  	baseUrl.Path += fmt.Sprintf("/v3/%v:move", req.GetName())
  1399  
  1400  	params := url.Values{}
  1401  	params.Add("$alt", "json;enum-encoding=int")
  1402  
  1403  	baseUrl.RawQuery = params.Encode()
  1404  
  1405  	// Build HTTP headers from client and context metadata.
  1406  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1407  
  1408  	hds = append(c.xGoogHeaders, hds...)
  1409  	hds = append(hds, "Content-Type", "application/json")
  1410  	headers := gax.BuildHeaders(ctx, hds...)
  1411  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1412  	resp := &longrunningpb.Operation{}
  1413  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1414  		if settings.Path != "" {
  1415  			baseUrl.Path = settings.Path
  1416  		}
  1417  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1418  		if err != nil {
  1419  			return err
  1420  		}
  1421  		httpReq = httpReq.WithContext(ctx)
  1422  		httpReq.Header = headers
  1423  
  1424  		httpRsp, err := c.httpClient.Do(httpReq)
  1425  		if err != nil {
  1426  			return err
  1427  		}
  1428  		defer httpRsp.Body.Close()
  1429  
  1430  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1431  			return err
  1432  		}
  1433  
  1434  		buf, err := io.ReadAll(httpRsp.Body)
  1435  		if err != nil {
  1436  			return err
  1437  		}
  1438  
  1439  		if err := unm.Unmarshal(buf, resp); err != nil {
  1440  			return err
  1441  		}
  1442  
  1443  		return nil
  1444  	}, opts...)
  1445  	if e != nil {
  1446  		return nil, e
  1447  	}
  1448  
  1449  	override := fmt.Sprintf("/v3/%s", resp.GetName())
  1450  	return &MoveFolderOperation{
  1451  		lro:      longrunning.InternalNewOperation(*c.LROClient, resp),
  1452  		pollPath: override,
  1453  	}, nil
  1454  }
  1455  
  1456  // DeleteFolder requests deletion of a folder. The folder is moved into the
  1457  // DELETE_REQUESTED
  1458  // state immediately, and is deleted approximately 30 days later. This method
  1459  // may only be called on an empty folder, where a folder is empty if it
  1460  // doesn’t contain any folders or projects in the
  1461  // [ACTIVE][google.cloud.resourcemanager.v3.Folder.State.ACTIVE (at http://google.cloud.resourcemanager.v3.Folder.State.ACTIVE)] state. If
  1462  // called on a folder in
  1463  // DELETE_REQUESTED
  1464  // state the operation will result in a no-op success.
  1465  // The caller must have resourcemanager.folders.delete permission on the
  1466  // identified folder.
  1467  func (c *foldersRESTClient) DeleteFolder(ctx context.Context, req *resourcemanagerpb.DeleteFolderRequest, opts ...gax.CallOption) (*DeleteFolderOperation, error) {
  1468  	baseUrl, err := url.Parse(c.endpoint)
  1469  	if err != nil {
  1470  		return nil, err
  1471  	}
  1472  	baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetName())
  1473  
  1474  	params := url.Values{}
  1475  	params.Add("$alt", "json;enum-encoding=int")
  1476  
  1477  	baseUrl.RawQuery = params.Encode()
  1478  
  1479  	// Build HTTP headers from client and context metadata.
  1480  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1481  
  1482  	hds = append(c.xGoogHeaders, hds...)
  1483  	hds = append(hds, "Content-Type", "application/json")
  1484  	headers := gax.BuildHeaders(ctx, hds...)
  1485  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1486  	resp := &longrunningpb.Operation{}
  1487  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1488  		if settings.Path != "" {
  1489  			baseUrl.Path = settings.Path
  1490  		}
  1491  		httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
  1492  		if err != nil {
  1493  			return err
  1494  		}
  1495  		httpReq = httpReq.WithContext(ctx)
  1496  		httpReq.Header = headers
  1497  
  1498  		httpRsp, err := c.httpClient.Do(httpReq)
  1499  		if err != nil {
  1500  			return err
  1501  		}
  1502  		defer httpRsp.Body.Close()
  1503  
  1504  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1505  			return err
  1506  		}
  1507  
  1508  		buf, err := io.ReadAll(httpRsp.Body)
  1509  		if err != nil {
  1510  			return err
  1511  		}
  1512  
  1513  		if err := unm.Unmarshal(buf, resp); err != nil {
  1514  			return err
  1515  		}
  1516  
  1517  		return nil
  1518  	}, opts...)
  1519  	if e != nil {
  1520  		return nil, e
  1521  	}
  1522  
  1523  	override := fmt.Sprintf("/v3/%s", resp.GetName())
  1524  	return &DeleteFolderOperation{
  1525  		lro:      longrunning.InternalNewOperation(*c.LROClient, resp),
  1526  		pollPath: override,
  1527  	}, nil
  1528  }
  1529  
  1530  // UndeleteFolder cancels the deletion request for a folder. This method may be called on a
  1531  // folder in any state. If the folder is in the
  1532  // [ACTIVE][google.cloud.resourcemanager.v3.Folder.State.ACTIVE (at http://google.cloud.resourcemanager.v3.Folder.State.ACTIVE)] state the
  1533  // result will be a no-op success. In order to succeed, the folder’s parent
  1534  // must be in the
  1535  // [ACTIVE][google.cloud.resourcemanager.v3.Folder.State.ACTIVE (at http://google.cloud.resourcemanager.v3.Folder.State.ACTIVE)] state. In
  1536  // addition, reintroducing the folder into the tree must not violate folder
  1537  // naming, height, and fanout constraints described in the
  1538  // CreateFolder
  1539  // documentation. The caller must have resourcemanager.folders.undelete
  1540  // permission on the identified folder.
  1541  func (c *foldersRESTClient) UndeleteFolder(ctx context.Context, req *resourcemanagerpb.UndeleteFolderRequest, opts ...gax.CallOption) (*UndeleteFolderOperation, error) {
  1542  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1543  	jsonReq, err := m.Marshal(req)
  1544  	if err != nil {
  1545  		return nil, err
  1546  	}
  1547  
  1548  	baseUrl, err := url.Parse(c.endpoint)
  1549  	if err != nil {
  1550  		return nil, err
  1551  	}
  1552  	baseUrl.Path += fmt.Sprintf("/v3/%v:undelete", req.GetName())
  1553  
  1554  	params := url.Values{}
  1555  	params.Add("$alt", "json;enum-encoding=int")
  1556  
  1557  	baseUrl.RawQuery = params.Encode()
  1558  
  1559  	// Build HTTP headers from client and context metadata.
  1560  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1561  
  1562  	hds = append(c.xGoogHeaders, hds...)
  1563  	hds = append(hds, "Content-Type", "application/json")
  1564  	headers := gax.BuildHeaders(ctx, hds...)
  1565  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1566  	resp := &longrunningpb.Operation{}
  1567  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1568  		if settings.Path != "" {
  1569  			baseUrl.Path = settings.Path
  1570  		}
  1571  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1572  		if err != nil {
  1573  			return err
  1574  		}
  1575  		httpReq = httpReq.WithContext(ctx)
  1576  		httpReq.Header = headers
  1577  
  1578  		httpRsp, err := c.httpClient.Do(httpReq)
  1579  		if err != nil {
  1580  			return err
  1581  		}
  1582  		defer httpRsp.Body.Close()
  1583  
  1584  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1585  			return err
  1586  		}
  1587  
  1588  		buf, err := io.ReadAll(httpRsp.Body)
  1589  		if err != nil {
  1590  			return err
  1591  		}
  1592  
  1593  		if err := unm.Unmarshal(buf, resp); err != nil {
  1594  			return err
  1595  		}
  1596  
  1597  		return nil
  1598  	}, opts...)
  1599  	if e != nil {
  1600  		return nil, e
  1601  	}
  1602  
  1603  	override := fmt.Sprintf("/v3/%s", resp.GetName())
  1604  	return &UndeleteFolderOperation{
  1605  		lro:      longrunning.InternalNewOperation(*c.LROClient, resp),
  1606  		pollPath: override,
  1607  	}, nil
  1608  }
  1609  
  1610  // GetIamPolicy gets the access control policy for a folder. The returned policy may be
  1611  // empty if no such policy or resource exists. The resource field should
  1612  // be the folder’s resource name, for example: “folders/1234”.
  1613  // The caller must have resourcemanager.folders.getIamPolicy permission
  1614  // on the identified folder.
  1615  func (c *foldersRESTClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
  1616  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1617  	jsonReq, err := m.Marshal(req)
  1618  	if err != nil {
  1619  		return nil, err
  1620  	}
  1621  
  1622  	baseUrl, err := url.Parse(c.endpoint)
  1623  	if err != nil {
  1624  		return nil, err
  1625  	}
  1626  	baseUrl.Path += fmt.Sprintf("/v3/%v:getIamPolicy", req.GetResource())
  1627  
  1628  	params := url.Values{}
  1629  	params.Add("$alt", "json;enum-encoding=int")
  1630  
  1631  	baseUrl.RawQuery = params.Encode()
  1632  
  1633  	// Build HTTP headers from client and context metadata.
  1634  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
  1635  
  1636  	hds = append(c.xGoogHeaders, hds...)
  1637  	hds = append(hds, "Content-Type", "application/json")
  1638  	headers := gax.BuildHeaders(ctx, hds...)
  1639  	opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
  1640  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1641  	resp := &iampb.Policy{}
  1642  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1643  		if settings.Path != "" {
  1644  			baseUrl.Path = settings.Path
  1645  		}
  1646  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1647  		if err != nil {
  1648  			return err
  1649  		}
  1650  		httpReq = httpReq.WithContext(ctx)
  1651  		httpReq.Header = headers
  1652  
  1653  		httpRsp, err := c.httpClient.Do(httpReq)
  1654  		if err != nil {
  1655  			return err
  1656  		}
  1657  		defer httpRsp.Body.Close()
  1658  
  1659  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1660  			return err
  1661  		}
  1662  
  1663  		buf, err := io.ReadAll(httpRsp.Body)
  1664  		if err != nil {
  1665  			return err
  1666  		}
  1667  
  1668  		if err := unm.Unmarshal(buf, resp); err != nil {
  1669  			return err
  1670  		}
  1671  
  1672  		return nil
  1673  	}, opts...)
  1674  	if e != nil {
  1675  		return nil, e
  1676  	}
  1677  	return resp, nil
  1678  }
  1679  
  1680  // SetIamPolicy sets the access control policy on a folder, replacing any existing policy.
  1681  // The resource field should be the folder’s resource name, for example:
  1682  // “folders/1234”.
  1683  // The caller must have resourcemanager.folders.setIamPolicy permission
  1684  // on the identified folder.
  1685  func (c *foldersRESTClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
  1686  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1687  	jsonReq, err := m.Marshal(req)
  1688  	if err != nil {
  1689  		return nil, err
  1690  	}
  1691  
  1692  	baseUrl, err := url.Parse(c.endpoint)
  1693  	if err != nil {
  1694  		return nil, err
  1695  	}
  1696  	baseUrl.Path += fmt.Sprintf("/v3/%v:setIamPolicy", req.GetResource())
  1697  
  1698  	params := url.Values{}
  1699  	params.Add("$alt", "json;enum-encoding=int")
  1700  
  1701  	baseUrl.RawQuery = params.Encode()
  1702  
  1703  	// Build HTTP headers from client and context metadata.
  1704  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
  1705  
  1706  	hds = append(c.xGoogHeaders, hds...)
  1707  	hds = append(hds, "Content-Type", "application/json")
  1708  	headers := gax.BuildHeaders(ctx, hds...)
  1709  	opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
  1710  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1711  	resp := &iampb.Policy{}
  1712  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1713  		if settings.Path != "" {
  1714  			baseUrl.Path = settings.Path
  1715  		}
  1716  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1717  		if err != nil {
  1718  			return err
  1719  		}
  1720  		httpReq = httpReq.WithContext(ctx)
  1721  		httpReq.Header = headers
  1722  
  1723  		httpRsp, err := c.httpClient.Do(httpReq)
  1724  		if err != nil {
  1725  			return err
  1726  		}
  1727  		defer httpRsp.Body.Close()
  1728  
  1729  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1730  			return err
  1731  		}
  1732  
  1733  		buf, err := io.ReadAll(httpRsp.Body)
  1734  		if err != nil {
  1735  			return err
  1736  		}
  1737  
  1738  		if err := unm.Unmarshal(buf, resp); err != nil {
  1739  			return err
  1740  		}
  1741  
  1742  		return nil
  1743  	}, opts...)
  1744  	if e != nil {
  1745  		return nil, e
  1746  	}
  1747  	return resp, nil
  1748  }
  1749  
  1750  // TestIamPermissions returns permissions that a caller has on the specified folder.
  1751  // The resource field should be the folder’s resource name,
  1752  // for example: “folders/1234”.
  1753  //
  1754  // There are no permissions required for making this API call.
  1755  func (c *foldersRESTClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
  1756  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1757  	jsonReq, err := m.Marshal(req)
  1758  	if err != nil {
  1759  		return nil, err
  1760  	}
  1761  
  1762  	baseUrl, err := url.Parse(c.endpoint)
  1763  	if err != nil {
  1764  		return nil, err
  1765  	}
  1766  	baseUrl.Path += fmt.Sprintf("/v3/%v:testIamPermissions", req.GetResource())
  1767  
  1768  	params := url.Values{}
  1769  	params.Add("$alt", "json;enum-encoding=int")
  1770  
  1771  	baseUrl.RawQuery = params.Encode()
  1772  
  1773  	// Build HTTP headers from client and context metadata.
  1774  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
  1775  
  1776  	hds = append(c.xGoogHeaders, hds...)
  1777  	hds = append(hds, "Content-Type", "application/json")
  1778  	headers := gax.BuildHeaders(ctx, hds...)
  1779  	opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
  1780  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1781  	resp := &iampb.TestIamPermissionsResponse{}
  1782  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1783  		if settings.Path != "" {
  1784  			baseUrl.Path = settings.Path
  1785  		}
  1786  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1787  		if err != nil {
  1788  			return err
  1789  		}
  1790  		httpReq = httpReq.WithContext(ctx)
  1791  		httpReq.Header = headers
  1792  
  1793  		httpRsp, err := c.httpClient.Do(httpReq)
  1794  		if err != nil {
  1795  			return err
  1796  		}
  1797  		defer httpRsp.Body.Close()
  1798  
  1799  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1800  			return err
  1801  		}
  1802  
  1803  		buf, err := io.ReadAll(httpRsp.Body)
  1804  		if err != nil {
  1805  			return err
  1806  		}
  1807  
  1808  		if err := unm.Unmarshal(buf, resp); err != nil {
  1809  			return err
  1810  		}
  1811  
  1812  		return nil
  1813  	}, opts...)
  1814  	if e != nil {
  1815  		return nil, e
  1816  	}
  1817  	return resp, nil
  1818  }
  1819  
  1820  // GetOperation is a utility method from google.longrunning.Operations.
  1821  func (c *foldersRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
  1822  	baseUrl, err := url.Parse(c.endpoint)
  1823  	if err != nil {
  1824  		return nil, err
  1825  	}
  1826  	baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetName())
  1827  
  1828  	params := url.Values{}
  1829  	params.Add("$alt", "json;enum-encoding=int")
  1830  
  1831  	baseUrl.RawQuery = params.Encode()
  1832  
  1833  	// Build HTTP headers from client and context metadata.
  1834  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1835  
  1836  	hds = append(c.xGoogHeaders, hds...)
  1837  	hds = append(hds, "Content-Type", "application/json")
  1838  	headers := gax.BuildHeaders(ctx, hds...)
  1839  	opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
  1840  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1841  	resp := &longrunningpb.Operation{}
  1842  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1843  		if settings.Path != "" {
  1844  			baseUrl.Path = settings.Path
  1845  		}
  1846  		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  1847  		if err != nil {
  1848  			return err
  1849  		}
  1850  		httpReq = httpReq.WithContext(ctx)
  1851  		httpReq.Header = headers
  1852  
  1853  		httpRsp, err := c.httpClient.Do(httpReq)
  1854  		if err != nil {
  1855  			return err
  1856  		}
  1857  		defer httpRsp.Body.Close()
  1858  
  1859  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1860  			return err
  1861  		}
  1862  
  1863  		buf, err := io.ReadAll(httpRsp.Body)
  1864  		if err != nil {
  1865  			return err
  1866  		}
  1867  
  1868  		if err := unm.Unmarshal(buf, resp); err != nil {
  1869  			return err
  1870  		}
  1871  
  1872  		return nil
  1873  	}, opts...)
  1874  	if e != nil {
  1875  		return nil, e
  1876  	}
  1877  	return resp, nil
  1878  }
  1879  
  1880  // CreateFolderOperation returns a new CreateFolderOperation from a given name.
  1881  // The name must be that of a previously created CreateFolderOperation, possibly from a different process.
  1882  func (c *foldersGRPCClient) CreateFolderOperation(name string) *CreateFolderOperation {
  1883  	return &CreateFolderOperation{
  1884  		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  1885  	}
  1886  }
  1887  
  1888  // CreateFolderOperation returns a new CreateFolderOperation from a given name.
  1889  // The name must be that of a previously created CreateFolderOperation, possibly from a different process.
  1890  func (c *foldersRESTClient) CreateFolderOperation(name string) *CreateFolderOperation {
  1891  	override := fmt.Sprintf("/v3/%s", name)
  1892  	return &CreateFolderOperation{
  1893  		lro:      longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  1894  		pollPath: override,
  1895  	}
  1896  }
  1897  
  1898  // DeleteFolderOperation returns a new DeleteFolderOperation from a given name.
  1899  // The name must be that of a previously created DeleteFolderOperation, possibly from a different process.
  1900  func (c *foldersGRPCClient) DeleteFolderOperation(name string) *DeleteFolderOperation {
  1901  	return &DeleteFolderOperation{
  1902  		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  1903  	}
  1904  }
  1905  
  1906  // DeleteFolderOperation returns a new DeleteFolderOperation from a given name.
  1907  // The name must be that of a previously created DeleteFolderOperation, possibly from a different process.
  1908  func (c *foldersRESTClient) DeleteFolderOperation(name string) *DeleteFolderOperation {
  1909  	override := fmt.Sprintf("/v3/%s", name)
  1910  	return &DeleteFolderOperation{
  1911  		lro:      longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  1912  		pollPath: override,
  1913  	}
  1914  }
  1915  
  1916  // MoveFolderOperation returns a new MoveFolderOperation from a given name.
  1917  // The name must be that of a previously created MoveFolderOperation, possibly from a different process.
  1918  func (c *foldersGRPCClient) MoveFolderOperation(name string) *MoveFolderOperation {
  1919  	return &MoveFolderOperation{
  1920  		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  1921  	}
  1922  }
  1923  
  1924  // MoveFolderOperation returns a new MoveFolderOperation from a given name.
  1925  // The name must be that of a previously created MoveFolderOperation, possibly from a different process.
  1926  func (c *foldersRESTClient) MoveFolderOperation(name string) *MoveFolderOperation {
  1927  	override := fmt.Sprintf("/v3/%s", name)
  1928  	return &MoveFolderOperation{
  1929  		lro:      longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  1930  		pollPath: override,
  1931  	}
  1932  }
  1933  
  1934  // UndeleteFolderOperation returns a new UndeleteFolderOperation from a given name.
  1935  // The name must be that of a previously created UndeleteFolderOperation, possibly from a different process.
  1936  func (c *foldersGRPCClient) UndeleteFolderOperation(name string) *UndeleteFolderOperation {
  1937  	return &UndeleteFolderOperation{
  1938  		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  1939  	}
  1940  }
  1941  
  1942  // UndeleteFolderOperation returns a new UndeleteFolderOperation from a given name.
  1943  // The name must be that of a previously created UndeleteFolderOperation, possibly from a different process.
  1944  func (c *foldersRESTClient) UndeleteFolderOperation(name string) *UndeleteFolderOperation {
  1945  	override := fmt.Sprintf("/v3/%s", name)
  1946  	return &UndeleteFolderOperation{
  1947  		lro:      longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  1948  		pollPath: override,
  1949  	}
  1950  }
  1951  
  1952  // UpdateFolderOperation returns a new UpdateFolderOperation from a given name.
  1953  // The name must be that of a previously created UpdateFolderOperation, possibly from a different process.
  1954  func (c *foldersGRPCClient) UpdateFolderOperation(name string) *UpdateFolderOperation {
  1955  	return &UpdateFolderOperation{
  1956  		lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  1957  	}
  1958  }
  1959  
  1960  // UpdateFolderOperation returns a new UpdateFolderOperation from a given name.
  1961  // The name must be that of a previously created UpdateFolderOperation, possibly from a different process.
  1962  func (c *foldersRESTClient) UpdateFolderOperation(name string) *UpdateFolderOperation {
  1963  	override := fmt.Sprintf("/v3/%s", name)
  1964  	return &UpdateFolderOperation{
  1965  		lro:      longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
  1966  		pollPath: override,
  1967  	}
  1968  }
  1969  

View as plain text