如何使用 http 客户端检索架构/将架构上传到 azure 架构注册表?

问题描述 投票:0回答:1

我正在尝试以编程方式从 Azure 架构注册表上传和检索架构。 看来,这不能通过 Terraform resssource 提供程序来完成,我希望能够通过管道上传模式。

我正在进行身份验证,并发送以下curl来检索我的架构组:

curl "https://management.azure.com/subscriptions/xxxx/resourceGroups/rg-event-hubs-cancellation-service-ab-dev/providers/Microsoft.EventHub/namespaces/evh-ns-cancellation-service-ab-dev/schemagroups/schgp-cancellation-service-ab-dev?api-version=2022-10-01-preview" -H "Accept: application/json" -H "Authorization: Bearer $(cat .ms_token)" | jq

我收到这样的回复:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   586  100   586    0     0    308      0  0:00:01  0:00:01 --:--:--   309
{
  "id": "/subscriptions/xxxx/resourceGroups/rg-event-hubs-cancellation-service-ab-dev/providers/Microsoft.EventHub/namespaces/evh-ns-cancellation-service-ab-dev/schemagroups/schgp-cancellation-service-ab-dev",
  "name": "schgp-cancellation-service-ab-dev",
  "type": "Microsoft.EventHub/Namespaces/SchemaGroups",
  "location": "North Europe",
  "properties": {
    "updatedAtUtc": "2023-10-22T14:26:46.6092604Z",
    "createdAtUtc": "2023-10-22T14:26:46.6092604Z",
    "eTag": "9aa2d9dc-1d85-4595-a29f-fcdc166d7867",
    "groupProperties": {},
    "schemaCompatibility": "Forward",
    "schemaType": "Avro"
  }
}

悬停,我被困在这里,没有指向模式或子实体的链接。 我尝试将“/schemas”和“/schema”添加到 URL 路径,但出现以下错误:

"Resource Provider does not support any route matching the request URI. If this is a request for an entity with multi-segment names, encode '/' with '~' in the entity name."

有人可以告诉我如何从 HTTP 客户端检索/上传模式吗?

azure avro azure-eventhub
1个回答
0
投票

我的理解如下: eventhubs 的 REST 文档列出了 API 被分成的

  • 控制平面,其 REST 端点以“management.core.windows.net”开头
  • 数据平面,其 REST 端点以
    eventhubs.azure.net
  • 开头

您可以使用管理 API 端点检索架构组,如问题中所写:

curl "https://management.azure.com/subscriptions/xxxx/resourceGroups/rg-event-hubs-cancellation-service-ab-dev/providers/Microsoft.EventHub/namespaces/evh-ns-cancellation-service-ab-dev/schemagroups/schgp-cancellation-service-ab-dev?api-version=2022-10-01-preview" -H "Accept: application/json" -H "Authorization: Bearer $TOKEN" 

您可以通过调用数据平面 REST 端点(此处使用 httpie)来检索模式列表

https -a $TOKEN -A bearer "$BASE/\$schemagroups/schgp-cancellation-service-ab-dev/schemas?api-version=2022-10"

哪里

BASE=https://<your-eventhub-namespace>.https://evh-ns-cancellation-service-ab-dev.servicebus.windows.net

愚弄我的是,您需要为管理端点使用不同的承载令牌,为数据平面端点使用不同的承载令牌。

可以通过以下调用获取 Bearer 令牌:

curl https://login.microsoftonline.com/$AZURE_TENANT_ID/oauth2/token \
     -H "Content-Type: application/x-www-form-urlencoded" \
     --data "grant_type=client_credentials&client_id=$AZURE_CLIENT_ID&client_secret=$AZURE_CLIENT_SECRET&resource=$RESOURCE"

其中

RESOURCE=https://management.core.windows.net
用于访问管理平面,
RESOURCE=https://eventhubs.azure.net
用于访问数据平面。

© www.soinside.com 2019 - 2024. All rights reserved.