From 52488d5f6d40cf3493345ab606383ff9439b90e7 Mon Sep 17 00:00:00 2001 From: Chris Turner <23338096+christopherjturner@users.noreply.github.com> Date: Wed, 15 Jan 2025 11:48:29 +0000 Subject: [PATCH] cleanup & safeguards --- .../Services/AppConfigVersionService.cs | 1 + .../Services/EnabledVanityUrlsService.cs | 1 + .../Services/NginxVanityUrlsService.cs | 1 + .../Services/ShutteredUrlsService.cs | 1 + .../Services/SquidProxyConfigService.cs | 1 + .../Services/TenantBucketsService.cs | 3 ++- .../Services/TenantServicesService.cs | 1 + .../Services/VanityUrlService.cs | 1 + .../Services/Service/ServiceOverviewService.cs | 2 +- .../Utils/Fetchers/SelfServiceOpsFetcher.cs | 17 ++++++++--------- 10 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/AppConfigVersionService.cs b/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/AppConfigVersionService.cs index ffb2dc9..433b649 100644 --- a/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/AppConfigVersionService.cs +++ b/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/AppConfigVersionService.cs @@ -47,6 +47,7 @@ protected override List> DefineIndexes( } } +[BsonIgnoreExtraElements] public record AppConfigVersion(string CommitSha, DateTime CommitTimestamp, string Environment) { [BsonId(IdGenerator = typeof(ObjectIdGenerator))] diff --git a/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/EnabledVanityUrlsService.cs b/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/EnabledVanityUrlsService.cs index 26c8e14..f2b00dd 100644 --- a/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/EnabledVanityUrlsService.cs +++ b/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/EnabledVanityUrlsService.cs @@ -56,6 +56,7 @@ public async Task PersistEvent(Event workflowEvent, Ca } } +[BsonIgnoreExtraElements] public record EnabledVanityUrlRecord(string Url, string Environment, string Service) { [BsonId(IdGenerator = typeof(ObjectIdGenerator))] diff --git a/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/NginxVanityUrlsService.cs b/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/NginxVanityUrlsService.cs index 34b0423..93ab52a 100644 --- a/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/NginxVanityUrlsService.cs +++ b/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/NginxVanityUrlsService.cs @@ -106,6 +106,7 @@ private async Task UpdateVanityUrls(List vanityUrls, } } +[BsonIgnoreExtraElements] public record NginxVanityUrlsRecord(string Environment, string ServiceName, string Url) { [BsonId(IdGenerator = typeof(ObjectIdGenerator))] diff --git a/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/ShutteredUrlsService.cs b/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/ShutteredUrlsService.cs index bfaeb35..2303d26 100644 --- a/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/ShutteredUrlsService.cs +++ b/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/ShutteredUrlsService.cs @@ -71,6 +71,7 @@ public async Task> FindShutteredUrls(CancellationToken } } +[BsonIgnoreExtraElements] public record ShutteredUrlRecord(string Environment, string Url) { [BsonId(IdGenerator = typeof(ObjectIdGenerator))] diff --git a/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/SquidProxyConfigService.cs b/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/SquidProxyConfigService.cs index 824a962..c154b54 100644 --- a/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/SquidProxyConfigService.cs +++ b/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/SquidProxyConfigService.cs @@ -114,6 +114,7 @@ private async Task UpdateSquidProxyConfigs(List squidPro } } +[BsonIgnoreExtraElements] public record SquidProxyConfigRecord(string Environment, string ServiceName, List DefaultDomains, List AllowedDomains) { [BsonId(IdGenerator = typeof(ObjectIdGenerator))] diff --git a/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/TenantBucketsService.cs b/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/TenantBucketsService.cs index 2c1447f..f25cc11 100644 --- a/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/TenantBucketsService.cs +++ b/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/TenantBucketsService.cs @@ -123,6 +123,7 @@ private async Task DeleteBuckets(List tenantBucketRecords, } } +[BsonIgnoreExtraElements] public record TenantBucketRecord( string Environment, string ServiceName, @@ -135,7 +136,7 @@ public record TenantBucketRecord( public virtual bool Equals(TenantBucketRecord? other) { - return Environment == other.Environment && ServiceName == other.ServiceName && Bucket == other.Bucket; + return Environment == other?.Environment && ServiceName == other.ServiceName && Bucket == other.Bucket; } public override int GetHashCode() => HashCode.Combine(Environment, ServiceName, Bucket); diff --git a/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/TenantServicesService.cs b/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/TenantServicesService.cs index 7191153..6e697cc 100644 --- a/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/TenantServicesService.cs +++ b/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/TenantServicesService.cs @@ -116,6 +116,7 @@ public async Task> FindAllServices(string service, Can } } +[BsonIgnoreExtraElements] public record TenantServiceRecord( string Environment, string ServiceName, diff --git a/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/VanityUrlService.cs b/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/VanityUrlService.cs index a120085..5b057a3 100644 --- a/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/VanityUrlService.cs +++ b/Defra.Cdp.Backend.Api/Services/GitHubWorkflowEvents/Services/VanityUrlService.cs @@ -110,6 +110,7 @@ private async Task> Find(BsonDocument matchStage, Cancella ]; } +[BsonIgnoreExtraElements] public record VanityUrlRecord(string Url, string Environment, string ServiceName, bool Enabled, bool Shuttered) { [BsonId(IdGenerator = typeof(ObjectIdGenerator))] diff --git a/Defra.Cdp.Backend.Api/Services/Service/ServiceOverviewService.cs b/Defra.Cdp.Backend.Api/Services/Service/ServiceOverviewService.cs index 1f55f4d..f1d53e8 100644 --- a/Defra.Cdp.Backend.Api/Services/Service/ServiceOverviewService.cs +++ b/Defra.Cdp.Backend.Api/Services/Service/ServiceOverviewService.cs @@ -22,7 +22,7 @@ public class ServiceOverviewService( IVanityUrlService vanityUrlService, IDeploymentsServiceV2 deploymentsService, SelfServiceOpsFetcher selfServiceOpsFetcher - ) : IServiceOverviewService +) : IServiceOverviewService { public async Task GetService(string name, CancellationToken cancellationToken = default) { diff --git a/Defra.Cdp.Backend.Api/Utils/Fetchers/SelfServiceOpsFetcher.cs b/Defra.Cdp.Backend.Api/Utils/Fetchers/SelfServiceOpsFetcher.cs index c3eacff..7d12f22 100644 --- a/Defra.Cdp.Backend.Api/Utils/Fetchers/SelfServiceOpsFetcher.cs +++ b/Defra.Cdp.Backend.Api/Utils/Fetchers/SelfServiceOpsFetcher.cs @@ -52,12 +52,11 @@ public async Task TriggerTestSuite(string imageName, string envi } } - public class CreationStatus { - public string Status { get; init; } - public string Kind { get; init; } - public DateTime Started { get; init; } + public required string Status { get; init; } + public string? Kind { get; init; } + public DateTime? Started { get; init; } public User? Creator { get; init; } public JsonObject? Content { get; set; } } @@ -70,13 +69,13 @@ public class SelfServiceOpsStatus public class RepoStatus { [property: JsonPropertyName("status")] - public string Status { get; init; } + public required string Status { get; init; } [property: JsonPropertyName("kind")] - public string Kind { get; init; } + public required string Kind { get; init; } [property: JsonPropertyName("started")] - public DateTime Started { get; init; } + public DateTime? Started { get; init; } [property: JsonPropertyName("creator")] public User? Creator { get; init; } @@ -86,7 +85,7 @@ public class RepoStatus public class User { [property: JsonPropertyName("id")] - string Id { get; init; } + string? Id { get; init; } [property: JsonPropertyName("displayName")] - string DisplayName { get; init; } + string? DisplayName { get; init; } } \ No newline at end of file