Browse Source

Enable nullable annotations for Volo.Abp.BlobStoring.Aws

pull/17120/head
liangshiwei 3 years ago
parent
commit
116c42903f
  1. 2
      framework/src/Volo.Abp.BlobStoring.Aws/Volo.Abp.BlobStoring.Aws.csproj
  2. 4
      framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AwsBlobProvider.cs
  3. 14
      framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AwsBlobProviderConfiguration.cs
  4. 6
      framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AwsTemporaryCredentialsCacheItem.cs
  5. 14
      framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/DefaultAmazonS3ClientFactory.cs
  6. 8
      framework/src/Volo.Abp.Core/Volo/Abp/Check.cs

2
framework/src/Volo.Abp.BlobStoring.Aws/Volo.Abp.BlobStoring.Aws.csproj

@ -5,6 +5,8 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>

4
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<Stream> GetOrNullAsync(BlobProviderGetArgs args)
public override async Task<Stream?> 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!);
}
}

14
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<string>(AwsBlobProviderConfigurationNames.AccessKeyId);
set => _containerConfiguration.SetConfiguration(AwsBlobProviderConfigurationNames.AccessKeyId, value);
}
public string SecretAccessKey {
public string? SecretAccessKey {
get => _containerConfiguration.GetConfigurationOrDefault<string>(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<string>(AwsBlobProviderConfigurationNames.ProfileName);
set => _containerConfiguration.SetConfiguration(AwsBlobProviderConfigurationNames.ProfileName, value);
}
public string ProfilesLocation {
public string? ProfilesLocation {
get => _containerConfiguration.GetConfigurationOrDefault<string>(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<string>(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 <see cref="BlobProviderArgs"/> will be used.
/// </summary>
public string ContainerName {
public string? ContainerName {
get => _containerConfiguration.GetConfigurationOrDefault<string>(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);
}

6
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()
{

14
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<SessionAWSCredentials> 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)

8
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);
}

Loading…
Cancel
Save