-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathIngestBlobToKusto.cs
39 lines (37 loc) · 1.9 KB
/
IngestBlobToKusto.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
using System.Threading.Tasks;
using System.Web;
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
using Azure.Storage.Sas;
using Microsoft.Azure.WebJobs.Kusto;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
namespace Microsoft.Azure.WebJobs.Extensions.Kusto.Samples.BlobTriggerIngestSample
{
public class IngestBlobToKusto
{
[FunctionName("IngestBlobToKusto")]
public static async Task Run(
[BlobTrigger("samples-blob-ingest/{name}", Connection = "StorageConnectionString")] BlobClient blobClient, string name, IBinder binder, ILogger logger)
{
BlobProperties blobProperties1 = await blobClient.GetPropertiesAsync();
logger.LogInformation("Blob sample-container/{name} has been updated on: {datetime}", name, blobProperties1.LastModified);
// Create a SAS token that's valid for one hour.
Uri sasToken = blobClient.GenerateSasUri(BlobSasPermissions.Read, DateTimeOffset.Now.AddHours(1));
string blobUploadUri = HttpUtility.UrlDecode(sasToken.OriginalString);
logger.LogTrace("SAS token for blob sample-container is: {sasToken}", blobUploadUri);
string ingestCommand = $".ingest into table eshopclothing ('{blobUploadUri}')";
var kustoIngest = new KustoAttribute("e2e")
{
Connection = "KustoConnectionString",
KqlCommand = ingestCommand
};
logger.LogInformation("Ingest command is: {ingestCommand}", ingestCommand);
JArray ingestResult = await binder.BindAsync<JArray>(kustoIngest);
logger.LogInformation("Ingestion result {ingestResult}", ingestResult);
}
}
}