Skip to content

Commit 29775bf

Browse files
authored
docs: correct az func secret store docs (#362)
1 parent f3b42d2 commit 29775bf

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

docs/preview/03-Features/secret-store/azure-functions.md

+50-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ layout: default
44
---
55

66
# Using secret store within Azure Functions
7+
This separate documentation section explains how the Arcus secret store can be used within Azure Functions environments (both in-process and isolated).
8+
9+
## Using secret store within in-process Azure Functions
10+
To more easily configure the secret store, we provided a dedicated package that builds on top of the `IFunctionsHostBuilder`:
711

812
## Installation
913
For this feature, the following package needs to be installed:
@@ -12,9 +16,8 @@ For this feature, the following package needs to be installed:
1216
PM > Install-Package Arcus.Security.AzureFunctions
1317
```
1418

15-
## Usage
19+
### Usage
1620
The secret stores are configured during the initial application build-up in the `Startup.cs`:
17-
1821
```csharp
1922
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
2023
using Microsoft.Extensions.Configuration;
@@ -32,15 +35,14 @@ namespace MyHttpAzureFunction
3235
{
3336
var keyVaultName = config["KeyVault_Name"];
3437
stores.AddEnvironmentVariables()
35-
.AddAzureKeyVaultWithManagedServiceIdentity($"https://{keyVaultName}.vault.azure.net");
38+
.AddAzureKeyVaultWithManagedIdentity($"https://{keyVaultName}.vault.azure.net");
3639
})
3740
}
3841
}
3942
}
4043
```
4144

4245
Once the secret providers are defined, the `ISecretProvider` can be used as any other registered service:
43-
4446
```csharp
4547
using Arcus.Security.Core;
4648

@@ -62,3 +64,47 @@ namespace Application
6264
}
6365
}
6466
```
67+
68+
## Using secret store within isolated Azure Functions
69+
Since isolated Azure Functions are built with the default `HostBuilder`, the general secret store packages can be used in this environment. No need to install the dedicated `Arcus.Security.AzureFunctions` package.
70+
71+
### Usage
72+
Using the available extensions on the `HostBuilder` or `IServiceCollection`, the secret store can be added, just like a Web API or console application.
73+
74+
```csharp
75+
var host = new HostBuilder()
76+
.ConfigureFunctionsWorkerDefaults(builder =>
77+
{
78+
79+
})
80+
.ConfigureSecretStore((context, config, stores) =>
81+
{
82+
builder.AddEnvironmentVariables()
83+
.AddAzureKeyVaultWithManagedIdentity($"https://{keyVaultName}.vault.azure.net");
84+
})
85+
.Build();
86+
```
87+
88+
Once the secret providers are defined, the `ISecretProvider` can be used as any other registered service:
89+
```csharp
90+
using Arcus.Security.Core;
91+
92+
namespace Application
93+
{
94+
public class MyHttpTrigger
95+
{
96+
public MyHttpTrigger(ISecretProvider secretProvider)
97+
{
98+
}
99+
100+
[Function("MyHttpTrigger")]
101+
public HttpResponseData Run(
102+
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestData req,
103+
ILogger log)
104+
{
105+
var response = req.CreateResponse(HttpStatusCode.OK);
106+
return response;
107+
}
108+
}
109+
}
110+
```

docs/preview/03-Features/secret-store/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public class Program
8888
#endif
8989
var keyVaultName = config["KeyVault_Name"];
9090
builder.AddEnvironmentVariables()
91-
.AddAzureKeyVaultWithManagedServiceIdentity($"https://{keyVaultName}.vault.azure.net");
91+
.AddAzureKeyVaultWithManagedIdentity($"https://{keyVaultName}.vault.azure.net");
9292
})
9393
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>());
9494
}

0 commit comments

Comments
 (0)