using System.ComponentModel.DataAnnotations; namespace StellaOps.Vexer.Connectors.Cisco.CSAF.Configuration; public sealed class CiscoConnectorOptions : IValidatableObject { public const string HttpClientName = "cisco-csaf"; /// /// Endpoint for Cisco CSAF provider metadata discovery. /// [Required] public string MetadataUri { get; set; } = "https://api.security.cisco.com/.well-known/csaf/provider-metadata.json"; /// /// Optional bearer token used when Cisco endpoints require authentication. /// public string? ApiToken { get; set; } /// /// How long provider metadata remains cached. /// public TimeSpan MetadataCacheDuration { get; set; } = TimeSpan.FromHours(6); /// /// Whether to prefer offline snapshots when fetching metadata. /// public bool PreferOfflineSnapshot { get; set; } /// /// When set, provider metadata will be persisted to the given file path. /// public bool PersistOfflineSnapshot { get; set; } public string? OfflineSnapshotPath { get; set; } public IEnumerable Validate(ValidationContext validationContext) { if (string.IsNullOrWhiteSpace(MetadataUri)) { yield return new ValidationResult("MetadataUri must be provided.", new[] { nameof(MetadataUri) }); } else if (!Uri.TryCreate(MetadataUri, UriKind.Absolute, out _)) { yield return new ValidationResult("MetadataUri must be an absolute URI.", new[] { nameof(MetadataUri) }); } if (MetadataCacheDuration <= TimeSpan.Zero) { yield return new ValidationResult("MetadataCacheDuration must be greater than zero.", new[] { nameof(MetadataCacheDuration) }); } if (PersistOfflineSnapshot && string.IsNullOrWhiteSpace(OfflineSnapshotPath)) { yield return new ValidationResult("OfflineSnapshotPath must be provided when PersistOfflineSnapshot is enabled.", new[] { nameof(OfflineSnapshotPath) }); } } }