Debian Codegraph @

firestore/apiv1/admin/firestore_admin_client.go

raw
1 // Copyright 2025 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 apiv1
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "log/slog"
24 "math"
25 "net/http"
26 "net/url"
27 "regexp"
28 "strings"
29 "time"
30
31 adminpb "cloud.google.com/go/firestore/apiv1/admin/adminpb"
32 "cloud.google.com/go/longrunning"
33 lroauto "cloud.google.com/go/longrunning/autogen"
34 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
35 gax "github.com/googleapis/gax-go/v2"
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 newFirestoreAdminClientHook clientHook
48
49 // FirestoreAdminCallOptions contains the retry settings for each method of FirestoreAdminClient.
50 type FirestoreAdminCallOptions struct {
51 CreateIndex []gax.CallOption
52 ListIndexes []gax.CallOption
53 GetIndex []gax.CallOption
54 DeleteIndex []gax.CallOption
55 GetField []gax.CallOption
56 UpdateField []gax.CallOption
57 ListFields []gax.CallOption
58 ExportDocuments []gax.CallOption
59 ImportDocuments []gax.CallOption
60 BulkDeleteDocuments []gax.CallOption
61 CreateDatabase []gax.CallOption
62 GetDatabase []gax.CallOption
63 ListDatabases []gax.CallOption
64 UpdateDatabase []gax.CallOption
65 DeleteDatabase []gax.CallOption
66 CreateUserCreds []gax.CallOption
67 GetUserCreds []gax.CallOption
68 ListUserCreds []gax.CallOption
69 EnableUserCreds []gax.CallOption
70 DisableUserCreds []gax.CallOption
71 ResetUserPassword []gax.CallOption
72 DeleteUserCreds []gax.CallOption
73 GetBackup []gax.CallOption
74 ListBackups []gax.CallOption
75 DeleteBackup []gax.CallOption
76 RestoreDatabase []gax.CallOption
77 CreateBackupSchedule []gax.CallOption
78 GetBackupSchedule []gax.CallOption
79 ListBackupSchedules []gax.CallOption
80 UpdateBackupSchedule []gax.CallOption
81 DeleteBackupSchedule []gax.CallOption
82 CloneDatabase []gax.CallOption
83 CancelOperation []gax.CallOption
84 DeleteOperation []gax.CallOption
85 GetOperation []gax.CallOption
86 ListOperations []gax.CallOption
87 }
88
89 func defaultFirestoreAdminGRPCClientOptions() []option.ClientOption {
90 return []option.ClientOption{
91 internaloption.WithDefaultEndpoint("firestore.googleapis.com:443"),
92 internaloption.WithDefaultEndpointTemplate("firestore.UNIVERSE_DOMAIN:443"),
93 internaloption.WithDefaultMTLSEndpoint("firestore.mtls.googleapis.com:443"),
94 internaloption.WithDefaultUniverseDomain("googleapis.com"),
95 internaloption.WithDefaultAudience("https://firestore.googleapis.com/"),
96 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
97 internaloption.EnableJwtWithScope(),
98 internaloption.EnableNewAuthLibrary(),
99 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
100 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
101 }
102 }
103
104 func defaultFirestoreAdminCallOptions() *FirestoreAdminCallOptions {
105 return &FirestoreAdminCallOptions{
106 CreateIndex: []gax.CallOption{
107 gax.WithTimeout(60000 * time.Millisecond),
108 },
109 ListIndexes: []gax.CallOption{
110 gax.WithTimeout(60000 * time.Millisecond),
111 gax.WithRetry(func() gax.Retryer {
112 return gax.OnCodes([]codes.Code{
113 codes.Unavailable,
114 codes.Internal,
115 codes.DeadlineExceeded,
116 }, gax.Backoff{
117 Initial: 100 * time.Millisecond,
118 Max: 60000 * time.Millisecond,
119 Multiplier: 1.30,
120 })
121 }),
122 },
123 GetIndex: []gax.CallOption{
124 gax.WithTimeout(60000 * time.Millisecond),
125 gax.WithRetry(func() gax.Retryer {
126 return gax.OnCodes([]codes.Code{
127 codes.Unavailable,
128 codes.Internal,
129 codes.DeadlineExceeded,
130 }, gax.Backoff{
131 Initial: 100 * time.Millisecond,
132 Max: 60000 * time.Millisecond,
133 Multiplier: 1.30,
134 })
135 }),
136 },
137 DeleteIndex: []gax.CallOption{
138 gax.WithTimeout(60000 * time.Millisecond),
139 gax.WithRetry(func() gax.Retryer {
140 return gax.OnCodes([]codes.Code{
141 codes.Unavailable,
142 codes.Internal,
143 codes.DeadlineExceeded,
144 }, gax.Backoff{
145 Initial: 100 * time.Millisecond,
146 Max: 60000 * time.Millisecond,
147 Multiplier: 1.30,
148 })
149 }),
150 },
151 GetField: []gax.CallOption{
152 gax.WithTimeout(60000 * time.Millisecond),
153 gax.WithRetry(func() gax.Retryer {
154 return gax.OnCodes([]codes.Code{
155 codes.Unavailable,
156 codes.Internal,
157 codes.DeadlineExceeded,
158 }, gax.Backoff{
159 Initial: 100 * time.Millisecond,
160 Max: 60000 * time.Millisecond,
161 Multiplier: 1.30,
162 })
163 }),
164 },
165 UpdateField: []gax.CallOption{
166 gax.WithTimeout(60000 * time.Millisecond),
167 },
168 ListFields: []gax.CallOption{
169 gax.WithTimeout(60000 * time.Millisecond),
170 gax.WithRetry(func() gax.Retryer {
171 return gax.OnCodes([]codes.Code{
172 codes.Unavailable,
173 codes.Internal,
174 codes.DeadlineExceeded,
175 }, gax.Backoff{
176 Initial: 100 * time.Millisecond,
177 Max: 60000 * time.Millisecond,
178 Multiplier: 1.30,
179 })
180 }),
181 },
182 ExportDocuments: []gax.CallOption{
183 gax.WithTimeout(60000 * time.Millisecond),
184 },
185 ImportDocuments: []gax.CallOption{
186 gax.WithTimeout(60000 * time.Millisecond),
187 },
188 BulkDeleteDocuments: []gax.CallOption{
189 gax.WithTimeout(60000 * time.Millisecond),
190 },
191 CreateDatabase: []gax.CallOption{
192 gax.WithTimeout(120000 * time.Millisecond),
193 },
194 GetDatabase: []gax.CallOption{},
195 ListDatabases: []gax.CallOption{},
196 UpdateDatabase: []gax.CallOption{},
197 DeleteDatabase: []gax.CallOption{},
198 CreateUserCreds: []gax.CallOption{},
199 GetUserCreds: []gax.CallOption{},
200 ListUserCreds: []gax.CallOption{},
201 EnableUserCreds: []gax.CallOption{},
202 DisableUserCreds: []gax.CallOption{},
203 ResetUserPassword: []gax.CallOption{},
204 DeleteUserCreds: []gax.CallOption{},
205 GetBackup: []gax.CallOption{},
206 ListBackups: []gax.CallOption{},
207 DeleteBackup: []gax.CallOption{},
208 RestoreDatabase: []gax.CallOption{
209 gax.WithTimeout(120000 * time.Millisecond),
210 },
211 CreateBackupSchedule: []gax.CallOption{},
212 GetBackupSchedule: []gax.CallOption{},
213 ListBackupSchedules: []gax.CallOption{},
214 UpdateBackupSchedule: []gax.CallOption{},
215 DeleteBackupSchedule: []gax.CallOption{},
216 CloneDatabase: []gax.CallOption{
217 gax.WithTimeout(120000 * time.Millisecond),
218 },
219 CancelOperation: []gax.CallOption{},
220 DeleteOperation: []gax.CallOption{},
221 GetOperation: []gax.CallOption{},
222 ListOperations: []gax.CallOption{},
223 }
224 }
225
226 func defaultFirestoreAdminRESTCallOptions() *FirestoreAdminCallOptions {
227 return &FirestoreAdminCallOptions{
228 CreateIndex: []gax.CallOption{
229 gax.WithTimeout(60000 * time.Millisecond),
230 },
231 ListIndexes: []gax.CallOption{
232 gax.WithTimeout(60000 * time.Millisecond),
233 gax.WithRetry(func() gax.Retryer {
234 return gax.OnHTTPCodes(gax.Backoff{
235 Initial: 100 * time.Millisecond,
236 Max: 60000 * time.Millisecond,
237 Multiplier: 1.30,
238 },
239 http.StatusServiceUnavailable,
240 http.StatusInternalServerError,
241 http.StatusGatewayTimeout)
242 }),
243 },
244 GetIndex: []gax.CallOption{
245 gax.WithTimeout(60000 * time.Millisecond),
246 gax.WithRetry(func() gax.Retryer {
247 return gax.OnHTTPCodes(gax.Backoff{
248 Initial: 100 * time.Millisecond,
249 Max: 60000 * time.Millisecond,
250 Multiplier: 1.30,
251 },
252 http.StatusServiceUnavailable,
253 http.StatusInternalServerError,
254 http.StatusGatewayTimeout)
255 }),
256 },
257 DeleteIndex: []gax.CallOption{
258 gax.WithTimeout(60000 * time.Millisecond),
259 gax.WithRetry(func() gax.Retryer {
260 return gax.OnHTTPCodes(gax.Backoff{
261 Initial: 100 * time.Millisecond,
262 Max: 60000 * time.Millisecond,
263 Multiplier: 1.30,
264 },
265 http.StatusServiceUnavailable,
266 http.StatusInternalServerError,
267 http.StatusGatewayTimeout)
268 }),
269 },
270 GetField: []gax.CallOption{
271 gax.WithTimeout(60000 * time.Millisecond),
272 gax.WithRetry(func() gax.Retryer {
273 return gax.OnHTTPCodes(gax.Backoff{
274 Initial: 100 * time.Millisecond,
275 Max: 60000 * time.Millisecond,
276 Multiplier: 1.30,
277 },
278 http.StatusServiceUnavailable,
279 http.StatusInternalServerError,
280 http.StatusGatewayTimeout)
281 }),
282 },
283 UpdateField: []gax.CallOption{
284 gax.WithTimeout(60000 * time.Millisecond),
285 },
286 ListFields: []gax.CallOption{
287 gax.WithTimeout(60000 * time.Millisecond),
288 gax.WithRetry(func() gax.Retryer {
289 return gax.OnHTTPCodes(gax.Backoff{
290 Initial: 100 * time.Millisecond,
291 Max: 60000 * time.Millisecond,
292 Multiplier: 1.30,
293 },
294 http.StatusServiceUnavailable,
295 http.StatusInternalServerError,
296 http.StatusGatewayTimeout)
297 }),
298 },
299 ExportDocuments: []gax.CallOption{
300 gax.WithTimeout(60000 * time.Millisecond),
301 },
302 ImportDocuments: []gax.CallOption{
303 gax.WithTimeout(60000 * time.Millisecond),
304 },
305 BulkDeleteDocuments: []gax.CallOption{
306 gax.WithTimeout(60000 * time.Millisecond),
307 },
308 CreateDatabase: []gax.CallOption{
309 gax.WithTimeout(120000 * time.Millisecond),
310 },
311 GetDatabase: []gax.CallOption{},
312 ListDatabases: []gax.CallOption{},
313 UpdateDatabase: []gax.CallOption{},
314 DeleteDatabase: []gax.CallOption{},
315 CreateUserCreds: []gax.CallOption{},
316 GetUserCreds: []gax.CallOption{},
317 ListUserCreds: []gax.CallOption{},
318 EnableUserCreds: []gax.CallOption{},
319 DisableUserCreds: []gax.CallOption{},
320 ResetUserPassword: []gax.CallOption{},
321 DeleteUserCreds: []gax.CallOption{},
322 GetBackup: []gax.CallOption{},
323 ListBackups: []gax.CallOption{},
324 DeleteBackup: []gax.CallOption{},
325 RestoreDatabase: []gax.CallOption{
326 gax.WithTimeout(120000 * time.Millisecond),
327 },
328 CreateBackupSchedule: []gax.CallOption{},
329 GetBackupSchedule: []gax.CallOption{},
330 ListBackupSchedules: []gax.CallOption{},
331 UpdateBackupSchedule: []gax.CallOption{},
332 DeleteBackupSchedule: []gax.CallOption{},
333 CloneDatabase: []gax.CallOption{
334 gax.WithTimeout(120000 * time.Millisecond),
335 },
336 CancelOperation: []gax.CallOption{},
337 DeleteOperation: []gax.CallOption{},
338 GetOperation: []gax.CallOption{},
339 ListOperations: []gax.CallOption{},
340 }
341 }
342
343 // internalFirestoreAdminClient is an interface that defines the methods available from Cloud Firestore API.
344 type internalFirestoreAdminClient interface {
345 Close() error
346 setGoogleClientInfo(...string)
347 Connection() *grpc.ClientConn
348 CreateIndex(context.Context, *adminpb.CreateIndexRequest, ...gax.CallOption) (*CreateIndexOperation, error)
349 CreateIndexOperation(name string) *CreateIndexOperation
350 ListIndexes(context.Context, *adminpb.ListIndexesRequest, ...gax.CallOption) *IndexIterator
351 GetIndex(context.Context, *adminpb.GetIndexRequest, ...gax.CallOption) (*adminpb.Index, error)
352 DeleteIndex(context.Context, *adminpb.DeleteIndexRequest, ...gax.CallOption) error
353 GetField(context.Context, *adminpb.GetFieldRequest, ...gax.CallOption) (*adminpb.Field, error)
354 UpdateField(context.Context, *adminpb.UpdateFieldRequest, ...gax.CallOption) (*UpdateFieldOperation, error)
355 UpdateFieldOperation(name string) *UpdateFieldOperation
356 ListFields(context.Context, *adminpb.ListFieldsRequest, ...gax.CallOption) *FieldIterator
357 ExportDocuments(context.Context, *adminpb.ExportDocumentsRequest, ...gax.CallOption) (*ExportDocumentsOperation, error)
358 ExportDocumentsOperation(name string) *ExportDocumentsOperation
359 ImportDocuments(context.Context, *adminpb.ImportDocumentsRequest, ...gax.CallOption) (*ImportDocumentsOperation, error)
360 ImportDocumentsOperation(name string) *ImportDocumentsOperation
361 BulkDeleteDocuments(context.Context, *adminpb.BulkDeleteDocumentsRequest, ...gax.CallOption) (*BulkDeleteDocumentsOperation, error)
362 BulkDeleteDocumentsOperation(name string) *BulkDeleteDocumentsOperation
363 CreateDatabase(context.Context, *adminpb.CreateDatabaseRequest, ...gax.CallOption) (*CreateDatabaseOperation, error)
364 CreateDatabaseOperation(name string) *CreateDatabaseOperation
365 GetDatabase(context.Context, *adminpb.GetDatabaseRequest, ...gax.CallOption) (*adminpb.Database, error)
366 ListDatabases(context.Context, *adminpb.ListDatabasesRequest, ...gax.CallOption) (*adminpb.ListDatabasesResponse, error)
367 UpdateDatabase(context.Context, *adminpb.UpdateDatabaseRequest, ...gax.CallOption) (*UpdateDatabaseOperation, error)
368 UpdateDatabaseOperation(name string) *UpdateDatabaseOperation
369 DeleteDatabase(context.Context, *adminpb.DeleteDatabaseRequest, ...gax.CallOption) (*DeleteDatabaseOperation, error)
370 DeleteDatabaseOperation(name string) *DeleteDatabaseOperation
371 CreateUserCreds(context.Context, *adminpb.CreateUserCredsRequest, ...gax.CallOption) (*adminpb.UserCreds, error)
372 GetUserCreds(context.Context, *adminpb.GetUserCredsRequest, ...gax.CallOption) (*adminpb.UserCreds, error)
373 ListUserCreds(context.Context, *adminpb.ListUserCredsRequest, ...gax.CallOption) (*adminpb.ListUserCredsResponse, error)
374 EnableUserCreds(context.Context, *adminpb.EnableUserCredsRequest, ...gax.CallOption) (*adminpb.UserCreds, error)
375 DisableUserCreds(context.Context, *adminpb.DisableUserCredsRequest, ...gax.CallOption) (*adminpb.UserCreds, error)
376 ResetUserPassword(context.Context, *adminpb.ResetUserPasswordRequest, ...gax.CallOption) (*adminpb.UserCreds, error)
377 DeleteUserCreds(context.Context, *adminpb.DeleteUserCredsRequest, ...gax.CallOption) error
378 GetBackup(context.Context, *adminpb.GetBackupRequest, ...gax.CallOption) (*adminpb.Backup, error)
379 ListBackups(context.Context, *adminpb.ListBackupsRequest, ...gax.CallOption) (*adminpb.ListBackupsResponse, error)
380 DeleteBackup(context.Context, *adminpb.DeleteBackupRequest, ...gax.CallOption) error
381 RestoreDatabase(context.Context, *adminpb.RestoreDatabaseRequest, ...gax.CallOption) (*RestoreDatabaseOperation, error)
382 RestoreDatabaseOperation(name string) *RestoreDatabaseOperation
383 CreateBackupSchedule(context.Context, *adminpb.CreateBackupScheduleRequest, ...gax.CallOption) (*adminpb.BackupSchedule, error)
384 GetBackupSchedule(context.Context, *adminpb.GetBackupScheduleRequest, ...gax.CallOption) (*adminpb.BackupSchedule, error)
385 ListBackupSchedules(context.Context, *adminpb.ListBackupSchedulesRequest, ...gax.CallOption) (*adminpb.ListBackupSchedulesResponse, error)
386 UpdateBackupSchedule(context.Context, *adminpb.UpdateBackupScheduleRequest, ...gax.CallOption) (*adminpb.BackupSchedule, error)
387 DeleteBackupSchedule(context.Context, *adminpb.DeleteBackupScheduleRequest, ...gax.CallOption) error
388 CloneDatabase(context.Context, *adminpb.CloneDatabaseRequest, ...gax.CallOption) (*CloneDatabaseOperation, error)
389 CloneDatabaseOperation(name string) *CloneDatabaseOperation
390 CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error
391 DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error
392 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
393 ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator
394 }
395
396 // FirestoreAdminClient is a client for interacting with Cloud Firestore API.
397 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
398 //
399 // The Cloud Firestore Admin API.
400 //
401 // This API provides several administrative services for Cloud Firestore.
402 //
403 // Project, Database, Namespace, Collection, Collection Group, and Document are
404 // used as defined in the Google Cloud Firestore API.
405 //
406 // Operation: An Operation represents work being performed in the background.
407 //
408 // The index service manages Cloud Firestore indexes.
409 //
410 // Index creation is performed asynchronously.
411 // An Operation resource is created for each such asynchronous operation.
412 // The state of the operation (including any errors encountered)
413 // may be queried via the Operation resource.
414 //
415 // The Operations collection provides a record of actions performed for the
416 // specified Project (including any Operations in progress). Operations are not
417 // created directly but through calls on other collections or resources.
418 //
419 // An Operation that is done may be deleted so that it is no longer listed as
420 // part of the Operation collection. Operations are garbage collected after
421 // 30 days. By default, ListOperations will only return in progress and failed
422 // operations. To list completed operation, issue a ListOperations request with
423 // the filter done: true.
424 //
425 // Operations are created by service FirestoreAdmin, but are accessed via
426 // service google.longrunning.Operations.
427 type FirestoreAdminClient struct {
428 // The internal transport-dependent client.
429 internalClient internalFirestoreAdminClient
430
431 // The call options for this service.
432 CallOptions *FirestoreAdminCallOptions
433
434 // LROClient is used internally to handle long-running operations.
435 // It is exposed so that its CallOptions can be modified if required.
436 // Users should not Close this client.
437 LROClient *lroauto.OperationsClient
438 }
439
440 // Wrapper methods routed to the internal client.
441
442 // Close closes the connection to the API service. The user should invoke this when
443 // the client is no longer required.
444 func (c *FirestoreAdminClient) Close() error {
445 return c.internalClient.Close()
446 }
447
448 // setGoogleClientInfo sets the name and version of the application in
449 // the `x-goog-api-client` header passed on each request. Intended for
450 // use by Google-written clients.
451 func (c *FirestoreAdminClient) setGoogleClientInfo(keyval ...string) {
452 c.internalClient.setGoogleClientInfo(keyval...)
453 }
454
455 // Connection returns a connection to the API service.
456 //
457 // Deprecated: Connections are now pooled so this method does not always
458 // return the same resource.
459 func (c *FirestoreAdminClient) Connection() *grpc.ClientConn {
460 return c.internalClient.Connection()
461 }
462
463 // CreateIndex creates a composite index. This returns a
464 // google.longrunning.Operation which may be
465 // used to track the status of the creation. The metadata for the operation
466 // will be the type
467 // IndexOperationMetadata.
468 func (c *FirestoreAdminClient) CreateIndex(ctx context.Context, req *adminpb.CreateIndexRequest, opts ...gax.CallOption) (*CreateIndexOperation, error) {
469 return c.internalClient.CreateIndex(ctx, req, opts...)
470 }
471
472 // CreateIndexOperation returns a new CreateIndexOperation from a given name.
473 // The name must be that of a previously created CreateIndexOperation, possibly from a different process.
474 func (c *FirestoreAdminClient) CreateIndexOperation(name string) *CreateIndexOperation {
475 return c.internalClient.CreateIndexOperation(name)
476 }
477
478 // ListIndexes lists composite indexes.
479 func (c *FirestoreAdminClient) ListIndexes(ctx context.Context, req *adminpb.ListIndexesRequest, opts ...gax.CallOption) *IndexIterator {
480 return c.internalClient.ListIndexes(ctx, req, opts...)
481 }
482
483 // GetIndex gets a composite index.
484 func (c *FirestoreAdminClient) GetIndex(ctx context.Context, req *adminpb.GetIndexRequest, opts ...gax.CallOption) (*adminpb.Index, error) {
485 return c.internalClient.GetIndex(ctx, req, opts...)
486 }
487
488 // DeleteIndex deletes a composite index.
489 func (c *FirestoreAdminClient) DeleteIndex(ctx context.Context, req *adminpb.DeleteIndexRequest, opts ...gax.CallOption) error {
490 return c.internalClient.DeleteIndex(ctx, req, opts...)
491 }
492
493 // GetField gets the metadata and configuration for a Field.
494 func (c *FirestoreAdminClient) GetField(ctx context.Context, req *adminpb.GetFieldRequest, opts ...gax.CallOption) (*adminpb.Field, error) {
495 return c.internalClient.GetField(ctx, req, opts...)
496 }
497
498 // UpdateField updates a field configuration. Currently, field updates apply only to
499 // single field index configuration. However, calls to
500 // FirestoreAdmin.UpdateField
501 // should provide a field mask to avoid changing any configuration that the
502 // caller isn’t aware of. The field mask should be specified as: { paths: "index_config" }.
503 //
504 // This call returns a
505 // google.longrunning.Operation which may be
506 // used to track the status of the field update. The metadata for the
507 // operation will be the type
508 // FieldOperationMetadata.
509 //
510 // To configure the default field settings for the database, use
511 // the special Field with resource name:
512 // projects/{project_id}/databases/{database_id}/collectionGroups/__default__/fields/*.
513 func (c *FirestoreAdminClient) UpdateField(ctx context.Context, req *adminpb.UpdateFieldRequest, opts ...gax.CallOption) (*UpdateFieldOperation, error) {
514 return c.internalClient.UpdateField(ctx, req, opts...)
515 }
516
517 // UpdateFieldOperation returns a new UpdateFieldOperation from a given name.
518 // The name must be that of a previously created UpdateFieldOperation, possibly from a different process.
519 func (c *FirestoreAdminClient) UpdateFieldOperation(name string) *UpdateFieldOperation {
520 return c.internalClient.UpdateFieldOperation(name)
521 }
522
523 // ListFields lists the field configuration and metadata for this database.
524 //
525 // Currently,
526 // FirestoreAdmin.ListFields
527 // only supports listing fields that have been explicitly overridden. To issue
528 // this query, call
529 // FirestoreAdmin.ListFields
530 // with the filter set to indexConfig.usesAncestorConfig:false or
531 // ttlConfig:*.
532 func (c *FirestoreAdminClient) ListFields(ctx context.Context, req *adminpb.ListFieldsRequest, opts ...gax.CallOption) *FieldIterator {
533 return c.internalClient.ListFields(ctx, req, opts...)
534 }
535
536 // ExportDocuments exports a copy of all or a subset of documents from Google Cloud Firestore
537 // to another storage system, such as Google Cloud Storage. Recent updates to
538 // documents may not be reflected in the export. The export occurs in the
539 // background and its progress can be monitored and managed via the
540 // Operation resource that is created. The output of an export may only be
541 // used once the associated operation is done. If an export operation is
542 // cancelled before completion it may leave partial data behind in Google
543 // Cloud Storage.
544 //
545 // For more details on export behavior and output format, refer to:
546 // https://cloud.google.com/firestore/docs/manage-data/export-import (at https://cloud.google.com/firestore/docs/manage-data/export-import)
547 func (c *FirestoreAdminClient) ExportDocuments(ctx context.Context, req *adminpb.ExportDocumentsRequest, opts ...gax.CallOption) (*ExportDocumentsOperation, error) {
548 return c.internalClient.ExportDocuments(ctx, req, opts...)
549 }
550
551 // ExportDocumentsOperation returns a new ExportDocumentsOperation from a given name.
552 // The name must be that of a previously created ExportDocumentsOperation, possibly from a different process.
553 func (c *FirestoreAdminClient) ExportDocumentsOperation(name string) *ExportDocumentsOperation {
554 return c.internalClient.ExportDocumentsOperation(name)
555 }
556
557 // ImportDocuments imports documents into Google Cloud Firestore. Existing documents with the
558 // same name are overwritten. The import occurs in the background and its
559 // progress can be monitored and managed via the Operation resource that is
560 // created. If an ImportDocuments operation is cancelled, it is possible
561 // that a subset of the data has already been imported to Cloud Firestore.
562 func (c *FirestoreAdminClient) ImportDocuments(ctx context.Context, req *adminpb.ImportDocumentsRequest, opts ...gax.CallOption) (*ImportDocumentsOperation, error) {
563 return c.internalClient.ImportDocuments(ctx, req, opts...)
564 }
565
566 // ImportDocumentsOperation returns a new ImportDocumentsOperation from a given name.
567 // The name must be that of a previously created ImportDocumentsOperation, possibly from a different process.
568 func (c *FirestoreAdminClient) ImportDocumentsOperation(name string) *ImportDocumentsOperation {
569 return c.internalClient.ImportDocumentsOperation(name)
570 }
571
572 // BulkDeleteDocuments bulk deletes a subset of documents from Google Cloud Firestore.
573 // Documents created or updated after the underlying system starts to process
574 // the request will not be deleted. The bulk delete occurs in the background
575 // and its progress can be monitored and managed via the Operation resource
576 // that is created.
577 //
578 // For more details on bulk delete behavior, refer to:
579 // https://cloud.google.com/firestore/docs/manage-data/bulk-delete (at https://cloud.google.com/firestore/docs/manage-data/bulk-delete)
580 func (c *FirestoreAdminClient) BulkDeleteDocuments(ctx context.Context, req *adminpb.BulkDeleteDocumentsRequest, opts ...gax.CallOption) (*BulkDeleteDocumentsOperation, error) {
581 return c.internalClient.BulkDeleteDocuments(ctx, req, opts...)
582 }
583
584 // BulkDeleteDocumentsOperation returns a new BulkDeleteDocumentsOperation from a given name.
585 // The name must be that of a previously created BulkDeleteDocumentsOperation, possibly from a different process.
586 func (c *FirestoreAdminClient) BulkDeleteDocumentsOperation(name string) *BulkDeleteDocumentsOperation {
587 return c.internalClient.BulkDeleteDocumentsOperation(name)
588 }
589
590 // CreateDatabase create a database.
591 func (c *FirestoreAdminClient) CreateDatabase(ctx context.Context, req *adminpb.CreateDatabaseRequest, opts ...gax.CallOption) (*CreateDatabaseOperation, error) {
592 return c.internalClient.CreateDatabase(ctx, req, opts...)
593 }
594
595 // CreateDatabaseOperation returns a new CreateDatabaseOperation from a given name.
596 // The name must be that of a previously created CreateDatabaseOperation, possibly from a different process.
597 func (c *FirestoreAdminClient) CreateDatabaseOperation(name string) *CreateDatabaseOperation {
598 return c.internalClient.CreateDatabaseOperation(name)
599 }
600
601 // GetDatabase gets information about a database.
602 func (c *FirestoreAdminClient) GetDatabase(ctx context.Context, req *adminpb.GetDatabaseRequest, opts ...gax.CallOption) (*adminpb.Database, error) {
603 return c.internalClient.GetDatabase(ctx, req, opts...)
604 }
605
606 // ListDatabases list all the databases in the project.
607 func (c *FirestoreAdminClient) ListDatabases(ctx context.Context, req *adminpb.ListDatabasesRequest, opts ...gax.CallOption) (*adminpb.ListDatabasesResponse, error) {
608 return c.internalClient.ListDatabases(ctx, req, opts...)
609 }
610
611 // UpdateDatabase updates a database.
612 func (c *FirestoreAdminClient) UpdateDatabase(ctx context.Context, req *adminpb.UpdateDatabaseRequest, opts ...gax.CallOption) (*UpdateDatabaseOperation, error) {
613 return c.internalClient.UpdateDatabase(ctx, req, opts...)
614 }
615
616 // UpdateDatabaseOperation returns a new UpdateDatabaseOperation from a given name.
617 // The name must be that of a previously created UpdateDatabaseOperation, possibly from a different process.
618 func (c *FirestoreAdminClient) UpdateDatabaseOperation(name string) *UpdateDatabaseOperation {
619 return c.internalClient.UpdateDatabaseOperation(name)
620 }
621
622 // DeleteDatabase deletes a database.
623 func (c *FirestoreAdminClient) DeleteDatabase(ctx context.Context, req *adminpb.DeleteDatabaseRequest, opts ...gax.CallOption) (*DeleteDatabaseOperation, error) {
624 return c.internalClient.DeleteDatabase(ctx, req, opts...)
625 }
626
627 // DeleteDatabaseOperation returns a new DeleteDatabaseOperation from a given name.
628 // The name must be that of a previously created DeleteDatabaseOperation, possibly from a different process.
629 func (c *FirestoreAdminClient) DeleteDatabaseOperation(name string) *DeleteDatabaseOperation {
630 return c.internalClient.DeleteDatabaseOperation(name)
631 }
632
633 // CreateUserCreds create a user creds.
634 func (c *FirestoreAdminClient) CreateUserCreds(ctx context.Context, req *adminpb.CreateUserCredsRequest, opts ...gax.CallOption) (*adminpb.UserCreds, error) {
635 return c.internalClient.CreateUserCreds(ctx, req, opts...)
636 }
637
638 // GetUserCreds gets a user creds resource. Note that the returned resource does not
639 // contain the secret value itself.
640 func (c *FirestoreAdminClient) GetUserCreds(ctx context.Context, req *adminpb.GetUserCredsRequest, opts ...gax.CallOption) (*adminpb.UserCreds, error) {
641 return c.internalClient.GetUserCreds(ctx, req, opts...)
642 }
643
644 // ListUserCreds list all user creds in the database. Note that the returned resource
645 // does not contain the secret value itself.
646 func (c *FirestoreAdminClient) ListUserCreds(ctx context.Context, req *adminpb.ListUserCredsRequest, opts ...gax.CallOption) (*adminpb.ListUserCredsResponse, error) {
647 return c.internalClient.ListUserCreds(ctx, req, opts...)
648 }
649
650 // EnableUserCreds enables a user creds. No-op if the user creds are already enabled.
651 func (c *FirestoreAdminClient) EnableUserCreds(ctx context.Context, req *adminpb.EnableUserCredsRequest, opts ...gax.CallOption) (*adminpb.UserCreds, error) {
652 return c.internalClient.EnableUserCreds(ctx, req, opts...)
653 }
654
655 // DisableUserCreds disables a user creds. No-op if the user creds are already disabled.
656 func (c *FirestoreAdminClient) DisableUserCreds(ctx context.Context, req *adminpb.DisableUserCredsRequest, opts ...gax.CallOption) (*adminpb.UserCreds, error) {
657 return c.internalClient.DisableUserCreds(ctx, req, opts...)
658 }
659
660 // ResetUserPassword resets the password of a user creds.
661 func (c *FirestoreAdminClient) ResetUserPassword(ctx context.Context, req *adminpb.ResetUserPasswordRequest, opts ...gax.CallOption) (*adminpb.UserCreds, error) {
662 return c.internalClient.ResetUserPassword(ctx, req, opts...)
663 }
664
665 // DeleteUserCreds deletes a user creds.
666 func (c *FirestoreAdminClient) DeleteUserCreds(ctx context.Context, req *adminpb.DeleteUserCredsRequest, opts ...gax.CallOption) error {
667 return c.internalClient.DeleteUserCreds(ctx, req, opts...)
668 }
669
670 // GetBackup gets information about a backup.
671 func (c *FirestoreAdminClient) GetBackup(ctx context.Context, req *adminpb.GetBackupRequest, opts ...gax.CallOption) (*adminpb.Backup, error) {
672 return c.internalClient.GetBackup(ctx, req, opts...)
673 }
674
675 // ListBackups lists all the backups.
676 func (c *FirestoreAdminClient) ListBackups(ctx context.Context, req *adminpb.ListBackupsRequest, opts ...gax.CallOption) (*adminpb.ListBackupsResponse, error) {
677 return c.internalClient.ListBackups(ctx, req, opts...)
678 }
679
680 // DeleteBackup deletes a backup.
681 func (c *FirestoreAdminClient) DeleteBackup(ctx context.Context, req *adminpb.DeleteBackupRequest, opts ...gax.CallOption) error {
682 return c.internalClient.DeleteBackup(ctx, req, opts...)
683 }
684
685 // RestoreDatabase creates a new database by restoring from an existing backup.
686 //
687 // The new database must be in the same cloud region or multi-region location
688 // as the existing backup. This behaves similar to
689 // FirestoreAdmin.CreateDatabase
690 // except instead of creating a new empty database, a new database is created
691 // with the database type, index configuration, and documents from an existing
692 // backup.
693 //
694 // The [long-running operation][google.longrunning.Operation] can be used to
695 // track the progress of the restore, with the Operation’s
696 // metadata field type being the
697 // RestoreDatabaseMetadata.
698 // The response type is the
699 // Database if the restore was
700 // successful. The new database is not readable or writeable until the LRO has
701 // completed.
702 func (c *FirestoreAdminClient) RestoreDatabase(ctx context.Context, req *adminpb.RestoreDatabaseRequest, opts ...gax.CallOption) (*RestoreDatabaseOperation, error) {
703 return c.internalClient.RestoreDatabase(ctx, req, opts...)
704 }
705
706 // RestoreDatabaseOperation returns a new RestoreDatabaseOperation from a given name.
707 // The name must be that of a previously created RestoreDatabaseOperation, possibly from a different process.
708 func (c *FirestoreAdminClient) RestoreDatabaseOperation(name string) *RestoreDatabaseOperation {
709 return c.internalClient.RestoreDatabaseOperation(name)
710 }
711
712 // CreateBackupSchedule creates a backup schedule on a database.
713 // At most two backup schedules can be configured on a database, one daily
714 // backup schedule and one weekly backup schedule.
715 func (c *FirestoreAdminClient) CreateBackupSchedule(ctx context.Context, req *adminpb.CreateBackupScheduleRequest, opts ...gax.CallOption) (*adminpb.BackupSchedule, error) {
716 return c.internalClient.CreateBackupSchedule(ctx, req, opts...)
717 }
718
719 // GetBackupSchedule gets information about a backup schedule.
720 func (c *FirestoreAdminClient) GetBackupSchedule(ctx context.Context, req *adminpb.GetBackupScheduleRequest, opts ...gax.CallOption) (*adminpb.BackupSchedule, error) {
721 return c.internalClient.GetBackupSchedule(ctx, req, opts...)
722 }
723
724 // ListBackupSchedules list backup schedules.
725 func (c *FirestoreAdminClient) ListBackupSchedules(ctx context.Context, req *adminpb.ListBackupSchedulesRequest, opts ...gax.CallOption) (*adminpb.ListBackupSchedulesResponse, error) {
726 return c.internalClient.ListBackupSchedules(ctx, req, opts...)
727 }
728
729 // UpdateBackupSchedule updates a backup schedule.
730 func (c *FirestoreAdminClient) UpdateBackupSchedule(ctx context.Context, req *adminpb.UpdateBackupScheduleRequest, opts ...gax.CallOption) (*adminpb.BackupSchedule, error) {
731 return c.internalClient.UpdateBackupSchedule(ctx, req, opts...)
732 }
733
734 // DeleteBackupSchedule deletes a backup schedule.
735 func (c *FirestoreAdminClient) DeleteBackupSchedule(ctx context.Context, req *adminpb.DeleteBackupScheduleRequest, opts ...gax.CallOption) error {
736 return c.internalClient.DeleteBackupSchedule(ctx, req, opts...)
737 }
738
739 // CloneDatabase creates a new database by cloning an existing one.
740 //
741 // The new database must be in the same cloud region or multi-region location
742 // as the existing database. This behaves similar to
743 // FirestoreAdmin.CreateDatabase
744 // except instead of creating a new empty database, a new database is created
745 // with the database type, index configuration, and documents from an existing
746 // database.
747 //
748 // The [long-running operation][google.longrunning.Operation] can be used to
749 // track the progress of the clone, with the Operation’s
750 // metadata field type being the
751 // CloneDatabaseMetadata.
752 // The response type is the
753 // Database if the clone was
754 // successful. The new database is not readable or writeable until the LRO has
755 // completed.
756 func (c *FirestoreAdminClient) CloneDatabase(ctx context.Context, req *adminpb.CloneDatabaseRequest, opts ...gax.CallOption) (*CloneDatabaseOperation, error) {
757 return c.internalClient.CloneDatabase(ctx, req, opts...)
758 }
759
760 // CloneDatabaseOperation returns a new CloneDatabaseOperation from a given name.
761 // The name must be that of a previously created CloneDatabaseOperation, possibly from a different process.
762 func (c *FirestoreAdminClient) CloneDatabaseOperation(name string) *CloneDatabaseOperation {
763 return c.internalClient.CloneDatabaseOperation(name)
764 }
765
766 // CancelOperation is a utility method from google.longrunning.Operations.
767 func (c *FirestoreAdminClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
768 return c.internalClient.CancelOperation(ctx, req, opts...)
769 }
770
771 // DeleteOperation is a utility method from google.longrunning.Operations.
772 func (c *FirestoreAdminClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
773 return c.internalClient.DeleteOperation(ctx, req, opts...)
774 }
775
776 // GetOperation is a utility method from google.longrunning.Operations.
777 func (c *FirestoreAdminClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
778 return c.internalClient.GetOperation(ctx, req, opts...)
779 }
780
781 // ListOperations is a utility method from google.longrunning.Operations.
782 func (c *FirestoreAdminClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
783 return c.internalClient.ListOperations(ctx, req, opts...)
784 }
785
786 // firestoreAdminGRPCClient is a client for interacting with Cloud Firestore API over gRPC transport.
787 //
788 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
789 type firestoreAdminGRPCClient struct {
790 // Connection pool of gRPC connections to the service.
791 connPool gtransport.ConnPool
792
793 // Points back to the CallOptions field of the containing FirestoreAdminClient
794 CallOptions **FirestoreAdminCallOptions
795
796 // The gRPC API client.
797 firestoreAdminClient adminpb.FirestoreAdminClient
798
799 // LROClient is used internally to handle long-running operations.
800 // It is exposed so that its CallOptions can be modified if required.
801 // Users should not Close this client.
802 LROClient **lroauto.OperationsClient
803
804 operationsClient longrunningpb.OperationsClient
805
806 // The x-goog-* metadata to be sent with each request.
807 xGoogHeaders []string
808
809 logger *slog.Logger
810 }
811
812 // NewFirestoreAdminClient creates a new firestore admin client based on gRPC.
813 // The returned client must be Closed when it is done being used to clean up its underlying connections.
814 //
815 // The Cloud Firestore Admin API.
816 //
817 // This API provides several administrative services for Cloud Firestore.
818 //
819 // Project, Database, Namespace, Collection, Collection Group, and Document are
820 // used as defined in the Google Cloud Firestore API.
821 //
822 // Operation: An Operation represents work being performed in the background.
823 //
824 // The index service manages Cloud Firestore indexes.
825 //
826 // Index creation is performed asynchronously.
827 // An Operation resource is created for each such asynchronous operation.
828 // The state of the operation (including any errors encountered)
829 // may be queried via the Operation resource.
830 //
831 // The Operations collection provides a record of actions performed for the
832 // specified Project (including any Operations in progress). Operations are not
833 // created directly but through calls on other collections or resources.
834 //
835 // An Operation that is done may be deleted so that it is no longer listed as
836 // part of the Operation collection. Operations are garbage collected after
837 // 30 days. By default, ListOperations will only return in progress and failed
838 // operations. To list completed operation, issue a ListOperations request with
839 // the filter done: true.
840 //
841 // Operations are created by service FirestoreAdmin, but are accessed via
842 // service google.longrunning.Operations.
843 func NewFirestoreAdminClient(ctx context.Context, opts ...option.ClientOption) (*FirestoreAdminClient, error) {
844 clientOpts := defaultFirestoreAdminGRPCClientOptions()
845 if newFirestoreAdminClientHook != nil {
846 hookOpts, err := newFirestoreAdminClientHook(ctx, clientHookParams{})
847 if err != nil {
848 return nil, err
849 }
850 clientOpts = append(clientOpts, hookOpts...)
851 }
852
853 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
854 if err != nil {
855 return nil, err
856 }
857 client := FirestoreAdminClient{CallOptions: defaultFirestoreAdminCallOptions()}
858
859 c := &firestoreAdminGRPCClient{
860 connPool: connPool,
861 firestoreAdminClient: adminpb.NewFirestoreAdminClient(connPool),
862 CallOptions: &client.CallOptions,
863 logger: internaloption.GetLogger(opts),
864 operationsClient: longrunningpb.NewOperationsClient(connPool),
865 }
866 c.setGoogleClientInfo()
867
868 client.internalClient = c
869
870 client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
871 if err != nil {
872 // This error "should not happen", since we are just reusing old connection pool
873 // and never actually need to dial.
874 // If this does happen, we could leak connp. However, we cannot close conn:
875 // If the user invoked the constructor with option.WithGRPCConn,
876 // we would close a connection that's still in use.
877 // TODO: investigate error conditions.
878 return nil, err
879 }
880 c.LROClient = &client.LROClient
881 return &client, nil
882 }
883
884 // Connection returns a connection to the API service.
885 //
886 // Deprecated: Connections are now pooled so this method does not always
887 // return the same resource.
888 func (c *firestoreAdminGRPCClient) Connection() *grpc.ClientConn {
889 return c.connPool.Conn()
890 }
891
892 // setGoogleClientInfo sets the name and version of the application in
893 // the `x-goog-api-client` header passed on each request. Intended for
894 // use by Google-written clients.
895 func (c *firestoreAdminGRPCClient) setGoogleClientInfo(keyval ...string) {
896 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
897 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
898 c.xGoogHeaders = []string{
899 "x-goog-api-client", gax.XGoogHeader(kv...),
900 }
901 }
902
903 // Close closes the connection to the API service. The user should invoke this when
904 // the client is no longer required.
905 func (c *firestoreAdminGRPCClient) Close() error {
906 return c.connPool.Close()
907 }
908
909 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
910 type firestoreAdminRESTClient struct {
911 // The http endpoint to connect to.
912 endpoint string
913
914 // The http client.
915 httpClient *http.Client
916
917 // LROClient is used internally to handle long-running operations.
918 // It is exposed so that its CallOptions can be modified if required.
919 // Users should not Close this client.
920 LROClient **lroauto.OperationsClient
921
922 // The x-goog-* headers to be sent with each request.
923 xGoogHeaders []string
924
925 // Points back to the CallOptions field of the containing FirestoreAdminClient
926 CallOptions **FirestoreAdminCallOptions
927
928 logger *slog.Logger
929 }
930
931 // NewFirestoreAdminRESTClient creates a new firestore admin rest client.
932 //
933 // The Cloud Firestore Admin API.
934 //
935 // This API provides several administrative services for Cloud Firestore.
936 //
937 // Project, Database, Namespace, Collection, Collection Group, and Document are
938 // used as defined in the Google Cloud Firestore API.
939 //
940 // Operation: An Operation represents work being performed in the background.
941 //
942 // The index service manages Cloud Firestore indexes.
943 //
944 // Index creation is performed asynchronously.
945 // An Operation resource is created for each such asynchronous operation.
946 // The state of the operation (including any errors encountered)
947 // may be queried via the Operation resource.
948 //
949 // The Operations collection provides a record of actions performed for the
950 // specified Project (including any Operations in progress). Operations are not
951 // created directly but through calls on other collections or resources.
952 //
953 // An Operation that is done may be deleted so that it is no longer listed as
954 // part of the Operation collection. Operations are garbage collected after
955 // 30 days. By default, ListOperations will only return in progress and failed
956 // operations. To list completed operation, issue a ListOperations request with
957 // the filter done: true.
958 //
959 // Operations are created by service FirestoreAdmin, but are accessed via
960 // service google.longrunning.Operations.
961 func NewFirestoreAdminRESTClient(ctx context.Context, opts ...option.ClientOption) (*FirestoreAdminClient, error) {
962 clientOpts := append(defaultFirestoreAdminRESTClientOptions(), opts...)
963 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
964 if err != nil {
965 return nil, err
966 }
967
968 callOpts := defaultFirestoreAdminRESTCallOptions()
969 c := &firestoreAdminRESTClient{
970 endpoint: endpoint,
971 httpClient: httpClient,
972 CallOptions: &callOpts,
973 logger: internaloption.GetLogger(opts),
974 }
975 c.setGoogleClientInfo()
976
977 lroOpts := []option.ClientOption{
978 option.WithHTTPClient(httpClient),
979 option.WithEndpoint(endpoint),
980 }
981 opClient, err := lroauto.NewOperationsRESTClient(ctx, lroOpts...)
982 if err != nil {
983 return nil, err
984 }
985 c.LROClient = &opClient
986
987 return &FirestoreAdminClient{internalClient: c, CallOptions: callOpts}, nil
988 }
989
990 func defaultFirestoreAdminRESTClientOptions() []option.ClientOption {
991 return []option.ClientOption{
992 internaloption.WithDefaultEndpoint("https://firestore.googleapis.com"),
993 internaloption.WithDefaultEndpointTemplate("https://firestore.UNIVERSE_DOMAIN"),
994 internaloption.WithDefaultMTLSEndpoint("https://firestore.mtls.googleapis.com"),
995 internaloption.WithDefaultUniverseDomain("googleapis.com"),
996 internaloption.WithDefaultAudience("https://firestore.googleapis.com/"),
997 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
998 internaloption.EnableNewAuthLibrary(),
999 }
1000 }
1001
1002 // setGoogleClientInfo sets the name and version of the application in
1003 // the `x-goog-api-client` header passed on each request. Intended for
1004 // use by Google-written clients.
1005 func (c *firestoreAdminRESTClient) setGoogleClientInfo(keyval ...string) {
1006 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
1007 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
1008 c.xGoogHeaders = []string{
1009 "x-goog-api-client", gax.XGoogHeader(kv...),
1010 }
1011 }
1012
1013 // Close closes the connection to the API service. The user should invoke this when
1014 // the client is no longer required.
1015 func (c *firestoreAdminRESTClient) Close() error {
1016 // Replace httpClient with nil to force cleanup.
1017 c.httpClient = nil
1018 return nil
1019 }
1020
1021 // Connection returns a connection to the API service.
1022 //
1023 // Deprecated: This method always returns nil.
1024 func (c *firestoreAdminRESTClient) Connection() *grpc.ClientConn {
1025 return nil
1026 }
1027 func (c *firestoreAdminGRPCClient) CreateIndex(ctx context.Context, req *adminpb.CreateIndexRequest, opts ...gax.CallOption) (*CreateIndexOperation, error) {
1028 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1029
1030 hds = append(c.xGoogHeaders, hds...)
1031 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1032 opts = append((*c.CallOptions).CreateIndex[0:len((*c.CallOptions).CreateIndex):len((*c.CallOptions).CreateIndex)], opts...)
1033 var resp *longrunningpb.Operation
1034 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1035 var err error
1036 resp, err = executeRPC(ctx, c.firestoreAdminClient.CreateIndex, req, settings.GRPC, c.logger, "CreateIndex")
1037 return err
1038 }, opts...)
1039 if err != nil {
1040 return nil, err
1041 }
1042 return &CreateIndexOperation{
1043 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1044 }, nil
1045 }
1046
1047 func (c *firestoreAdminGRPCClient) ListIndexes(ctx context.Context, req *adminpb.ListIndexesRequest, opts ...gax.CallOption) *IndexIterator {
1048 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1049
1050 hds = append(c.xGoogHeaders, hds...)
1051 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1052 opts = append((*c.CallOptions).ListIndexes[0:len((*c.CallOptions).ListIndexes):len((*c.CallOptions).ListIndexes)], opts...)
1053 it := &IndexIterator{}
1054 req = proto.Clone(req).(*adminpb.ListIndexesRequest)
1055 it.InternalFetch = func(pageSize int, pageToken string) ([]*adminpb.Index, string, error) {
1056 resp := &adminpb.ListIndexesResponse{}
1057 if pageToken != "" {
1058 req.PageToken = pageToken
1059 }
1060 if pageSize > math.MaxInt32 {
1061 req.PageSize = math.MaxInt32
1062 } else if pageSize != 0 {
1063 req.PageSize = int32(pageSize)
1064 }
1065 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1066 var err error
1067 resp, err = executeRPC(ctx, c.firestoreAdminClient.ListIndexes, req, settings.GRPC, c.logger, "ListIndexes")
1068 return err
1069 }, opts...)
1070 if err != nil {
1071 return nil, "", err
1072 }
1073
1074 it.Response = resp
1075 return resp.GetIndexes(), resp.GetNextPageToken(), nil
1076 }
1077 fetch := func(pageSize int, pageToken string) (string, error) {
1078 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1079 if err != nil {
1080 return "", err
1081 }
1082 it.items = append(it.items, items...)
1083 return nextPageToken, nil
1084 }
1085
1086 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1087 it.pageInfo.MaxSize = int(req.GetPageSize())
1088 it.pageInfo.Token = req.GetPageToken()
1089
1090 return it
1091 }
1092
1093 func (c *firestoreAdminGRPCClient) GetIndex(ctx context.Context, req *adminpb.GetIndexRequest, opts ...gax.CallOption) (*adminpb.Index, error) {
1094 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1095
1096 hds = append(c.xGoogHeaders, hds...)
1097 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1098 opts = append((*c.CallOptions).GetIndex[0:len((*c.CallOptions).GetIndex):len((*c.CallOptions).GetIndex)], opts...)
1099 var resp *adminpb.Index
1100 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1101 var err error
1102 resp, err = executeRPC(ctx, c.firestoreAdminClient.GetIndex, req, settings.GRPC, c.logger, "GetIndex")
1103 return err
1104 }, opts...)
1105 if err != nil {
1106 return nil, err
1107 }
1108 return resp, nil
1109 }
1110
1111 func (c *firestoreAdminGRPCClient) DeleteIndex(ctx context.Context, req *adminpb.DeleteIndexRequest, opts ...gax.CallOption) error {
1112 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1113
1114 hds = append(c.xGoogHeaders, hds...)
1115 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1116 opts = append((*c.CallOptions).DeleteIndex[0:len((*c.CallOptions).DeleteIndex):len((*c.CallOptions).DeleteIndex)], opts...)
1117 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1118 var err error
1119 _, err = executeRPC(ctx, c.firestoreAdminClient.DeleteIndex, req, settings.GRPC, c.logger, "DeleteIndex")
1120 return err
1121 }, opts...)
1122 return err
1123 }
1124
1125 func (c *firestoreAdminGRPCClient) GetField(ctx context.Context, req *adminpb.GetFieldRequest, opts ...gax.CallOption) (*adminpb.Field, error) {
1126 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1127
1128 hds = append(c.xGoogHeaders, hds...)
1129 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1130 opts = append((*c.CallOptions).GetField[0:len((*c.CallOptions).GetField):len((*c.CallOptions).GetField)], opts...)
1131 var resp *adminpb.Field
1132 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1133 var err error
1134 resp, err = executeRPC(ctx, c.firestoreAdminClient.GetField, req, settings.GRPC, c.logger, "GetField")
1135 return err
1136 }, opts...)
1137 if err != nil {
1138 return nil, err
1139 }
1140 return resp, nil
1141 }
1142
1143 func (c *firestoreAdminGRPCClient) UpdateField(ctx context.Context, req *adminpb.UpdateFieldRequest, opts ...gax.CallOption) (*UpdateFieldOperation, error) {
1144 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "field.name", url.QueryEscape(req.GetField().GetName()))}
1145
1146 hds = append(c.xGoogHeaders, hds...)
1147 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1148 opts = append((*c.CallOptions).UpdateField[0:len((*c.CallOptions).UpdateField):len((*c.CallOptions).UpdateField)], opts...)
1149 var resp *longrunningpb.Operation
1150 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1151 var err error
1152 resp, err = executeRPC(ctx, c.firestoreAdminClient.UpdateField, req, settings.GRPC, c.logger, "UpdateField")
1153 return err
1154 }, opts...)
1155 if err != nil {
1156 return nil, err
1157 }
1158 return &UpdateFieldOperation{
1159 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1160 }, nil
1161 }
1162
1163 func (c *firestoreAdminGRPCClient) ListFields(ctx context.Context, req *adminpb.ListFieldsRequest, opts ...gax.CallOption) *FieldIterator {
1164 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1165
1166 hds = append(c.xGoogHeaders, hds...)
1167 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1168 opts = append((*c.CallOptions).ListFields[0:len((*c.CallOptions).ListFields):len((*c.CallOptions).ListFields)], opts...)
1169 it := &FieldIterator{}
1170 req = proto.Clone(req).(*adminpb.ListFieldsRequest)
1171 it.InternalFetch = func(pageSize int, pageToken string) ([]*adminpb.Field, string, error) {
1172 resp := &adminpb.ListFieldsResponse{}
1173 if pageToken != "" {
1174 req.PageToken = pageToken
1175 }
1176 if pageSize > math.MaxInt32 {
1177 req.PageSize = math.MaxInt32
1178 } else if pageSize != 0 {
1179 req.PageSize = int32(pageSize)
1180 }
1181 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1182 var err error
1183 resp, err = executeRPC(ctx, c.firestoreAdminClient.ListFields, req, settings.GRPC, c.logger, "ListFields")
1184 return err
1185 }, opts...)
1186 if err != nil {
1187 return nil, "", err
1188 }
1189
1190 it.Response = resp
1191 return resp.GetFields(), resp.GetNextPageToken(), nil
1192 }
1193 fetch := func(pageSize int, pageToken string) (string, error) {
1194 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1195 if err != nil {
1196 return "", err
1197 }
1198 it.items = append(it.items, items...)
1199 return nextPageToken, nil
1200 }
1201
1202 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1203 it.pageInfo.MaxSize = int(req.GetPageSize())
1204 it.pageInfo.Token = req.GetPageToken()
1205
1206 return it
1207 }
1208
1209 func (c *firestoreAdminGRPCClient) ExportDocuments(ctx context.Context, req *adminpb.ExportDocumentsRequest, opts ...gax.CallOption) (*ExportDocumentsOperation, error) {
1210 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1211
1212 hds = append(c.xGoogHeaders, hds...)
1213 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1214 opts = append((*c.CallOptions).ExportDocuments[0:len((*c.CallOptions).ExportDocuments):len((*c.CallOptions).ExportDocuments)], opts...)
1215 var resp *longrunningpb.Operation
1216 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1217 var err error
1218 resp, err = executeRPC(ctx, c.firestoreAdminClient.ExportDocuments, req, settings.GRPC, c.logger, "ExportDocuments")
1219 return err
1220 }, opts...)
1221 if err != nil {
1222 return nil, err
1223 }
1224 return &ExportDocumentsOperation{
1225 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1226 }, nil
1227 }
1228
1229 func (c *firestoreAdminGRPCClient) ImportDocuments(ctx context.Context, req *adminpb.ImportDocumentsRequest, opts ...gax.CallOption) (*ImportDocumentsOperation, error) {
1230 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1231
1232 hds = append(c.xGoogHeaders, hds...)
1233 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1234 opts = append((*c.CallOptions).ImportDocuments[0:len((*c.CallOptions).ImportDocuments):len((*c.CallOptions).ImportDocuments)], opts...)
1235 var resp *longrunningpb.Operation
1236 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1237 var err error
1238 resp, err = executeRPC(ctx, c.firestoreAdminClient.ImportDocuments, req, settings.GRPC, c.logger, "ImportDocuments")
1239 return err
1240 }, opts...)
1241 if err != nil {
1242 return nil, err
1243 }
1244 return &ImportDocumentsOperation{
1245 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1246 }, nil
1247 }
1248
1249 func (c *firestoreAdminGRPCClient) BulkDeleteDocuments(ctx context.Context, req *adminpb.BulkDeleteDocumentsRequest, opts ...gax.CallOption) (*BulkDeleteDocumentsOperation, error) {
1250 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1251
1252 hds = append(c.xGoogHeaders, hds...)
1253 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1254 opts = append((*c.CallOptions).BulkDeleteDocuments[0:len((*c.CallOptions).BulkDeleteDocuments):len((*c.CallOptions).BulkDeleteDocuments)], opts...)
1255 var resp *longrunningpb.Operation
1256 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1257 var err error
1258 resp, err = executeRPC(ctx, c.firestoreAdminClient.BulkDeleteDocuments, req, settings.GRPC, c.logger, "BulkDeleteDocuments")
1259 return err
1260 }, opts...)
1261 if err != nil {
1262 return nil, err
1263 }
1264 return &BulkDeleteDocumentsOperation{
1265 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1266 }, nil
1267 }
1268
1269 func (c *firestoreAdminGRPCClient) CreateDatabase(ctx context.Context, req *adminpb.CreateDatabaseRequest, opts ...gax.CallOption) (*CreateDatabaseOperation, error) {
1270 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1271
1272 hds = append(c.xGoogHeaders, hds...)
1273 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1274 opts = append((*c.CallOptions).CreateDatabase[0:len((*c.CallOptions).CreateDatabase):len((*c.CallOptions).CreateDatabase)], opts...)
1275 var resp *longrunningpb.Operation
1276 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1277 var err error
1278 resp, err = executeRPC(ctx, c.firestoreAdminClient.CreateDatabase, req, settings.GRPC, c.logger, "CreateDatabase")
1279 return err
1280 }, opts...)
1281 if err != nil {
1282 return nil, err
1283 }
1284 return &CreateDatabaseOperation{
1285 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1286 }, nil
1287 }
1288
1289 func (c *firestoreAdminGRPCClient) GetDatabase(ctx context.Context, req *adminpb.GetDatabaseRequest, opts ...gax.CallOption) (*adminpb.Database, error) {
1290 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1291
1292 hds = append(c.xGoogHeaders, hds...)
1293 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1294 opts = append((*c.CallOptions).GetDatabase[0:len((*c.CallOptions).GetDatabase):len((*c.CallOptions).GetDatabase)], opts...)
1295 var resp *adminpb.Database
1296 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1297 var err error
1298 resp, err = executeRPC(ctx, c.firestoreAdminClient.GetDatabase, req, settings.GRPC, c.logger, "GetDatabase")
1299 return err
1300 }, opts...)
1301 if err != nil {
1302 return nil, err
1303 }
1304 return resp, nil
1305 }
1306
1307 func (c *firestoreAdminGRPCClient) ListDatabases(ctx context.Context, req *adminpb.ListDatabasesRequest, opts ...gax.CallOption) (*adminpb.ListDatabasesResponse, error) {
1308 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1309
1310 hds = append(c.xGoogHeaders, hds...)
1311 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1312 opts = append((*c.CallOptions).ListDatabases[0:len((*c.CallOptions).ListDatabases):len((*c.CallOptions).ListDatabases)], opts...)
1313 var resp *adminpb.ListDatabasesResponse
1314 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1315 var err error
1316 resp, err = executeRPC(ctx, c.firestoreAdminClient.ListDatabases, req, settings.GRPC, c.logger, "ListDatabases")
1317 return err
1318 }, opts...)
1319 if err != nil {
1320 return nil, err
1321 }
1322 return resp, nil
1323 }
1324
1325 func (c *firestoreAdminGRPCClient) UpdateDatabase(ctx context.Context, req *adminpb.UpdateDatabaseRequest, opts ...gax.CallOption) (*UpdateDatabaseOperation, error) {
1326 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "database.name", url.QueryEscape(req.GetDatabase().GetName()))}
1327
1328 hds = append(c.xGoogHeaders, hds...)
1329 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1330 opts = append((*c.CallOptions).UpdateDatabase[0:len((*c.CallOptions).UpdateDatabase):len((*c.CallOptions).UpdateDatabase)], opts...)
1331 var resp *longrunningpb.Operation
1332 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1333 var err error
1334 resp, err = executeRPC(ctx, c.firestoreAdminClient.UpdateDatabase, req, settings.GRPC, c.logger, "UpdateDatabase")
1335 return err
1336 }, opts...)
1337 if err != nil {
1338 return nil, err
1339 }
1340 return &UpdateDatabaseOperation{
1341 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1342 }, nil
1343 }
1344
1345 func (c *firestoreAdminGRPCClient) DeleteDatabase(ctx context.Context, req *adminpb.DeleteDatabaseRequest, opts ...gax.CallOption) (*DeleteDatabaseOperation, error) {
1346 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1347
1348 hds = append(c.xGoogHeaders, hds...)
1349 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1350 opts = append((*c.CallOptions).DeleteDatabase[0:len((*c.CallOptions).DeleteDatabase):len((*c.CallOptions).DeleteDatabase)], opts...)
1351 var resp *longrunningpb.Operation
1352 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1353 var err error
1354 resp, err = executeRPC(ctx, c.firestoreAdminClient.DeleteDatabase, req, settings.GRPC, c.logger, "DeleteDatabase")
1355 return err
1356 }, opts...)
1357 if err != nil {
1358 return nil, err
1359 }
1360 return &DeleteDatabaseOperation{
1361 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1362 }, nil
1363 }
1364
1365 func (c *firestoreAdminGRPCClient) CreateUserCreds(ctx context.Context, req *adminpb.CreateUserCredsRequest, opts ...gax.CallOption) (*adminpb.UserCreds, error) {
1366 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1367
1368 hds = append(c.xGoogHeaders, hds...)
1369 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1370 opts = append((*c.CallOptions).CreateUserCreds[0:len((*c.CallOptions).CreateUserCreds):len((*c.CallOptions).CreateUserCreds)], opts...)
1371 var resp *adminpb.UserCreds
1372 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1373 var err error
1374 resp, err = executeRPC(ctx, c.firestoreAdminClient.CreateUserCreds, req, settings.GRPC, c.logger, "CreateUserCreds")
1375 return err
1376 }, opts...)
1377 if err != nil {
1378 return nil, err
1379 }
1380 return resp, nil
1381 }
1382
1383 func (c *firestoreAdminGRPCClient) GetUserCreds(ctx context.Context, req *adminpb.GetUserCredsRequest, opts ...gax.CallOption) (*adminpb.UserCreds, error) {
1384 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1385
1386 hds = append(c.xGoogHeaders, hds...)
1387 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1388 opts = append((*c.CallOptions).GetUserCreds[0:len((*c.CallOptions).GetUserCreds):len((*c.CallOptions).GetUserCreds)], opts...)
1389 var resp *adminpb.UserCreds
1390 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1391 var err error
1392 resp, err = executeRPC(ctx, c.firestoreAdminClient.GetUserCreds, req, settings.GRPC, c.logger, "GetUserCreds")
1393 return err
1394 }, opts...)
1395 if err != nil {
1396 return nil, err
1397 }
1398 return resp, nil
1399 }
1400
1401 func (c *firestoreAdminGRPCClient) ListUserCreds(ctx context.Context, req *adminpb.ListUserCredsRequest, opts ...gax.CallOption) (*adminpb.ListUserCredsResponse, error) {
1402 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1403
1404 hds = append(c.xGoogHeaders, hds...)
1405 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1406 opts = append((*c.CallOptions).ListUserCreds[0:len((*c.CallOptions).ListUserCreds):len((*c.CallOptions).ListUserCreds)], opts...)
1407 var resp *adminpb.ListUserCredsResponse
1408 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1409 var err error
1410 resp, err = executeRPC(ctx, c.firestoreAdminClient.ListUserCreds, req, settings.GRPC, c.logger, "ListUserCreds")
1411 return err
1412 }, opts...)
1413 if err != nil {
1414 return nil, err
1415 }
1416 return resp, nil
1417 }
1418
1419 func (c *firestoreAdminGRPCClient) EnableUserCreds(ctx context.Context, req *adminpb.EnableUserCredsRequest, opts ...gax.CallOption) (*adminpb.UserCreds, error) {
1420 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1421
1422 hds = append(c.xGoogHeaders, hds...)
1423 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1424 opts = append((*c.CallOptions).EnableUserCreds[0:len((*c.CallOptions).EnableUserCreds):len((*c.CallOptions).EnableUserCreds)], opts...)
1425 var resp *adminpb.UserCreds
1426 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1427 var err error
1428 resp, err = executeRPC(ctx, c.firestoreAdminClient.EnableUserCreds, req, settings.GRPC, c.logger, "EnableUserCreds")
1429 return err
1430 }, opts...)
1431 if err != nil {
1432 return nil, err
1433 }
1434 return resp, nil
1435 }
1436
1437 func (c *firestoreAdminGRPCClient) DisableUserCreds(ctx context.Context, req *adminpb.DisableUserCredsRequest, opts ...gax.CallOption) (*adminpb.UserCreds, error) {
1438 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1439
1440 hds = append(c.xGoogHeaders, hds...)
1441 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1442 opts = append((*c.CallOptions).DisableUserCreds[0:len((*c.CallOptions).DisableUserCreds):len((*c.CallOptions).DisableUserCreds)], opts...)
1443 var resp *adminpb.UserCreds
1444 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1445 var err error
1446 resp, err = executeRPC(ctx, c.firestoreAdminClient.DisableUserCreds, req, settings.GRPC, c.logger, "DisableUserCreds")
1447 return err
1448 }, opts...)
1449 if err != nil {
1450 return nil, err
1451 }
1452 return resp, nil
1453 }
1454
1455 func (c *firestoreAdminGRPCClient) ResetUserPassword(ctx context.Context, req *adminpb.ResetUserPasswordRequest, opts ...gax.CallOption) (*adminpb.UserCreds, error) {
1456 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1457
1458 hds = append(c.xGoogHeaders, hds...)
1459 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1460 opts = append((*c.CallOptions).ResetUserPassword[0:len((*c.CallOptions).ResetUserPassword):len((*c.CallOptions).ResetUserPassword)], opts...)
1461 var resp *adminpb.UserCreds
1462 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1463 var err error
1464 resp, err = executeRPC(ctx, c.firestoreAdminClient.ResetUserPassword, req, settings.GRPC, c.logger, "ResetUserPassword")
1465 return err
1466 }, opts...)
1467 if err != nil {
1468 return nil, err
1469 }
1470 return resp, nil
1471 }
1472
1473 func (c *firestoreAdminGRPCClient) DeleteUserCreds(ctx context.Context, req *adminpb.DeleteUserCredsRequest, opts ...gax.CallOption) error {
1474 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1475
1476 hds = append(c.xGoogHeaders, hds...)
1477 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1478 opts = append((*c.CallOptions).DeleteUserCreds[0:len((*c.CallOptions).DeleteUserCreds):len((*c.CallOptions).DeleteUserCreds)], opts...)
1479 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1480 var err error
1481 _, err = executeRPC(ctx, c.firestoreAdminClient.DeleteUserCreds, req, settings.GRPC, c.logger, "DeleteUserCreds")
1482 return err
1483 }, opts...)
1484 return err
1485 }
1486
1487 func (c *firestoreAdminGRPCClient) GetBackup(ctx context.Context, req *adminpb.GetBackupRequest, opts ...gax.CallOption) (*adminpb.Backup, error) {
1488 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1489
1490 hds = append(c.xGoogHeaders, hds...)
1491 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1492 opts = append((*c.CallOptions).GetBackup[0:len((*c.CallOptions).GetBackup):len((*c.CallOptions).GetBackup)], opts...)
1493 var resp *adminpb.Backup
1494 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1495 var err error
1496 resp, err = executeRPC(ctx, c.firestoreAdminClient.GetBackup, req, settings.GRPC, c.logger, "GetBackup")
1497 return err
1498 }, opts...)
1499 if err != nil {
1500 return nil, err
1501 }
1502 return resp, nil
1503 }
1504
1505 func (c *firestoreAdminGRPCClient) ListBackups(ctx context.Context, req *adminpb.ListBackupsRequest, opts ...gax.CallOption) (*adminpb.ListBackupsResponse, error) {
1506 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1507
1508 hds = append(c.xGoogHeaders, hds...)
1509 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1510 opts = append((*c.CallOptions).ListBackups[0:len((*c.CallOptions).ListBackups):len((*c.CallOptions).ListBackups)], opts...)
1511 var resp *adminpb.ListBackupsResponse
1512 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1513 var err error
1514 resp, err = executeRPC(ctx, c.firestoreAdminClient.ListBackups, req, settings.GRPC, c.logger, "ListBackups")
1515 return err
1516 }, opts...)
1517 if err != nil {
1518 return nil, err
1519 }
1520 return resp, nil
1521 }
1522
1523 func (c *firestoreAdminGRPCClient) DeleteBackup(ctx context.Context, req *adminpb.DeleteBackupRequest, opts ...gax.CallOption) error {
1524 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1525
1526 hds = append(c.xGoogHeaders, hds...)
1527 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1528 opts = append((*c.CallOptions).DeleteBackup[0:len((*c.CallOptions).DeleteBackup):len((*c.CallOptions).DeleteBackup)], opts...)
1529 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1530 var err error
1531 _, err = executeRPC(ctx, c.firestoreAdminClient.DeleteBackup, req, settings.GRPC, c.logger, "DeleteBackup")
1532 return err
1533 }, opts...)
1534 return err
1535 }
1536
1537 func (c *firestoreAdminGRPCClient) RestoreDatabase(ctx context.Context, req *adminpb.RestoreDatabaseRequest, opts ...gax.CallOption) (*RestoreDatabaseOperation, error) {
1538 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1539
1540 hds = append(c.xGoogHeaders, hds...)
1541 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1542 opts = append((*c.CallOptions).RestoreDatabase[0:len((*c.CallOptions).RestoreDatabase):len((*c.CallOptions).RestoreDatabase)], opts...)
1543 var resp *longrunningpb.Operation
1544 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1545 var err error
1546 resp, err = executeRPC(ctx, c.firestoreAdminClient.RestoreDatabase, req, settings.GRPC, c.logger, "RestoreDatabase")
1547 return err
1548 }, opts...)
1549 if err != nil {
1550 return nil, err
1551 }
1552 return &RestoreDatabaseOperation{
1553 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1554 }, nil
1555 }
1556
1557 func (c *firestoreAdminGRPCClient) CreateBackupSchedule(ctx context.Context, req *adminpb.CreateBackupScheduleRequest, opts ...gax.CallOption) (*adminpb.BackupSchedule, error) {
1558 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1559
1560 hds = append(c.xGoogHeaders, hds...)
1561 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1562 opts = append((*c.CallOptions).CreateBackupSchedule[0:len((*c.CallOptions).CreateBackupSchedule):len((*c.CallOptions).CreateBackupSchedule)], opts...)
1563 var resp *adminpb.BackupSchedule
1564 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1565 var err error
1566 resp, err = executeRPC(ctx, c.firestoreAdminClient.CreateBackupSchedule, req, settings.GRPC, c.logger, "CreateBackupSchedule")
1567 return err
1568 }, opts...)
1569 if err != nil {
1570 return nil, err
1571 }
1572 return resp, nil
1573 }
1574
1575 func (c *firestoreAdminGRPCClient) GetBackupSchedule(ctx context.Context, req *adminpb.GetBackupScheduleRequest, opts ...gax.CallOption) (*adminpb.BackupSchedule, error) {
1576 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1577
1578 hds = append(c.xGoogHeaders, hds...)
1579 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1580 opts = append((*c.CallOptions).GetBackupSchedule[0:len((*c.CallOptions).GetBackupSchedule):len((*c.CallOptions).GetBackupSchedule)], opts...)
1581 var resp *adminpb.BackupSchedule
1582 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1583 var err error
1584 resp, err = executeRPC(ctx, c.firestoreAdminClient.GetBackupSchedule, req, settings.GRPC, c.logger, "GetBackupSchedule")
1585 return err
1586 }, opts...)
1587 if err != nil {
1588 return nil, err
1589 }
1590 return resp, nil
1591 }
1592
1593 func (c *firestoreAdminGRPCClient) ListBackupSchedules(ctx context.Context, req *adminpb.ListBackupSchedulesRequest, opts ...gax.CallOption) (*adminpb.ListBackupSchedulesResponse, error) {
1594 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1595
1596 hds = append(c.xGoogHeaders, hds...)
1597 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1598 opts = append((*c.CallOptions).ListBackupSchedules[0:len((*c.CallOptions).ListBackupSchedules):len((*c.CallOptions).ListBackupSchedules)], opts...)
1599 var resp *adminpb.ListBackupSchedulesResponse
1600 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1601 var err error
1602 resp, err = executeRPC(ctx, c.firestoreAdminClient.ListBackupSchedules, req, settings.GRPC, c.logger, "ListBackupSchedules")
1603 return err
1604 }, opts...)
1605 if err != nil {
1606 return nil, err
1607 }
1608 return resp, nil
1609 }
1610
1611 func (c *firestoreAdminGRPCClient) UpdateBackupSchedule(ctx context.Context, req *adminpb.UpdateBackupScheduleRequest, opts ...gax.CallOption) (*adminpb.BackupSchedule, error) {
1612 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "backup_schedule.name", url.QueryEscape(req.GetBackupSchedule().GetName()))}
1613
1614 hds = append(c.xGoogHeaders, hds...)
1615 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1616 opts = append((*c.CallOptions).UpdateBackupSchedule[0:len((*c.CallOptions).UpdateBackupSchedule):len((*c.CallOptions).UpdateBackupSchedule)], opts...)
1617 var resp *adminpb.BackupSchedule
1618 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1619 var err error
1620 resp, err = executeRPC(ctx, c.firestoreAdminClient.UpdateBackupSchedule, req, settings.GRPC, c.logger, "UpdateBackupSchedule")
1621 return err
1622 }, opts...)
1623 if err != nil {
1624 return nil, err
1625 }
1626 return resp, nil
1627 }
1628
1629 func (c *firestoreAdminGRPCClient) DeleteBackupSchedule(ctx context.Context, req *adminpb.DeleteBackupScheduleRequest, opts ...gax.CallOption) error {
1630 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1631
1632 hds = append(c.xGoogHeaders, hds...)
1633 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1634 opts = append((*c.CallOptions).DeleteBackupSchedule[0:len((*c.CallOptions).DeleteBackupSchedule):len((*c.CallOptions).DeleteBackupSchedule)], opts...)
1635 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1636 var err error
1637 _, err = executeRPC(ctx, c.firestoreAdminClient.DeleteBackupSchedule, req, settings.GRPC, c.logger, "DeleteBackupSchedule")
1638 return err
1639 }, opts...)
1640 return err
1641 }
1642
1643 func (c *firestoreAdminGRPCClient) CloneDatabase(ctx context.Context, req *adminpb.CloneDatabaseRequest, opts ...gax.CallOption) (*CloneDatabaseOperation, error) {
1644 routingHeaders := ""
1645 routingHeadersMap := make(map[string]string)
1646 if reg := regexp.MustCompile("projects/(?P<project_id>[^/]+)(?:/.*)?"); reg.MatchString(req.GetPitrSnapshot().GetDatabase()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetPitrSnapshot().GetDatabase())[1])) > 0 {
1647 routingHeadersMap["project_id"] = url.QueryEscape(reg.FindStringSubmatch(req.GetPitrSnapshot().GetDatabase())[1])
1648 }
1649 if reg := regexp.MustCompile("projects/[^/]+/databases/(?P<database_id>[^/]+)(?:/.*)?"); reg.MatchString(req.GetPitrSnapshot().GetDatabase()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetPitrSnapshot().GetDatabase())[1])) > 0 {
1650 routingHeadersMap["database_id"] = url.QueryEscape(reg.FindStringSubmatch(req.GetPitrSnapshot().GetDatabase())[1])
1651 }
1652 for headerName, headerValue := range routingHeadersMap {
1653 routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
1654 }
1655 routingHeaders = strings.TrimSuffix(routingHeaders, "&")
1656 hds := []string{"x-goog-request-params", routingHeaders}
1657
1658 hds = append(c.xGoogHeaders, hds...)
1659 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1660 opts = append((*c.CallOptions).CloneDatabase[0:len((*c.CallOptions).CloneDatabase):len((*c.CallOptions).CloneDatabase)], opts...)
1661 var resp *longrunningpb.Operation
1662 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1663 var err error
1664 resp, err = executeRPC(ctx, c.firestoreAdminClient.CloneDatabase, req, settings.GRPC, c.logger, "CloneDatabase")
1665 return err
1666 }, opts...)
1667 if err != nil {
1668 return nil, err
1669 }
1670 return &CloneDatabaseOperation{
1671 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1672 }, nil
1673 }
1674
1675 func (c *firestoreAdminGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
1676 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1677
1678 hds = append(c.xGoogHeaders, hds...)
1679 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1680 opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...)
1681 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1682 var err error
1683 _, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation")
1684 return err
1685 }, opts...)
1686 return err
1687 }
1688
1689 func (c *firestoreAdminGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
1690 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1691
1692 hds = append(c.xGoogHeaders, hds...)
1693 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1694 opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...)
1695 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1696 var err error
1697 _, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation")
1698 return err
1699 }, opts...)
1700 return err
1701 }
1702
1703 func (c *firestoreAdminGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
1704 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1705
1706 hds = append(c.xGoogHeaders, hds...)
1707 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1708 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
1709 var resp *longrunningpb.Operation
1710 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1711 var err error
1712 resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation")
1713 return err
1714 }, opts...)
1715 if err != nil {
1716 return nil, err
1717 }
1718 return resp, nil
1719 }
1720
1721 func (c *firestoreAdminGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
1722 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1723
1724 hds = append(c.xGoogHeaders, hds...)
1725 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1726 opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...)
1727 it := &OperationIterator{}
1728 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
1729 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
1730 resp := &longrunningpb.ListOperationsResponse{}
1731 if pageToken != "" {
1732 req.PageToken = pageToken
1733 }
1734 if pageSize > math.MaxInt32 {
1735 req.PageSize = math.MaxInt32
1736 } else if pageSize != 0 {
1737 req.PageSize = int32(pageSize)
1738 }
1739 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1740 var err error
1741 resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations")
1742 return err
1743 }, opts...)
1744 if err != nil {
1745 return nil, "", err
1746 }
1747
1748 it.Response = resp
1749 return resp.GetOperations(), resp.GetNextPageToken(), nil
1750 }
1751 fetch := func(pageSize int, pageToken string) (string, error) {
1752 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1753 if err != nil {
1754 return "", err
1755 }
1756 it.items = append(it.items, items...)
1757 return nextPageToken, nil
1758 }
1759
1760 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1761 it.pageInfo.MaxSize = int(req.GetPageSize())
1762 it.pageInfo.Token = req.GetPageToken()
1763
1764 return it
1765 }
1766
1767 // CreateIndex creates a composite index. This returns a
1768 // google.longrunning.Operation which may be
1769 // used to track the status of the creation. The metadata for the operation
1770 // will be the type
1771 // IndexOperationMetadata.
1772 func (c *firestoreAdminRESTClient) CreateIndex(ctx context.Context, req *adminpb.CreateIndexRequest, opts ...gax.CallOption) (*CreateIndexOperation, error) {
1773 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1774 body := req.GetIndex()
1775 jsonReq, err := m.Marshal(body)
1776 if err != nil {
1777 return nil, err
1778 }
1779
1780 baseUrl, err := url.Parse(c.endpoint)
1781 if err != nil {
1782 return nil, err
1783 }
1784 baseUrl.Path += fmt.Sprintf("/v1/%v/indexes", req.GetParent())
1785
1786 params := url.Values{}
1787 params.Add("$alt", "json;enum-encoding=int")
1788
1789 baseUrl.RawQuery = params.Encode()
1790
1791 // Build HTTP headers from client and context metadata.
1792 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1793
1794 hds = append(c.xGoogHeaders, hds...)
1795 hds = append(hds, "Content-Type", "application/json")
1796 headers := gax.BuildHeaders(ctx, hds...)
1797 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1798 resp := &longrunningpb.Operation{}
1799 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1800 if settings.Path != "" {
1801 baseUrl.Path = settings.Path
1802 }
1803 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1804 if err != nil {
1805 return err
1806 }
1807 httpReq = httpReq.WithContext(ctx)
1808 httpReq.Header = headers
1809
1810 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateIndex")
1811 if err != nil {
1812 return err
1813 }
1814 if err := unm.Unmarshal(buf, resp); err != nil {
1815 return err
1816 }
1817
1818 return nil
1819 }, opts...)
1820 if e != nil {
1821 return nil, e
1822 }
1823
1824 override := fmt.Sprintf("/v1/%s", resp.GetName())
1825 return &CreateIndexOperation{
1826 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1827 pollPath: override,
1828 }, nil
1829 }
1830
1831 // ListIndexes lists composite indexes.
1832 func (c *firestoreAdminRESTClient) ListIndexes(ctx context.Context, req *adminpb.ListIndexesRequest, opts ...gax.CallOption) *IndexIterator {
1833 it := &IndexIterator{}
1834 req = proto.Clone(req).(*adminpb.ListIndexesRequest)
1835 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1836 it.InternalFetch = func(pageSize int, pageToken string) ([]*adminpb.Index, string, error) {
1837 resp := &adminpb.ListIndexesResponse{}
1838 if pageToken != "" {
1839 req.PageToken = pageToken
1840 }
1841 if pageSize > math.MaxInt32 {
1842 req.PageSize = math.MaxInt32
1843 } else if pageSize != 0 {
1844 req.PageSize = int32(pageSize)
1845 }
1846 baseUrl, err := url.Parse(c.endpoint)
1847 if err != nil {
1848 return nil, "", err
1849 }
1850 baseUrl.Path += fmt.Sprintf("/v1/%v/indexes", req.GetParent())
1851
1852 params := url.Values{}
1853 params.Add("$alt", "json;enum-encoding=int")
1854 if req.GetFilter() != "" {
1855 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
1856 }
1857 if req.GetPageSize() != 0 {
1858 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1859 }
1860 if req.GetPageToken() != "" {
1861 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1862 }
1863
1864 baseUrl.RawQuery = params.Encode()
1865
1866 // Build HTTP headers from client and context metadata.
1867 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1868 headers := gax.BuildHeaders(ctx, hds...)
1869 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1870 if settings.Path != "" {
1871 baseUrl.Path = settings.Path
1872 }
1873 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1874 if err != nil {
1875 return err
1876 }
1877 httpReq.Header = headers
1878
1879 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListIndexes")
1880 if err != nil {
1881 return err
1882 }
1883 if err := unm.Unmarshal(buf, resp); err != nil {
1884 return err
1885 }
1886
1887 return nil
1888 }, opts...)
1889 if e != nil {
1890 return nil, "", e
1891 }
1892 it.Response = resp
1893 return resp.GetIndexes(), resp.GetNextPageToken(), nil
1894 }
1895
1896 fetch := func(pageSize int, pageToken string) (string, error) {
1897 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1898 if err != nil {
1899 return "", err
1900 }
1901 it.items = append(it.items, items...)
1902 return nextPageToken, nil
1903 }
1904
1905 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1906 it.pageInfo.MaxSize = int(req.GetPageSize())
1907 it.pageInfo.Token = req.GetPageToken()
1908
1909 return it
1910 }
1911
1912 // GetIndex gets a composite index.
1913 func (c *firestoreAdminRESTClient) GetIndex(ctx context.Context, req *adminpb.GetIndexRequest, opts ...gax.CallOption) (*adminpb.Index, error) {
1914 baseUrl, err := url.Parse(c.endpoint)
1915 if err != nil {
1916 return nil, err
1917 }
1918 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
1919
1920 params := url.Values{}
1921 params.Add("$alt", "json;enum-encoding=int")
1922
1923 baseUrl.RawQuery = params.Encode()
1924
1925 // Build HTTP headers from client and context metadata.
1926 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1927
1928 hds = append(c.xGoogHeaders, hds...)
1929 hds = append(hds, "Content-Type", "application/json")
1930 headers := gax.BuildHeaders(ctx, hds...)
1931 opts = append((*c.CallOptions).GetIndex[0:len((*c.CallOptions).GetIndex):len((*c.CallOptions).GetIndex)], opts...)
1932 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1933 resp := &adminpb.Index{}
1934 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1935 if settings.Path != "" {
1936 baseUrl.Path = settings.Path
1937 }
1938 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1939 if err != nil {
1940 return err
1941 }
1942 httpReq = httpReq.WithContext(ctx)
1943 httpReq.Header = headers
1944
1945 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetIndex")
1946 if err != nil {
1947 return err
1948 }
1949
1950 if err := unm.Unmarshal(buf, resp); err != nil {
1951 return err
1952 }
1953
1954 return nil
1955 }, opts...)
1956 if e != nil {
1957 return nil, e
1958 }
1959 return resp, nil
1960 }
1961
1962 // DeleteIndex deletes a composite index.
1963 func (c *firestoreAdminRESTClient) DeleteIndex(ctx context.Context, req *adminpb.DeleteIndexRequest, opts ...gax.CallOption) error {
1964 baseUrl, err := url.Parse(c.endpoint)
1965 if err != nil {
1966 return err
1967 }
1968 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
1969
1970 params := url.Values{}
1971 params.Add("$alt", "json;enum-encoding=int")
1972
1973 baseUrl.RawQuery = params.Encode()
1974
1975 // Build HTTP headers from client and context metadata.
1976 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1977
1978 hds = append(c.xGoogHeaders, hds...)
1979 hds = append(hds, "Content-Type", "application/json")
1980 headers := gax.BuildHeaders(ctx, hds...)
1981 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1982 if settings.Path != "" {
1983 baseUrl.Path = settings.Path
1984 }
1985 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
1986 if err != nil {
1987 return err
1988 }
1989 httpReq = httpReq.WithContext(ctx)
1990 httpReq.Header = headers
1991
1992 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteIndex")
1993 return err
1994 }, opts...)
1995 }
1996
1997 // GetField gets the metadata and configuration for a Field.
1998 func (c *firestoreAdminRESTClient) GetField(ctx context.Context, req *adminpb.GetFieldRequest, opts ...gax.CallOption) (*adminpb.Field, error) {
1999 baseUrl, err := url.Parse(c.endpoint)
2000 if err != nil {
2001 return nil, err
2002 }
2003 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
2004
2005 params := url.Values{}
2006 params.Add("$alt", "json;enum-encoding=int")
2007
2008 baseUrl.RawQuery = params.Encode()
2009
2010 // Build HTTP headers from client and context metadata.
2011 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2012
2013 hds = append(c.xGoogHeaders, hds...)
2014 hds = append(hds, "Content-Type", "application/json")
2015 headers := gax.BuildHeaders(ctx, hds...)
2016 opts = append((*c.CallOptions).GetField[0:len((*c.CallOptions).GetField):len((*c.CallOptions).GetField)], opts...)
2017 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2018 resp := &adminpb.Field{}
2019 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2020 if settings.Path != "" {
2021 baseUrl.Path = settings.Path
2022 }
2023 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2024 if err != nil {
2025 return err
2026 }
2027 httpReq = httpReq.WithContext(ctx)
2028 httpReq.Header = headers
2029
2030 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetField")
2031 if err != nil {
2032 return err
2033 }
2034
2035 if err := unm.Unmarshal(buf, resp); err != nil {
2036 return err
2037 }
2038
2039 return nil
2040 }, opts...)
2041 if e != nil {
2042 return nil, e
2043 }
2044 return resp, nil
2045 }
2046
2047 // UpdateField updates a field configuration. Currently, field updates apply only to
2048 // single field index configuration. However, calls to
2049 // FirestoreAdmin.UpdateField
2050 // should provide a field mask to avoid changing any configuration that the
2051 // caller isn’t aware of. The field mask should be specified as: { paths: "index_config" }.
2052 //
2053 // This call returns a
2054 // google.longrunning.Operation which may be
2055 // used to track the status of the field update. The metadata for the
2056 // operation will be the type
2057 // FieldOperationMetadata.
2058 //
2059 // To configure the default field settings for the database, use
2060 // the special Field with resource name:
2061 // projects/{project_id}/databases/{database_id}/collectionGroups/__default__/fields/*.
2062 func (c *firestoreAdminRESTClient) UpdateField(ctx context.Context, req *adminpb.UpdateFieldRequest, opts ...gax.CallOption) (*UpdateFieldOperation, error) {
2063 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2064 body := req.GetField()
2065 jsonReq, err := m.Marshal(body)
2066 if err != nil {
2067 return nil, err
2068 }
2069
2070 baseUrl, err := url.Parse(c.endpoint)
2071 if err != nil {
2072 return nil, err
2073 }
2074 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetField().GetName())
2075
2076 params := url.Values{}
2077 params.Add("$alt", "json;enum-encoding=int")
2078 if req.GetUpdateMask() != nil {
2079 field, err := protojson.Marshal(req.GetUpdateMask())
2080 if err != nil {
2081 return nil, err
2082 }
2083 params.Add("updateMask", string(field[1:len(field)-1]))
2084 }
2085
2086 baseUrl.RawQuery = params.Encode()
2087
2088 // Build HTTP headers from client and context metadata.
2089 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "field.name", url.QueryEscape(req.GetField().GetName()))}
2090
2091 hds = append(c.xGoogHeaders, hds...)
2092 hds = append(hds, "Content-Type", "application/json")
2093 headers := gax.BuildHeaders(ctx, hds...)
2094 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2095 resp := &longrunningpb.Operation{}
2096 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2097 if settings.Path != "" {
2098 baseUrl.Path = settings.Path
2099 }
2100 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
2101 if err != nil {
2102 return err
2103 }
2104 httpReq = httpReq.WithContext(ctx)
2105 httpReq.Header = headers
2106
2107 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateField")
2108 if err != nil {
2109 return err
2110 }
2111 if err := unm.Unmarshal(buf, resp); err != nil {
2112 return err
2113 }
2114
2115 return nil
2116 }, opts...)
2117 if e != nil {
2118 return nil, e
2119 }
2120
2121 override := fmt.Sprintf("/v1/%s", resp.GetName())
2122 return &UpdateFieldOperation{
2123 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
2124 pollPath: override,
2125 }, nil
2126 }
2127
2128 // ListFields lists the field configuration and metadata for this database.
2129 //
2130 // Currently,
2131 // FirestoreAdmin.ListFields
2132 // only supports listing fields that have been explicitly overridden. To issue
2133 // this query, call
2134 // FirestoreAdmin.ListFields
2135 // with the filter set to indexConfig.usesAncestorConfig:false or
2136 // ttlConfig:*.
2137 func (c *firestoreAdminRESTClient) ListFields(ctx context.Context, req *adminpb.ListFieldsRequest, opts ...gax.CallOption) *FieldIterator {
2138 it := &FieldIterator{}
2139 req = proto.Clone(req).(*adminpb.ListFieldsRequest)
2140 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2141 it.InternalFetch = func(pageSize int, pageToken string) ([]*adminpb.Field, string, error) {
2142 resp := &adminpb.ListFieldsResponse{}
2143 if pageToken != "" {
2144 req.PageToken = pageToken
2145 }
2146 if pageSize > math.MaxInt32 {
2147 req.PageSize = math.MaxInt32
2148 } else if pageSize != 0 {
2149 req.PageSize = int32(pageSize)
2150 }
2151 baseUrl, err := url.Parse(c.endpoint)
2152 if err != nil {
2153 return nil, "", err
2154 }
2155 baseUrl.Path += fmt.Sprintf("/v1/%v/fields", req.GetParent())
2156
2157 params := url.Values{}
2158 params.Add("$alt", "json;enum-encoding=int")
2159 if req.GetFilter() != "" {
2160 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
2161 }
2162 if req.GetPageSize() != 0 {
2163 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
2164 }
2165 if req.GetPageToken() != "" {
2166 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
2167 }
2168
2169 baseUrl.RawQuery = params.Encode()
2170
2171 // Build HTTP headers from client and context metadata.
2172 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
2173 headers := gax.BuildHeaders(ctx, hds...)
2174 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2175 if settings.Path != "" {
2176 baseUrl.Path = settings.Path
2177 }
2178 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2179 if err != nil {
2180 return err
2181 }
2182 httpReq.Header = headers
2183
2184 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListFields")
2185 if err != nil {
2186 return err
2187 }
2188 if err := unm.Unmarshal(buf, resp); err != nil {
2189 return err
2190 }
2191
2192 return nil
2193 }, opts...)
2194 if e != nil {
2195 return nil, "", e
2196 }
2197 it.Response = resp
2198 return resp.GetFields(), resp.GetNextPageToken(), nil
2199 }
2200
2201 fetch := func(pageSize int, pageToken string) (string, error) {
2202 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
2203 if err != nil {
2204 return "", err
2205 }
2206 it.items = append(it.items, items...)
2207 return nextPageToken, nil
2208 }
2209
2210 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
2211 it.pageInfo.MaxSize = int(req.GetPageSize())
2212 it.pageInfo.Token = req.GetPageToken()
2213
2214 return it
2215 }
2216
2217 // ExportDocuments exports a copy of all or a subset of documents from Google Cloud Firestore
2218 // to another storage system, such as Google Cloud Storage. Recent updates to
2219 // documents may not be reflected in the export. The export occurs in the
2220 // background and its progress can be monitored and managed via the
2221 // Operation resource that is created. The output of an export may only be
2222 // used once the associated operation is done. If an export operation is
2223 // cancelled before completion it may leave partial data behind in Google
2224 // Cloud Storage.
2225 //
2226 // For more details on export behavior and output format, refer to:
2227 // https://cloud.google.com/firestore/docs/manage-data/export-import (at https://cloud.google.com/firestore/docs/manage-data/export-import)
2228 func (c *firestoreAdminRESTClient) ExportDocuments(ctx context.Context, req *adminpb.ExportDocumentsRequest, opts ...gax.CallOption) (*ExportDocumentsOperation, error) {
2229 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2230 jsonReq, err := m.Marshal(req)
2231 if err != nil {
2232 return nil, err
2233 }
2234
2235 baseUrl, err := url.Parse(c.endpoint)
2236 if err != nil {
2237 return nil, err
2238 }
2239 baseUrl.Path += fmt.Sprintf("/v1/%v:exportDocuments", req.GetName())
2240
2241 params := url.Values{}
2242 params.Add("$alt", "json;enum-encoding=int")
2243
2244 baseUrl.RawQuery = params.Encode()
2245
2246 // Build HTTP headers from client and context metadata.
2247 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2248
2249 hds = append(c.xGoogHeaders, hds...)
2250 hds = append(hds, "Content-Type", "application/json")
2251 headers := gax.BuildHeaders(ctx, hds...)
2252 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2253 resp := &longrunningpb.Operation{}
2254 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2255 if settings.Path != "" {
2256 baseUrl.Path = settings.Path
2257 }
2258 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2259 if err != nil {
2260 return err
2261 }
2262 httpReq = httpReq.WithContext(ctx)
2263 httpReq.Header = headers
2264
2265 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ExportDocuments")
2266 if err != nil {
2267 return err
2268 }
2269 if err := unm.Unmarshal(buf, resp); err != nil {
2270 return err
2271 }
2272
2273 return nil
2274 }, opts...)
2275 if e != nil {
2276 return nil, e
2277 }
2278
2279 override := fmt.Sprintf("/v1/%s", resp.GetName())
2280 return &ExportDocumentsOperation{
2281 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
2282 pollPath: override,
2283 }, nil
2284 }
2285
2286 // ImportDocuments imports documents into Google Cloud Firestore. Existing documents with the
2287 // same name are overwritten. The import occurs in the background and its
2288 // progress can be monitored and managed via the Operation resource that is
2289 // created. If an ImportDocuments operation is cancelled, it is possible
2290 // that a subset of the data has already been imported to Cloud Firestore.
2291 func (c *firestoreAdminRESTClient) ImportDocuments(ctx context.Context, req *adminpb.ImportDocumentsRequest, opts ...gax.CallOption) (*ImportDocumentsOperation, error) {
2292 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2293 jsonReq, err := m.Marshal(req)
2294 if err != nil {
2295 return nil, err
2296 }
2297
2298 baseUrl, err := url.Parse(c.endpoint)
2299 if err != nil {
2300 return nil, err
2301 }
2302 baseUrl.Path += fmt.Sprintf("/v1/%v:importDocuments", req.GetName())
2303
2304 params := url.Values{}
2305 params.Add("$alt", "json;enum-encoding=int")
2306
2307 baseUrl.RawQuery = params.Encode()
2308
2309 // Build HTTP headers from client and context metadata.
2310 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2311
2312 hds = append(c.xGoogHeaders, hds...)
2313 hds = append(hds, "Content-Type", "application/json")
2314 headers := gax.BuildHeaders(ctx, hds...)
2315 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2316 resp := &longrunningpb.Operation{}
2317 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2318 if settings.Path != "" {
2319 baseUrl.Path = settings.Path
2320 }
2321 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2322 if err != nil {
2323 return err
2324 }
2325 httpReq = httpReq.WithContext(ctx)
2326 httpReq.Header = headers
2327
2328 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ImportDocuments")
2329 if err != nil {
2330 return err
2331 }
2332 if err := unm.Unmarshal(buf, resp); err != nil {
2333 return err
2334 }
2335
2336 return nil
2337 }, opts...)
2338 if e != nil {
2339 return nil, e
2340 }
2341
2342 override := fmt.Sprintf("/v1/%s", resp.GetName())
2343 return &ImportDocumentsOperation{
2344 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
2345 pollPath: override,
2346 }, nil
2347 }
2348
2349 // BulkDeleteDocuments bulk deletes a subset of documents from Google Cloud Firestore.
2350 // Documents created or updated after the underlying system starts to process
2351 // the request will not be deleted. The bulk delete occurs in the background
2352 // and its progress can be monitored and managed via the Operation resource
2353 // that is created.
2354 //
2355 // For more details on bulk delete behavior, refer to:
2356 // https://cloud.google.com/firestore/docs/manage-data/bulk-delete (at https://cloud.google.com/firestore/docs/manage-data/bulk-delete)
2357 func (c *firestoreAdminRESTClient) BulkDeleteDocuments(ctx context.Context, req *adminpb.BulkDeleteDocumentsRequest, opts ...gax.CallOption) (*BulkDeleteDocumentsOperation, error) {
2358 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2359 jsonReq, err := m.Marshal(req)
2360 if err != nil {
2361 return nil, err
2362 }
2363
2364 baseUrl, err := url.Parse(c.endpoint)
2365 if err != nil {
2366 return nil, err
2367 }
2368 baseUrl.Path += fmt.Sprintf("/v1/%v:bulkDeleteDocuments", req.GetName())
2369
2370 params := url.Values{}
2371 params.Add("$alt", "json;enum-encoding=int")
2372
2373 baseUrl.RawQuery = params.Encode()
2374
2375 // Build HTTP headers from client and context metadata.
2376 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2377
2378 hds = append(c.xGoogHeaders, hds...)
2379 hds = append(hds, "Content-Type", "application/json")
2380 headers := gax.BuildHeaders(ctx, hds...)
2381 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2382 resp := &longrunningpb.Operation{}
2383 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2384 if settings.Path != "" {
2385 baseUrl.Path = settings.Path
2386 }
2387 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2388 if err != nil {
2389 return err
2390 }
2391 httpReq = httpReq.WithContext(ctx)
2392 httpReq.Header = headers
2393
2394 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "BulkDeleteDocuments")
2395 if err != nil {
2396 return err
2397 }
2398 if err := unm.Unmarshal(buf, resp); err != nil {
2399 return err
2400 }
2401
2402 return nil
2403 }, opts...)
2404 if e != nil {
2405 return nil, e
2406 }
2407
2408 override := fmt.Sprintf("/v1/%s", resp.GetName())
2409 return &BulkDeleteDocumentsOperation{
2410 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
2411 pollPath: override,
2412 }, nil
2413 }
2414
2415 // CreateDatabase create a database.
2416 func (c *firestoreAdminRESTClient) CreateDatabase(ctx context.Context, req *adminpb.CreateDatabaseRequest, opts ...gax.CallOption) (*CreateDatabaseOperation, error) {
2417 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2418 body := req.GetDatabase()
2419 jsonReq, err := m.Marshal(body)
2420 if err != nil {
2421 return nil, err
2422 }
2423
2424 baseUrl, err := url.Parse(c.endpoint)
2425 if err != nil {
2426 return nil, err
2427 }
2428 baseUrl.Path += fmt.Sprintf("/v1/%v/databases", req.GetParent())
2429
2430 params := url.Values{}
2431 params.Add("$alt", "json;enum-encoding=int")
2432 params.Add("databaseId", fmt.Sprintf("%v", req.GetDatabaseId()))
2433
2434 baseUrl.RawQuery = params.Encode()
2435
2436 // Build HTTP headers from client and context metadata.
2437 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
2438
2439 hds = append(c.xGoogHeaders, hds...)
2440 hds = append(hds, "Content-Type", "application/json")
2441 headers := gax.BuildHeaders(ctx, hds...)
2442 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2443 resp := &longrunningpb.Operation{}
2444 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2445 if settings.Path != "" {
2446 baseUrl.Path = settings.Path
2447 }
2448 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2449 if err != nil {
2450 return err
2451 }
2452 httpReq = httpReq.WithContext(ctx)
2453 httpReq.Header = headers
2454
2455 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateDatabase")
2456 if err != nil {
2457 return err
2458 }
2459 if err := unm.Unmarshal(buf, resp); err != nil {
2460 return err
2461 }
2462
2463 return nil
2464 }, opts...)
2465 if e != nil {
2466 return nil, e
2467 }
2468
2469 override := fmt.Sprintf("/v1/%s", resp.GetName())
2470 return &CreateDatabaseOperation{
2471 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
2472 pollPath: override,
2473 }, nil
2474 }
2475
2476 // GetDatabase gets information about a database.
2477 func (c *firestoreAdminRESTClient) GetDatabase(ctx context.Context, req *adminpb.GetDatabaseRequest, opts ...gax.CallOption) (*adminpb.Database, error) {
2478 baseUrl, err := url.Parse(c.endpoint)
2479 if err != nil {
2480 return nil, err
2481 }
2482 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
2483
2484 params := url.Values{}
2485 params.Add("$alt", "json;enum-encoding=int")
2486
2487 baseUrl.RawQuery = params.Encode()
2488
2489 // Build HTTP headers from client and context metadata.
2490 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2491
2492 hds = append(c.xGoogHeaders, hds...)
2493 hds = append(hds, "Content-Type", "application/json")
2494 headers := gax.BuildHeaders(ctx, hds...)
2495 opts = append((*c.CallOptions).GetDatabase[0:len((*c.CallOptions).GetDatabase):len((*c.CallOptions).GetDatabase)], opts...)
2496 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2497 resp := &adminpb.Database{}
2498 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2499 if settings.Path != "" {
2500 baseUrl.Path = settings.Path
2501 }
2502 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2503 if err != nil {
2504 return err
2505 }
2506 httpReq = httpReq.WithContext(ctx)
2507 httpReq.Header = headers
2508
2509 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetDatabase")
2510 if err != nil {
2511 return err
2512 }
2513
2514 if err := unm.Unmarshal(buf, resp); err != nil {
2515 return err
2516 }
2517
2518 return nil
2519 }, opts...)
2520 if e != nil {
2521 return nil, e
2522 }
2523 return resp, nil
2524 }
2525
2526 // ListDatabases list all the databases in the project.
2527 func (c *firestoreAdminRESTClient) ListDatabases(ctx context.Context, req *adminpb.ListDatabasesRequest, opts ...gax.CallOption) (*adminpb.ListDatabasesResponse, error) {
2528 baseUrl, err := url.Parse(c.endpoint)
2529 if err != nil {
2530 return nil, err
2531 }
2532 baseUrl.Path += fmt.Sprintf("/v1/%v/databases", req.GetParent())
2533
2534 params := url.Values{}
2535 params.Add("$alt", "json;enum-encoding=int")
2536 if req.GetShowDeleted() {
2537 params.Add("showDeleted", fmt.Sprintf("%v", req.GetShowDeleted()))
2538 }
2539
2540 baseUrl.RawQuery = params.Encode()
2541
2542 // Build HTTP headers from client and context metadata.
2543 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
2544
2545 hds = append(c.xGoogHeaders, hds...)
2546 hds = append(hds, "Content-Type", "application/json")
2547 headers := gax.BuildHeaders(ctx, hds...)
2548 opts = append((*c.CallOptions).ListDatabases[0:len((*c.CallOptions).ListDatabases):len((*c.CallOptions).ListDatabases)], opts...)
2549 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2550 resp := &adminpb.ListDatabasesResponse{}
2551 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2552 if settings.Path != "" {
2553 baseUrl.Path = settings.Path
2554 }
2555 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2556 if err != nil {
2557 return err
2558 }
2559 httpReq = httpReq.WithContext(ctx)
2560 httpReq.Header = headers
2561
2562 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListDatabases")
2563 if err != nil {
2564 return err
2565 }
2566
2567 if err := unm.Unmarshal(buf, resp); err != nil {
2568 return err
2569 }
2570
2571 return nil
2572 }, opts...)
2573 if e != nil {
2574 return nil, e
2575 }
2576 return resp, nil
2577 }
2578
2579 // UpdateDatabase updates a database.
2580 func (c *firestoreAdminRESTClient) UpdateDatabase(ctx context.Context, req *adminpb.UpdateDatabaseRequest, opts ...gax.CallOption) (*UpdateDatabaseOperation, error) {
2581 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2582 body := req.GetDatabase()
2583 jsonReq, err := m.Marshal(body)
2584 if err != nil {
2585 return nil, err
2586 }
2587
2588 baseUrl, err := url.Parse(c.endpoint)
2589 if err != nil {
2590 return nil, err
2591 }
2592 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetDatabase().GetName())
2593
2594 params := url.Values{}
2595 params.Add("$alt", "json;enum-encoding=int")
2596 if req.GetUpdateMask() != nil {
2597 field, err := protojson.Marshal(req.GetUpdateMask())
2598 if err != nil {
2599 return nil, err
2600 }
2601 params.Add("updateMask", string(field[1:len(field)-1]))
2602 }
2603
2604 baseUrl.RawQuery = params.Encode()
2605
2606 // Build HTTP headers from client and context metadata.
2607 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "database.name", url.QueryEscape(req.GetDatabase().GetName()))}
2608
2609 hds = append(c.xGoogHeaders, hds...)
2610 hds = append(hds, "Content-Type", "application/json")
2611 headers := gax.BuildHeaders(ctx, hds...)
2612 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2613 resp := &longrunningpb.Operation{}
2614 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2615 if settings.Path != "" {
2616 baseUrl.Path = settings.Path
2617 }
2618 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
2619 if err != nil {
2620 return err
2621 }
2622 httpReq = httpReq.WithContext(ctx)
2623 httpReq.Header = headers
2624
2625 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateDatabase")
2626 if err != nil {
2627 return err
2628 }
2629 if err := unm.Unmarshal(buf, resp); err != nil {
2630 return err
2631 }
2632
2633 return nil
2634 }, opts...)
2635 if e != nil {
2636 return nil, e
2637 }
2638
2639 override := fmt.Sprintf("/v1/%s", resp.GetName())
2640 return &UpdateDatabaseOperation{
2641 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
2642 pollPath: override,
2643 }, nil
2644 }
2645
2646 // DeleteDatabase deletes a database.
2647 func (c *firestoreAdminRESTClient) DeleteDatabase(ctx context.Context, req *adminpb.DeleteDatabaseRequest, opts ...gax.CallOption) (*DeleteDatabaseOperation, error) {
2648 baseUrl, err := url.Parse(c.endpoint)
2649 if err != nil {
2650 return nil, err
2651 }
2652 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
2653
2654 params := url.Values{}
2655 params.Add("$alt", "json;enum-encoding=int")
2656 if req.GetEtag() != "" {
2657 params.Add("etag", fmt.Sprintf("%v", req.GetEtag()))
2658 }
2659
2660 baseUrl.RawQuery = params.Encode()
2661
2662 // Build HTTP headers from client and context metadata.
2663 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2664
2665 hds = append(c.xGoogHeaders, hds...)
2666 hds = append(hds, "Content-Type", "application/json")
2667 headers := gax.BuildHeaders(ctx, hds...)
2668 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2669 resp := &longrunningpb.Operation{}
2670 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2671 if settings.Path != "" {
2672 baseUrl.Path = settings.Path
2673 }
2674 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
2675 if err != nil {
2676 return err
2677 }
2678 httpReq = httpReq.WithContext(ctx)
2679 httpReq.Header = headers
2680
2681 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteDatabase")
2682 if err != nil {
2683 return err
2684 }
2685 if err := unm.Unmarshal(buf, resp); err != nil {
2686 return err
2687 }
2688
2689 return nil
2690 }, opts...)
2691 if e != nil {
2692 return nil, e
2693 }
2694
2695 override := fmt.Sprintf("/v1/%s", resp.GetName())
2696 return &DeleteDatabaseOperation{
2697 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
2698 pollPath: override,
2699 }, nil
2700 }
2701
2702 // CreateUserCreds create a user creds.
2703 func (c *firestoreAdminRESTClient) CreateUserCreds(ctx context.Context, req *adminpb.CreateUserCredsRequest, opts ...gax.CallOption) (*adminpb.UserCreds, error) {
2704 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2705 body := req.GetUserCreds()
2706 jsonReq, err := m.Marshal(body)
2707 if err != nil {
2708 return nil, err
2709 }
2710
2711 baseUrl, err := url.Parse(c.endpoint)
2712 if err != nil {
2713 return nil, err
2714 }
2715 baseUrl.Path += fmt.Sprintf("/v1/%v/userCreds", req.GetParent())
2716
2717 params := url.Values{}
2718 params.Add("$alt", "json;enum-encoding=int")
2719 params.Add("userCredsId", fmt.Sprintf("%v", req.GetUserCredsId()))
2720
2721 baseUrl.RawQuery = params.Encode()
2722
2723 // Build HTTP headers from client and context metadata.
2724 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
2725
2726 hds = append(c.xGoogHeaders, hds...)
2727 hds = append(hds, "Content-Type", "application/json")
2728 headers := gax.BuildHeaders(ctx, hds...)
2729 opts = append((*c.CallOptions).CreateUserCreds[0:len((*c.CallOptions).CreateUserCreds):len((*c.CallOptions).CreateUserCreds)], opts...)
2730 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2731 resp := &adminpb.UserCreds{}
2732 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2733 if settings.Path != "" {
2734 baseUrl.Path = settings.Path
2735 }
2736 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2737 if err != nil {
2738 return err
2739 }
2740 httpReq = httpReq.WithContext(ctx)
2741 httpReq.Header = headers
2742
2743 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateUserCreds")
2744 if err != nil {
2745 return err
2746 }
2747
2748 if err := unm.Unmarshal(buf, resp); err != nil {
2749 return err
2750 }
2751
2752 return nil
2753 }, opts...)
2754 if e != nil {
2755 return nil, e
2756 }
2757 return resp, nil
2758 }
2759
2760 // GetUserCreds gets a user creds resource. Note that the returned resource does not
2761 // contain the secret value itself.
2762 func (c *firestoreAdminRESTClient) GetUserCreds(ctx context.Context, req *adminpb.GetUserCredsRequest, opts ...gax.CallOption) (*adminpb.UserCreds, error) {
2763 baseUrl, err := url.Parse(c.endpoint)
2764 if err != nil {
2765 return nil, err
2766 }
2767 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
2768
2769 params := url.Values{}
2770 params.Add("$alt", "json;enum-encoding=int")
2771
2772 baseUrl.RawQuery = params.Encode()
2773
2774 // Build HTTP headers from client and context metadata.
2775 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2776
2777 hds = append(c.xGoogHeaders, hds...)
2778 hds = append(hds, "Content-Type", "application/json")
2779 headers := gax.BuildHeaders(ctx, hds...)
2780 opts = append((*c.CallOptions).GetUserCreds[0:len((*c.CallOptions).GetUserCreds):len((*c.CallOptions).GetUserCreds)], opts...)
2781 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2782 resp := &adminpb.UserCreds{}
2783 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2784 if settings.Path != "" {
2785 baseUrl.Path = settings.Path
2786 }
2787 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2788 if err != nil {
2789 return err
2790 }
2791 httpReq = httpReq.WithContext(ctx)
2792 httpReq.Header = headers
2793
2794 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetUserCreds")
2795 if err != nil {
2796 return err
2797 }
2798
2799 if err := unm.Unmarshal(buf, resp); err != nil {
2800 return err
2801 }
2802
2803 return nil
2804 }, opts...)
2805 if e != nil {
2806 return nil, e
2807 }
2808 return resp, nil
2809 }
2810
2811 // ListUserCreds list all user creds in the database. Note that the returned resource
2812 // does not contain the secret value itself.
2813 func (c *firestoreAdminRESTClient) ListUserCreds(ctx context.Context, req *adminpb.ListUserCredsRequest, opts ...gax.CallOption) (*adminpb.ListUserCredsResponse, error) {
2814 baseUrl, err := url.Parse(c.endpoint)
2815 if err != nil {
2816 return nil, err
2817 }
2818 baseUrl.Path += fmt.Sprintf("/v1/%v/userCreds", req.GetParent())
2819
2820 params := url.Values{}
2821 params.Add("$alt", "json;enum-encoding=int")
2822
2823 baseUrl.RawQuery = params.Encode()
2824
2825 // Build HTTP headers from client and context metadata.
2826 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
2827
2828 hds = append(c.xGoogHeaders, hds...)
2829 hds = append(hds, "Content-Type", "application/json")
2830 headers := gax.BuildHeaders(ctx, hds...)
2831 opts = append((*c.CallOptions).ListUserCreds[0:len((*c.CallOptions).ListUserCreds):len((*c.CallOptions).ListUserCreds)], opts...)
2832 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2833 resp := &adminpb.ListUserCredsResponse{}
2834 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2835 if settings.Path != "" {
2836 baseUrl.Path = settings.Path
2837 }
2838 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2839 if err != nil {
2840 return err
2841 }
2842 httpReq = httpReq.WithContext(ctx)
2843 httpReq.Header = headers
2844
2845 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListUserCreds")
2846 if err != nil {
2847 return err
2848 }
2849
2850 if err := unm.Unmarshal(buf, resp); err != nil {
2851 return err
2852 }
2853
2854 return nil
2855 }, opts...)
2856 if e != nil {
2857 return nil, e
2858 }
2859 return resp, nil
2860 }
2861
2862 // EnableUserCreds enables a user creds. No-op if the user creds are already enabled.
2863 func (c *firestoreAdminRESTClient) EnableUserCreds(ctx context.Context, req *adminpb.EnableUserCredsRequest, opts ...gax.CallOption) (*adminpb.UserCreds, error) {
2864 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2865 jsonReq, err := m.Marshal(req)
2866 if err != nil {
2867 return nil, err
2868 }
2869
2870 baseUrl, err := url.Parse(c.endpoint)
2871 if err != nil {
2872 return nil, err
2873 }
2874 baseUrl.Path += fmt.Sprintf("/v1/%v:enable", req.GetName())
2875
2876 params := url.Values{}
2877 params.Add("$alt", "json;enum-encoding=int")
2878
2879 baseUrl.RawQuery = params.Encode()
2880
2881 // Build HTTP headers from client and context metadata.
2882 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2883
2884 hds = append(c.xGoogHeaders, hds...)
2885 hds = append(hds, "Content-Type", "application/json")
2886 headers := gax.BuildHeaders(ctx, hds...)
2887 opts = append((*c.CallOptions).EnableUserCreds[0:len((*c.CallOptions).EnableUserCreds):len((*c.CallOptions).EnableUserCreds)], opts...)
2888 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2889 resp := &adminpb.UserCreds{}
2890 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2891 if settings.Path != "" {
2892 baseUrl.Path = settings.Path
2893 }
2894 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2895 if err != nil {
2896 return err
2897 }
2898 httpReq = httpReq.WithContext(ctx)
2899 httpReq.Header = headers
2900
2901 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "EnableUserCreds")
2902 if err != nil {
2903 return err
2904 }
2905
2906 if err := unm.Unmarshal(buf, resp); err != nil {
2907 return err
2908 }
2909
2910 return nil
2911 }, opts...)
2912 if e != nil {
2913 return nil, e
2914 }
2915 return resp, nil
2916 }
2917
2918 // DisableUserCreds disables a user creds. No-op if the user creds are already disabled.
2919 func (c *firestoreAdminRESTClient) DisableUserCreds(ctx context.Context, req *adminpb.DisableUserCredsRequest, opts ...gax.CallOption) (*adminpb.UserCreds, error) {
2920 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2921 jsonReq, err := m.Marshal(req)
2922 if err != nil {
2923 return nil, err
2924 }
2925
2926 baseUrl, err := url.Parse(c.endpoint)
2927 if err != nil {
2928 return nil, err
2929 }
2930 baseUrl.Path += fmt.Sprintf("/v1/%v:disable", req.GetName())
2931
2932 params := url.Values{}
2933 params.Add("$alt", "json;enum-encoding=int")
2934
2935 baseUrl.RawQuery = params.Encode()
2936
2937 // Build HTTP headers from client and context metadata.
2938 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2939
2940 hds = append(c.xGoogHeaders, hds...)
2941 hds = append(hds, "Content-Type", "application/json")
2942 headers := gax.BuildHeaders(ctx, hds...)
2943 opts = append((*c.CallOptions).DisableUserCreds[0:len((*c.CallOptions).DisableUserCreds):len((*c.CallOptions).DisableUserCreds)], opts...)
2944 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2945 resp := &adminpb.UserCreds{}
2946 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2947 if settings.Path != "" {
2948 baseUrl.Path = settings.Path
2949 }
2950 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2951 if err != nil {
2952 return err
2953 }
2954 httpReq = httpReq.WithContext(ctx)
2955 httpReq.Header = headers
2956
2957 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "DisableUserCreds")
2958 if err != nil {
2959 return err
2960 }
2961
2962 if err := unm.Unmarshal(buf, resp); err != nil {
2963 return err
2964 }
2965
2966 return nil
2967 }, opts...)
2968 if e != nil {
2969 return nil, e
2970 }
2971 return resp, nil
2972 }
2973
2974 // ResetUserPassword resets the password of a user creds.
2975 func (c *firestoreAdminRESTClient) ResetUserPassword(ctx context.Context, req *adminpb.ResetUserPasswordRequest, opts ...gax.CallOption) (*adminpb.UserCreds, error) {
2976 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2977 jsonReq, err := m.Marshal(req)
2978 if err != nil {
2979 return nil, err
2980 }
2981
2982 baseUrl, err := url.Parse(c.endpoint)
2983 if err != nil {
2984 return nil, err
2985 }
2986 baseUrl.Path += fmt.Sprintf("/v1/%v:resetPassword", req.GetName())
2987
2988 params := url.Values{}
2989 params.Add("$alt", "json;enum-encoding=int")
2990
2991 baseUrl.RawQuery = params.Encode()
2992
2993 // Build HTTP headers from client and context metadata.
2994 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2995
2996 hds = append(c.xGoogHeaders, hds...)
2997 hds = append(hds, "Content-Type", "application/json")
2998 headers := gax.BuildHeaders(ctx, hds...)
2999 opts = append((*c.CallOptions).ResetUserPassword[0:len((*c.CallOptions).ResetUserPassword):len((*c.CallOptions).ResetUserPassword)], opts...)
3000 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
3001 resp := &adminpb.UserCreds{}
3002 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3003 if settings.Path != "" {
3004 baseUrl.Path = settings.Path
3005 }
3006 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
3007 if err != nil {
3008 return err
3009 }
3010 httpReq = httpReq.WithContext(ctx)
3011 httpReq.Header = headers
3012
3013 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ResetUserPassword")
3014 if err != nil {
3015 return err
3016 }
3017
3018 if err := unm.Unmarshal(buf, resp); err != nil {
3019 return err
3020 }
3021
3022 return nil
3023 }, opts...)
3024 if e != nil {
3025 return nil, e
3026 }
3027 return resp, nil
3028 }
3029
3030 // DeleteUserCreds deletes a user creds.
3031 func (c *firestoreAdminRESTClient) DeleteUserCreds(ctx context.Context, req *adminpb.DeleteUserCredsRequest, opts ...gax.CallOption) error {
3032 baseUrl, err := url.Parse(c.endpoint)
3033 if err != nil {
3034 return err
3035 }
3036 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
3037
3038 params := url.Values{}
3039 params.Add("$alt", "json;enum-encoding=int")
3040
3041 baseUrl.RawQuery = params.Encode()
3042
3043 // Build HTTP headers from client and context metadata.
3044 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
3045
3046 hds = append(c.xGoogHeaders, hds...)
3047 hds = append(hds, "Content-Type", "application/json")
3048 headers := gax.BuildHeaders(ctx, hds...)
3049 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3050 if settings.Path != "" {
3051 baseUrl.Path = settings.Path
3052 }
3053 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
3054 if err != nil {
3055 return err
3056 }
3057 httpReq = httpReq.WithContext(ctx)
3058 httpReq.Header = headers
3059
3060 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteUserCreds")
3061 return err
3062 }, opts...)
3063 }
3064
3065 // GetBackup gets information about a backup.
3066 func (c *firestoreAdminRESTClient) GetBackup(ctx context.Context, req *adminpb.GetBackupRequest, opts ...gax.CallOption) (*adminpb.Backup, error) {
3067 baseUrl, err := url.Parse(c.endpoint)
3068 if err != nil {
3069 return nil, err
3070 }
3071 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
3072
3073 params := url.Values{}
3074 params.Add("$alt", "json;enum-encoding=int")
3075
3076 baseUrl.RawQuery = params.Encode()
3077
3078 // Build HTTP headers from client and context metadata.
3079 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
3080
3081 hds = append(c.xGoogHeaders, hds...)
3082 hds = append(hds, "Content-Type", "application/json")
3083 headers := gax.BuildHeaders(ctx, hds...)
3084 opts = append((*c.CallOptions).GetBackup[0:len((*c.CallOptions).GetBackup):len((*c.CallOptions).GetBackup)], opts...)
3085 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
3086 resp := &adminpb.Backup{}
3087 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3088 if settings.Path != "" {
3089 baseUrl.Path = settings.Path
3090 }
3091 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
3092 if err != nil {
3093 return err
3094 }
3095 httpReq = httpReq.WithContext(ctx)
3096 httpReq.Header = headers
3097
3098 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetBackup")
3099 if err != nil {
3100 return err
3101 }
3102
3103 if err := unm.Unmarshal(buf, resp); err != nil {
3104 return err
3105 }
3106
3107 return nil
3108 }, opts...)
3109 if e != nil {
3110 return nil, e
3111 }
3112 return resp, nil
3113 }
3114
3115 // ListBackups lists all the backups.
3116 func (c *firestoreAdminRESTClient) ListBackups(ctx context.Context, req *adminpb.ListBackupsRequest, opts ...gax.CallOption) (*adminpb.ListBackupsResponse, error) {
3117 baseUrl, err := url.Parse(c.endpoint)
3118 if err != nil {
3119 return nil, err
3120 }
3121 baseUrl.Path += fmt.Sprintf("/v1/%v/backups", req.GetParent())
3122
3123 params := url.Values{}
3124 params.Add("$alt", "json;enum-encoding=int")
3125 if req.GetFilter() != "" {
3126 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
3127 }
3128
3129 baseUrl.RawQuery = params.Encode()
3130
3131 // Build HTTP headers from client and context metadata.
3132 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
3133
3134 hds = append(c.xGoogHeaders, hds...)
3135 hds = append(hds, "Content-Type", "application/json")
3136 headers := gax.BuildHeaders(ctx, hds...)
3137 opts = append((*c.CallOptions).ListBackups[0:len((*c.CallOptions).ListBackups):len((*c.CallOptions).ListBackups)], opts...)
3138 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
3139 resp := &adminpb.ListBackupsResponse{}
3140 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3141 if settings.Path != "" {
3142 baseUrl.Path = settings.Path
3143 }
3144 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
3145 if err != nil {
3146 return err
3147 }
3148 httpReq = httpReq.WithContext(ctx)
3149 httpReq.Header = headers
3150
3151 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListBackups")
3152 if err != nil {
3153 return err
3154 }
3155
3156 if err := unm.Unmarshal(buf, resp); err != nil {
3157 return err
3158 }
3159
3160 return nil
3161 }, opts...)
3162 if e != nil {
3163 return nil, e
3164 }
3165 return resp, nil
3166 }
3167
3168 // DeleteBackup deletes a backup.
3169 func (c *firestoreAdminRESTClient) DeleteBackup(ctx context.Context, req *adminpb.DeleteBackupRequest, opts ...gax.CallOption) error {
3170 baseUrl, err := url.Parse(c.endpoint)
3171 if err != nil {
3172 return err
3173 }
3174 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
3175
3176 params := url.Values{}
3177 params.Add("$alt", "json;enum-encoding=int")
3178
3179 baseUrl.RawQuery = params.Encode()
3180
3181 // Build HTTP headers from client and context metadata.
3182 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
3183
3184 hds = append(c.xGoogHeaders, hds...)
3185 hds = append(hds, "Content-Type", "application/json")
3186 headers := gax.BuildHeaders(ctx, hds...)
3187 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3188 if settings.Path != "" {
3189 baseUrl.Path = settings.Path
3190 }
3191 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
3192 if err != nil {
3193 return err
3194 }
3195 httpReq = httpReq.WithContext(ctx)
3196 httpReq.Header = headers
3197
3198 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteBackup")
3199 return err
3200 }, opts...)
3201 }
3202
3203 // RestoreDatabase creates a new database by restoring from an existing backup.
3204 //
3205 // The new database must be in the same cloud region or multi-region location
3206 // as the existing backup. This behaves similar to
3207 // FirestoreAdmin.CreateDatabase
3208 // except instead of creating a new empty database, a new database is created
3209 // with the database type, index configuration, and documents from an existing
3210 // backup.
3211 //
3212 // The [long-running operation][google.longrunning.Operation] can be used to
3213 // track the progress of the restore, with the Operation’s
3214 // metadata field type being the
3215 // RestoreDatabaseMetadata.
3216 // The response type is the
3217 // Database if the restore was
3218 // successful. The new database is not readable or writeable until the LRO has
3219 // completed.
3220 func (c *firestoreAdminRESTClient) RestoreDatabase(ctx context.Context, req *adminpb.RestoreDatabaseRequest, opts ...gax.CallOption) (*RestoreDatabaseOperation, error) {
3221 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
3222 jsonReq, err := m.Marshal(req)
3223 if err != nil {
3224 return nil, err
3225 }
3226
3227 baseUrl, err := url.Parse(c.endpoint)
3228 if err != nil {
3229 return nil, err
3230 }
3231 baseUrl.Path += fmt.Sprintf("/v1/%v/databases:restore", req.GetParent())
3232
3233 params := url.Values{}
3234 params.Add("$alt", "json;enum-encoding=int")
3235
3236 baseUrl.RawQuery = params.Encode()
3237
3238 // Build HTTP headers from client and context metadata.
3239 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
3240
3241 hds = append(c.xGoogHeaders, hds...)
3242 hds = append(hds, "Content-Type", "application/json")
3243 headers := gax.BuildHeaders(ctx, hds...)
3244 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
3245 resp := &longrunningpb.Operation{}
3246 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3247 if settings.Path != "" {
3248 baseUrl.Path = settings.Path
3249 }
3250 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
3251 if err != nil {
3252 return err
3253 }
3254 httpReq = httpReq.WithContext(ctx)
3255 httpReq.Header = headers
3256
3257 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "RestoreDatabase")
3258 if err != nil {
3259 return err
3260 }
3261 if err := unm.Unmarshal(buf, resp); err != nil {
3262 return err
3263 }
3264
3265 return nil
3266 }, opts...)
3267 if e != nil {
3268 return nil, e
3269 }
3270
3271 override := fmt.Sprintf("/v1/%s", resp.GetName())
3272 return &RestoreDatabaseOperation{
3273 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
3274 pollPath: override,
3275 }, nil
3276 }
3277
3278 // CreateBackupSchedule creates a backup schedule on a database.
3279 // At most two backup schedules can be configured on a database, one daily
3280 // backup schedule and one weekly backup schedule.
3281 func (c *firestoreAdminRESTClient) CreateBackupSchedule(ctx context.Context, req *adminpb.CreateBackupScheduleRequest, opts ...gax.CallOption) (*adminpb.BackupSchedule, error) {
3282 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
3283 body := req.GetBackupSchedule()
3284 jsonReq, err := m.Marshal(body)
3285 if err != nil {
3286 return nil, err
3287 }
3288
3289 baseUrl, err := url.Parse(c.endpoint)
3290 if err != nil {
3291 return nil, err
3292 }
3293 baseUrl.Path += fmt.Sprintf("/v1/%v/backupSchedules", req.GetParent())
3294
3295 params := url.Values{}
3296 params.Add("$alt", "json;enum-encoding=int")
3297
3298 baseUrl.RawQuery = params.Encode()
3299
3300 // Build HTTP headers from client and context metadata.
3301 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
3302
3303 hds = append(c.xGoogHeaders, hds...)
3304 hds = append(hds, "Content-Type", "application/json")
3305 headers := gax.BuildHeaders(ctx, hds...)
3306 opts = append((*c.CallOptions).CreateBackupSchedule[0:len((*c.CallOptions).CreateBackupSchedule):len((*c.CallOptions).CreateBackupSchedule)], opts...)
3307 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
3308 resp := &adminpb.BackupSchedule{}
3309 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3310 if settings.Path != "" {
3311 baseUrl.Path = settings.Path
3312 }
3313 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
3314 if err != nil {
3315 return err
3316 }
3317 httpReq = httpReq.WithContext(ctx)
3318 httpReq.Header = headers
3319
3320 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateBackupSchedule")
3321 if err != nil {
3322 return err
3323 }
3324
3325 if err := unm.Unmarshal(buf, resp); err != nil {
3326 return err
3327 }
3328
3329 return nil
3330 }, opts...)
3331 if e != nil {
3332 return nil, e
3333 }
3334 return resp, nil
3335 }
3336
3337 // GetBackupSchedule gets information about a backup schedule.
3338 func (c *firestoreAdminRESTClient) GetBackupSchedule(ctx context.Context, req *adminpb.GetBackupScheduleRequest, opts ...gax.CallOption) (*adminpb.BackupSchedule, error) {
3339 baseUrl, err := url.Parse(c.endpoint)
3340 if err != nil {
3341 return nil, err
3342 }
3343 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
3344
3345 params := url.Values{}
3346 params.Add("$alt", "json;enum-encoding=int")
3347
3348 baseUrl.RawQuery = params.Encode()
3349
3350 // Build HTTP headers from client and context metadata.
3351 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
3352
3353 hds = append(c.xGoogHeaders, hds...)
3354 hds = append(hds, "Content-Type", "application/json")
3355 headers := gax.BuildHeaders(ctx, hds...)
3356 opts = append((*c.CallOptions).GetBackupSchedule[0:len((*c.CallOptions).GetBackupSchedule):len((*c.CallOptions).GetBackupSchedule)], opts...)
3357 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
3358 resp := &adminpb.BackupSchedule{}
3359 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3360 if settings.Path != "" {
3361 baseUrl.Path = settings.Path
3362 }
3363 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
3364 if err != nil {
3365 return err
3366 }
3367 httpReq = httpReq.WithContext(ctx)
3368 httpReq.Header = headers
3369
3370 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetBackupSchedule")
3371 if err != nil {
3372 return err
3373 }
3374
3375 if err := unm.Unmarshal(buf, resp); err != nil {
3376 return err
3377 }
3378
3379 return nil
3380 }, opts...)
3381 if e != nil {
3382 return nil, e
3383 }
3384 return resp, nil
3385 }
3386
3387 // ListBackupSchedules list backup schedules.
3388 func (c *firestoreAdminRESTClient) ListBackupSchedules(ctx context.Context, req *adminpb.ListBackupSchedulesRequest, opts ...gax.CallOption) (*adminpb.ListBackupSchedulesResponse, error) {
3389 baseUrl, err := url.Parse(c.endpoint)
3390 if err != nil {
3391 return nil, err
3392 }
3393 baseUrl.Path += fmt.Sprintf("/v1/%v/backupSchedules", req.GetParent())
3394
3395 params := url.Values{}
3396 params.Add("$alt", "json;enum-encoding=int")
3397
3398 baseUrl.RawQuery = params.Encode()
3399
3400 // Build HTTP headers from client and context metadata.
3401 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
3402
3403 hds = append(c.xGoogHeaders, hds...)
3404 hds = append(hds, "Content-Type", "application/json")
3405 headers := gax.BuildHeaders(ctx, hds...)
3406 opts = append((*c.CallOptions).ListBackupSchedules[0:len((*c.CallOptions).ListBackupSchedules):len((*c.CallOptions).ListBackupSchedules)], opts...)
3407 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
3408 resp := &adminpb.ListBackupSchedulesResponse{}
3409 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3410 if settings.Path != "" {
3411 baseUrl.Path = settings.Path
3412 }
3413 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
3414 if err != nil {
3415 return err
3416 }
3417 httpReq = httpReq.WithContext(ctx)
3418 httpReq.Header = headers
3419
3420 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListBackupSchedules")
3421 if err != nil {
3422 return err
3423 }
3424
3425 if err := unm.Unmarshal(buf, resp); err != nil {
3426 return err
3427 }
3428
3429 return nil
3430 }, opts...)
3431 if e != nil {
3432 return nil, e
3433 }
3434 return resp, nil
3435 }
3436
3437 // UpdateBackupSchedule updates a backup schedule.
3438 func (c *firestoreAdminRESTClient) UpdateBackupSchedule(ctx context.Context, req *adminpb.UpdateBackupScheduleRequest, opts ...gax.CallOption) (*adminpb.BackupSchedule, error) {
3439 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
3440 body := req.GetBackupSchedule()
3441 jsonReq, err := m.Marshal(body)
3442 if err != nil {
3443 return nil, err
3444 }
3445
3446 baseUrl, err := url.Parse(c.endpoint)
3447 if err != nil {
3448 return nil, err
3449 }
3450 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetBackupSchedule().GetName())
3451
3452 params := url.Values{}
3453 params.Add("$alt", "json;enum-encoding=int")
3454 if req.GetUpdateMask() != nil {
3455 field, err := protojson.Marshal(req.GetUpdateMask())
3456 if err != nil {
3457 return nil, err
3458 }
3459 params.Add("updateMask", string(field[1:len(field)-1]))
3460 }
3461
3462 baseUrl.RawQuery = params.Encode()
3463
3464 // Build HTTP headers from client and context metadata.
3465 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "backup_schedule.name", url.QueryEscape(req.GetBackupSchedule().GetName()))}
3466
3467 hds = append(c.xGoogHeaders, hds...)
3468 hds = append(hds, "Content-Type", "application/json")
3469 headers := gax.BuildHeaders(ctx, hds...)
3470 opts = append((*c.CallOptions).UpdateBackupSchedule[0:len((*c.CallOptions).UpdateBackupSchedule):len((*c.CallOptions).UpdateBackupSchedule)], opts...)
3471 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
3472 resp := &adminpb.BackupSchedule{}
3473 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3474 if settings.Path != "" {
3475 baseUrl.Path = settings.Path
3476 }
3477 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
3478 if err != nil {
3479 return err
3480 }
3481 httpReq = httpReq.WithContext(ctx)
3482 httpReq.Header = headers
3483
3484 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateBackupSchedule")
3485 if err != nil {
3486 return err
3487 }
3488
3489 if err := unm.Unmarshal(buf, resp); err != nil {
3490 return err
3491 }
3492
3493 return nil
3494 }, opts...)
3495 if e != nil {
3496 return nil, e
3497 }
3498 return resp, nil
3499 }
3500
3501 // DeleteBackupSchedule deletes a backup schedule.
3502 func (c *firestoreAdminRESTClient) DeleteBackupSchedule(ctx context.Context, req *adminpb.DeleteBackupScheduleRequest, opts ...gax.CallOption) error {
3503 baseUrl, err := url.Parse(c.endpoint)
3504 if err != nil {
3505 return err
3506 }
3507 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
3508
3509 params := url.Values{}
3510 params.Add("$alt", "json;enum-encoding=int")
3511
3512 baseUrl.RawQuery = params.Encode()
3513
3514 // Build HTTP headers from client and context metadata.
3515 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
3516
3517 hds = append(c.xGoogHeaders, hds...)
3518 hds = append(hds, "Content-Type", "application/json")
3519 headers := gax.BuildHeaders(ctx, hds...)
3520 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3521 if settings.Path != "" {
3522 baseUrl.Path = settings.Path
3523 }
3524 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
3525 if err != nil {
3526 return err
3527 }
3528 httpReq = httpReq.WithContext(ctx)
3529 httpReq.Header = headers
3530
3531 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteBackupSchedule")
3532 return err
3533 }, opts...)
3534 }
3535
3536 // CloneDatabase creates a new database by cloning an existing one.
3537 //
3538 // The new database must be in the same cloud region or multi-region location
3539 // as the existing database. This behaves similar to
3540 // FirestoreAdmin.CreateDatabase
3541 // except instead of creating a new empty database, a new database is created
3542 // with the database type, index configuration, and documents from an existing
3543 // database.
3544 //
3545 // The [long-running operation][google.longrunning.Operation] can be used to
3546 // track the progress of the clone, with the Operation’s
3547 // metadata field type being the
3548 // CloneDatabaseMetadata.
3549 // The response type is the
3550 // Database if the clone was
3551 // successful. The new database is not readable or writeable until the LRO has
3552 // completed.
3553 func (c *firestoreAdminRESTClient) CloneDatabase(ctx context.Context, req *adminpb.CloneDatabaseRequest, opts ...gax.CallOption) (*CloneDatabaseOperation, error) {
3554 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
3555 jsonReq, err := m.Marshal(req)
3556 if err != nil {
3557 return nil, err
3558 }
3559
3560 baseUrl, err := url.Parse(c.endpoint)
3561 if err != nil {
3562 return nil, err
3563 }
3564 baseUrl.Path += fmt.Sprintf("/v1/%v/databases:clone", req.GetParent())
3565
3566 params := url.Values{}
3567 params.Add("$alt", "json;enum-encoding=int")
3568
3569 baseUrl.RawQuery = params.Encode()
3570
3571 // Build HTTP headers from client and context metadata.
3572 routingHeaders := ""
3573 routingHeadersMap := make(map[string]string)
3574 if reg := regexp.MustCompile("projects/(?P<project_id>[^/]+)(?:/.*)?"); reg.MatchString(req.GetPitrSnapshot().GetDatabase()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetPitrSnapshot().GetDatabase())[1])) > 0 {
3575 routingHeadersMap["project_id"] = url.QueryEscape(reg.FindStringSubmatch(req.GetPitrSnapshot().GetDatabase())[1])
3576 }
3577 if reg := regexp.MustCompile("projects/[^/]+/databases/(?P<database_id>[^/]+)(?:/.*)?"); reg.MatchString(req.GetPitrSnapshot().GetDatabase()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetPitrSnapshot().GetDatabase())[1])) > 0 {
3578 routingHeadersMap["database_id"] = url.QueryEscape(reg.FindStringSubmatch(req.GetPitrSnapshot().GetDatabase())[1])
3579 }
3580 for headerName, headerValue := range routingHeadersMap {
3581 routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
3582 }
3583 routingHeaders = strings.TrimSuffix(routingHeaders, "&")
3584 hds := []string{"x-goog-request-params", routingHeaders}
3585
3586 hds = append(c.xGoogHeaders, hds...)
3587 hds = append(hds, "Content-Type", "application/json")
3588 headers := gax.BuildHeaders(ctx, hds...)
3589 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
3590 resp := &longrunningpb.Operation{}
3591 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3592 if settings.Path != "" {
3593 baseUrl.Path = settings.Path
3594 }
3595 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
3596 if err != nil {
3597 return err
3598 }
3599 httpReq = httpReq.WithContext(ctx)
3600 httpReq.Header = headers
3601
3602 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CloneDatabase")
3603 if err != nil {
3604 return err
3605 }
3606 if err := unm.Unmarshal(buf, resp); err != nil {
3607 return err
3608 }
3609
3610 return nil
3611 }, opts...)
3612 if e != nil {
3613 return nil, e
3614 }
3615
3616 override := fmt.Sprintf("/v1/%s", resp.GetName())
3617 return &CloneDatabaseOperation{
3618 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
3619 pollPath: override,
3620 }, nil
3621 }
3622
3623 // CancelOperation is a utility method from google.longrunning.Operations.
3624 func (c *firestoreAdminRESTClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
3625 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
3626 jsonReq, err := m.Marshal(req)
3627 if err != nil {
3628 return err
3629 }
3630
3631 baseUrl, err := url.Parse(c.endpoint)
3632 if err != nil {
3633 return err
3634 }
3635 baseUrl.Path += fmt.Sprintf("/v1/%v:cancel", req.GetName())
3636
3637 params := url.Values{}
3638 params.Add("$alt", "json;enum-encoding=int")
3639
3640 baseUrl.RawQuery = params.Encode()
3641
3642 // Build HTTP headers from client and context metadata.
3643 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
3644
3645 hds = append(c.xGoogHeaders, hds...)
3646 hds = append(hds, "Content-Type", "application/json")
3647 headers := gax.BuildHeaders(ctx, hds...)
3648 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3649 if settings.Path != "" {
3650 baseUrl.Path = settings.Path
3651 }
3652 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
3653 if err != nil {
3654 return err
3655 }
3656 httpReq = httpReq.WithContext(ctx)
3657 httpReq.Header = headers
3658
3659 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CancelOperation")
3660 return err
3661 }, opts...)
3662 }
3663
3664 // DeleteOperation is a utility method from google.longrunning.Operations.
3665 func (c *firestoreAdminRESTClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
3666 baseUrl, err := url.Parse(c.endpoint)
3667 if err != nil {
3668 return err
3669 }
3670 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
3671
3672 params := url.Values{}
3673 params.Add("$alt", "json;enum-encoding=int")
3674
3675 baseUrl.RawQuery = params.Encode()
3676
3677 // Build HTTP headers from client and context metadata.
3678 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
3679
3680 hds = append(c.xGoogHeaders, hds...)
3681 hds = append(hds, "Content-Type", "application/json")
3682 headers := gax.BuildHeaders(ctx, hds...)
3683 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3684 if settings.Path != "" {
3685 baseUrl.Path = settings.Path
3686 }
3687 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
3688 if err != nil {
3689 return err
3690 }
3691 httpReq = httpReq.WithContext(ctx)
3692 httpReq.Header = headers
3693
3694 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteOperation")
3695 return err
3696 }, opts...)
3697 }
3698
3699 // GetOperation is a utility method from google.longrunning.Operations.
3700 func (c *firestoreAdminRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
3701 baseUrl, err := url.Parse(c.endpoint)
3702 if err != nil {
3703 return nil, err
3704 }
3705 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
3706
3707 params := url.Values{}
3708 params.Add("$alt", "json;enum-encoding=int")
3709
3710 baseUrl.RawQuery = params.Encode()
3711
3712 // Build HTTP headers from client and context metadata.
3713 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
3714
3715 hds = append(c.xGoogHeaders, hds...)
3716 hds = append(hds, "Content-Type", "application/json")
3717 headers := gax.BuildHeaders(ctx, hds...)
3718 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
3719 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
3720 resp := &longrunningpb.Operation{}
3721 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3722 if settings.Path != "" {
3723 baseUrl.Path = settings.Path
3724 }
3725 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
3726 if err != nil {
3727 return err
3728 }
3729 httpReq = httpReq.WithContext(ctx)
3730 httpReq.Header = headers
3731
3732 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation")
3733 if err != nil {
3734 return err
3735 }
3736
3737 if err := unm.Unmarshal(buf, resp); err != nil {
3738 return err
3739 }
3740
3741 return nil
3742 }, opts...)
3743 if e != nil {
3744 return nil, e
3745 }
3746 return resp, nil
3747 }
3748
3749 // ListOperations is a utility method from google.longrunning.Operations.
3750 func (c *firestoreAdminRESTClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
3751 it := &OperationIterator{}
3752 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
3753 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
3754 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
3755 resp := &longrunningpb.ListOperationsResponse{}
3756 if pageToken != "" {
3757 req.PageToken = pageToken
3758 }
3759 if pageSize > math.MaxInt32 {
3760 req.PageSize = math.MaxInt32
3761 } else if pageSize != 0 {
3762 req.PageSize = int32(pageSize)
3763 }
3764 baseUrl, err := url.Parse(c.endpoint)
3765 if err != nil {
3766 return nil, "", err
3767 }
3768 baseUrl.Path += fmt.Sprintf("/v1/%v/operations", req.GetName())
3769
3770 params := url.Values{}
3771 params.Add("$alt", "json;enum-encoding=int")
3772 if req.GetFilter() != "" {
3773 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
3774 }
3775 if req.GetPageSize() != 0 {
3776 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
3777 }
3778 if req.GetPageToken() != "" {
3779 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
3780 }
3781
3782 baseUrl.RawQuery = params.Encode()
3783
3784 // Build HTTP headers from client and context metadata.
3785 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
3786 headers := gax.BuildHeaders(ctx, hds...)
3787 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
3788 if settings.Path != "" {
3789 baseUrl.Path = settings.Path
3790 }
3791 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
3792 if err != nil {
3793 return err
3794 }
3795 httpReq.Header = headers
3796
3797 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations")
3798 if err != nil {
3799 return err
3800 }
3801 if err := unm.Unmarshal(buf, resp); err != nil {
3802 return err
3803 }
3804
3805 return nil
3806 }, opts...)
3807 if e != nil {
3808 return nil, "", e
3809 }
3810 it.Response = resp
3811 return resp.GetOperations(), resp.GetNextPageToken(), nil
3812 }
3813
3814 fetch := func(pageSize int, pageToken string) (string, error) {
3815 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
3816 if err != nil {
3817 return "", err
3818 }
3819 it.items = append(it.items, items...)
3820 return nextPageToken, nil
3821 }
3822
3823 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
3824 it.pageInfo.MaxSize = int(req.GetPageSize())
3825 it.pageInfo.Token = req.GetPageToken()
3826
3827 return it
3828 }
3829
3830 // BulkDeleteDocumentsOperation returns a new BulkDeleteDocumentsOperation from a given name.
3831 // The name must be that of a previously created BulkDeleteDocumentsOperation, possibly from a different process.
3832 func (c *firestoreAdminGRPCClient) BulkDeleteDocumentsOperation(name string) *BulkDeleteDocumentsOperation {
3833 return &BulkDeleteDocumentsOperation{
3834 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
3835 }
3836 }
3837
3838 // BulkDeleteDocumentsOperation returns a new BulkDeleteDocumentsOperation from a given name.
3839 // The name must be that of a previously created BulkDeleteDocumentsOperation, possibly from a different process.
3840 func (c *firestoreAdminRESTClient) BulkDeleteDocumentsOperation(name string) *BulkDeleteDocumentsOperation {
3841 override := fmt.Sprintf("/v1/%s", name)
3842 return &BulkDeleteDocumentsOperation{
3843 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
3844 pollPath: override,
3845 }
3846 }
3847
3848 // CloneDatabaseOperation returns a new CloneDatabaseOperation from a given name.
3849 // The name must be that of a previously created CloneDatabaseOperation, possibly from a different process.
3850 func (c *firestoreAdminGRPCClient) CloneDatabaseOperation(name string) *CloneDatabaseOperation {
3851 return &CloneDatabaseOperation{
3852 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
3853 }
3854 }
3855
3856 // CloneDatabaseOperation returns a new CloneDatabaseOperation from a given name.
3857 // The name must be that of a previously created CloneDatabaseOperation, possibly from a different process.
3858 func (c *firestoreAdminRESTClient) CloneDatabaseOperation(name string) *CloneDatabaseOperation {
3859 override := fmt.Sprintf("/v1/%s", name)
3860 return &CloneDatabaseOperation{
3861 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
3862 pollPath: override,
3863 }
3864 }
3865
3866 // CreateDatabaseOperation returns a new CreateDatabaseOperation from a given name.
3867 // The name must be that of a previously created CreateDatabaseOperation, possibly from a different process.
3868 func (c *firestoreAdminGRPCClient) CreateDatabaseOperation(name string) *CreateDatabaseOperation {
3869 return &CreateDatabaseOperation{
3870 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
3871 }
3872 }
3873
3874 // CreateDatabaseOperation returns a new CreateDatabaseOperation from a given name.
3875 // The name must be that of a previously created CreateDatabaseOperation, possibly from a different process.
3876 func (c *firestoreAdminRESTClient) CreateDatabaseOperation(name string) *CreateDatabaseOperation {
3877 override := fmt.Sprintf("/v1/%s", name)
3878 return &CreateDatabaseOperation{
3879 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
3880 pollPath: override,
3881 }
3882 }
3883
3884 // CreateIndexOperation returns a new CreateIndexOperation from a given name.
3885 // The name must be that of a previously created CreateIndexOperation, possibly from a different process.
3886 func (c *firestoreAdminGRPCClient) CreateIndexOperation(name string) *CreateIndexOperation {
3887 return &CreateIndexOperation{
3888 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
3889 }
3890 }
3891
3892 // CreateIndexOperation returns a new CreateIndexOperation from a given name.
3893 // The name must be that of a previously created CreateIndexOperation, possibly from a different process.
3894 func (c *firestoreAdminRESTClient) CreateIndexOperation(name string) *CreateIndexOperation {
3895 override := fmt.Sprintf("/v1/%s", name)
3896 return &CreateIndexOperation{
3897 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
3898 pollPath: override,
3899 }
3900 }
3901
3902 // DeleteDatabaseOperation returns a new DeleteDatabaseOperation from a given name.
3903 // The name must be that of a previously created DeleteDatabaseOperation, possibly from a different process.
3904 func (c *firestoreAdminGRPCClient) DeleteDatabaseOperation(name string) *DeleteDatabaseOperation {
3905 return &DeleteDatabaseOperation{
3906 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
3907 }
3908 }
3909
3910 // DeleteDatabaseOperation returns a new DeleteDatabaseOperation from a given name.
3911 // The name must be that of a previously created DeleteDatabaseOperation, possibly from a different process.
3912 func (c *firestoreAdminRESTClient) DeleteDatabaseOperation(name string) *DeleteDatabaseOperation {
3913 override := fmt.Sprintf("/v1/%s", name)
3914 return &DeleteDatabaseOperation{
3915 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
3916 pollPath: override,
3917 }
3918 }
3919
3920 // ExportDocumentsOperation returns a new ExportDocumentsOperation from a given name.
3921 // The name must be that of a previously created ExportDocumentsOperation, possibly from a different process.
3922 func (c *firestoreAdminGRPCClient) ExportDocumentsOperation(name string) *ExportDocumentsOperation {
3923 return &ExportDocumentsOperation{
3924 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
3925 }
3926 }
3927
3928 // ExportDocumentsOperation returns a new ExportDocumentsOperation from a given name.
3929 // The name must be that of a previously created ExportDocumentsOperation, possibly from a different process.
3930 func (c *firestoreAdminRESTClient) ExportDocumentsOperation(name string) *ExportDocumentsOperation {
3931 override := fmt.Sprintf("/v1/%s", name)
3932 return &ExportDocumentsOperation{
3933 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
3934 pollPath: override,
3935 }
3936 }
3937
3938 // ImportDocumentsOperation returns a new ImportDocumentsOperation from a given name.
3939 // The name must be that of a previously created ImportDocumentsOperation, possibly from a different process.
3940 func (c *firestoreAdminGRPCClient) ImportDocumentsOperation(name string) *ImportDocumentsOperation {
3941 return &ImportDocumentsOperation{
3942 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
3943 }
3944 }
3945
3946 // ImportDocumentsOperation returns a new ImportDocumentsOperation from a given name.
3947 // The name must be that of a previously created ImportDocumentsOperation, possibly from a different process.
3948 func (c *firestoreAdminRESTClient) ImportDocumentsOperation(name string) *ImportDocumentsOperation {
3949 override := fmt.Sprintf("/v1/%s", name)
3950 return &ImportDocumentsOperation{
3951 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
3952 pollPath: override,
3953 }
3954 }
3955
3956 // RestoreDatabaseOperation returns a new RestoreDatabaseOperation from a given name.
3957 // The name must be that of a previously created RestoreDatabaseOperation, possibly from a different process.
3958 func (c *firestoreAdminGRPCClient) RestoreDatabaseOperation(name string) *RestoreDatabaseOperation {
3959 return &RestoreDatabaseOperation{
3960 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
3961 }
3962 }
3963
3964 // RestoreDatabaseOperation returns a new RestoreDatabaseOperation from a given name.
3965 // The name must be that of a previously created RestoreDatabaseOperation, possibly from a different process.
3966 func (c *firestoreAdminRESTClient) RestoreDatabaseOperation(name string) *RestoreDatabaseOperation {
3967 override := fmt.Sprintf("/v1/%s", name)
3968 return &RestoreDatabaseOperation{
3969 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
3970 pollPath: override,
3971 }
3972 }
3973
3974 // UpdateDatabaseOperation returns a new UpdateDatabaseOperation from a given name.
3975 // The name must be that of a previously created UpdateDatabaseOperation, possibly from a different process.
3976 func (c *firestoreAdminGRPCClient) UpdateDatabaseOperation(name string) *UpdateDatabaseOperation {
3977 return &UpdateDatabaseOperation{
3978 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
3979 }
3980 }
3981
3982 // UpdateDatabaseOperation returns a new UpdateDatabaseOperation from a given name.
3983 // The name must be that of a previously created UpdateDatabaseOperation, possibly from a different process.
3984 func (c *firestoreAdminRESTClient) UpdateDatabaseOperation(name string) *UpdateDatabaseOperation {
3985 override := fmt.Sprintf("/v1/%s", name)
3986 return &UpdateDatabaseOperation{
3987 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
3988 pollPath: override,
3989 }
3990 }
3991
3992 // UpdateFieldOperation returns a new UpdateFieldOperation from a given name.
3993 // The name must be that of a previously created UpdateFieldOperation, possibly from a different process.
3994 func (c *firestoreAdminGRPCClient) UpdateFieldOperation(name string) *UpdateFieldOperation {
3995 return &UpdateFieldOperation{
3996 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
3997 }
3998 }
3999
4000 // UpdateFieldOperation returns a new UpdateFieldOperation from a given name.
4001 // The name must be that of a previously created UpdateFieldOperation, possibly from a different process.
4002 func (c *firestoreAdminRESTClient) UpdateFieldOperation(name string) *UpdateFieldOperation {
4003 override := fmt.Sprintf("/v1/%s", name)
4004 return &UpdateFieldOperation{
4005 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
4006 pollPath: override,
4007 }
4008 }