Resolve Concelier/Excititor merge conflicts
This commit is contained in:
		| @@ -0,0 +1,8 @@ | ||||
| id: excititor-my-provider | ||||
| assembly: StellaOps.Excititor.Connectors.MyProvider.dll | ||||
| entryPoint: StellaOps.Excititor.Connectors.MyProvider.MyConnectorPlugin | ||||
| description: | | ||||
|   Example connector template. Replace metadata before shipping. | ||||
| tags: | ||||
|   - excititor | ||||
|   - template | ||||
| @@ -0,0 +1,12 @@ | ||||
| <Project Sdk="Microsoft.NET.Sdk"> | ||||
|   <PropertyGroup> | ||||
|     <TargetFramework>net10.0</TargetFramework> | ||||
|     <Nullable>enable</Nullable> | ||||
|     <ImplicitUsings>enable</ImplicitUsings> | ||||
|     <TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||||
|   </PropertyGroup> | ||||
|   <ItemGroup> | ||||
|     <!-- Adjust the relative path when copying this template into a repo --> | ||||
|     <ProjectReference Include="..\..\..\..\src\StellaOps.Excititor.Connectors.Abstractions\StellaOps.Excititor.Connectors.Abstractions.csproj" /> | ||||
|   </ItemGroup> | ||||
| </Project> | ||||
							
								
								
									
										72
									
								
								docs/dev/templates/excititor-connector/src/MyConnector.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								docs/dev/templates/excititor-connector/src/MyConnector.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,72 @@ | ||||
| using System.Collections.Generic; | ||||
| using System.Collections.Immutable; | ||||
| using System.Runtime.CompilerServices; | ||||
| using Microsoft.Extensions.Logging; | ||||
| using StellaOps.Excititor.Connectors.Abstractions; | ||||
| using StellaOps.Excititor.Core; | ||||
|  | ||||
| namespace StellaOps.Excititor.Connectors.MyProvider; | ||||
|  | ||||
| public sealed class MyConnector : VexConnectorBase | ||||
| { | ||||
|     private readonly IEnumerable<IVexConnectorOptionsValidator<MyConnectorOptions>> _validators; | ||||
|     private MyConnectorOptions? _options; | ||||
|  | ||||
|     public MyConnector(VexConnectorDescriptor descriptor, ILogger<MyConnector> logger, TimeProvider timeProvider, IEnumerable<IVexConnectorOptionsValidator<MyConnectorOptions>> validators) | ||||
|         : base(descriptor, logger, timeProvider) | ||||
|     { | ||||
|         _validators = validators; | ||||
|     } | ||||
|  | ||||
|     public override ValueTask ValidateAsync(VexConnectorSettings settings, CancellationToken cancellationToken) | ||||
|     { | ||||
|         _options = VexConnectorOptionsBinder.Bind( | ||||
|             Descriptor, | ||||
|             settings, | ||||
|             validators: _validators); | ||||
|  | ||||
|         LogConnectorEvent(LogLevel.Information, "validate", "MyConnector configuration loaded.", | ||||
|             new Dictionary<string, object?> | ||||
|             { | ||||
|                 ["catalogUri"] = _options.CatalogUri, | ||||
|                 ["maxParallelRequests"] = _options.MaxParallelRequests, | ||||
|             }); | ||||
|  | ||||
|         return ValueTask.CompletedTask; | ||||
|     } | ||||
|  | ||||
|     public override IAsyncEnumerable<VexRawDocument> FetchAsync(VexConnectorContext context, CancellationToken cancellationToken) | ||||
|     { | ||||
|         if (_options is null) | ||||
|         { | ||||
|             throw new InvalidOperationException("Connector not validated."); | ||||
|         } | ||||
|  | ||||
|         return FetchInternalAsync(context, cancellationToken); | ||||
|     } | ||||
|  | ||||
|     private async IAsyncEnumerable<VexRawDocument> FetchInternalAsync(VexConnectorContext context, [EnumeratorCancellation] CancellationToken cancellationToken) | ||||
|     { | ||||
|         LogConnectorEvent(LogLevel.Information, "fetch", "Fetching catalog window..."); | ||||
|  | ||||
|         // Replace with real HTTP logic. | ||||
|         await Task.Delay(10, cancellationToken); | ||||
|  | ||||
|         var metadata = BuildMetadata(builder => builder | ||||
|             .Add("sourceUri", _options!.CatalogUri) | ||||
|             .Add("window", context.Since?.ToString("O") ?? "full")); | ||||
|  | ||||
|         yield return CreateRawDocument( | ||||
|             VexDocumentFormat.CsafJson, | ||||
|             new Uri($"{_options.CatalogUri.TrimEnd('/')}/sample.json"), | ||||
|             new byte[] { 0x7B, 0x7D }, | ||||
|             metadata); | ||||
|     } | ||||
|  | ||||
|     public override ValueTask<VexClaimBatch> NormalizeAsync(VexRawDocument document, CancellationToken cancellationToken) | ||||
|     { | ||||
|         var claims = ImmutableArray<VexClaim>.Empty; | ||||
|         var diagnostics = ImmutableDictionary<string, string>.Empty; | ||||
|         return ValueTask.FromResult(new VexClaimBatch(document, claims, diagnostics)); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,16 @@ | ||||
| using System.ComponentModel.DataAnnotations; | ||||
|  | ||||
| namespace StellaOps.Excititor.Connectors.MyProvider; | ||||
|  | ||||
| public sealed class MyConnectorOptions | ||||
| { | ||||
|     [Required] | ||||
|     [Url] | ||||
|     public string CatalogUri { get; set; } = default!; | ||||
|  | ||||
|     [Required] | ||||
|     public string ApiKey { get; set; } = default!; | ||||
|  | ||||
|     [Range(1, 32)] | ||||
|     public int MaxParallelRequests { get; set; } = 4; | ||||
| } | ||||
| @@ -0,0 +1,15 @@ | ||||
| using System.Collections.Generic; | ||||
| using StellaOps.Excititor.Connectors.Abstractions; | ||||
|  | ||||
| namespace StellaOps.Excititor.Connectors.MyProvider; | ||||
|  | ||||
| public sealed class MyConnectorOptionsValidator : IVexConnectorOptionsValidator<MyConnectorOptions> | ||||
| { | ||||
|     public void Validate(VexConnectorDescriptor descriptor, MyConnectorOptions options, IList<string> errors) | ||||
|     { | ||||
|         if (!options.CatalogUri.StartsWith("https://", StringComparison.OrdinalIgnoreCase)) | ||||
|         { | ||||
|             errors.Add("CatalogUri must use HTTPS."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,27 @@ | ||||
| using Microsoft.Extensions.DependencyInjection; | ||||
| using Microsoft.Extensions.Logging; | ||||
| using StellaOps.Plugin; | ||||
| using StellaOps.Excititor.Connectors.Abstractions; | ||||
| using StellaOps.Excititor.Core; | ||||
|  | ||||
| namespace StellaOps.Excititor.Connectors.MyProvider; | ||||
|  | ||||
| public sealed class MyConnectorPlugin : IConnectorPlugin | ||||
| { | ||||
|     private static readonly VexConnectorDescriptor Descriptor = new( | ||||
|         id: "excititor:my-provider", | ||||
|         kind: VexProviderKind.Vendor, | ||||
|         displayName: "My Provider VEX"); | ||||
|  | ||||
|     public string Name => Descriptor.DisplayName; | ||||
|  | ||||
|     public bool IsAvailable(IServiceProvider services) => true; | ||||
|  | ||||
|     public IFeedConnector Create(IServiceProvider services) | ||||
|     { | ||||
|         var logger = services.GetRequiredService<ILogger<MyConnector>>(); | ||||
|         var timeProvider = services.GetRequiredService<TimeProvider>(); | ||||
|         var validators = services.GetServices<IVexConnectorOptionsValidator<MyConnectorOptions>>(); | ||||
|         return new MyConnector(Descriptor, logger, timeProvider, validators); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user