This page shows how to get started with the Cloud Client Libraries for the Container Analysis API. Read more about the client libraries for Cloud APIs, including the older Google APIs Client Libraries, in Client Libraries Explained.
Installing the client library
Go
For more information, see Setting Up a Go Development Environment.
go get -u cloud.google.com/go/containeranalysis/apiv1
Java
For more information, see Setting Up a Java Development Environment.
Si vous utilisez Maven avec un BOM, ajoutez les éléments suivants à votre fichier pom.xml
:
Si vous utilisez Maven sans BOM, ajoutez les éléments suivants à vos dépendances :
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 @google-cloud/containeranalysis
Python
For more information, see Setting Up a Python Development Environment.
It is recommended to install this library in a virtualenv using
pip
. Virtualenv allows you to install the Python libraries in an isolated
environment, preventing conflicts with the system dependencies.
Mac and Linux
pip install virtualenv virtualenv <your-env> source <your-env>/bin/activate <your-env>/bin/pip install google-cloud-containeranalysis</your-env></your-env></your-env>
Windows
pip install virtualenv virtualenv <your-env> <your-env>\Scripts\activate <your-env>\Scripts\pip.exe install google-cloud-containeranalysis</your-env></your-env></your-env>
Ruby
For more information, see Setting Up a Ruby Development Environment.
gem install google-cloud-container_analysis
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.
Go
To use this sample, prepare your machine for Go development, and complete the Container Analysis quickstart. For more information, see the Container Analysis Go API reference documentation.
Java
Before trying this sample, follow the Java setup instructions in Setting Up a Java Development Environment. For more information, see the Container Analysis Java API reference documentation.
Node.js
Before trying this sample, follow the Node.js setup instructions in Setting Up a Node.js Development Environment. For more information, see the Container Analysis Node.js API reference documentation.
Python
Before trying this sample, follow the Python setup instructions in Setting Up a Python Development Environment. For more information, see the Container Analysis Python API reference documentation.
Ruby
Before trying this sample, follow the Ruby setup instructions in Setting Up a Ruby Development Environment. For more information, see the Container Analysis Ruby API reference documentation.
require "logger" module MyLogger LOGGER = Logger.new $stderr, level: Logger::WARN def logger LOGGER end end # Define a gRPC module-level logger method before grpc/logconfig.rb loads. module GRPC extend MyLogger end