Skip to content

Commit 9e01969

Browse files
justinyooDerich367
authored andcommitted
Add built-in OpenAPI app settings object (Azure#525)
1 parent ea1fb82 commit 9e01969

File tree

16 files changed

+518
-25
lines changed

16 files changed

+518
-25
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Configurations
2+
{
3+
/// <summary>
4+
/// This represents the environment variable settings entity for OpenAPI document auth level.
5+
/// </summary>
6+
public class OpenApiAuthLevelSettings
7+
{
8+
/// <summary>
9+
/// Gets or sets the <see cref="AuthorizationLevel"/> value for OpenAPI document rendering endpoints.
10+
/// </summary>
11+
public virtual AuthorizationLevel? Document { get; set; }
12+
13+
/// <summary>
14+
/// Gets or sets the <see cref="AuthorizationLevel"/> value for Swagger UI page rendering endpoints.
15+
/// </summary>
16+
public virtual AuthorizationLevel? UI { get; set; }
17+
}
18+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums;
2+
3+
namespace Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Configurations
4+
{
5+
/// <summary>
6+
/// This represents the environment variable settings entity for OpenAPI document.
7+
/// </summary>
8+
public class OpenApiSettings
9+
{
10+
/// <summary>
11+
/// Gets the name of the collection of the environment variables for OpenAPI.
12+
/// </summary>
13+
public const string Name = "OpenApi";
14+
15+
/// <summary>
16+
/// Gets or sets the OpenAPI spec version.
17+
/// </summary>
18+
public virtual OpenApiVersionType Version { get; set; }
19+
20+
/// <summary>
21+
/// Gets or sets the OpenAPI document version.
22+
/// </summary>
23+
public virtual string DocVersion { get; set; }
24+
25+
/// <summary>
26+
/// Gets or sets the OpenAPI document title.
27+
/// </summary>
28+
public virtual string DocTitle { get; set; }
29+
30+
/// <summary>
31+
/// Gets or sets the OpenAPI document description.
32+
/// </summary>
33+
public virtual string DocDescription { get; set; }
34+
35+
/// <summary>
36+
/// Gets or sets the comma delimited host names.
37+
/// </summary>
38+
public virtual string HostNames { get; set; }
39+
40+
/// <summary>
41+
/// Gets or sets the value indicating whether to force the HTTPS connection or not.
42+
/// </summary>
43+
public virtual bool ForceHttps { get; set; }
44+
45+
/// <summary>
46+
/// Gets or sets the value indicating whether to force the HTTP connection or not.
47+
/// </summary>
48+
public virtual bool ForceHttp { get; set; }
49+
50+
/// <summary>
51+
/// Gets or sets the value indicating whether to hide the Swagger UI page or not.
52+
/// </summary>
53+
public virtual bool HideSwaggerUI { get; set; }
54+
55+
/// <summary>
56+
/// Gets or sets the value indicating whether to hide the OpenAPI document pages or not.
57+
/// </summary>
58+
public virtual bool HideDocument { get; set; }
59+
60+
/// <summary>
61+
/// Gets or sets the API key to access to OpenAPI document.
62+
/// </summary>
63+
public virtual string ApiKey { get; set; }
64+
65+
/// <summary>
66+
/// Gets or sets the <see cref="OpenApiAuthLevelSettings"/> object.
67+
/// </summary>
68+
public virtual OpenApiAuthLevelSettings AuthLevel { get; set; } = new OpenApiAuthLevelSettings();
69+
70+
/// <summary>
71+
/// Gets or sets the backend URL for Azure Functions Proxy.
72+
/// </summary>
73+
public virtual string BackendProxyUrl { get; set; }
74+
}
75+
}

src/Microsoft.Azure.Functions.Worker.Extensions.OpenApi/HttpRequestObject.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
using System.Collections.Generic;
12
using System.IO;
23
using System.Linq;
4+
using System.Security.Claims;
35

46
using Microsoft.AspNetCore.Http;
57
using Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Extensions;
@@ -29,6 +31,7 @@ public HttpRequestObject(HttpRequestData req)
2931

3032
this.Headers = req.Headers();
3133
this.Query = req.Queries();
34+
this.Identities = req.Identities;
3235
this.Body = req.Body;
3336
}
3437

@@ -42,9 +45,13 @@ public HttpRequestObject(HttpRequestData req)
4245
public virtual IHeaderDictionary Headers { get; }
4346

4447
/// <inheritdoc/>
45-
public virtual IQueryCollection Query { get;}
48+
public virtual IQueryCollection Query { get; }
4649

4750
/// <inheritdoc/>
48-
public virtual Stream Body { get;}
51+
/// <remarks>This property has implementation but will appear on the interface from v2.0.0.</remarks>
52+
public virtual IEnumerable<ClaimsIdentity> Identities { get; }
53+
54+
/// <inheritdoc/>
55+
public virtual Stream Body { get; }
4956
}
5057
}

src/Microsoft.Azure.Functions.Worker.Extensions.OpenApi/OpenApiWorkerStartup.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using Microsoft.Azure.Functions.Worker.Core;
22
using Microsoft.Azure.Functions.Worker.Extensions.OpenApi;
3+
using Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Configurations;
34
using Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Functions;
5+
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Configurations.AppSettings.Extensions;
6+
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Configurations.AppSettings.Resolvers;
47
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions;
58
using Microsoft.Extensions.DependencyInjection;
69

@@ -16,6 +19,10 @@ public class OpenApiWorkerStartup : WorkerExtensionStartup
1619
/// <inheritdoc />
1720
public override void Configure(IFunctionsWorkerApplicationBuilder applicationBuilder)
1821
{
22+
var config = ConfigurationResolver.Resolve();
23+
var settings = config.Get<OpenApiSettings>(OpenApiSettings.Name);
24+
25+
applicationBuilder.Services.AddSingleton(settings);
1926
applicationBuilder.Services.AddSingleton<IOpenApiHttpTriggerContext, OpenApiHttpTriggerContext>();
2027
applicationBuilder.Services.AddSingleton<IOpenApiTriggerFunction, OpenApiTriggerFunction>();
2128
//applicationBuilder.Services.AddSingleton<DefaultOpenApiHttpTrigger, DefaultOpenApiHttpTrigger>();

src/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/Abstractions/IHttpRequestDataObject.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
using System.Collections.Generic;
12
using System.IO;
3+
using System.Security.Claims;
24

35
using Microsoft.AspNetCore.Http;
46

@@ -29,9 +31,15 @@ public interface IHttpRequestDataObject
2931
/// </summary>
3032
IQueryCollection Query { get; }
3133

34+
/// <summary>
35+
/// Gets the list of <see cref="ClaimsIdentity"/>
36+
/// </summary>
37+
/// <remarks>This will be added to v2.0.0</remarks>
38+
//IEnumerable<ClaimsIdentity> Identities { get; }
39+
3240
/// <summary>
3341
/// Gets the request payload stream.
3442
/// </summary>
35-
Stream Body { get;}
43+
Stream Body { get; }
3644
}
3745
}

src/Microsoft.Azure.WebJobs.Extensions.OpenApi/Configurations/OpenApiSettings.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Configurations
77
/// </summary>
88
public class OpenApiSettings
99
{
10+
/// <summary>
11+
/// Gets the name of the collection of the environment variables for OpenAPI.
12+
/// </summary>
13+
public const string Name = "OpenApi";
14+
1015
/// <summary>
1116
/// Gets or sets the OpenAPI spec version.
1217
/// </summary>

src/Microsoft.Azure.WebJobs.Extensions.OpenApi/HttpRequestObject.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
using System.Collections.Generic;
12
using System.IO;
3+
using System.Security.Claims;
24

35
using Microsoft.AspNetCore.Http;
46
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions;
@@ -23,6 +25,7 @@ public HttpRequestObject(HttpRequest req)
2325
this.Host = req.Host;
2426
this.Headers = req.Headers;
2527
this.Query = req.Query;
28+
this.Identities = req.HttpContext.User.Identities;
2629
this.Body = req.Body;
2730
}
2831

@@ -36,9 +39,13 @@ public HttpRequestObject(HttpRequest req)
3639
public virtual IHeaderDictionary Headers { get; }
3740

3841
/// <inheritdoc/>
39-
public virtual IQueryCollection Query { get;}
42+
public virtual IQueryCollection Query { get; }
4043

4144
/// <inheritdoc/>
42-
public virtual Stream Body { get;}
45+
/// <remarks>This property has implementation but will appear on the interface from v2.0.0.</remarks>
46+
public virtual IEnumerable<ClaimsIdentity> Identities { get; }
47+
48+
/// <inheritdoc/>
49+
public virtual Stream Body { get; }
4350
}
4451
}

src/Microsoft.Azure.WebJobs.Extensions.OpenApi/OpenApiWebJobsStartup.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi
1717
/// </summary>
1818
public class OpenApiWebJobsStartup : IWebJobsStartup
1919
{
20-
private const string OpenApiSettingsKey = "OpenApi";
21-
2220
/// <inheritdoc />
2321
public void Configure(IWebJobsBuilder builder)
2422
{
2523
var config = ConfigurationResolver.Resolve();
26-
var settings = config.Get<OpenApiSettings>(OpenApiSettingsKey);
24+
var settings = config.Get<OpenApiSettings>(OpenApiSettings.Name);
2725

2826
builder.Services.AddSingleton(settings);
2927
builder.Services.AddSingleton<IFunctionProvider, OpenApiTriggerFunctionProvider>();

0 commit comments

Comments
 (0)