包裝程式 API 套裝程式元件

包裝函式 API 套件包含包裝函式 API 的封存檔案、用於部署的 Terraform 指令碼,以及對應的 Postman 集合。

  • 包裝程式 API 封存檔案的名稱為 <ChaincodeName>WrapperAPI.zip。它也包含必須部署至堆疊資源的 Terraform 命令檔。
  • Postman 集合檔案的名稱為 <ChaincodeName>_WrapperAPI.postman_collection.json。您可以使用此集合來呼叫所有包裝函式 API。

包裝程式 API 套裝程式

包裝函式 API 套裝程式包含 Terraform 命令檔,可佈建建立包裝函式 API 所需的所有 Oracle Cloud Infrastructure (OCI) 資源。每個 API 都有額外的 Terraform 支援檔案和一個 Oracle Functions 資料夾。包裝程式 API 套裝程式會建立下列 OCI 資源。

  • 虛擬雲端網路 (VCN):建立通訊的網路基礎架構。
  • 應用程式 (Oracle Functions):部署無伺服器函數以處理 API 邏輯。
  • API 閘道:建立閘道以管理及路由 API 要求。
  • API 部署:在 API 閘道上設定和部署 API。
  • API 部署原則:設定必要的 IAM 原則以啟用安全存取。
  • OCI 登錄:提供用於管理 Docker 映像檔的容器登錄檔。
After you generate wrapper APIs, if you want to change any configuration variables, you can update them in Visual Studio Code, or you can extract the wrapper API package and update the terraform.tfvars file with updated endpoints and resource names and the routes.go file with updated endpoints.編輯 terraform.tfvars 檔案中的 function_paths 變數以更新端點。function_paths 變數使用下列語法定義端點:{endpoint, methodType}。下列文字顯示 function_paths 變數的範例。
function_paths="[{\"endpoint\":\"/activateCBDCAccount\",\"methodType\":[\"POST\"]},{\"endpoint\":\"/addCBAdmin\",\"methodType\":[\"POST\"]},{\"endpoint\":\"/approveBurn\",\"methodType\":[\"POST\"]}]"
routes.go 檔案位於 <ChaincodeName>OCIFunction 資料夾中。routeData 變數包含閘道中建立之所有路由的描述資料,包括路由名稱、引數,以及是否有選擇性引數。當您更新 terraform.tfvars 檔案中 function_paths 變數的端點時,也必須更新 routes.go 檔案中 routeData 變數的對應項目,如下列範例所示。
var routeData = map[string]Route{
    "/activateCBDCAccount": {
        Args:           []string{"activateAccount", "orgId", "userId", "tokenId"},
        OptionalParams: true,
    },
}

Postman Collection

Postman Collection 現在支援機密鏈碼和 OAuth 2.0 認證。如需詳細資訊,請參閱 Postman Collections 的增強功能

Postman 集合包括所有 API 的更新端點和有效負載。下列程式碼顯示有效負載範例。
{
    "orgId": "{{bc-org-id}}",
    "userId": "user1",
    "tokenType": "fungible",
    "applicationGroups": "[\"application_groups value\"]",
    "dailyLimits": "{\"max_daily_amount\":10000,\"max_daily_transactions\":100}",
    "endorsers": {{endorsers}}
}
下表顯示 Postman Collection 變數。
變數 描述 預設值
bc-admin-user 具有 admin 角色且可存取所有 POST 要求的管理使用者。依預設,此使用者是鏈碼中所有 POST 要求的呼叫者。 bc-admin-user 值
bc-admin-user-password 管理使用者密碼。 bc-admin-user-password 值
bc-org-id 所有 POST 要求中的預設組織 ID,其中 orgId 是參數名稱 bc-org-id 值
bc-user-id 所有 POST 要求中的預設使用者 ID,其中 userId 是參數名稱 bc-user-id 值
bc-token-id 所有 POST 要求中的預設記號 ID,其中 tokenId 是參數名稱 bc-token-id 值
endorsers 背書人陣列會列出特定對等 (例如:peer1、peer2) 以背書此交易。 ["org1-xyz-abc.blockchain.ocp.oraclecloud.com:20009", "org2-xyz-abc.blockchain.ocp.oraclecloud.com:20009"]
api-gateway-endpoint 每個要求的端點,作為包裝函式 API 端點的基礎路徑。

如果 API 少於 50 個,則會使用單一端點。如果 API 數目超過 50 個,端點會根據 API 數目動態產生為 api-gateway-endpoint1api-gateway-endpoint2 等等。

https://xyz.apigateway.region.oci.customer-oci.com/CBDC
bc-url Oracle Blockchain Platform 執行處理的 REST 代理主機 URL。 https://test-xyz-abc.blockchain.ocp.oraclecloud.com:7443/restproxy
access-token-url Oracle Identity Cloud Service (IDCS) 存取權杖 URL。例如:<idcs_endpoint>/oauth/v1/token access-token-url 值
client-id Oracle Blockchain Platform 執行處理的用戶端 ID。 客戶端 ID
client-secret Oracle Blockchain Platform 執行處理的用戶端密碼。 客戶機密
peer 此變數僅存在於機密鏈碼包裝程式 API Postman 集合中,此集合需要所有 setter 和 getter API 的對等標頭。 組織 -xyz-abc.blockchain.ocp.oraclecloud.com:20009

部署包裝函式 API 套裝程式之後,堆疊資源部署的輸出為包含閘道端點值的 JSON 物件。如果產生 50 個以上的 API,則會產生多個閘道端點,每 50 個 API 各產生一個 API。您必須更新與這些端點相關的 Postman 收集變數。Postman 集合中的端點相關變數必須使用「堆疊資源管理程式」中包裝程式 API 套裝程式部署輸出的適當值來更新。

包裝程式 API Postman 集合中的所有 setter API 都包含要求有效負載中的 endorserssameOrgEndorser 參數。指定需要 sameOrgEndorser 參數之 API 的資訊,是在鏈碼中 .ochain.json 檔案的 sameOrgEndorserOptionInWrapperAPI 參數中定義。此參數中所列的 API 在其有效負載中將 sameOrgEndorser 設為 true。所有其他的 setter API 將改為包含 endorsers 參數。下列範例顯示批發 CBDC 鏈碼的參數。
"sameOrgEndorserOptionInWrapperAPI": ["addConversionRate","addTokenAdmin","addTokenAuditor","approveBurn","approveMint","burnTokens","createExchangePoolAccounts","deleteHistoricalTransactions","initializeCBDCToken","initializeExchangePoolUser","mintWithFundingExchangePool","rejectBurn","rejectMint","removeTokenAdmin","removeTokenAuditor","requestBurn","requestMint","updateCBDCToken","updateConversionRate"]
您可以視需要自訂 .ochain.json 檔案中的 sameOrgEndorserOptionInWrapperAPI 參數。當您產生包裝函式 API 時,指定的 API 會在其有效負載中包含 sameOrgEndorser 參數作為 true