From 116c42903ff2809c9a8434e82e67f63532ae9dba Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 14 Jul 2023 14:55:39 +0800 Subject: [PATCH] Enable nullable annotations for Volo.Abp.BlobStoring.Aws --- .../Volo.Abp.BlobStoring.Aws.csproj | 2 ++ .../Volo/Abp/BlobStoring/Aws/AwsBlobProvider.cs | 4 ++-- .../Aws/AwsBlobProviderConfiguration.cs | 14 +++++++------- .../Aws/AwsTemporaryCredentialsCacheItem.cs | 6 +++--- .../Aws/DefaultAmazonS3ClientFactory.cs | 14 +++++++------- framework/src/Volo.Abp.Core/Volo/Abp/Check.cs | 8 ++++---- 6 files changed, 25 insertions(+), 23 deletions(-) diff --git a/framework/src/Volo.Abp.BlobStoring.Aws/Volo.Abp.BlobStoring.Aws.csproj b/framework/src/Volo.Abp.BlobStoring.Aws/Volo.Abp.BlobStoring.Aws.csproj index a5f94b783b..c89685a016 100644 --- a/framework/src/Volo.Abp.BlobStoring.Aws/Volo.Abp.BlobStoring.Aws.csproj +++ b/framework/src/Volo.Abp.BlobStoring.Aws/Volo.Abp.BlobStoring.Aws.csproj @@ -5,6 +5,8 @@ netstandard2.0;netstandard2.1;net7.0 + enable + Nullable false false false diff --git a/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AwsBlobProvider.cs b/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AwsBlobProvider.cs index ff75625636..00a82a0f3e 100644 --- a/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AwsBlobProvider.cs +++ b/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AwsBlobProvider.cs @@ -85,7 +85,7 @@ public class AwsBlobProvider : BlobProviderBase, ITransientDependency } } - public override async Task GetOrNullAsync(BlobProviderGetArgs args) + public override async Task GetOrNullAsync(BlobProviderGetArgs args) { var blobName = AwsBlobNameCalculator.Calculate(args); var containerName = GetContainerName(args); @@ -154,6 +154,6 @@ public class AwsBlobProvider : BlobProviderBase, ITransientDependency var configuration = args.Configuration.GetAwsConfiguration(); return configuration.ContainerName.IsNullOrWhiteSpace() ? args.ContainerName - : BlobNormalizeNamingService.NormalizeContainerName(args.Configuration, configuration.ContainerName); + : BlobNormalizeNamingService.NormalizeContainerName(args.Configuration, configuration.ContainerName!); } } diff --git a/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AwsBlobProviderConfiguration.cs b/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AwsBlobProviderConfiguration.cs index 789304018d..1b31d176c8 100644 --- a/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AwsBlobProviderConfiguration.cs +++ b/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AwsBlobProviderConfiguration.cs @@ -4,12 +4,12 @@ namespace Volo.Abp.BlobStoring.Aws; public class AwsBlobProviderConfiguration { - public string AccessKeyId { + public string? AccessKeyId { get => _containerConfiguration.GetConfigurationOrDefault(AwsBlobProviderConfigurationNames.AccessKeyId); set => _containerConfiguration.SetConfiguration(AwsBlobProviderConfigurationNames.AccessKeyId, value); } - public string SecretAccessKey { + public string? SecretAccessKey { get => _containerConfiguration.GetConfigurationOrDefault(AwsBlobProviderConfigurationNames.SecretAccessKey); set => _containerConfiguration.SetConfiguration(AwsBlobProviderConfigurationNames.SecretAccessKey, value); } @@ -29,12 +29,12 @@ public class AwsBlobProviderConfiguration set => _containerConfiguration.SetConfiguration(AwsBlobProviderConfigurationNames.UseTemporaryFederatedCredentials, value); } - public string ProfileName { + public string? ProfileName { get => _containerConfiguration.GetConfigurationOrDefault(AwsBlobProviderConfigurationNames.ProfileName); set => _containerConfiguration.SetConfiguration(AwsBlobProviderConfigurationNames.ProfileName, value); } - public string ProfilesLocation { + public string? ProfilesLocation { get => _containerConfiguration.GetConfigurationOrDefault(AwsBlobProviderConfigurationNames.ProfilesLocation); set => _containerConfiguration.SetConfiguration(AwsBlobProviderConfigurationNames.ProfilesLocation, value); } @@ -52,7 +52,7 @@ public class AwsBlobProviderConfiguration set => _containerConfiguration.SetConfiguration(AwsBlobProviderConfigurationNames.Name, value); } - public string Policy { + public string? Policy { get => _containerConfiguration.GetConfigurationOrDefault(AwsBlobProviderConfigurationNames.Policy); set => _containerConfiguration.SetConfiguration(AwsBlobProviderConfigurationNames.Policy, value); } @@ -68,7 +68,7 @@ public class AwsBlobProviderConfiguration /// The name must also be between 3 and 63 characters long. /// If this parameter is not specified, the ContainerName of the will be used. /// - public string ContainerName { + public string? ContainerName { get => _containerConfiguration.GetConfigurationOrDefault(AwsBlobProviderConfigurationNames.ContainerName); set => _containerConfiguration.SetConfiguration(AwsBlobProviderConfigurationNames.ContainerName, value); } @@ -82,7 +82,7 @@ public class AwsBlobProviderConfiguration } private readonly string _temporaryCredentialsCacheKey; - public string TemporaryCredentialsCacheKey { + public string? TemporaryCredentialsCacheKey { get => _containerConfiguration.GetConfigurationOrDefault(AwsBlobProviderConfigurationNames.TemporaryCredentialsCacheKey, _temporaryCredentialsCacheKey); set => _containerConfiguration.SetConfiguration(AwsBlobProviderConfigurationNames.TemporaryCredentialsCacheKey, value); } diff --git a/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AwsTemporaryCredentialsCacheItem.cs b/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AwsTemporaryCredentialsCacheItem.cs index 69ae65fc97..52b6291ea0 100644 --- a/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AwsTemporaryCredentialsCacheItem.cs +++ b/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AwsTemporaryCredentialsCacheItem.cs @@ -5,11 +5,11 @@ namespace Volo.Abp.BlobStoring.Aws; [Serializable] public class AwsTemporaryCredentialsCacheItem { - public string AccessKeyId { get; set; } + public string AccessKeyId { get; set; } = default!; - public string SecretAccessKey { get; set; } + public string SecretAccessKey { get; set; } = default!; - public string SessionToken { get; set; } + public string SessionToken { get; set; } = default!; public AwsTemporaryCredentialsCacheItem() { diff --git a/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/DefaultAmazonS3ClientFactory.cs b/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/DefaultAmazonS3ClientFactory.cs index 35fab8abe3..dee0bf5096 100644 --- a/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/DefaultAmazonS3ClientFactory.cs +++ b/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/DefaultAmazonS3ClientFactory.cs @@ -57,7 +57,7 @@ public class DefaultAmazonS3ClientFactory : IAmazonS3ClientFactory, ITransientDe return new AmazonS3Client(configuration.AccessKeyId, configuration.SecretAccessKey, region); } - protected virtual AWSCredentials GetAwsCredentials( + protected virtual AWSCredentials? GetAwsCredentials( AwsBlobProviderConfiguration configuration) { if (configuration.ProfileName.IsNullOrWhiteSpace()) @@ -78,7 +78,7 @@ public class DefaultAmazonS3ClientFactory : IAmazonS3ClientFactory, ITransientDe protected virtual async Task GetTemporaryCredentialsAsync( AwsBlobProviderConfiguration configuration) { - var temporaryCredentialsCache = await Cache.GetAsync(configuration.TemporaryCredentialsCacheKey); + var temporaryCredentialsCache = await Cache.GetAsync(configuration.TemporaryCredentialsCacheKey!); if (temporaryCredentialsCache == null) { @@ -127,7 +127,7 @@ public class DefaultAmazonS3ClientFactory : IAmazonS3ClientFactory, ITransientDe Check.NotNullOrWhiteSpace(configuration.Name, nameof(configuration.Name)); Check.NotNullOrWhiteSpace(configuration.Policy, nameof(configuration.Policy)); - var temporaryCredentialsCache = await Cache.GetAsync(configuration.TemporaryCredentialsCacheKey); + var temporaryCredentialsCache = await Cache.GetAsync(configuration.TemporaryCredentialsCacheKey!); if (temporaryCredentialsCache == null) { @@ -177,11 +177,11 @@ public class DefaultAmazonS3ClientFactory : IAmazonS3ClientFactory, ITransientDe Credentials credentials) { var temporaryCredentialsCache = new AwsTemporaryCredentialsCacheItem( - StringEncryptionService.Encrypt(credentials.AccessKeyId), - StringEncryptionService.Encrypt(credentials.SecretAccessKey), - StringEncryptionService.Encrypt(credentials.SessionToken)); + StringEncryptionService.Encrypt(credentials.AccessKeyId)!, + StringEncryptionService.Encrypt(credentials.SecretAccessKey)!, + StringEncryptionService.Encrypt(credentials.SessionToken)!); - await Cache.SetAsync(configuration.TemporaryCredentialsCacheKey, temporaryCredentialsCache, + await Cache.SetAsync(configuration.TemporaryCredentialsCacheKey!, temporaryCredentialsCache, new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(configuration.DurationSeconds - 10) diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs index dbb8dc20fb..4aa3c10ecb 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Check.cs @@ -62,7 +62,7 @@ public static class Check [ContractAnnotation("value:null => halt")] public static string NotNullOrWhiteSpace( - string value, + string? value, [InvokerParameterName][NotNull] string parameterName, int maxLength = int.MaxValue, int minLength = 0) @@ -72,7 +72,7 @@ public static class Check throw new ArgumentException($"{parameterName} can not be null, empty or white space!", parameterName); } - if (value.Length > maxLength) + if (value!.Length > maxLength) { throw new ArgumentException($"{parameterName} length must be equal to or lower than {maxLength}!", parameterName); } @@ -87,7 +87,7 @@ public static class Check [ContractAnnotation("value:null => halt")] public static string NotNullOrEmpty( - string value, + string? value, [InvokerParameterName][NotNull] string parameterName, int maxLength = int.MaxValue, int minLength = 0) @@ -97,7 +97,7 @@ public static class Check throw new ArgumentException($"{parameterName} can not be null or empty!", parameterName); } - if (value.Length > maxLength) + if (value!.Length > maxLength) { throw new ArgumentException($"{parameterName} length must be equal to or lower than {maxLength}!", parameterName); }