-
Notifications
You must be signed in to change notification settings - Fork 73
/
ShowBetaFeature.cs
45 lines (38 loc) · 1.84 KB
/
ShowBetaFeature.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
40
41
42
43
44
45
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
using Microsoft.Extensions.Logging;
using Microsoft.FeatureManagement;
namespace FunctionApp
{
public class ShowBetaFeature
{
private readonly IFeatureManagerSnapshot _featureManagerSnapshot;
private readonly IConfigurationRefresher _configurationRefresher;
public ShowBetaFeature(IFeatureManagerSnapshot featureManagerSnapshot, IConfigurationRefresherProvider refresherProvider)
{
_featureManagerSnapshot = featureManagerSnapshot;
_configurationRefresher = refresherProvider.Refreshers.First();
}
[FunctionName("ShowBetaFeature")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
// Signal to refresh the feature flags from Azure App Configuration.
// This will be a no-op if the cache expiration time window is not reached.
// Remove the 'await' operator if it's preferred to refresh without blocking.
await _configurationRefresher.TryRefreshAsync();
string featureName = "Beta";
bool featureEnalbed = await _featureManagerSnapshot.IsEnabledAsync(featureName);
return featureEnalbed
? (ActionResult)new OkObjectResult($"{featureName} feature is On")
: new BadRequestObjectResult($"{featureName} feature is Off (or the feature flag '{featureName}' is not present in Azure App Configuration).");
}
}
}