Cloud Deploy クライアント ライブラリ

このページでは、Cloud Deploy API の Cloud クライアント ライブラリの使用を開始する方法について説明します。ただし、Google App Engine スタンダード環境で実行している場合は、古い Google API クライアント ライブラリを使用することをおすすめします。Cloud APIs 用のクライアント ライブラリの詳細については、クライアント ライブラリの説明をご覧ください。

クライアント ライブラリをインストールする

C++

このクライアント ライブラリの要件とインストールの依存関係の詳細については、C++ 開発環境の設定をご覧ください。

C#

詳細については、C# 開発環境の設定をご覧ください。

Install-Package Google.Cloud.Deploy.V1 -Pre

Go

詳細については、Go 開発環境の設定をご覧ください。

go get cloud.google.com/go/storage

Java

詳細については、Java 開発環境の設定をご覧ください。

Maven を使用している場合は、pom.xml ファイルに以下を追加します。

<dependency>
    <groupId>com.google.cloud</groupId>
    <artifactId>google-cloud-deploy</artifactId>
    <version></version>
</dependency>

Gradle を使用している場合は、依存関係に以下の内容を追加します。

compile group: 'com.google.cloud', name: 'google-cloud-deploy', version: ''

Node.js

詳細については、Node.js 開発環境の設定をご覧ください。

npm install --save @google-cloud/deploy

PHP

詳細については、Google Cloud での PHP の使用をご覧ください。

composer require google/cloud-deploy

Python

詳細については、Python 開発環境の設定をご覧ください。

pip install --upgrade google-cloud-deploy

Ruby

詳細については、Ruby 開発環境の設定をご覧ください。

gem install google-cloud-deploy

認証を設定する

クライアント ライブラリを使用する場合は、アプリケーションのデフォルト認証情報(ADC)を使用して認証を行います。ADC の設定については、アプリケーションのデフォルト認証情報に認証情報を提供するをご覧ください。クライアント ライブラリで ADC を使用する方法については、クライアント ライブラリを使用して認証するをご覧ください。

クライアント ライブラリの使用

次の例は、クライアント ライブラリの使用方法を示しています。

C++

Cloud Deploy に対して認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


#include "google/cloud/deploy/v1/cloud_deploy_client.h"
#include <iostream>

int main(int argc, char* argv[]) try {
  if (argc != 3) {
    std::cerr << "Usage: " << argv[0] << " project-id location-id\n";
    return 1;
  }

  namespace deploy = ::google::cloud::deploy_v1;
  auto client = deploy::CloudDeployClient(deploy::MakeCloudDeployConnection());

  auto const parent =
      std::string{"projects/"} + argv[1] + "/locations/" + argv[2];
  for (auto r : client.ListDeliveryPipelines(parent)) {
    if (!r) throw std::move(r).status();
    std::cout << r->DebugString() << "\n";
  }

  return 0;
} catch (google::cloud::Status const& status) {
  std::cerr << "google::cloud::Status thrown: " << status << "\n";
  return 1;
}

Node.js

Cloud Deploy に対して認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

/**
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  Required. The parent, which owns this collection of pipelines. Format must be
 *  projects/{project_id}/locations/{location_name}.
 */
// const parent = 'abc123'
/**
 *  The maximum number of pipelines to return. The service may return
 *  fewer than this value. If unspecified, at most 50 pipelines will
 *  be returned. The maximum value is 1000; values above 1000 will be set
 *  to 1000.
 */
// const pageSize = 1234
/**
 *  A page token, received from a previous `ListDeliveryPipelines` call.
 *  Provide this to retrieve the subsequent page.
 *  When paginating, all other provided parameters match
 *  the call that provided the page token.
 */
// const pageToken = 'abc123'
/**
 *  Filter builds to be returned. See https://google.aip.dev/160 for more
 *  details.
 */
// const filter = 'abc123'
/**
 *  Field to sort by. See https://google.aip.dev/132#ordering for more details.
 */
// const orderBy = 'abc123'

// Imports the Deploy library
const {CloudDeployClient} = require('@google-cloud/deploy').v1;

// Instantiates a client
const deployClient = new CloudDeployClient();

async function listDeliveryPipelines() {
  // Construct request
  const request = {
    parent,
  };

  // Run request
  const iterable = await deployClient.listDeliveryPipelinesAsync(request);
  for await (const response of iterable) {
    console.log(response);
  }
}

listDeliveryPipelines();

その他のリソース