Gérer les API et les bibliothèques Cloud dans Cloud Code pour IntelliJ
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Vous pouvez accéder aux produits et services Google Cloud à partir de votre code à l'aide des API Cloud. Ces API Cloud présentent une interface REST JSON simple que vous pouvez appeler via des bibliothèques clientes.
Ce document explique comment parcourir les API disponibles, activer des API Cloud, ajouter des bibliothèques clientes Cloud à votre projet, et configurer l'authentification en fonction de vos besoins pour le développement.
Parcourir les API Cloud
Pour explorer toutes les API Google Cloud disponibles dans votre IDE, procédez comme suit :
Sélectionnez Tools > Cloud Code > Add Cloud libraries and Manage Cloud APIs (Outils > Cloud Code > Ajouter des bibliothèques Cloud et Gérer les API Cloud).
Développez l'arborescence de l'explorateur des API Google Cloud pour afficher toutes les API disponibles.
L'explorateur regroupe les API Cloud par catégorie. Vous pouvez également rechercher une API spécifique à l'aide de la barre de recherche des API.
Cliquez sur une API pour afficher plus de détails, tels que son état, les instructions d'installation par langage des bibliothèques clientes correspondantes et la documentation correspondante.
Activer les API Cloud
Pour activer rapidement les API Cloud pour un projet à l'aide des détails de l'API, procédez comme suit :
Dans la vue Détails de l'API Cloud, choisissez un projet Google Cloud pour lequel vous souhaitez activer l'API Cloud.
Cliquez sur le bouton Activer l'API.
Une fois l'API activée, un message confirme cette modification.
Ajouter des bibliothèques clientes Google Cloud
Pour ajouter des bibliothèques à votre projet dans IntelliJ, procédez comme suit :
La boîte de dialogue Manage Google Cloud API (Gérer des API Google Cloud) affiche les bibliothèques prises en charge.
Sélectionnez le type de bibliothèque souhaité entre la bibliothèque cliente Google Cloud (recommandé) et la bibliothèque Java Spring Google Cloud.
Dans le menu déroulant Module, sélectionnez le module auquel vous souhaitez ajouter la bibliothèque.
Cliquez sur Ajouter une dépendance Maven pour ajouter un BOM et une bibliothèque cliente à votre projet.
Pour tous les autres projets
Sélectionnez Tools > Cloud Code > Add Cloud libraries and Manage Cloud APIs (Outils > Cloud Code > Ajouter des bibliothèques Cloud et Gérer les API Cloud).
La boîte de dialogue Add Google Cloud Libraries (Ajouter des bibliothèques Google Cloud) affiche les bibliothèques prises en charge.
Installez l'API en suivant les instructions d'installation indiquées sur la page des détails de l'API correspondant à la langue de votre choix.
Configurer l'authentification
Une fois que vous avez activé les API et ajouté les bibliothèques clientes nécessaires, vous devez configurer votre application pour qu'elle puisse s'authentifier. La configuration à effectuer dépend du type de développement et de la plate-forme sur laquelle vous exécutez l'application.
Une fois les étapes d'authentification effectuées, votre application peut s'authentifier et est prête à être déployée.
Développement à distance avec le gestionnaire de secrets activé
Si vous développez votre application à distance, que vous utilisez un compte de service pour l'authentification et que votre application utilise des secrets, vous devez suivre quelques étapes supplémentaires pour attribuer à votre compte de service Google le rôle qui lui permettra d'accéder à un secret spécifique du gestionnaire de secrets :
Ouvrez le panneau "Secret Manager" (Gestionnaire de secrets) et sélectionnez le secret auquel vous souhaitez accéder depuis votre code.
Accédez à l'onglet "Autorisations", puis configurez les autorisations de votre secret en cliquant sur ModifierModifier l'autorisation. La page de configuration de Secret Manager pour le secret s'ouvre dans votre navigateur Web.
Dans la console Google Cloud , cliquez sur Afficher le panneau d'informations, puis sur Ajouter un compte principal.
Attribuez le rôle Accesseur de secrets de Secret Manager à votre compte de service.
Votre compte de service est autorisé à accéder à ce secret.
Obtenir de l'aide
Pour envoyer des commentaires ou signaler un problème dans votre IDE IntelliJ, accédez à Outils > Cloud Code > Aide / À propos > Envoyer des commentaires ou signaler un problème pour signaler un problème sur GitHub.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (UTC)."],[[["\u003cp\u003eGoogle Cloud APIs can be accessed via a JSON REST interface and client libraries, allowing developers to integrate Google Cloud products and services into their code.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can browse and enable Google Cloud APIs directly within their IDE using Cloud Code, which groups APIs by category and provides details on each API's status and documentation.\u003c/p\u003e\n"],["\u003cp\u003eCloud Code facilitates adding client libraries to projects, supporting both Google Cloud Client Library and Java Spring Google Cloud Library, and managing dependencies using the Google Cloud Java Bill of Materials (BOM).\u003c/p\u003e\n"],["\u003cp\u003eAuthentication setup for applications varies based on the development environment, such as local development with minikube or remote deployment on Google Kubernetes Engine or Cloud Run, often requiring Application Default Credentials (ADC) and sometimes service account configuration.\u003c/p\u003e\n"],["\u003cp\u003eFor remote development with Secret Manager, service accounts must be granted the "Secret Manager Secret Accessor" role to allow access to specific secrets, ensuring secure handling of sensitive information within applications.\u003c/p\u003e\n"]]],[],null,["# Manage Cloud APIs and libraries in Cloud Code for IntelliJ\n\nYou can access Google Cloud products and services from your code using\n[Cloud APIs](/apis/docs/overview). These Cloud APIs expose a simple JSON REST\ninterface that you can call via client libraries.\n\nThis document describes how to browse available APIs, enable Cloud APIs and\nadd Cloud Client Libraries to your project, and set up authentication depending\non your development needs.\n| **Note:** For projects that don't use both Java and Maven, Cloud Code does not add the Cloud Client Libraries to your build automatically, but does support the other features described here and provides build snippets for your build system.\n\nBrowsing Cloud APIs\n-------------------\n\nTo explore all available Google Cloud APIs in your IDE, follow these steps:\n\n1. Select **Tools** \\\u003e **Cloud Code** \\\u003e **Add Cloud Libraries and Manage Cloud APIs**.\n2. Expand the Google Cloud APIs explorer tree to view all available APIs. The explorer groups Cloud APIs by category. You can also look for a specific API using the Search APIs search bar.\n3. Click an API to view more details, such as its status, language-specific installation instructions for its corresponding client libraries, and relevant documentation.\n\n\u003cbr /\u003e\n\nEnabling Cloud APIs\n-------------------\n\nTo quickly enable Cloud APIs for a project using the API details, follow these steps:\n\n1. In the Cloud API details view, choose a Google Cloud project that you'd like to enable the Cloud API for.\n2. Click the **Enable API** button.\n\n\n Once the API has been enabled you'll see a message confirming this change.\n\n\u003cbr /\u003e\n\nAdding the Cloud Client Libraries\n---------------------------------\n\nTo add libraries to your project in IntelliJ, follow these steps: \n\n### For Java Maven projects\n\n1. Select **Tools** \\\u003e **Cloud Code** \\\u003e **Cloud APIs**.\n2. The **Manage Google Cloud APIs** dialog displays the supported libraries.\n3. Select your preferred library type from the choice of Google Cloud Client Library (recommended) or Java Spring Google Cloud Library.\n4. In the **Module** drop-down menu, select the module that you want to add the library to.\n| **Note:** **Google Cloud Java** solves version conflicts between libraries by adding the [Google Cloud Java Bill of Materials (BOM)](https://github.com/googleapis/google-cloud-java#version-management) to the `pom.xml` file of your projects.\n5. Click **Add Maven Dependency** to add BOM and client library to your project.\n\n### For all other projects\n\n1. Select **Tools** \\\u003e **Cloud Code** \\\u003e **Add Cloud Libraries and Manage Cloud APIs**.\n2. The **Add Google Cloud Libraries** dialog displays the supported libraries.\n3. Install the API using the installation instructions listed on the API details page for your preferred language. If you're developing a Java application, you need to also specify your library preference, Google Cloud Client Library (recommended) or Java Spring Google Cloud Library.\n\nSetting up authentication\n-------------------------\n\nAfter you've enabled the required APIs and added the necessary client libraries,\nyou need to configure your application in order for it to be successfully\nauthenticated. Your configuration depends on your type of development and\nthe platform you're running on.\n\nOnce you complete the relevant authentication steps, your application can\nauthenticate and is ready to be deployed.\n\n### Local development\n\n### minikube\n\n\n1. Ensure that you have Application Default Credentials (ADC) set by running `gcloud auth application-default login`. This lets minikube find your ADC to authenticate with.\n\n\u003cbr /\u003e\n\n### minikube\n\n\n1. Ensure that you have Application Default Credentials (ADC) set by running `gcloud auth application-default login`. This lets minikube find your ADC to authenticate with.\n2. Start minikube with `minikube start --addons gcp-auth`. This mounts your ADC in your pods. For a detailed minikube auth guide for Google Cloud, refer to the [minikube gcp-auth docs](https://minikube.sigs.k8s.io/docs/handbook/addons/gcp-auth/).\n\n\u003cbr /\u003e\n\n### Local Kubernetes cluster\n\n\n1. Ensure that you have Application Default Credentials (ADC) set by running `gcloud auth application-default login`.\n2. Mount your local `gcloud` directory in your Kubernetes pods by editing the deployment manifests, so that the Google Cloud client libraries can find your credentials. Kubernetes pod configuration example: \n\n apiVersion: v1\n kind: Pod\n metadata:\n name: my-app\n labels:\n name: my-app\n spec:\n containers:\n - name: my-app\n image: gcr.io/google-containers/busybox\n ports:\n - containerPort: 8080\n volumeMounts:\n - mountPath: /root/.config/gcloud\n name: gcloud-volume\n volumes:\n - name: gcloud-volume\n hostPath:\n path: /path/to/home/.config/gcloud\n\n\u003cbr /\u003e\n\n### Cloud Run\n\n\n1. Ensure that you have Application Default Credentials (ADC) set by running `gcloud auth application-default login`. This lets the Cloud Run local simulated environment find your ADC to authenticate with.\n\n\u003cbr /\u003e\n\n### Remote development\n\n### Google Kubernetes Engine\n\n\n1. [Configure your GKE cluster and application with Workload Identity](https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity) to authenticate Google Cloud services on GKE. This associates your Kubernetes service account with your Google service account.\n2. If the Google Cloud service you're trying to access requires additional roles, grant them for the Google service account you're using to develop your app. \n For a list of IAM role types and predefined roles you can grant to identities, see the [Understanding roles guide](https://cloud.google.com/iam/docs/understanding-roles). For steps to grant the roles, see [Granting, changing, and revoking access to resources](/iam/docs/granting-changing-revoking-access).\n3. Configure your Kubernetes Deployment to reference the Kubernetes service account by setting the `.spec.serviceAccountName` field in your Kubernetes Deployment YAML file. \n If you're working on an app created from a Cloud Code template, this file is located under the kubernetes-manifests folder.\n\n\u003cbr /\u003e\n\n### Cloud Run\n\n\n1. To create a new unique service account for deploying your Cloud Run application, on the Service Accounts page, select the project that your secret is stored in. [Go to the Service Accounts\n page](https://console.cloud.google.com/iam-admin/serviceaccounts)\n\n2. Click **Create service account**.\n3. In the **Create service account** dialog, enter a descriptive name for the service account.\n4. Change the **Service account ID** to a unique, recognizable value and then click **Create**.\n5. If the Google Cloud service you're trying to access requires additional roles, grant them, click **Continue** , and then click **Done**.\n6. To add your service account to your deploy configuration, navigate to your **Cloud Run: Deploy** run configuration, expand the **Advanced revision settings** section, and then specify your service account in the **Service Account** field. \n\n\u003cbr /\u003e\n\n### Cloud Run\n\n\n1. [Configure your GKE cluster and application with Workload Identity](https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity) to authenticate Google Cloud services on GKE. This associates your Kubernetes service account with your Google service account.\n2. If the Google Cloud service you're trying to access requires additional roles, grant them for the Google service account you're using to develop your app. \n The [Understanding roles guide](https://cloud.google.com/iam/docs/understanding-roles) describes IAM role types and lists available predefined roles you can grant to identities.\n3. To add your Kubernetes service account to your deploy configuration, navigate to your **Cloud Run: Deploy** run configuration, expand the **Advanced revision settings** section, and then specify your Kubernetes service account in the **Service\n Account** field. \n\n\u003cbr /\u003e\n\n### Remote development with Secret Manager enabled\n\nIf you're developing remotely, using a service account for authentication,\nand your application uses [secrets](/code/docs/intellij/secret-manager-ux), you\nneed to complete a few more steps to assign your Google service account\nthe role required to access a particular Secret Manager secret:\n\n1. Open the Secret Manager panel and select the secret you want to access in your\n code.\n\n2. Switch to the Permissions tab and then configure your secret's permissions\n by clicking edit\n **Edit Permission**. The Secret Manager configuration page for\n the secret opens in your web browser.\n\n3. In Google Cloud console, click **Show Info Panel** and then click **Add principal**.\n\n4. Assign your service account the **Secret Manager Secret Accessor** role.\n\n Your service account has permission to access this secret.\n\nGet support\n-----------\n\nTo submit feedback or report an issue in your IntelliJ IDE, go to **Tools** \\\u003e **Cloud Code** \\\u003e **Help / About** \\\u003e **Submit\nfeedback or report an issue** to report an issue on [GitHub](https://github.com/GoogleCloudPlatform/cloud-code-intellij/issues)."]]