本頁說明如何開始使用 Cloud Data Loss Prevention API 適用的 Cloud 用戶端程式庫。用戶端程式庫可讓您從支援的語言輕鬆存取Google Cloud API。雖然您可以直接向伺服器發出原始要求來使用Google Cloud API,但用戶端程式庫提供簡化功能,可大幅減少您需要編寫的程式碼數量。
如要進一步瞭解 Cloud 用戶端程式庫和舊版 Google API 用戶端程式庫,請參閱用戶端程式庫說明。
Cloud Data Loss Prevention API (DLP API) 屬於機密資料保護服務。Compute Engine、App Engine 彈性環境、Google Kubernetes Engine 和 Cloud Run 函式支援本頁所述的 Sensitive Data Protection 用戶端程式庫。App Engine 標準環境上的 Java 8 支援 Java 適用的 Sensitive Data Protection 用戶端程式庫。
如果您在 App Engine 標準環境上使用 Java 7,或將 App Engine 標準環境與 Go、PHP 或 Python 搭配使用,請使用 REST 介面存取 Sensitive Data Protection。
安裝用戶端程式庫
C#
如要建構及執行範例,請使用 Visual Studio 2015 以上版本,開啟解決方案檔案 (Dlp.sln) 並建構範例。詳情請參閱 README。
詳情請參閱設定 C# 開發環境。
Go
go get cloud.google.com/go/dlp
詳情請參閱「設定 Go 開發環境」。
Java
If you are using Maven, add
the following to your pom.xml
file. For more information about
BOMs, see The Google Cloud Platform Libraries BOM.
If you are using Gradle, add the following to your dependencies:
If you are using sbt, add the following to your dependencies:
If you're using Visual Studio Code, IntelliJ, or Eclipse, you can add client libraries to your project using the following IDE plugins:
The plugins provide additional functionality, such as key management for service accounts. Refer to each plugin's documentation for details.
詳情請參閱「設定 Java 開發環境」。
Node.js
npm install @google-cloud/dlp
詳情請參閱「設定 Node.js 開發環境」。
PHP
composer require google/cloud-dlp
詳情請參閱「在 Google Cloud 上使用 PHP」。
Python
- 如果您沒有 pip 和 virtualenv,請先安裝這兩個程式。如需操作說明,請參閱 Python 開發環境設定指南 Google Cloud。
- 前往 GitHub 複製或下載 Google Cloud Python 文件範例。
- 建立 virtualenv。範例與 Python 2.7.x 和 3.4 以上版本相容。
$ python -m venv dlp $ source dlp/bin/activate
- 從已複製或解壓縮的 Google Cloud Python Docs Samples 目錄下的 dlp 目錄,安裝執行範例所需的依附元件。
$ pip install -r requirements.txt
Ruby
gem install google-api-client
詳情請參閱「設定 Ruby 開發環境」。
設定驗證方法
為驗證對 Google Cloud API 的呼叫,用戶端程式庫支援應用程式預設憑證 (ADC);程式庫會在定義的一組位置中尋找憑證,並使用這些憑證驗證對 API 的要求。使用 ADC,您可以在各種環境 (例如本機開發或正式版) 中,為應用程式提供憑證,不必修改應用程式程式碼。在實際工作環境中,設定 ADC 的方式取決於服務和環境。詳情請參閱「設定應用程式預設憑證」。
在本地開發環境中,您可以使用與 Google 帳戶相關聯的憑證設定 ADC:
-
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
畫面上會顯示登入畫面。登入後,您的憑證會儲存在 ADC 使用的 本機憑證檔案中。
使用用戶端程式庫
以下範例將說明用戶端程式庫的使用方法。
C#
Go
Java
Node.js
PHP
Python
其他資源
C#
下列清單包含 C# 專用用戶端程式庫的相關資源連結:
Go
下列清單包含與 Go 專用用戶端程式庫相關的更多資源連結:
Java
以下列出與 Java 用戶端程式庫相關的更多資源連結:
Node.js
以下清單列出與 Node.js 用戶端程式庫相關的更多資源連結:
PHP
下列清單包含與 PHP 用戶端程式庫相關的更多資源連結:
Python
以下清單包含適用於 Python 的用戶端程式庫相關資源連結:
Ruby
以下清單提供與 Ruby 用戶端程式庫相關的更多資源連結: