Reputation: 1566
I've enabled Static Website on my Azure Storage account.
We are uploading files there using the primary service URL (mycontainer.blob.core.windows.net
), and making those files available using the static website URL (mycontainer.z6.web.core.windows.net
).
The app has the connection string for the container, for uploading. But I need to know what the resultant public static website URL will be.
Is there any way to programmatically retrieve the static website URL, from within my app, using the REST API? (I know I can do it with PowerShell or Azure Portal, that's not what I need here.)
The app is hosted in a few different environments, and I don't want to have a separate app config param for both the primary and web endpoints. I should be able to have a single source of truth.
I'm using the Node SDK (@azure/storage-blob
). I see there's a way to do it with @azure/arm-storage
, but that would require a different authentication method so is not great.
I'm even prepared to stitch it together myself, but I need a way to figure out what the z6
(in the example) is going to be.
Upvotes: 0
Views: 1390
Reputation: 829
You can retrieve the web endpoint thanks to the storage account REST API : https://learn.microsoft.com/en-us/rest/api/storagerp/storage-accounts/get-properties#storageaccountgetproperties
Response example :
{
"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"
}
You can find the url with the following json path : primaryEndpoints.web
Upvotes: 2