| | 1 | | #pragma warning disable CA1050 |
| | 2 | | /// <summary> |
| | 3 | | /// Specifies the API context in which a Kestrun route or schedule can be executed. |
| | 4 | | /// </summary> |
| | 5 | | [Flags] |
| | 6 | | public enum KestrunApiContext |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// No API context specified. |
| | 10 | | /// </summary> |
| | 11 | | None = 0, |
| | 12 | | /// <summary> |
| | 13 | | /// Used during module/configuration time. |
| | 14 | | /// </summary> |
| | 15 | | Definition = 1 << 0, // module/configuration time |
| | 16 | | /// <summary> |
| | 17 | | /// Used inside HTTP route execution. |
| | 18 | | /// </summary> |
| | 19 | | Route = 1 << 1, // inside HTTP route execution |
| | 20 | |
|
| | 21 | | /// <summary> |
| | 22 | | /// Used during scheduled execution. |
| | 23 | | /// </summary> |
| | 24 | | Schedule = 1 << 2, // keep room for future split |
| | 25 | |
|
| | 26 | | /// <summary> |
| | 27 | | /// Used during both scheduled execution and module/configuration time (shorthand for Schedule | Definition). |
| | 28 | | /// </summary> |
| | 29 | | ScheduleAndDefinition = Schedule | Definition, |
| | 30 | | /// <summary> |
| | 31 | | /// Used during both HTTP route and scheduled execution (shorthand for Route | Schedule). |
| | 32 | | /// </summary> |
| | 33 | | Runtime = Route | Schedule, // if you like a shorthand |
| | 34 | | /// <summary> |
| | 35 | | /// Used in all available API contexts (Definition, Route, and Schedule). |
| | 36 | | /// </summary> |
| | 37 | | Everywhere = Definition | Route | Schedule |
| | 38 | | } |
| | 39 | | /// <summary> |
| | 40 | | /// Attribute to specify runtime API context and notes for Kestrun routes or schedules. |
| | 41 | | /// </summary> |
| | 42 | | /// <remarks> |
| | 43 | | /// Initializes a new instance of the <see cref="KestrunRuntimeApiAttribute"/> class with the specified API contexts. |
| | 44 | | /// </remarks> |
| | 45 | | /// <param name="contexts">The API contexts in which the route or schedule can be executed.</param> |
| | 46 | | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = false, AllowMultiple = false)] |
| 1 | 47 | | public sealed class KestrunRuntimeApiAttribute(KestrunApiContext contexts) : Attribute |
| | 48 | | { |
| | 49 | | /// <summary> |
| | 50 | | /// Gets the API contexts in which the route or schedule can be executed. |
| | 51 | | /// </summary> |
| 3 | 52 | | public KestrunApiContext Contexts { get; } = contexts; |
| | 53 | |
|
| | 54 | | /// <summary> |
| | 55 | | /// Indicates whether the route is safe to be executed by untrusted callers. |
| | 56 | | /// </summary> |
| 2 | 57 | | public bool SafeForUntrusted { get; init; } // optional policy flag |
| | 58 | | /// <summary> |
| | 59 | | /// Optional notes or description for the route. |
| | 60 | | /// </summary> |
| 2 | 61 | | public string? Notes { get; init; } |
| | 62 | | } |
| | 63 | | #pragma warning restore CA1050 |
| | 64 | |
|