Skip to content

Commit bbeba63

Browse files
aishwaryabhliliankasemsurgupta-msftJoshLove-msft
committed
Implement SDK-binding tables converter (#1506)
--------- Co-authored-by: Lilian Kasem <likasem@microsoft.com> Co-authored-by: Surgupta <surgupta@microsoft.com> Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
1 parent 27a47c6 commit bbeba63

36 files changed

Lines changed: 1978 additions & 19 deletions

extensions/Worker.Extensions.Kafka/release_notes.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
- My change description (#PR/#issue)
55
-->
66

7-
### Microsoft.Azure.Functions.Worker.Extensions.Kafka 3.9.0
7+
### Microsoft.Azure.Functions.Worker.Extensions.Kafka <version>
88

9-
- Add `BindingCapabilities` attribute to KafkaTrigger to express function-level retry capabilities. (#1457)
10-
- Updated Kafka Extension nuget package to most recent version (3.9.0) (#1713)
11-
- Exposed an important scaling parameter `LagThreshold`` to let a user configure their scaling preferences within Kafka Trigger function. (#1713)
9+
- <entry>

extensions/Worker.Extensions.Shared/Configuration/ConfigurationExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

44
using System;

extensions/Worker.Extensions.Storage.Blobs/src/Config/BlobStorageBindingOptionsSetup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

44
using System;
@@ -61,4 +61,4 @@ public void Configure(string name, BlobStorageBindingOptions options)
6161
options.Credential = _componentFactory.CreateTokenCredential(connectionSection);
6262
}
6363
}
64-
}
64+
}

extensions/Worker.Extensions.Tables/release_notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66

77
### Microsoft.Azure.Functions.Worker.Extensions.Tables <version>
88

9-
- <entry>
9+
- <entry>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System;
5+
using Azure.Core;
6+
using Azure.Data.Tables;
7+
8+
namespace Microsoft.Azure.Functions.Worker.Extensions.Tables.Config
9+
{
10+
internal class TablesBindingOptions
11+
{
12+
public string? ConnectionString { get; set; }
13+
14+
public Uri? ServiceUri { get; set; }
15+
16+
public TokenCredential? Credential { get; set; }
17+
18+
public TableClientOptions? TableClientOptions { get; set; }
19+
20+
private TableServiceClient? TableServiceClient;
21+
22+
internal virtual TableServiceClient CreateClient()
23+
{
24+
if (ConnectionString is null && ServiceUri is null)
25+
{
26+
throw new ArgumentNullException(nameof(ConnectionString) + " " + nameof(ServiceUri));
27+
}
28+
29+
if (TableServiceClient is not null)
30+
{
31+
return TableServiceClient;
32+
}
33+
34+
TableServiceClient = !string.IsNullOrEmpty(ConnectionString)
35+
? new TableServiceClient(ConnectionString, TableClientOptions) // Connection string based auth;
36+
: new TableServiceClient(ServiceUri, Credential, TableClientOptions); // AAD auth
37+
38+
return TableServiceClient;
39+
}
40+
}
41+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System;
2+
using Azure.Data.Tables;
3+
using Microsoft.Extensions.Azure;
4+
using Microsoft.Extensions.Configuration;
5+
using Microsoft.Extensions.Options;
6+
7+
namespace Microsoft.Azure.Functions.Worker.Extensions.Tables.Config
8+
{
9+
internal class TablesBindingOptionsSetup : IConfigureNamedOptions<TablesBindingOptions>
10+
{
11+
private readonly IConfiguration _configuration;
12+
private readonly AzureComponentFactory _componentFactory;
13+
14+
private const string TablesServiceUriSubDomain = "table";
15+
16+
public TablesBindingOptionsSetup(IConfiguration configuration, AzureComponentFactory componentFactory)
17+
{
18+
_configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
19+
_componentFactory = componentFactory ?? throw new ArgumentNullException(nameof(componentFactory));
20+
}
21+
22+
public void Configure(TablesBindingOptions options)
23+
{
24+
Configure(Options.DefaultName, options);
25+
}
26+
27+
public void Configure(string name, TablesBindingOptions options)
28+
{
29+
if (string.IsNullOrWhiteSpace(name))
30+
{
31+
name = Constants.Storage; // default
32+
}
33+
34+
IConfigurationSection connectionSection = _configuration.GetWebJobsConnectionStringSection(name);
35+
36+
if (!connectionSection.Exists())
37+
{
38+
// Not found
39+
throw new InvalidOperationException($"Tables connection configuration '{name}' does not exist. " +
40+
"Make sure that it is a defined App Setting.");
41+
}
42+
43+
if (!string.IsNullOrWhiteSpace(connectionSection.Value))
44+
{
45+
options.ConnectionString = connectionSection.Value;
46+
}
47+
else
48+
{
49+
if (connectionSection.TryGetServiceUriForStorageAccounts(TablesServiceUriSubDomain, out Uri serviceUri))
50+
{
51+
options.ServiceUri = serviceUri;
52+
}
53+
}
54+
55+
options.TableClientOptions = (TableClientOptions)_componentFactory.CreateClientOptions(typeof(TableClientOptions), null, connectionSection);
56+
options.Credential = _componentFactory.CreateTokenCredential(connectionSection);
57+
}
58+
}
59+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Microsoft.Azure.Functions.Worker.Extensions.Tables
6+
{
7+
internal class Constants
8+
{
9+
internal const string Storage = "Storage";
10+
internal const string TablesExtensionName = "AzureStorageTables";
11+
internal const string TableName = "TableName";
12+
internal const string PartitionKey = "PartitionKey";
13+
internal const string RowKey = "RowKey";
14+
internal const string Connection = "Connection";
15+
internal const string Take = "Take";
16+
internal const string Filter = "Filter";
17+
// Media content types
18+
internal const string JsonContentType = "application/json";
19+
}
20+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<clear />
5+
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
6+
</packageSources>
7+
</configuration>
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4-
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;
4+
using System.Runtime.CompilerServices;
5+
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;
56

6-
[assembly: ExtensionInformation("Microsoft.Azure.WebJobs.Extensions.Tables", "1.1.0")]
7+
[assembly: ExtensionInformation("Microsoft.Azure.WebJobs.Extensions.Tables", "1.2.0-beta.1")]
8+
[assembly: InternalsVisibleTo("Microsoft.Azure.Functions.Worker.Extensions.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001005148be37ac1d9f58bd40a2e472c9d380d635b6048278f7d47480b08c928858f0f7fe17a6e4ce98da0e7a7f0b8c308aecd9e9b02d7e9680a5b5b75ac7773cec096fbbc64aebd429e77cb5f89a569a79b28e9c76426783f624b6b70327eb37341eb498a2c3918af97c4860db6cdca4732787150841e395a29cfacb959c1fd971c1")]
9+
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System;
5+
using Microsoft.Azure.Functions.Worker;
6+
using Microsoft.Azure.Functions.Worker.Core;
7+
using Microsoft.Azure.Functions.Worker.Extensions.Tables.Config;
8+
using Microsoft.Extensions.Azure;
9+
using Microsoft.Extensions.DependencyInjection;
10+
using Microsoft.Extensions.Options;
11+
12+
[assembly: WorkerExtensionStartup(typeof(TableExtensionStartup))]
13+
14+
namespace Microsoft.Azure.Functions.Worker
15+
{
16+
/// <summary>
17+
/// Table extension startup.
18+
/// </summary>
19+
public class TableExtensionStartup : WorkerExtensionStartup
20+
{
21+
/// <summary>
22+
/// Configure table extension startup.
23+
/// </summary>
24+
public override void Configure(IFunctionsWorkerApplicationBuilder applicationBuilder)
25+
{
26+
if (applicationBuilder == null)
27+
{
28+
throw new ArgumentNullException(nameof(applicationBuilder));
29+
}
30+
31+
applicationBuilder.Services.AddAzureClientsCore(); // Adds AzureComponentFactory
32+
applicationBuilder.Services.AddOptions<TablesBindingOptions>();
33+
applicationBuilder.Services.AddSingleton<IConfigureOptions<TablesBindingOptions>, TablesBindingOptionsSetup>();
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)