我们想通过 Azure Functions 将 bacpac 文件从 Blob 存储导入 Azure SQL 服务器,这是 Blob 触发函数。
我们已经实现它如下
log.Info($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
var apimUrl = "https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/sqlRG/providers/Microsoft.Sql/servers/sqldev/import?api-version=2014-04-01";
var content = "{'databaseName': 'TestDbImport'," +
"'edition': 'Basic'," +
"'serviceObjectiveName': 'Basic'," +
"'maxSizeBytes': '2147483648'," +
"'storageKeyType': 'SharedAccessKey'," +
"'storageKey': 'xxxxxxx'," +
"'storageUri': 'https://account.blob.core.windows.net/sql-backup/test.bacpac'," +
"'administratorLogin': 'user'," +
"'administratorLoginPassword': 'password'," +
"'authenticationType': 'SQL'}";
HttpClient Client = new HttpClient();
var AADToken = "token";
Client = new HttpClient();
Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AADToken);
Client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key","subKey");
var foo = Client.PostAsync(apimUrl, new StringContent(content.ToString())).Result;
log.Info($"result: {foo}");
我需要帮助来了解如何获取 AADToken 以及需要传入标头以验证此请求的 subKey(我也很困惑,为什么我需要在 Azure 本身执行所有内容时进行身份验证)
如果我不传递标头,则会得到 401(未经授权)错误代码。