重要事項
本文中的部分資訊與發行前版本產品有關,在產品正式發行前可能會大幅度修改。 Microsoft 對此處提供的資訊,不提供任何明確或隱含的瑕疵擔保。
代理程式開發人員通常需要發出 HTTP 請求來建立完整的使用案例。
此範例示範如何建立代理程式,以利用外掛程式搭配 API 工具,連線到名為 freeipapi.com的 REST API 服務,該服務提供 Geo-IP 查閱功能。
整個過程如下:
步驟 1:建立並發佈定義 API 的 OpenAPI 規格
步驟 2:建立資訊清單檔案並將其上傳至 Security Copilot
步驟 3:建立並上傳使用外掛程式的代理程式
步驟 4:將套件發佈至安全性存放區 (僅適用於合作夥伴代理程式)
注意事項
如需使用 API 工具 (技能) 的資訊清單 YAML 範例,請參閱 使用多個工具建置代理程式。 它提供如何上傳代理程式、設定和執行在「作用中代理程式」頁面上發佈的代理程式的指示。
步驟 1:建立並發佈 OpenAPI 規格
此範例與免費 IP REST API 整合,以執行 IP 位址地理位置查詢。 您必須在線上發佈此規格 (GitHub gist 運作良好) 。 請參閱下列範例來建立及代管您的規格。 如需驗證的範例,請參閱 驗證類型。
openapi: 3.0.0
info:
title: Free IP API
description: A free IP lookup API
version: "v1"
servers:
- url: https://freeipapi.com/api/
paths:
/json/{ipaddress}:
get:
operationId: lookupIpAddressGeolocation
summary: Lookup IP Address Geolocation information
parameters:
- in: path
name: ipaddress
schema:
type: string
required: true
description: The ip address to lookup
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/lookupIpAddressGeolocationResponse"
components:
schemas:
lookupIpAddressGeolocationResponse:
type: object
properties:
ipVersion:
type: integer
description: The IP address version
ipAddress:
type: string
description: The IP address
latitude:
type: number
description: The latutude
longitude:
type: number
description: The longitude
countryName:
type: string
description: The country
zipCode:
type: string
description: The zip code
cityName:
type: string
description: The city
regionName:
type: string
description: The region
continent:
type: string
description: The continent
步驟 2:建立並上傳 API 資訊清單 (外掛程式)
建立名為工具格式
API的檔案http_manifest.yaml。Descriptor: Name: DCA_SampleAPIPlugin DisplayName: TESTDCA_Free IP API Description: Skills for looking up geolocation information for an IP address using the Free IP API SkillGroups: - Format: API Settings: OpenApiSpecUrl: <Reference to your openapispec.yaml schema created in Step 1> EndpointUrl: https://sampleurl <The server endpoint that is hosting the API>將 yaml 上傳至 Security Copilot。 上傳 YAML 的指示請參閱 建置代理程式資訊清單。
注意事項
您必須完成設定步驟,外掛程式才能使用,並顯示在 「自訂」 區段中。 只有在資訊清單 YAML 具有) 定義代理程式定義 (
AgentDefinitions時,上傳的 YAML 或資訊清單才會以代理程式的形式發佈至作用中代理程式。您可以導覽至提示中的「系統功能」,然後搜尋
lookupIpAddressGeolocation,這是operationId您在步驟 1 中定義的 API 規格中的值,以測試此工具或外掛程式。會顯示執行工具後的回應。
步驟 3:建立並上傳使用 API 外掛程式的代理程式
現在,上傳使用 API 外掛程式的代理程式。
上傳代理程式時,請確定您在新增外掛程式畫面中選擇此工作區中的任何人。
將代理程式 YAML 上傳至 Security Copilot。
步驟 4: (選擇性的) 將套件發佈至安全性存放區
此步驟僅適用於開發必須發佈至安全性存放區的代理程式的合作夥伴。
將 API 資訊清單發佈至安全性存放區的重要考量:
將套件發佈至安全性存放區時,必須
openapispec.yaml包含在套件中。必須
OpenApiSpecUrl參考套件內的本機檔案路徑。是
EndpointUrlOpenAPI 規格的公開託管端點。如果在 Open API 規格中參照 ,
ChildSkills請確定 OpenAPISpec 的廣域 URL 及本端 OpenAPISpec yaml 是最新的。必須
openapispec.yaml與代理程式資訊清單 yaml (http_manifest.yaml) 位於相同的資料夾中,且必須遵循命名慣例:openapispec_<number>.yaml。