Skip to content

Adding support for parameter binding as an input to the in-process extension #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;

namespace Lib.Azure.WebJobs.Extensions.WebPush.Bindings
{
internal class PushServiceParameterBindingDataContent
{
public string PublicKey { get; set; }

public string PrivateKey { get; set; }

public string Subject { get; set; }

public bool AutoRetryAfter { get; set; }

public int MaxRetriesAfter { get; set; }

public int? DefaultTimeToLive { get; set; }

public PushServiceParameterBindingDataContent(PushServiceAttribute attribute, PushServiceOptions options)
{
PublicKey = !String.IsNullOrEmpty(attribute.PublicKeySetting) ? attribute.PublicKeySetting : options?.PublicKey;
PrivateKey = !String.IsNullOrEmpty(attribute.PrivateKeySetting) ? attribute.PrivateKeySetting : options?.PrivateKey;
Subject = !String.IsNullOrEmpty(attribute.SubjectSetting) ? attribute.SubjectSetting : options?.Subject;
AutoRetryAfter = attribute.AutoRetryAfter;
MaxRetriesAfter = attribute.MaxRetriesAfter;
DefaultTimeToLive = attribute.DefaultTimeToLive;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using System;
using System.Net.Http;
using Microsoft.Extensions.Options;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Description;
using Microsoft.Azure.WebJobs.Host.Config;
using Lib.Azure.WebJobs.Extensions.WebPush.Bindings;
using Lib.Net.Http.WebPush;

namespace Lib.Azure.WebJobs.Extensions.WebPush.Config
{
[Extension("PushService")]
[Extension(Constants.PushServiceExtensionName)]
internal class PushServiceExtensionConfigProvider : IExtensionConfigProvider
{
private readonly PushServiceOptions _options;
Expand All @@ -32,6 +33,7 @@ public void Initialize(ExtensionConfigContext context)
bindingAttributeBindingRule.AddValidator(ValidateVapidAuthentication);

bindingAttributeBindingRule.BindToInput<PushServiceClient>(typeof(PushServiceClientConverter), _options, _httpClientFactory);
bindingAttributeBindingRule.BindToInput<ParameterBindingData>(CreateParameterBindingData);
}

private void ValidateVapidAuthentication(PushServiceAttribute attribute, Type paramType)
Expand All @@ -50,5 +52,14 @@ private void ValidateVapidAuthentication(PushServiceAttribute attribute, Type pa
throw new InvalidOperationException($"The application server private key must be set either via the {attributeProperty} property or via {optionsProperty}.");
}
}

internal ParameterBindingData CreateParameterBindingData(PushServiceAttribute attribute)
{
var pushServiceParameterBindingData = new PushServiceParameterBindingDataContent(attribute, _options);
var pushServiceParameterBinaryData = new BinaryData(pushServiceParameterBindingData);
var parameterBindingData = new ParameterBindingData("1.0", Constants.PushServiceExtensionName, pushServiceParameterBinaryData, "application/json");

return parameterBindingData;
}
}
}
7 changes: 7 additions & 0 deletions src/Lib.Azure.WebJobs.Extensions.WebPush/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Lib.Azure.WebJobs.Extensions.WebPush
{
internal static class Constants
{
internal const string PushServiceExtensionName = "PushService";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Description>This package contains Azure Functions and Azure WebJobs binding extensions for Web Push Protocol based client for Push Service.</Description>
<Tags>Azure WebJobs AzureFunctions WebPush</Tags>
<Copyright>Copyright © 2019 - 2024 Tomasz Pęczek</Copyright>
<VersionPrefix>1.4.1</VersionPrefix>
<VersionPrefix>1.5.0</VersionPrefix>
<Authors>Tomasz Pęczek</Authors>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyTitle>Lib.Azure.WebJobs.Extensions.WebPush</AssemblyTitle>
Expand All @@ -29,7 +29,7 @@
<None Include="..\..\README.md" Pack="true" PackagePath="\"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.0" />
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.37" />
<PackageReference Include="Microsoft.Extensions.Http" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
Expand Down
Loading