reCAPTCHA Enterprise 사이트 키 삭제

지정된 프로젝트 ID에 대해 지정된 reCAPTCHA 사이트 키를 삭제합니다.

코드 샘플

Java

reCAPTCHA Enterprise에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.


import com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient;
import com.google.recaptchaenterprise.v1.DeleteKeyRequest;
import com.google.recaptchaenterprise.v1.KeyName;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class DeleteSiteKey {

  public static void main(String[] args)
      throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // TODO(developer): Replace these variables before running the sample.
    String projectID = "your-project-id";
    String recaptchaSiteKey = "recaptcha-site-key";

    deleteSiteKey(projectID, recaptchaSiteKey);
  }

  /**
   * Delete the given reCAPTCHA site key present under the project ID.
   *
   * @param projectID: GCloud Project ID.
   * @param recaptchaSiteKey: Specify the site key to be deleted.
   */
  public static void deleteSiteKey(String projectID, String recaptchaSiteKey)
      throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the `client.close()` method on the client to safely
    // clean up any remaining background resources.
    try (RecaptchaEnterpriseServiceClient client = RecaptchaEnterpriseServiceClient.create()) {

      // Set the project ID and reCAPTCHA site key.
      DeleteKeyRequest deleteKeyRequest =
          DeleteKeyRequest.newBuilder()
              .setName(KeyName.of(projectID, recaptchaSiteKey).toString())
              .build();

      client.deleteKeyCallable().futureCall(deleteKeyRequest).get(5, TimeUnit.SECONDS);
      System.out.println("reCAPTCHA Site key successfully deleted !");
    }
  }
}

PHP

reCAPTCHA Enterprise에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

use Google\ApiCore\ApiException;
use Google\Cloud\RecaptchaEnterprise\V1\Client\RecaptchaEnterpriseServiceClient;
use Google\Cloud\RecaptchaEnterprise\V1\DeleteKeyRequest;

/**
 * Delete an existing reCAPTCHA key from your Google Cloud project
 *
 * @param string $projectId Your Google Cloud project ID
 * @param string $keyId The 40 char long key ID you wish to delete
 */
function delete_key(string $projectId, string $keyId): void
{
    $client = new RecaptchaEnterpriseServiceClient();
    $formattedKeyName = $client->keyName($projectId, $keyId);

    try {
        $deleteKeyRequest = (new DeleteKeyRequest())
            ->setName($formattedKeyName);
        $client->deleteKey($deleteKeyRequest);
        printf('The key: %s is deleted.' . PHP_EOL, $keyId);
    } catch (ApiException $e) {
        if ($e->getStatus() === 'NOT_FOUND') {
            printf('The key with Key ID: %s doesn\'t exist.' . PHP_EOL, $keyId);
        } else {
            print('deleteKey() call failed with the following error: ');
            print($e->getBasicMessage() . PHP_EOL);
        }
    }
}

Python

reCAPTCHA Enterprise에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

from google.cloud import recaptchaenterprise_v1

def delete_site_key(project_id: str, recaptcha_site_key: str) -> None:
    """Delete the given reCAPTCHA site key present under the project ID.

    Args:
    project_id : GCloud Project ID.
    recaptcha_site_key: Specify the key ID to be deleted.
    """

    client = recaptchaenterprise_v1.RecaptchaEnterpriseServiceClient()

    # Construct the key details.
    key_name = f"projects/{project_id}/keys/{recaptcha_site_key}"

    # Set the project ID and reCAPTCHA site key.
    request = recaptchaenterprise_v1.DeleteKeyRequest()
    request.name = key_name

    client.delete_key(request)
    print("reCAPTCHA Site key deleted successfully ! ")

Ruby

reCAPTCHA Enterprise에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

require "google/cloud/recaptcha_enterprise"

# Delete site key registered to use recaptcha services.
#
# @param project_id [String] GCloud Project ID.
# @param site_key [String] Site key to be updated.
# @return [void]
def delete_site_key project_id:, site_key:
  # Create the reCAPTCHA client.
  client = ::Google::Cloud::RecaptchaEnterprise.recaptcha_enterprise_service

  client.delete_key name: "projects/#{project_id}/keys/#{site_key}"
  puts "reCAPTCHA Site key deleted successfully !"
end

다음 단계

다른 Google Cloud 제품의 코드 샘플을 검색하고 필터링하려면 Google Cloud 샘플 브라우저를 참조하세요.