Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add DeleteDatabase API and delete protection #1508

Merged
merged 6 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import com.google.firestore.admin.v1.CreateIndexRequest;
import com.google.firestore.admin.v1.Database;
import com.google.firestore.admin.v1.DatabaseName;
import com.google.firestore.admin.v1.DeleteDatabaseMetadata;
import com.google.firestore.admin.v1.DeleteDatabaseRequest;
import com.google.firestore.admin.v1.DeleteIndexRequest;
import com.google.firestore.admin.v1.ExportDocumentsMetadata;
import com.google.firestore.admin.v1.ExportDocumentsRequest;
Expand Down Expand Up @@ -1106,7 +1108,7 @@ public final UnaryCallable<UpdateFieldRequest, Operation> updateFieldCallable()
* <p>Currently, [FirestoreAdmin.ListFields][google.firestore.admin.v1.FirestoreAdmin.ListFields]
* only supports listing fields that have been explicitly overridden. To issue this query, call
* [FirestoreAdmin.ListFields][google.firestore.admin.v1.FirestoreAdmin.ListFields] with the
* filter set to `indexConfig.usesAncestorConfig:false` .
* filter set to `indexConfig.usesAncestorConfig:false or `ttlConfig:&#42;`.
*
* <p>Sample code:
*
Expand Down Expand Up @@ -1142,7 +1144,7 @@ public final ListFieldsPagedResponse listFields(CollectionGroupName parent) {
* <p>Currently, [FirestoreAdmin.ListFields][google.firestore.admin.v1.FirestoreAdmin.ListFields]
* only supports listing fields that have been explicitly overridden. To issue this query, call
* [FirestoreAdmin.ListFields][google.firestore.admin.v1.FirestoreAdmin.ListFields] with the
* filter set to `indexConfig.usesAncestorConfig:false` .
* filter set to `indexConfig.usesAncestorConfig:false or `ttlConfig:&#42;`.
*
* <p>Sample code:
*
Expand Down Expand Up @@ -1176,7 +1178,7 @@ public final ListFieldsPagedResponse listFields(String parent) {
* <p>Currently, [FirestoreAdmin.ListFields][google.firestore.admin.v1.FirestoreAdmin.ListFields]
* only supports listing fields that have been explicitly overridden. To issue this query, call
* [FirestoreAdmin.ListFields][google.firestore.admin.v1.FirestoreAdmin.ListFields] with the
* filter set to `indexConfig.usesAncestorConfig:false` .
* filter set to `indexConfig.usesAncestorConfig:false or `ttlConfig:&#42;`.
*
* <p>Sample code:
*
Expand Down Expand Up @@ -1215,7 +1217,7 @@ public final ListFieldsPagedResponse listFields(ListFieldsRequest request) {
* <p>Currently, [FirestoreAdmin.ListFields][google.firestore.admin.v1.FirestoreAdmin.ListFields]
* only supports listing fields that have been explicitly overridden. To issue this query, call
* [FirestoreAdmin.ListFields][google.firestore.admin.v1.FirestoreAdmin.ListFields] with the
* filter set to `indexConfig.usesAncestorConfig:false` .
* filter set to `indexConfig.usesAncestorConfig:false or `ttlConfig:&#42;`.
*
* <p>Sample code:
*
Expand Down Expand Up @@ -1253,7 +1255,7 @@ public final UnaryCallable<ListFieldsRequest, ListFieldsPagedResponse> listField
* <p>Currently, [FirestoreAdmin.ListFields][google.firestore.admin.v1.FirestoreAdmin.ListFields]
* only supports listing fields that have been explicitly overridden. To issue this query, call
* [FirestoreAdmin.ListFields][google.firestore.admin.v1.FirestoreAdmin.ListFields] with the
* filter set to `indexConfig.usesAncestorConfig:false` .
* filter set to `indexConfig.usesAncestorConfig:false or `ttlConfig:&#42;`.
*
* <p>Sample code:
*
Expand Down Expand Up @@ -1678,7 +1680,10 @@ public final UnaryCallable<ImportDocumentsRequest, Operation> importDocumentsCal
* @param database Required. The Database to create.
* @param databaseId Required. The ID to use for the database, which will become the final
* component of the database's resource name.
* <p>The value must be set to "(default)".
* <p>This value should be 4-63 characters. Valid characters are /[a-z][0-9]-/ with first
* character a letter and the last a letter or a number. Must not be UUID-like
* /[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}/.
* <p>"(default)" database id is also valid.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final OperationFuture<Database, CreateDatabaseMetadata> createDatabaseAsync(
Expand Down Expand Up @@ -1717,7 +1722,10 @@ public final OperationFuture<Database, CreateDatabaseMetadata> createDatabaseAsy
* @param database Required. The Database to create.
* @param databaseId Required. The ID to use for the database, which will become the final
* component of the database's resource name.
* <p>The value must be set to "(default)".
* <p>This value should be 4-63 characters. Valid characters are /[a-z][0-9]-/ with first
* character a letter and the last a letter or a number. Must not be UUID-like
* /[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}/.
* <p>"(default)" database id is also valid.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final OperationFuture<Database, CreateDatabaseMetadata> createDatabaseAsync(
Expand Down Expand Up @@ -2161,6 +2169,149 @@ public final UnaryCallable<UpdateDatabaseRequest, Operation> updateDatabaseCalla
return stub.updateDatabaseCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Deletes a database.
*
* <p>Sample code:
*
* <pre>{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
* DatabaseName name = DatabaseName.of("[PROJECT]", "[DATABASE]");
* Database response = firestoreAdminClient.deleteDatabaseAsync(name).get();
* }
* }</pre>
*
* @param name Required. A name of the form `projects/{project_id}/databases/{database_id}`
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final OperationFuture<Database, DeleteDatabaseMetadata> deleteDatabaseAsync(
DatabaseName name) {
DeleteDatabaseRequest request =
DeleteDatabaseRequest.newBuilder().setName(name == null ? null : name.toString()).build();
return deleteDatabaseAsync(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Deletes a database.
*
* <p>Sample code:
*
* <pre>{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
* String name = DatabaseName.of("[PROJECT]", "[DATABASE]").toString();
* Database response = firestoreAdminClient.deleteDatabaseAsync(name).get();
* }
* }</pre>
*
* @param name Required. A name of the form `projects/{project_id}/databases/{database_id}`
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final OperationFuture<Database, DeleteDatabaseMetadata> deleteDatabaseAsync(String name) {
DeleteDatabaseRequest request = DeleteDatabaseRequest.newBuilder().setName(name).build();
return deleteDatabaseAsync(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Deletes a database.
*
* <p>Sample code:
*
* <pre>{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
* DeleteDatabaseRequest request =
* DeleteDatabaseRequest.newBuilder()
* .setName(DatabaseName.of("[PROJECT]", "[DATABASE]").toString())
* .setEtag("etag3123477")
* .build();
* Database response = firestoreAdminClient.deleteDatabaseAsync(request).get();
* }
* }</pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final OperationFuture<Database, DeleteDatabaseMetadata> deleteDatabaseAsync(
DeleteDatabaseRequest request) {
return deleteDatabaseOperationCallable().futureCall(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Deletes a database.
*
* <p>Sample code:
*
* <pre>{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
* DeleteDatabaseRequest request =
* DeleteDatabaseRequest.newBuilder()
* .setName(DatabaseName.of("[PROJECT]", "[DATABASE]").toString())
* .setEtag("etag3123477")
* .build();
* OperationFuture<Database, DeleteDatabaseMetadata> future =
* firestoreAdminClient.deleteDatabaseOperationCallable().futureCall(request);
* // Do something.
* Database response = future.get();
* }
* }</pre>
*/
public final OperationCallable<DeleteDatabaseRequest, Database, DeleteDatabaseMetadata>
deleteDatabaseOperationCallable() {
return stub.deleteDatabaseOperationCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Deletes a database.
*
* <p>Sample code:
*
* <pre>{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create()) {
* DeleteDatabaseRequest request =
* DeleteDatabaseRequest.newBuilder()
* .setName(DatabaseName.of("[PROJECT]", "[DATABASE]").toString())
* .setEtag("etag3123477")
* .build();
* ApiFuture<Operation> future =
* firestoreAdminClient.deleteDatabaseCallable().futureCall(request);
* // Do something.
* Operation response = future.get();
* }
* }</pre>
*/
public final UnaryCallable<DeleteDatabaseRequest, Operation> deleteDatabaseCallable() {
return stub.deleteDatabaseCallable();
}

@Override
public final void close() {
stub.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import com.google.firestore.admin.v1.CreateDatabaseRequest;
import com.google.firestore.admin.v1.CreateIndexRequest;
import com.google.firestore.admin.v1.Database;
import com.google.firestore.admin.v1.DeleteDatabaseMetadata;
import com.google.firestore.admin.v1.DeleteDatabaseRequest;
import com.google.firestore.admin.v1.DeleteIndexRequest;
import com.google.firestore.admin.v1.ExportDocumentsMetadata;
import com.google.firestore.admin.v1.ExportDocumentsRequest;
Expand Down Expand Up @@ -209,6 +211,17 @@ public UnaryCallSettings<UpdateDatabaseRequest, Operation> updateDatabaseSetting
return ((FirestoreAdminStubSettings) getStubSettings()).updateDatabaseOperationSettings();
}

/** Returns the object with the settings used for calls to deleteDatabase. */
public UnaryCallSettings<DeleteDatabaseRequest, Operation> deleteDatabaseSettings() {
return ((FirestoreAdminStubSettings) getStubSettings()).deleteDatabaseSettings();
}

/** Returns the object with the settings used for calls to deleteDatabase. */
public OperationCallSettings<DeleteDatabaseRequest, Database, DeleteDatabaseMetadata>
deleteDatabaseOperationSettings() {
return ((FirestoreAdminStubSettings) getStubSettings()).deleteDatabaseOperationSettings();
}

public static final FirestoreAdminSettings create(FirestoreAdminStubSettings stub)
throws IOException {
return new FirestoreAdminSettings.Builder(stub.toBuilder()).build();
Expand Down Expand Up @@ -430,6 +443,17 @@ public UnaryCallSettings.Builder<UpdateDatabaseRequest, Operation> updateDatabas
return getStubSettingsBuilder().updateDatabaseOperationSettings();
}

/** Returns the builder for the settings used for calls to deleteDatabase. */
public UnaryCallSettings.Builder<DeleteDatabaseRequest, Operation> deleteDatabaseSettings() {
return getStubSettingsBuilder().deleteDatabaseSettings();
}

/** Returns the builder for the settings used for calls to deleteDatabase. */
public OperationCallSettings.Builder<DeleteDatabaseRequest, Database, DeleteDatabaseMetadata>
deleteDatabaseOperationSettings() {
return getStubSettingsBuilder().deleteDatabaseOperationSettings();
}

@Override
public FirestoreAdminSettings build() throws IOException {
return new FirestoreAdminSettings(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"CreateIndex": {
"methods": ["createIndexAsync", "createIndexAsync", "createIndexAsync", "createIndexOperationCallable", "createIndexCallable"]
},
"DeleteDatabase": {
"methods": ["deleteDatabaseAsync", "deleteDatabaseAsync", "deleteDatabaseAsync", "deleteDatabaseOperationCallable", "deleteDatabaseCallable"]
},
"DeleteIndex": {
"methods": ["deleteIndex", "deleteIndex", "deleteIndex", "deleteIndexCallable"]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import com.google.firestore.admin.v1.CreateDatabaseRequest;
import com.google.firestore.admin.v1.CreateIndexRequest;
import com.google.firestore.admin.v1.Database;
import com.google.firestore.admin.v1.DeleteDatabaseMetadata;
import com.google.firestore.admin.v1.DeleteDatabaseRequest;
import com.google.firestore.admin.v1.DeleteIndexRequest;
import com.google.firestore.admin.v1.ExportDocumentsMetadata;
import com.google.firestore.admin.v1.ExportDocumentsRequest;
Expand Down Expand Up @@ -160,6 +162,15 @@ public UnaryCallable<UpdateDatabaseRequest, Operation> updateDatabaseCallable()
throw new UnsupportedOperationException("Not implemented: updateDatabaseCallable()");
}

public OperationCallable<DeleteDatabaseRequest, Database, DeleteDatabaseMetadata>
deleteDatabaseOperationCallable() {
throw new UnsupportedOperationException("Not implemented: deleteDatabaseOperationCallable()");
}

public UnaryCallable<DeleteDatabaseRequest, Operation> deleteDatabaseCallable() {
throw new UnsupportedOperationException("Not implemented: deleteDatabaseCallable()");
}

@Override
public abstract void close();
}
Loading