【问题标题】:Azure Storage - How to get the static website URL programmatically?Azure 存储 - 如何以编程方式获取静态网站 URL?
【发布时间】:2022-01-05 04:06:56
【问题描述】:

我已在我的 Azure 存储帐户上启用静态网站。

我们使用主要服务 URL (mycontainer.blob.core.windows.net) 上传文件,并使用静态网站 URL (mycontainer.z6.web.core.windows.net) 提供这些文件。

应用程序具有容器的连接字符串,用于上传。但我需要知道生成的公共静态网站 URL 是什么。

是否有任何方法可以使用 REST API 从我的应用程序中以编程方式检索静态网站 URL? (我知道我可以使用 PowerShell 或 Azure Portal 来做到这一点,这不是我需要的。)

该应用程序托管在几个不同的环境中,我不希望主端点和 Web 端点都有单独的应用程序配置参数。我应该能够拥有单一的事实来源。

我正在使用 Node SDK (@azure/storage-blob)。我看到有一种方法可以使用 @azure/arm-storage,但这需要不同的身份验证方法,所以不是很好。

我什至准备自己将它缝合在一起,但我需要一种方法来弄清楚z6(在示例中)将是什么。

【问题讨论】:

标签: azure azure-blob-storage azure-storage


【解决方案1】:

借助存储帐户 REST API,您可以检索 Web 端点:https://docs.microsoft.com/en-us/rest/api/storagerp/storage-accounts/get-properties#storageaccountgetproperties

响应示例:

{
  "id": "/subscriptions/{subscription-id}/resourceGroups/res9407/providers/Microsoft.Storage/storageAccounts/sto8596",
  "kind": "Storage",
  "location": "eastus2(stage)",
  "name": "sto8596",
  "properties": {
    "keyCreationTime": {
      "key1": "2021-03-18T04:42:22.4322836Z",
      "key2": "2021-03-18T04:42:22.4322836Z"
    },
    "geoReplicationStats": {
      "status": "Live",
      "lastSyncTime": "2018-10-30T00:25:34Z",
      "canFailover": true
    },
    "isHnsEnabled": true,
    "creationTime": "2017-06-01T02:42:41.7633306Z",
    "networkAcls": {
      "bypass": "AzureServices",
      "defaultAction": "Allow",
      "ipRules": [],
      "virtualNetworkRules": [],
      "resourceAccessRules": [
        {
          "tenantId": "72f988bf-86f1-41af-91ab-2d7cd011db47",
          "resourceId": "/subscriptions/a7e99807-abbf-4642-bdec-2c809a96a8bc/resourceGroups/res9407/providers/Microsoft.Synapse/workspaces/testworkspace"
        }
      ]
    },
    "primaryEndpoints": {
      "web": "https://sto8596.web.core.windows.net/",
      "dfs": "https://sto8596.dfs.core.windows.net/",
      "blob": "https://sto8596.blob.core.windows.net/",
      "file": "https://sto8596.file.core.windows.net/",
      "queue": "https://sto8596.queue.core.windows.net/",
      "table": "https://sto8596.table.core.windows.net/",
      "microsoftEndpoints": {
        "web": "https://sto8596-microsoftrouting.web.core.windows.net/",
        "dfs": "https://sto8596-microsoftrouting.dfs.core.windows.net/",
        "blob": "https://sto8596-microsoftrouting.blob.core.windows.net/",
        "file": "https://sto8596-microsoftrouting.file.core.windows.net/",
        "queue": "https://sto8596-microsoftrouting.queue.core.windows.net/",
        "table": "https://sto8596-microsoftrouting.table.core.windows.net/"
      },
      "internetEndpoints": {
        "web": "https://sto8596-internetrouting.web.core.windows.net/",
        "dfs": "https://sto8596-internetrouting.dfs.core.windows.net/",
        "blob": "https://sto8596-internetrouting.blob.core.windows.net/",
        "file": "https://sto8596-internetrouting.file.core.windows.net/"
      }
    },
    "primaryLocation": "eastus2(stage)",
    "provisioningState": "Succeeded",
    "routingPreference": {
      "routingChoice": "MicrosoftRouting",
      "publishMicrosoftEndpoints": true,
      "publishInternetEndpoints": true
    },
    "encryption": {
      "services": {
        "file": {
          "keyType": "Account",
          "enabled": true,
          "lastEnabledTime": "2019-12-11T20:49:31.7036140Z"
        },
        "blob": {
          "keyType": "Account",
          "enabled": true,
          "lastEnabledTime": "2019-12-11T20:49:31.7036140Z"
        }
      },
      "keySource": "Microsoft.Storage"
    },
    "secondaryLocation": "northcentralus(stage)",
    "statusOfPrimary": "available",
    "statusOfSecondary": "available",
    "supportsHttpsTrafficOnly": false
  },
  "sku": {
    "name": "Standard_GRS",
    "tier": "Standard"
  },
  "tags": {
    "key1": "value1",
    "key2": "value2"
  },
  "type": "Microsoft.Storage/storageAccounts"
}

您可以找到具有以下 json 路径的 url:primaryEndpoints.web

【讨论】:

  • 谢谢。是的,这有我需要的信息,但令人沮丧的是我无法使用我的存储连接字符串或存储 SDK 来访问它,所以我需要添加一个全新的库、身份验证层和凭据,只是用于检索 'z6' :) 在这种情况下,我认为使用 URL 添加新的应用程序配置参数是较小的邪恶
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-28
  • 1970-01-01
  • 2019-06-05
相关资源
最近更新 更多