【发布时间】:2019-08-19 20:03:54
【问题描述】:
如果我正确阅读了 Microsoft 的文档并与一位在使用 Azure Functions 所利用的 Web 开发范例方面有一定经验的朋友交谈,我了解 Azure Functions 可能是 Internet 上的开放端点。粗略阅读有关该主题的安全论坛和堆栈溢出问题使我至少了解了几个保护它们的选项,即
上下文/我的 Azure 函数有什么作用?它管理与从 SFTP 源到 SQL 端点的供应商数据的 ETL 相关的 blob 容器,该 ETL 利用中间 blob 容器进行文件传输和源数据的长期冷存储。 Azure 函数在将 Blob 加载到 SQL 终结点后将其从一个容器移动到存档容器。为什么选择 Azure Function 来管理 blob 容器?
- SSIS 缺乏执行 blob 操作(即复制和删除)的能力
- 逻辑应用无法执行连接(加载到 SQL 端点的文件和 blob 容器中的文件名)
其中一个函数的示例如下所示:
using System.IO;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Net.Http;
using System.Net;
using Microsoft.WindowsAzure.Storage.Blob;
using System.Collections.Generic;
using System.Text;
namespace AFA_ArchiveBlob
{
public static class HttpTrigger_BlobInput
{
[FunctionName("HttpTrigger_BlobInput")]
public static async Task<HttpResponseMessage> Run(
//public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "{name}")] HttpRequest req,
string name,
ILogger log,
[Blob("{name}/blobname",FileAccess.ReadWrite,Connection = "AzureWebJobsStorage")] CloudBlobContainer myCloudBlobContainer
)
{
//Execution Logged.
log.LogInformation($"HttpTrigger_BlobInput - C# HTTP trigger function processed a request.");
//Run the query against the blob to list the contents.
BlobContinuationToken continuationToken = null;
List<IListBlobItem> results = new List<IListBlobItem>();
do
{
var response = await myCloudBlobContainer.ListBlobsSegmentedAsync(continuationToken);
continuationToken = response.ContinuationToken;
results.AddRange(response.Results);
}
while (continuationToken != null);
//Query the names of the blobs. Todo: can this be a single line linq query select instead?
List<string> listBlobNames = new List<string>();
foreach (CloudBlockBlob b in results)
{
listBlobNames.Add(b.Name);
}
//Serialize the list of blob names to json for passing to function caller via return statement
var jsonReturn = JsonConvert.SerializeObject(listBlobNames);
log.LogInformation("Returning the following JSON");
log.LogInformation(jsonReturn);
return new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(jsonReturn, Encoding.UTF8, "application/json")
};
}
}
}
【问题讨论】:
标签: azure security azure-active-directory azure-functions azure-logic-apps