diff --git a/src/Application/Channels/Commands/PatchChannelCommand.cs b/src/Application/Channels/Commands/PatchChannelCommand.cs index 988a7b888..7066b6b7c 100644 --- a/src/Application/Channels/Commands/PatchChannelCommand.cs +++ b/src/Application/Channels/Commands/PatchChannelCommand.cs @@ -60,7 +60,7 @@ public async Task Handle(PatchChannelCommand request, CancellationToken ca return Unit.Value; } - private void UpdateEnvironmentVariables(PatchChannelCommand request, Channel? channel) + private void UpdateEnvironmentVariables(PatchChannelCommand request, Channel channel) { var existingVariables = GetExistingEnvironmentVariables(request.ChannelId); @@ -75,13 +75,13 @@ private void UpdateEnvironmentVariables(PatchChannelCommand request, Channel? ch _context.EnvironmentVariables.AddRange(envVariablesToBeAdded); - if (existingVariables.Count > 0 && request.EnvironmentVariables.Value != null) + if (existingVariables.Count > 0 && request.EnvironmentVariables.Value is not null) { foreach (var environmentVariable in request.EnvironmentVariables.Value) { var updatedEnvVar = existingVariables.FirstOrDefault(v => v.Id == environmentVariable.Id); - if (updatedEnvVar == null) + if (updatedEnvVar is null) { continue; } @@ -107,15 +107,15 @@ private List GetExistingEnvironmentVariables(Guid channelId .ToList(); } - private static List EnvironmentVariablesToBeAdded(List environmentVariables, Channel channel) + private static List EnvironmentVariablesToBeAdded(List? environmentVariables, Channel channel) { - if (environmentVariables == null) + if (environmentVariables is null) { return new List(); } var toBeAdded = new List(); - var newVariables = environmentVariables.Where(v => v.Id == null); + var newVariables = environmentVariables.Where(v => v.Id is null); foreach (var environmentVariable in newVariables) { @@ -133,22 +133,22 @@ private static List EnvironmentVariablesToBeAdded(List EnvironmentVariablesToBeUpdated(List existingVariables, - List environmentVariables) + List? environmentVariables) { - if (environmentVariables == null) + if (environmentVariables is null) { return new List(); } - var environmentVariablesIds = environmentVariables?.Select(v => v.Id); + var environmentVariablesIds = environmentVariables.Select(v => v.Id); return existingVariables.Where(v => environmentVariablesIds.Contains(v.Id)).ToList(); } private static List EnvironmentVariablesToBeRemoved(List existingVariables, - List environmentVariables) + List? environmentVariables) { - if (environmentVariables == null) + if (environmentVariables is null) { environmentVariables = new List(); } diff --git a/src/Application/Channels/EventHandlers/ChannelCreatedEventHandler.cs b/src/Application/Channels/EventHandlers/ChannelCreatedEventHandler.cs index a721dea8a..314658cc2 100644 --- a/src/Application/Channels/EventHandlers/ChannelCreatedEventHandler.cs +++ b/src/Application/Channels/EventHandlers/ChannelCreatedEventHandler.cs @@ -25,7 +25,7 @@ public Task Handle(CreatedEvent notification, CancellationToken cancell _logger.LogInformation($"Hippo Domain Event: {notification.GetType().Name}"); - if (channel.ActiveRevision != null) + if (channel.ActiveRevision is not null) { _logger.LogInformation($"{channel.App.Name}: Starting channel {channel.Name} at revision {channel.ActiveRevision.RevisionNumber}"); var envvars = channel.EnvironmentVariables.ToDictionary( diff --git a/src/Application/Channels/Queries/GetChannelQuery.cs b/src/Application/Channels/Queries/GetChannelQuery.cs index 7366a17ed..06394e4bc 100644 --- a/src/Application/Channels/Queries/GetChannelQuery.cs +++ b/src/Application/Channels/Queries/GetChannelQuery.cs @@ -45,6 +45,11 @@ public async Task Handle(GetChannelQuery request, CancellationToken .Select(a => a.ToAppSummaryDto()) .FirstOrDefaultAsync(cancellationToken); + if (entity.ActiveRevision is not null) + { + entity.ActiveRevision.Type = entity.ActiveRevision.Components.FirstOrDefault()?.Type; + } + return entity; } } diff --git a/src/Application/Common/Extensions/IgnoreNoMapExtensions.cs b/src/Application/Common/Extensions/IgnoreNoMapExtensions.cs index 693138953..d0cf5e3f0 100644 --- a/src/Application/Common/Extensions/IgnoreNoMapExtensions.cs +++ b/src/Application/Common/Extensions/IgnoreNoMapExtensions.cs @@ -12,11 +12,11 @@ public static IMappingExpression IgnoreMarkedAttributes( foreach (var property in destinationType.GetProperties()) { PropertyDescriptor? descriptor = TypeDescriptor.GetProperties(destinationType)?[property.Name]; - if (descriptor == null || descriptor.Attributes == null) + if (descriptor is null || descriptor.Attributes is null) continue; var attribute = descriptor.Attributes[typeof(NoMapAttribute)]; - if (attribute != null && (NoMapAttribute)attribute != null) + if (attribute is not null && (NoMapAttribute)attribute is not null) { expression.ForMember(property.Name, opt => opt.Ignore()); } diff --git a/src/Application/JobStatuses/Queries/GetJobStatusesQuery.cs b/src/Application/JobStatuses/Queries/GetJobStatusesQuery.cs index 2698a3c4f..f9d556df3 100644 --- a/src/Application/JobStatuses/Queries/GetJobStatusesQuery.cs +++ b/src/Application/JobStatuses/Queries/GetJobStatusesQuery.cs @@ -41,19 +41,19 @@ public async Task> Handle(GetJobStatusesQuery request Items = entities, PageIndex = request.PageIndex, PageSize = request.PageSize, - TotalItems = jobs == null ? 0 : jobs.Count + TotalItems = jobs is null ? 0 : jobs.Count }; } private static JobStatus GetJobStatus(List? jobs, Guid jobId) { - if (jobs == null) + if (jobs is null) { return JobStatus.Unknown; } var job = jobs.Where(job => job.Id == jobId).FirstOrDefault(); - return job != null ? job.Status : JobStatus.Dead; + return job is not null ? job.Status : JobStatus.Dead; } } diff --git a/src/Application/Revisions/Commands/UpdateRevisionDetailsCommand.cs b/src/Application/Revisions/Commands/UpdateRevisionDetailsCommand.cs index e7e18b960..ce81e0549 100644 --- a/src/Application/Revisions/Commands/UpdateRevisionDetailsCommand.cs +++ b/src/Application/Revisions/Commands/UpdateRevisionDetailsCommand.cs @@ -32,7 +32,7 @@ public async Task Handle(UpdateRevisionDetailsCommand request, Cancellatio .SingleOrDefaultAsync(cancellationToken); _ = revision ?? throw new NotFoundException(nameof(Core.Entities.Revision), request.RevisionId); var revisionDetails = request.RevisionDetails; - if (revisionDetails == null || revisionDetails.SpinToml == null) + if (revisionDetails is null || revisionDetails.SpinToml is null) { return Unit.Value; } diff --git a/src/Application/Revisions/Queries/RevisionItem.cs b/src/Application/Revisions/Queries/RevisionItem.cs index 46e66d771..461ede173 100644 --- a/src/Application/Revisions/Queries/RevisionItem.cs +++ b/src/Application/Revisions/Queries/RevisionItem.cs @@ -1,4 +1,5 @@ using System.ComponentModel.DataAnnotations; +using Hippo.Application.Common.Attributes; using Hippo.Application.Common.Mappings; using Hippo.Core.Entities; @@ -18,6 +19,9 @@ public class RevisionItem : IMapFrom [Required] public IList Components { get; private set; } = new List(); + [NoMap] + public string? Type { get; set; } + public string OrderKey() { if (SemVer.Version.TryParse(RevisionNumber, out var version)) diff --git a/src/Core/Models/Extensions/FieldExtensions.cs b/src/Core/Models/Extensions/FieldExtensions.cs index 47c75346e..f43e4adbb 100644 --- a/src/Core/Models/Extensions/FieldExtensions.cs +++ b/src/Core/Models/Extensions/FieldExtensions.cs @@ -4,7 +4,7 @@ public static class FieldExtensions { public static bool IsSet(this Field field) { - return field != null; + return field is not null; } public static void WhenSet(this Field field, Action action) diff --git a/src/Core/Models/Extensions/FilteringExtensions.cs b/src/Core/Models/Extensions/FilteringExtensions.cs index 9a07bd481..710d18581 100644 --- a/src/Core/Models/Extensions/FilteringExtensions.cs +++ b/src/Core/Models/Extensions/FilteringExtensions.cs @@ -7,7 +7,7 @@ public static IEnumerable SortBy(this IEnumerable items, string sortBy, IOrderedEnumerable orderedItems; var sortPropInfo = typeof(T).GetProperty(sortBy); - if (sortPropInfo == null) + if (sortPropInfo is null) { throw new Exception("Sort field does it exist"); } diff --git a/src/Core/Models/Filter.cs b/src/Core/Models/Filter.cs index daa6090cf..0d5855156 100644 --- a/src/Core/Models/Filter.cs +++ b/src/Core/Models/Filter.cs @@ -24,7 +24,7 @@ public class PageAndSortFilter : IPageFilter, ISortFilter public int PageIndex { get; set; } public int PageSize { get; set; } public int Offset { get { return PageIndex * PageSize; } } - public string SortBy { get; set; } + public string SortBy { get; set; } = string.Empty; public bool IsSortedAscending { get; set; } public PageAndSortFilter() diff --git a/src/Core/Models/Page.cs b/src/Core/Models/Page.cs index 6be1fb41f..206331ade 100644 --- a/src/Core/Models/Page.cs +++ b/src/Core/Models/Page.cs @@ -15,7 +15,7 @@ public Page(IReadOnlyCollection items, int totalItems) /// /// the fetched items /// - public IReadOnlyCollection Items { get; set; } + public IReadOnlyCollection Items { get; set; } = new List(); /// /// the total number of items for the requested query @@ -38,7 +38,7 @@ public bool? IsLastPage { if (!PageIndex.HasValue || !PageSize.HasValue) return null; - + return TotalItems == PageIndex * PageSize + Items.Count; } } diff --git a/src/Core/Serialization/FieldConverter.cs b/src/Core/Serialization/FieldConverter.cs index 9ed0942ee..ec231a6d0 100644 --- a/src/Core/Serialization/FieldConverter.cs +++ b/src/Core/Serialization/FieldConverter.cs @@ -10,31 +10,36 @@ public override bool CanConvert(Type objectType) throw new NotImplementedException(); } - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) { var fieldInnerPropertyType = objectType - .GetProperty(nameof(Field.Value)) + .GetProperty(nameof(Field.Value))? .PropertyType; var jsonValue = ReadInnerFieldValue(reader, serializer, fieldInnerPropertyType); return Activator.CreateInstance(objectType, new[] { jsonValue }); } - private static object ReadInnerFieldValue(JsonReader reader, JsonSerializer serializer, Type fieldInnerPropertyType) + private static object? ReadInnerFieldValue(JsonReader reader, JsonSerializer serializer, Type? fieldInnerPropertyType) { - if (reader.TokenType == JsonToken.Null) + if (reader.TokenType == JsonToken.Null || fieldInnerPropertyType is null) return null; - + return serializer.Deserialize(reader, fieldInnerPropertyType); } - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) { - var fieldInnerProperty = value - .GetType() - .GetProperty(nameof(Field.Value)); + object? val = null; + if (value is not null) + { + var fieldInnerProperty = value + .GetType() + .GetProperty(nameof(Field.Value)); + + val = fieldInnerProperty is null ? null : fieldInnerProperty.GetValue(value); + } - var fieldInnerValue = fieldInnerProperty.GetValue(value); - serializer.Serialize(writer, fieldInnerValue); + serializer.Serialize(writer, val); } } diff --git a/src/Infrastructure/Data/Interceptors/AuditableEntitySaveChangesInterceptor.cs b/src/Infrastructure/Data/Interceptors/AuditableEntitySaveChangesInterceptor.cs index 5e9c91a75..301defbfb 100644 --- a/src/Infrastructure/Data/Interceptors/AuditableEntitySaveChangesInterceptor.cs +++ b/src/Infrastructure/Data/Interceptors/AuditableEntitySaveChangesInterceptor.cs @@ -36,7 +36,7 @@ public override ValueTask> SavingChangesAsync(DbContextE public void UpdateEntities(DbContext? context) { - if (context == null) return; + if (context is null) return; foreach (var entry in context.ChangeTracker.Entries()) { @@ -59,7 +59,7 @@ public static class Extensions { public static bool HasChangedOwnedEntities(this EntityEntry entry) => entry.References.Any(r => - r.TargetEntry != null && + r.TargetEntry is not null && r.TargetEntry.Metadata.IsOwned() && (r.TargetEntry.State == EntityState.Added || r.TargetEntry.State == EntityState.Modified)); } diff --git a/src/Infrastructure/Services/BindleService.cs b/src/Infrastructure/Services/BindleService.cs index 073722698..3f2707d83 100644 --- a/src/Infrastructure/Services/BindleService.cs +++ b/src/Infrastructure/Services/BindleService.cs @@ -86,7 +86,7 @@ public async Task> QueryAvailableStorages(string query, ulon if (matches.Total == 0) return new List(); return matches.Invoices - .Where(i => i.Bindle != null && !string.IsNullOrEmpty(i.Bindle.Name)) + .Where(i => i.Bindle is not null && !string.IsNullOrEmpty(i.Bindle.Name)) .Select(i => new string(i.Bindle?.Name)) .Distinct() .Take(limit ?? int.MaxValue); diff --git a/src/Infrastructure/Services/NomadJobService.cs b/src/Infrastructure/Services/NomadJobService.cs index 923bb1b70..28410845e 100644 --- a/src/Infrastructure/Services/NomadJobService.cs +++ b/src/Infrastructure/Services/NomadJobService.cs @@ -57,7 +57,7 @@ public string[] GetJobLogs(string jobName) .Select(a => a.ID) .FirstOrDefault(); - if (allocationId == null) + if (allocationId is null) { return new string[] { }; } @@ -149,12 +149,19 @@ private Service GenerateJobService(NomadJob nomadJob) tags.Add("traefik.http.routers." + nomadJob.Id + @".tls.domains[0].main=" + nomadJob.Domain); } - return new Service + var serviceProvider = _configuration.GetValue("Nomad:ServiceProvider", "consul"); + + var service = new Service { PortLabel = "http", Name = nomadJob.Id.ToString(), Tags = tags, - Checks = new List + Provider = serviceProvider, + }; + + if (serviceProvider == "consul") + { + service.Checks = new List { new ServiceCheck { @@ -163,8 +170,10 @@ private Service GenerateJobService(NomadJob nomadJob) Interval = 10000000000, Timeout = 2000000000 } - } - }; + }; + + } + return service; } private Fermyon.Nomad.Model.Task GenerateJobTask(NomadJob nomadJob) diff --git a/src/Web/ClientApp/src/app/components/channel/channel.component.html b/src/Web/ClientApp/src/app/components/channel/channel.component.html index 3957c1429..bcabf325a 100644 --- a/src/Web/ClientApp/src/app/components/channel/channel.component.html +++ b/src/Web/ClientApp/src/app/components/channel/channel.component.html @@ -1,7 +1,12 @@

{{channel.appSummary.name}}

- {{channel.domain}} + +
+

{{channel.domain}}

+