Introdução à API Service Management

Esta página descreve como configurar o seu ambiente de desenvolvimento para trabalhar com a API Service Management. A abordagem mais simples para usar a API Service Management (além de usar apenas a IU Web da Google Cloud consola ) e a nossa recomendação para a maioria dos exemplos de utilização operacional é através da gcloud interface de linha de comandos. Se precisar de programar com base na API Service Management, recomendamos que use uma das nossas bibliotecas cliente fornecidas. Para experimentar a API, pode seguir as instruções de configuração alternativas abaixo e usar o comando curl para interagir com a API sem configurar um ambiente de desenvolvimento de aplicações completo.

Configuração através do gcloud

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Enable the Service Management API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  4. Install the Google Cloud CLI.

  5. Se estiver a usar um fornecedor de identidade (IdP) externo, tem primeiro de iniciar sessão na CLI gcloud com a sua identidade federada.

  6. Para inicializar a CLI gcloud, execute o seguinte comando:

    gcloud init
  7. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  8. Enable the Service Management API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  9. Install the Google Cloud CLI.

  10. Se estiver a usar um fornecedor de identidade (IdP) externo, tem primeiro de iniciar sessão na CLI gcloud com a sua identidade federada.

  11. Para inicializar a CLI gcloud, execute o seguinte comando:

    gcloud init
  12. Configuração para chamar a API diretamente

    Esta secção descreve os passos básicos necessários para configurar o seu ambiente local para experimentar a API Service Management através do comando curl. Destina-se a programadores que precisam de programar em função da API Service Management.

    Configuração inicial

    1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
    2. Install the Google Cloud CLI.

    3. Se estiver a usar um fornecedor de identidade (IdP) externo, tem primeiro de iniciar sessão na CLI gcloud com a sua identidade federada.

    4. Para inicializar a CLI gcloud, execute o seguinte comando:

      gcloud init
    5. Create or select a Google Cloud project.

      Roles required to select or create a project

      • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
      • Create a project: To create a project, you need the Project Creator (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.
      • Create a Google Cloud project:

        gcloud projects create PROJECT_ID

        Replace PROJECT_ID with a name for the Google Cloud project you are creating.

      • Select the Google Cloud project that you created:

        gcloud config set project PROJECT_ID

        Replace PROJECT_ID with your Google Cloud project name.

    6. Enable the Service Management API:

      Roles required to enable APIs

      To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

      gcloud services enable servicemanagement.googleapis.com
    7. Grant roles to your user account. Run the following command once for each of the following IAM roles: roles/servicemanagement.admin

      gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE

      Replace the following:

      • PROJECT_ID: Your project ID.
      • USER_IDENTIFIER: The identifier for your user account. For example, myemail@example.com.
      • ROLE: The IAM role that you grant to your user account.
    8. Install the Google Cloud CLI.

    9. Se estiver a usar um fornecedor de identidade (IdP) externo, tem primeiro de iniciar sessão na CLI gcloud com a sua identidade federada.

    10. Para inicializar a CLI gcloud, execute o seguinte comando:

      gcloud init
    11. Create or select a Google Cloud project.

      Roles required to select or create a project

      • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
      • Create a project: To create a project, you need the Project Creator (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.
      • Create a Google Cloud project:

        gcloud projects create PROJECT_ID

        Replace PROJECT_ID with a name for the Google Cloud project you are creating.

      • Select the Google Cloud project that you created:

        gcloud config set project PROJECT_ID

        Replace PROJECT_ID with your Google Cloud project name.

    12. Enable the Service Management API:

      Roles required to enable APIs

      To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

      gcloud services enable servicemanagement.googleapis.com
    13. Grant roles to your user account. Run the following command once for each of the following IAM roles: roles/servicemanagement.admin

      gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE

      Replace the following:

      • PROJECT_ID: Your project ID.
      • USER_IDENTIFIER: The identifier for your user account. For example, myemail@example.com.
      • ROLE: The IAM role that you grant to your user account.
    14. Teste com curl

      1. Defina um alias de shell conveniente para chamar as APIs REST da Google:

        $ alias gcurl='curl -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json"'
        
      2. Experimente listar serviços acessíveis publicamente:

        $ gcurl https://servicemanagement.googleapis.com/v1/services
        

        Se vir uma lista de serviços, a configuração foi concluída com êxito.

      Passos seguintes

      Se estiver a criar um serviço gerido e não estiver a usar o Cloud Endpoints:

      1. Siga as instruções em Criar e eliminar serviços para criar serviços geridos. Esta ação cria um recurso de serviço gerido de nível superior.
      2. Siga as instruções em Gerir configurações de serviços para enviar configurações de serviços que descrevam as funcionalidades usadas pelo serviço.

      3. Siga o artigo Implementar configurações de serviços para implementar as configurações de serviços.