Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compiler warnings related to nullability in Files module #509

Merged
merged 20 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
14f6918
Make fields in data calsses required/nullable
MH321Productions Jan 29, 2024
208bbf2
Make FilesRepository Find method nullable
MH321Productions Jan 29, 2024
56ca6ae
Remove redundant null checks
MH321Productions Jan 29, 2024
18fdd4d
Assert Container is non-null
MH321Productions Jan 29, 2024
00502b4
Use default ConverterMappingHints
MH321Productions Jan 29, 2024
8e9d4a7
Add default initializers
MH321Productions Jan 29, 2024
2ef1e8f
Merge branch 'main' into fix-files-nullability-issues
MH321Productions Jan 29, 2024
046ac08
Merge main into fix-files-nullability-issues
github-actions[bot] Jan 29, 2024
e16ae83
Merge main into fix-files-nullability-issues
github-actions[bot] Jan 30, 2024
8a44b8a
Merge main into fix-files-nullability-issues
github-actions[bot] Feb 5, 2024
c5ea36a
Merge main into fix-files-nullability-issues
github-actions[bot] Feb 5, 2024
559a013
Merge main into fix-files-nullability-issues
github-actions[bot] Feb 6, 2024
78f4726
Merge main into fix-files-nullability-issues
github-actions[bot] Feb 9, 2024
1dd5874
Merge main into fix-files-nullability-issues
github-actions[bot] Feb 9, 2024
e334d82
chore: use null! instead of string.Empty
tnotheis Feb 9, 2024
8e43a8d
chore: make properties in BlobStorageOptions not nullable
tnotheis Feb 9, 2024
ec9902c
chore: minor cleanup
tnotheis Feb 9, 2024
9a72243
chore: add explaining comment to usage of null!
tnotheis Feb 9, 2024
3e0dd33
chore: initialize ConnectionInfo with null!
tnotheis Feb 9, 2024
2989edd
chore: remove unnecessary stuff from .csproj files
tnotheis Feb 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Backbone.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=ecdsa/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=enrichers/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=firebase/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Iddict/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=inexistent/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mediat/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Onboarded/@EntryIndexedValue">True</s:Boolean>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void AddBlobStorage(this IServiceCollection services, BlobStorageO
services.AddGoogleCloudStorage(googleCloudStorageOptions =>
{
googleCloudStorageOptions.GcpAuthJson = options.ConnectionInfo;
googleCloudStorageOptions.BucketName = options.Container!;
googleCloudStorageOptions.BucketName = options.Container;
});
else if (options.CloudProvider.IsNullOrEmpty())
throw new NotSupportedException("No cloud provider was specified.");
Expand All @@ -41,15 +41,9 @@ public static void AddBlobStorage(this IServiceCollection services, BlobStorageO

public class BlobStorageOptions
{
/**
* This property will never be null as it makes no sense, but is marked as nullable due to how AddBlobStorage method uses BlobStorageOptions.
*/
public string? CloudProvider { get; set; }
public string CloudProvider { get; set; } = null!;

/**
* This property will never be null as it makes no sense, but is marked as nullable due to how AddBlobStorage method uses BlobStorageOptions.
*/
public string? Container { get; set; }
public string Container { get; set; } = null!;

public string? ConnectionInfo { get; set; }
public string? ConnectionInfo { get; set; } = null;
}
30 changes: 15 additions & 15 deletions Modules/Files/src/Files.Application/Files/DTOs/FileMetadataDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ namespace Backbone.Modules.Files.Application.Files.DTOs;

public class FileMetadataDTO : IHaveCustomMapping
{
public FileId Id { get; set; }
public required FileId Id { get; set; }

public DateTime CreatedAt { get; set; }
public IdentityAddress CreatedBy { get; set; }
public DeviceId CreatedByDevice { get; set; }
public required DateTime CreatedAt { get; set; }
public required IdentityAddress CreatedBy { get; set; }
public required DeviceId CreatedByDevice { get; set; }

public DateTime ModifiedAt { get; set; }
public IdentityAddress ModifiedBy { get; set; }
public DeviceId ModifiedByDevice { get; set; }
public required DateTime ModifiedAt { get; set; }
public required IdentityAddress ModifiedBy { get; set; }
public required DeviceId ModifiedByDevice { get; set; }

public DateTime? DeletedAt { get; set; }
public IdentityAddress DeletedBy { get; set; }
public DeviceId DeletedByDevice { get; set; }
public IdentityAddress? DeletedBy { get; set; }
public DeviceId? DeletedByDevice { get; set; }

public IdentityAddress Owner { get; set; }
public byte[] OwnerSignature { get; set; }
public required IdentityAddress Owner { get; set; }
public required byte[] OwnerSignature { get; set; }

public long CipherSize { get; set; }
public byte[] CipherHash { get; set; }
public required long CipherSize { get; set; }
public required byte[] CipherHash { get; set; }

public DateTime ExpiresAt { get; set; }
public required DateTime ExpiresAt { get; set; }

public byte[] EncryptedProperties { get; set; }
public required byte[] EncryptedProperties { get; set; }

public void CreateMappings(Profile configuration)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ namespace Backbone.Modules.Files.Application.Files.Queries.GetFileContent;

public class GetFileContentQuery : IRequest<GetFileContentResponse>
{
public FileId Id { get; set; }
public required FileId Id { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public class GetFileContentResponse
{
public byte[] FileContent { get; set; }
public required byte[] FileContent { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ namespace Backbone.Modules.Files.Application.Files.Queries.GetFileMetadata;

public class GetFileMetadataQuery : IRequest<FileMetadataDTO>
{
public FileId Id { get; set; }
public required FileId Id { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public class BlobOptions
{
public string RootFolder { get; set; }
public required string RootFolder { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Backbone.Modules.Files.Application.Infrastructure.Persistence.Repository;
public interface IFilesRepository
{
Task<File> Find(FileId id, CancellationToken cancellationToken, bool track = false, bool fillContent = true);
Task<File?> Find(FileId id, CancellationToken cancellationToken, bool track = false, bool fillContent = true);
Task<DbPaginationResult<File>> FindFilesByCreator(IEnumerable<FileId> fileIds, IdentityAddress creatorAddress, PaginationFilter paginationFilter, CancellationToken cancellationToken);
Task Add(File file, CancellationToken cancellationToken);
}
17 changes: 14 additions & 3 deletions Modules/Files/src/Files.Domain/Entities/File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@ namespace Backbone.Modules.Files.Domain.Entities;

public class File
{
#pragma warning disable CS8618
private File() { }
#pragma warning restore CS8618
private File()
{
// This constructor is for EF Core only; initializing the properties with null is therefore not a problem
Id = null!;
CreatedBy = null!;
CreatedByDevice = null!;
ModifiedBy = null!;
ModifiedByDevice = null!;
Owner = null!;
OwnerSignature = null!;
CipherHash = null!;
Content = null!;
EncryptedProperties = null!;
}

public File(IdentityAddress createdBy, DeviceId createdByDevice, IdentityAddress owner, byte[] ownerSignature, byte[] cipherHash, byte[] content, long cipherSize, DateTime expiresAt, byte[] encryptedProperties)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Persistence\Migrations\**" />
<EmbeddedResource Remove="Persistence\Migrations\**" />
<None Remove="Persistence\Migrations\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Backbone.Modules.Files.Infrastructure.Persistence.Database.EntityTypeConfigurations;

public class FileEntityTypeConfiguration : IEntityTypeConfiguration<Domain.Entities.File>
public class FileEntityTypeConfiguration : IEntityTypeConfiguration<File>
{
public void Configure(EntityTypeBuilder<File> builder)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public FilesDbContext(DbContextOptions<FilesDbContext> options) : base(options)

public FilesDbContext(DbContextOptions<FilesDbContext> options, IServiceProvider serviceProvider) : base(options, serviceProvider) { }

public DbSet<File> FileMetadata { get; set; }
public DbSet<File> FileMetadata { get; set; } = null!;

protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class IServiceCollectionExtensions
public static void AddDatabase(this IServiceCollection services, Action<DbOptions> setupOptions)
{
var options = new DbOptions();
setupOptions?.Invoke(options);
setupOptions.Invoke(options);

services.AddDatabase(options);
}
Expand Down Expand Up @@ -56,8 +56,8 @@ public static void AddDatabase(this IServiceCollection services, DbOptions optio

public class DbOptions
{
public string Provider { get; set; }
public string DbConnectionString { get; set; }
public string Provider { get; set; } = null!;
public string DbConnectionString { get; set; } = null!;
public RetryOptions RetryOptions { get; set; } = new();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task Add(File file, CancellationToken cancellationToken)

}

public async Task<File> Find(FileId fileId, CancellationToken cancellationToken, bool track = false, bool fillContent = true)
public async Task<File?> Find(FileId fileId, CancellationToken cancellationToken, bool track = false, bool fillContent = true)
{
var file = await (track ? _files : _readOnlyFiles)
.WithId(fileId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ namespace Backbone.Modules.Files.Infrastructure.Persistence.Database.ValueConver

public class FileIdEntityFrameworkValueConverter : ValueConverter<FileId, string>
{
public FileIdEntityFrameworkValueConverter() : this(null) { }
public FileIdEntityFrameworkValueConverter() : this(new ConverterMappingHints()) { }

public FileIdEntityFrameworkValueConverter(ConverterMappingHints mappingHints)
: base(
id => id == null ? null : id.StringValue,
id => id.StringValue,
value => FileId.Parse(value),
mappingHints
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class IServiceCollectionExtensions
public static void AddPersistence(this IServiceCollection services, Action<PersistenceOptions> setupOptions)
{
var options = new PersistenceOptions();
setupOptions?.Invoke(options);
setupOptions.Invoke(options);

services.AddPersistence(options);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">

<PropertyGroup>
<UserSecretsId>dotnet-Files.Jobs.SanityCheck-9f22e8e4-eb64-498c-9599-b971e0419647</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..\..\..</DockerfileContext>
<Nullable>enable</Nullable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public SanityCheck(IDataSource dataSource, IReporter reporter)
{
_dataSource = dataSource;
_reporter = reporter;
_databaseIds = [];
_blobIds = [];
}

public async Task Run(CancellationToken cancellationToken)
Expand Down
6 changes: 5 additions & 1 deletion Modules/Files/src/Files.Jobs.SanityCheck/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public Worker(IHostApplicationLifetime host, IServiceScopeFactory serviceScopeFa
{
_host = host;
_serviceScopeFactory = serviceScopeFactory;

// the following fields are initialized in StartAsync, which is always called before any other method
_dataSource = null!;
_reporter = null!;
}

public async Task StartAsync(CancellationToken cancellationToken)
Expand All @@ -33,7 +37,7 @@ public Task StopAsync(CancellationToken cancellationToken)
return Task.CompletedTask;
}

public async Task RunSanityCheck(CancellationToken cancellationToken)
private async Task RunSanityCheck(CancellationToken cancellationToken)
{
var sanityCheck = new Infrastructure.SanityCheck.SanityCheck(_dataSource, _reporter);

Expand Down
8 changes: 4 additions & 4 deletions Modules/Files/test/Files.Application.Tests/TestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public static class Devices

public static class Payloads
{
public static readonly byte[] EMPTY = Array.Empty<byte>();
public static readonly byte[] PAYLOAD_1 = { 1, 1, 1 };
public static readonly byte[] PAYLOAD_2 = { 2, 2, 2 };
public static readonly byte[] PAYLOAD_3 = { 3, 3, 3 };
public static readonly byte[] EMPTY = [];
public static readonly byte[] PAYLOAD_1 = [1, 1, 1];
public static readonly byte[] PAYLOAD_2 = [2, 2, 2];
public static readonly byte[] PAYLOAD_3 = [3, 3, 3];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace Backbone.Modules.Files.Jobs.SanityCheck.Tests.Infrastructure.DataSourc

public class FakeDataSource : IDataSource
{
public List<FileId> DatabaseIds { get; } = new();
public List<string> BlobIds { get; } = new();
public List<FileId> DatabaseIds { get; } = [];
public List<string> BlobIds { get; } = [];

public Task<IEnumerable<string>> GetBlobIdsAsync(CancellationToken cancellationToken)
{
Expand Down