This page shows how to get started with the Cloud Client Libraries for the Secret Manager API. Read more about the client libraries for Cloud APIs in Client Libraries Explained.
Installing the client library
C#
For more information, see Setting Up a C# Development Environment.
Using PowerShell:
$ Install-Package Google.Cloud.SecretManager.V1 -Version 1.0.0
Using the dotnet CLI:
$ dotnet add package Google.Cloud.SecretManager.V1 --version 1.0.0
Go
For more information, see Setting Up a Go Development Environment.
$ go get -u cloud.google.com/go/secretmanager/apiv1 $ go get -u google.golang.org/genproto/googleapis/cloud/secretmanager/v1
Java
For more information, see Setting Up a Java Development Environment.
Si vous utilisez Maven, ajoutez les lignes suivantes à votre fichier pom.xml
. Pour en savoir plus sur les BOM, consultez la page The Google Cloud Platform Libraries BOM (BOM des bibliothèques Google Cloud Platform).
Si vous utilisez Gradle, ajoutez les éléments suivants à vos dépendances :
Si vous utilisez sbt, ajoutez les éléments suivants à vos dépendances :
Si vous utilisez IntelliJ ou Eclipse, vous pouvez ajouter des bibliothèques clientes à votre projet à l'aide des plug-ins IDE suivants :
Les plug-ins offrent des fonctionnalités supplémentaires, telles que la gestion des clés pour les comptes de service. Reportez-vous à la documentation de chaque plug-in pour plus de détails.
Node.js
For more information, see Setting Up a Node.js Development Environment.
$ npm install --save @google-cloud/secret-manager
PHP
For more information, see Using PHP on Google Cloud.
$ composer require google/cloud-secret-manager
Python
For more information, see Setting Up a Python Development Environment.
$ pip install google-cloud-secret-manager
Ruby
For more information, see Setting Up a Ruby Development Environment.
$ gem install google-cloud-secret_manager
Setting up authentication
To run the client library, you must first set up authentication by creating a service account and setting an environment variable. Complete the following steps to set up authentication. For other ways to authenticate, see the GCP authentication documentation.
Cloud Console
-
Dans Cloud Console, accédez à la page Créer une clé de compte de service.
Accéder à la page "Créer une clé de compte de service" - Dans la liste Compte de service, sélectionnez Nouveau compte de service.
- Dans le champ Nom du compte de service, saisissez un nom.
Dans la liste Rôle, sélectionnez Projet > Propriétaire
- Cliquez sur Créer. Un fichier JSON contenant votre clé est téléchargé sur votre ordinateur.
Ligne de commande
Vous pouvez exécuter les commandes suivantes à l'aide du SDK Cloud sur votre ordinateur local, ou dans Cloud Shell.
-
Créez le compte de service. Remplacez NAME par le nom que vous souhaitez donner au compte de service.
gcloud iam service-accounts create NAME
-
Accordez des autorisations au compte de service. Remplacez PROJECT_ID par votre ID de projet.
gcloud projects add-iam-policy-binding PROJECT_ID --member="serviceAccount:NAME@PROJECT_ID.iam.gserviceaccount.com" --role="roles/owner"
-
Générez le fichier de clé. Remplacez FILE_NAME par le nom du fichier de clé.
gcloud iam service-accounts keys create FILE_NAME.json --iam-account=NAME@PROJECT_ID.iam.gserviceaccount.com
Fournissez des identifiants d'authentification au code de votre application en définissant la variable d'environnement GOOGLE_APPLICATION_CREDENTIALS
.
Remplacez [PATH] par le chemin du fichier JSON contenant la clé de votre compte de service. Cette variable ne s'applique qu'à la session d'interface système actuelle. Par conséquent, si vous ouvrez une nouvelle session, vous devez la définir à nouveau.
Linux ou macOS
export GOOGLE_APPLICATION_CREDENTIALS="[PATH]"
Exemple :
export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/my-key.json"
Windows
Avec PowerShell :
$env:GOOGLE_APPLICATION_CREDENTIALS="[PATH]"
Exemple :
$env:GOOGLE_APPLICATION_CREDENTIALS="C:\Users\username\Downloads\my-key.json"
Avec l'invite de commande :
set GOOGLE_APPLICATION_CREDENTIALS=[PATH]
Using the client library
The following example shows how to use the client library.
C#
To learn how to install and use the client library for Secret Manager, see the Secret Manager Client Libraries. For more information, see the Secret Manager C# API reference documentation.
Go
To learn how to install and use the client library for Secret Manager, see the Secret Manager Client Libraries. For more information, see the Secret Manager Go API reference documentation.
Java
To learn how to install and use the client library for Secret Manager, see the Secret Manager Client Libraries. For more information, see the Secret Manager Java API reference documentation.
Node.js
To learn how to install and use the client library for Secret Manager, see the Secret Manager Client Libraries. For more information, see the Secret Manager Node.js API reference documentation.
PHP
To learn how to install and use the client library for Secret Manager, see the Secret Manager Client Libraries. For more information, see the Secret Manager PHP API reference documentation.
Python
To learn how to install and use the client library for Secret Manager, see the Secret Manager Client Libraries. For more information, see the Secret Manager Python API reference documentation.
Ruby
To learn how to install and use the client library for Secret Manager, see the Secret Manager Client Libraries. For more information, see the Secret Manager Ruby API reference documentation.