Google Cloud Storage 拡張機能

現在、Apigee Edge のドキュメントを表示しています。
Apigee X のドキュメントをご確認ください
情報

バージョン: 1.4.1

Cloud Storage バケット内のファイルに対して、署名付き URL の一覧表示、ダウンロード、生成を行います。

ここでは、この拡張機能の構成と使用について説明します。API プロキシからこの拡張機能を使用する前に、次のことを行う必要があります。

  1. Cloud Storage バケットを作成します。

  2. バケットにオブジェクトをアップロードする。

  3. Google Cloud Storage 拡張機能を表す GCP サービス アカウントにバケットにアクセスするための権限を付与します。使用するロールの詳細については、Cloud Storage のロールをご覧ください。Cloud Storage の権限の詳細については、Identity and Access Management(IAM)の権限の使用をご覧ください。

  4. GCP Console を使用してサービス アカウント キーを生成します

  5. 構成リファレンスを使用して拡張機能を追加および構成するときは、生成されたキー JSON ファイルの内容を使用します。

Cloud Storage について

Cloud Storage は、安全で耐久性があり、スケーラブルなファイル ストレージのためのサービスです。Cloud Storage を使い始めたばかりの方は、Cloud Storage ドキュメントのクイックスタートをご覧ください。

サンプル

次の例は、ExtensionCallout ポリシーを使用して Cloud Storage 拡張機能アクションのサポートを構成する方法を示しています。

ファイルの一覧表示

次の例では、拡張機能の listFiles アクションがファイルのリストを取得し、配列で返します。listFiles アクションは入力パラメータを受け取りません。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ConnectorCallout async="false" continueOnError="false" enabled="true" name="Get-Storage-File-List">
    <DisplayName>Get Storage File List</DisplayName>
    <Connector>cloud-storage-extension-example</Connector>
    <Action>listFiles</Action>
    <Input><![CDATA[{}]]></Input>
    <Output parsed="false">storage.filelist.retrieved</Output>
</ConnectorCallout>

レスポンス値は次のようになります。

["example-text.txt","example-image.png"]

次の Assign Message ポリシーは、上記の ExtensionCallout ポリシーからレスポンス値を取得し、レスポンス ペイロードにコピーします。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Storage-File-List">
    <DisplayName>Assign Storage File List</DisplayName>
    <AssignTo type="response" createNew="false"/>
    <Set>
        <Payload contentType="application/json">{storage.filelist.retrieved}</Payload>
    </Set>
</AssignMessage>

ファイルのダウンロード

次の ExtensionCallout ポリシーは、Google Cloud Storage 拡張機能を使用して、コンテンツが単に Some example text. である単純なテキスト ファイルをダウンロードします。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ConnectorCallout async="false" continueOnError="false" enabled="true" name="Download-File">
    <DisplayName>Download File</DisplayName>
    <Connector>cloud-storage-extension-example</Connector>
    <Action>downloadFile</Action>
    <Input><![CDATA[{"fileName": "example-text.txt"}]]></Input>
    <Output>storage.file.retrieved</Output>
</ConnectorCallout>

レスポンス値は次のようになります。

{"content":"Some example text."}

次の Assign Message ポリシーは、拡張機能から返された値を取得し、レスポンス ペイロードにコピーします。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Storage-File-List">
    <DisplayName>Assign Storage File List</DisplayName>
    <AssignTo type="response" createNew="false"/>
    <Set>
        <Payload contentType="application/json">{storage.file.retrieved}</Payload>
    </Set>
</AssignMessage>

署名付き URL を生成する

次の ExtensionCallout ポリシーは、この拡張機能を使用して、指定されたファイルを Cloud Storage バケットからダウンロードするための URL を生成します。このファイルには、ファイル名と、その URL が期限切れになり機能しなくなる日付を渡します。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ConnectorCallout async="false" continueOnError="false" enabled="true" name="Get-Signed-URL">
    <DisplayName>Get Signed URL</DisplayName>
    <Connector>cloud-storage-extension-example</Connector>
    <Action>generateSignedURL</Action>
    <Input><![CDATA[{
        "fileName" : "example-text.txt",
        "expiresOn" : "2018-08-05"
    }]]></Input>
    <Output>storage.url.retrieved</Output>
</ConnectorCallout>

拡張機能の戻り値は次のようになります。

{"url":"https://storage.googleapis.com/storage-extension-example/example-text.txt?GoogleAccessId=extension-test%40my-test-33333.iam.gserviceaccount.com&Expires=1533427200&Signature=Y1cE1DCHesWeIZILRhdIuDR%2FhzZXZ%2BPeY3J1PUkRiosFYj41itHBWh2%2BTQgH9kI6E8s2mWrVDFU43YR7s8Tm9W5VgWRwh0nXSactQ0xKbkKbGZmCcWxgIscOezc1zc%2Bp7lnXSx1qd4wIlIKVH4KCd9WLx4qB1dLxGNxMKB32tA3dio5IiMXaHEA%2FR2fYc0Pjh45t8L5rilk5pekv7jfd3sfsgdfgfdglkj%2F7E%2FlJ%2B60RnetqV2IDqrc0sVEgSLTpgTbDGU%2Ft3EcitRUFOSdOb5czt7CiIwKAYSmDEFMSNHHiNTWjvLzq4IU%2BCa4Z5aKyvww%3D%3D"}

次の Assign Message ポリシーは、拡張機能から返された値を取得し、レスポンスの本文にコピーします。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Storage-File-URL">
    <DisplayName>Assign Storage File URL</DisplayName>
    <AssignTo type="response" createNew="false"/>
    <Set>
        <Payload contentType="application/json">{storage.url.retrieved}</Payload>
    </Set>
</AssignMessage>

アクション

downloadFile

指定されたファイルをダウンロードします。

リクエスト パラメータ

パラメータ 説明 種類 デフォルト 必須
fileName ダウンロードするファイル。 文字列 なし。 はい、できます。

構文

<Input><![CDATA[{"fileName" : "the-file-to-download"}]]></Input>

<Input><![CDATA[{"fileName" : "example-text.txt"}]]></Input>

レスポンス

ダウンロードしたファイルの内容を持つオブジェクトを表す JSON。例:

{"content":"Some example text."}

listFiles

ダウンロード可能なファイルを一覧表示します。

リクエスト パラメータ

なし。

レスポンス

ファイル名の配列。例:

["example-text.txt","example-image.png"]

generateSignedURL

バケット内の指定されたファイルの署名付き URL を作成します。この URL を使用してファイルをダウンロードできます。

リクエスト パラメータ

パラメータ 説明 種類 デフォルト 必須
fileName 署名付き URL を生成する Cloud Storage オブジェクトの名前。 文字列 なし。 はい、できます。
expiresOn 署名付き URL が期限切れになる日付。 文字列 なし。 違います

構文

<Input><![CDATA[{
  "fileName" : "file-for-which-to-generate-url",
  "expiresOn" : "date-to-expire-url"
}]]></Input>

<Input><![CDATA[{
  "fileName" : "example-text.txt",
  "expiresOn" : "2018-08-05"
}]]></Input>

レスポンス

署名付き URL を使用してオブジェクトを表す JSON。例:

{"url":"https://storage.googleapis.com/storage-extension-example/example-text.txt?GoogleAccessId=extension-test%40my-test-33333.iam.gserviceaccount.com&Expires=1533427200&Signature=Y1cE1DCHesWeIZILRhdIuDR%2FhzZXZ%2BPeY3J1PUkRiosFYj41itHBWh2%2BTQgH9kI6E8s2mWrVDFU43YR7s8Tm9W5VgWRwh0nXSactQ0xKbkKbGZmCcWxgIscOezc1zc%2Bp7lnXSx1qd4wIlIKVH4KCd9WLx4qB1dLxGNxMKB32tA3dio5IiMXaHEA%2FR2fYc0Pjh45t8L5rilk5pekv7jfd3sfsgdfgfdglkj%2F7E%2FlJ%2B60RnetqV2IDqrc0sVEgSLTpgTbDGU%2Ft3EcitRUFOSdOb5czt7CiIwKAYSmDEFMSNHHiNTWjvLzq4IU%2BCa4Z5aKyvww%3D%3D"}

構成リファレンス

API プロキシで使用するためにこの拡張機能を構成およびデプロイする場合は、以下を使用します。Apigee コンソールを使用して拡張機能を構成する手順については、拡張機能の追加と構成をご覧ください。

共通の拡張プロパティ

すべての拡張機能には次のプロパティがあります。

プロパティ 説明 デフォルト 必須
name この拡張機能に付ける名前。 なし
packageName Apigee Edge から提供された拡張機能パッケージの名前。 なし
version 拡張機能を構成する拡張機能パッケージのバージョン番号。 なし
configuration 追加する拡張機能に固有の構成値。この拡張機能パッケージのプロパティをご覧ください。 なし

この拡張機能パッケージのプロパティ

プロパティ 説明 デフォルト 必須
bucketName この拡張機能がやり取りする GCS バケット。 なし。 はい、できます。