Google Cloud Storage 擴充功能

您正在查看 Apigee Edge 說明文件。
前往 Apigee X 說明文件
info

版本:2.0.0

列出、下載及產生 Cloud Storage 值區中檔案的已簽署 URL。

本內容提供設定和使用此擴充功能的參考資訊。在透過 API 代理程式使用這個擴充功能前,您必須:

  1. 建立 Cloud Storage 值區

  2. 將物件上傳至 bucket。

  3. 將存取值區的權限授予代表 Google Cloud Storage 擴充功能的 GCP 服務帳戶。如要進一步瞭解應使用的角色,請參閱「Cloud Storage 角色」。如要進一步瞭解 Cloud Storage 中的權限,請參閱「使用身分與存取權管理 (IAM) 權限」。

  4. 使用 GCP 主控台為服務帳戶產生金鑰

  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"]

以下的「指派訊息」政策會從上述的「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."}

以下的「指派訊息」政策會擷取擴充功能傳回的值,並將該值複製到回應酬載中。

<?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>

產生已簽署網址

以下的 ExtensionCallout 政策會使用這項擴充功能,產生網址,用於從 Cloud Storage 值區下載指定檔案。它會傳遞檔案名稱,以及網址到期後的日期,屆時網址就會失效。

<?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"}

以下的「指派訊息」政策會擷取擴充功能傳回的值,並將該值複製到回應主體。

<?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

為值區中指定的檔案建立已簽署的網址。這個網址可用於下載檔案。

要求參數

參數 說明 類型 預設 必填
fileName 要產生已簽署網址的 Cloud Storage 物件名稱。 字串 無。 是。
expiresOn 已簽署網址的到期日。 字串 無。 不會。

語法

<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>

回應

代表含有已簽署網址的物件的 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 值區。 無。 是。