public static async Task Run( [BlobTrigger("azure-ip-files/{name}.json")] Stream awsIpFile, ILogger log, [Table("IpAddresses")] CloudTable table) { try { var ipData = await JsonSerializer.DeserializeAsync <AzureIpFile>(awsIpFile); var entities = ipData.Values.SelectMany(value => { return(value.Properties.AddressPrefixes.Select(prefix => new IPAddressEntity("Azure", value.Properties.Region, value.Properties.SystemService, prefix))); }).ToList(); foreach (var batch in IPAddressEntity.Chunk(entities)) { var batchOperation = new TableBatchOperation(); foreach (var operation in batch) { batchOperation.InsertOrReplace(operation); } await table.ExecuteBatchAsync(batchOperation); } } catch (Exception e) { log.LogError(e, "Failed to import IP ranges"); throw; } }
public static async Task Run( [BlobTrigger("aws-ip-files/{name}.json")] Stream awsIpFile, ILogger log, [Table("IpAddresses")] CloudTable table) { try { var ipData = await JsonSerializer.DeserializeAsync <AwsIpFile>(awsIpFile); var entities = ipData.Prefixes .Concat <AwsIpPrefix>(ipData.Ipv6Prefixes) .GroupBy(prefix => prefix.IpPrefix) .Select(prefix => { var distinctRecord = prefix.First(); return(new IPAddressEntity("AWS", distinctRecord.Region, distinctRecord.Service, distinctRecord.IpPrefix)); }) .ToList(); foreach (var batch in IPAddressEntity.Chunk(entities)) { var batchOperation = new TableBatchOperation(); foreach (var operation in batch) { batchOperation.InsertOrReplace(operation); } await table.ExecuteBatchAsync(batchOperation); } } catch (Exception e) { log.LogError(e, "Failed to import IP ranges"); throw; } }