|
1 |
| -using KubeOps.Abstractions.Builder; |
2 |
| -using KubeOps.Operator.Web.LocalTunnel; |
3 |
| - |
4 |
| -using Microsoft.Extensions.DependencyInjection; |
5 |
| - |
6 |
| -namespace KubeOps.Operator.Web.Builder; |
7 |
| - |
8 |
| -/// <summary> |
9 |
| -/// Method extensions for the operator builder to register web specific services. |
10 |
| -/// </summary> |
11 |
| -public static class OperatorBuilderExtensions |
12 |
| -{ |
13 |
| - /// <summary> |
14 |
| - /// Adds a hosted service to the system that creates a "Local Tunnel" |
15 |
| - /// (http://localtunnel.github.io/www/) to the running application. |
16 |
| - /// The tunnel points to the configured host/port configuration and then |
17 |
| - /// registers itself as webhook target within Kubernetes. This |
18 |
| - /// enables developers to easily create webhooks without the requirement |
19 |
| - /// of registering ngrok / localtunnel urls themselves. |
20 |
| - /// </summary> |
21 |
| - /// <param name="builder">The operator builder.</param> |
22 |
| - /// <param name="port">The desired port that the asp.net application will run on.</param> |
23 |
| - /// <param name="hostname">The desired hostname.</param> |
24 |
| - /// <returns>The builder for chaining.</returns> |
25 |
| - /// <example> |
26 |
| - /// Attach the development tunnel to the operator if in debug mode. |
27 |
| - /// <code> |
28 |
| - /// var builder = WebApplication.CreateBuilder(args); |
29 |
| - /// builder.Services |
30 |
| - /// .AddKubernetesOperator() |
31 |
| - /// .RegisterComponents() |
32 |
| - /// #if DEBUG |
33 |
| - /// .AddDevelopmentTunnel(5000) |
34 |
| - /// #endif |
35 |
| - /// ; |
36 |
| - /// </code> |
37 |
| - /// </example> |
38 |
| - public static IOperatorBuilder AddDevelopmentTunnel( |
39 |
| - this IOperatorBuilder builder, |
40 |
| - ushort port, |
41 |
| - string hostname = "localhost") |
42 |
| - { |
43 |
| - builder.Services.AddHostedService<DevelopmentTunnelService>(); |
44 |
| - builder.Services.AddSingleton(new TunnelConfig(hostname, port)); |
45 |
| - return builder; |
46 |
| - } |
47 |
| -} |
| 1 | +using System.Reflection; |
| 2 | + |
| 3 | +using KubeOps.Abstractions.Builder; |
| 4 | +using KubeOps.Operator.Web.LocalTunnel; |
| 5 | + |
| 6 | +using Microsoft.Extensions.DependencyInjection; |
| 7 | + |
| 8 | +namespace KubeOps.Operator.Web.Builder; |
| 9 | + |
| 10 | +/// <summary> |
| 11 | +/// Method extensions for the operator builder to register web specific services. |
| 12 | +/// </summary> |
| 13 | +public static class OperatorBuilderExtensions |
| 14 | +{ |
| 15 | + /// <summary> |
| 16 | + /// Adds a hosted service to the system that creates a "Local Tunnel" |
| 17 | + /// (http://localtunnel.github.io/www/) to the running application. |
| 18 | + /// The tunnel points to the configured host/port configuration and then |
| 19 | + /// registers itself as webhook target within Kubernetes. This |
| 20 | + /// enables developers to easily create webhooks without the requirement |
| 21 | + /// of registering ngrok / localtunnel urls themselves. |
| 22 | + /// </summary> |
| 23 | + /// <param name="builder">The operator builder.</param> |
| 24 | + /// <param name="port">The desired port that the asp.net application will run on.</param> |
| 25 | + /// <param name="hostname">The desired hostname.</param> |
| 26 | + /// <returns>The builder for chaining.</returns> |
| 27 | + /// <example> |
| 28 | + /// Attach the development tunnel to the operator if in debug mode. |
| 29 | + /// <code> |
| 30 | + /// var builder = WebApplication.CreateBuilder(args); |
| 31 | + /// builder.Services |
| 32 | + /// .AddKubernetesOperator() |
| 33 | + /// .RegisterComponents() |
| 34 | + /// #if DEBUG |
| 35 | + /// .AddDevelopmentTunnel(5000) |
| 36 | + /// #endif |
| 37 | + /// ; |
| 38 | + /// </code> |
| 39 | + /// </example> |
| 40 | + public static IOperatorBuilder AddDevelopmentTunnel( |
| 41 | + this IOperatorBuilder builder, |
| 42 | + ushort port, |
| 43 | + string hostname = "localhost") |
| 44 | + { |
| 45 | + builder.Services.AddHostedService<DevelopmentTunnelService>(); |
| 46 | + builder.Services.AddSingleton(new TunnelConfig(hostname, port)); |
| 47 | + builder.Services.AddSingleton(new WebhookLoader(Assembly.GetEntryAssembly()!)); |
| 48 | + return builder; |
| 49 | + } |
| 50 | +} |
0 commit comments