Enable nullable annotations for Volo.Abp.BlobStoring.Aliyun

pull/17120/head
liangshiwei 2 years ago
parent 7ffbb7a014
commit 66b034cf6a

@ -5,6 +5,8 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<AssemblyName>Volo.Abp.BlobStoring.Aliyun</AssemblyName>
<PackageId>Volo.Abp.BlobStoring.Aliyun</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>

@ -76,7 +76,7 @@ public class AliyunBlobProvider : BlobProviderBase, ITransientDependency
return Task.FromResult(BlobExists(ossClient, containerName, blobName));
}
public override async Task<Stream> GetOrNullAsync(BlobProviderGetArgs args)
public override async Task<Stream?> GetOrNullAsync(BlobProviderGetArgs args)
{
var containerName = GetContainerName(args);
var blobName = AliyunBlobNameCalculator.Calculate(args);
@ -94,7 +94,7 @@ public class AliyunBlobProvider : BlobProviderBase, ITransientDependency
var configuration = args.Configuration.GetAliyunConfiguration();
return configuration.ContainerName.IsNullOrWhiteSpace()
? args.ContainerName
: BlobNormalizeNamingService.NormalizeContainerName(args.Configuration, configuration.ContainerName);
: BlobNormalizeNamingService.NormalizeContainerName(args.Configuration, configuration.ContainerName!);
}
protected virtual bool BlobExists(IOss ossClient, string containerName, string blobName)

@ -70,7 +70,7 @@ public class AliyunBlobProviderConfiguration
/// 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>(AliyunBlobProviderConfigurationNames.ContainerName);
set => _containerConfiguration.SetConfiguration(AliyunBlobProviderConfigurationNames.ContainerName, value);
}
@ -84,7 +84,7 @@ public class AliyunBlobProviderConfiguration
}
private readonly string _temporaryCredentialsCacheKey;
public string TemporaryCredentialsCacheKey {
public string? TemporaryCredentialsCacheKey {
get => _containerConfiguration.GetConfigurationOrDefault(AliyunBlobProviderConfigurationNames.TemporaryCredentialsCacheKey, _temporaryCredentialsCacheKey);
set => _containerConfiguration.SetConfiguration(AliyunBlobProviderConfigurationNames.TemporaryCredentialsCacheKey, value);
}

@ -8,11 +8,11 @@ namespace Volo.Abp.BlobStoring.Aliyun;
[Serializable]
public class AliyunTemporaryCredentialsCacheItem
{
public string AccessKeyId { get; set; }
public string AccessKeyId { get; set; } = default!;
public string AccessKeySecret { get; set; }
public string AccessKeySecret { get; set; } = default!;
public string SecurityToken { get; set; }
public string SecurityToken { get; set; } = default!;
public AliyunTemporaryCredentialsCacheItem()
{

@ -49,7 +49,7 @@ public class DefaultOssClientFactory : IOssClientFactory, ITransientDependency
{
Check.NotNullOrWhiteSpace(configuration.RoleArn, nameof(configuration.RoleArn));
Check.NotNullOrWhiteSpace(configuration.RoleSessionName, nameof(configuration.RoleSessionName));
var cacheItem = Cache.Get(configuration.TemporaryCredentialsCacheKey);
var cacheItem = Cache.Get(configuration.TemporaryCredentialsCacheKey!);
if (cacheItem == null)
{
IClientProfile profile = DefaultProfile.GetProfile(
@ -83,11 +83,11 @@ public class DefaultOssClientFactory : IOssClientFactory, ITransientDependency
AssumeRole_Credentials credentials)
{
var temporaryCredentialsCache = new AliyunTemporaryCredentialsCacheItem(
StringEncryptionService.Encrypt(credentials.AccessKeyId),
StringEncryptionService.Encrypt(credentials.AccessKeySecret),
StringEncryptionService.Encrypt(credentials.SecurityToken));
StringEncryptionService.Encrypt(credentials.AccessKeyId)!,
StringEncryptionService.Encrypt(credentials.AccessKeySecret)!,
StringEncryptionService.Encrypt(credentials.SecurityToken)!);
Cache.Set(configuration.TemporaryCredentialsCacheKey, temporaryCredentialsCache,
Cache.Set(configuration.TemporaryCredentialsCacheKey!, temporaryCredentialsCache,
new DistributedCacheEntryOptions
{
AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(configuration.DurationSeconds - 10)

@ -12,7 +12,7 @@ public abstract class BlobProviderBase : IBlobProvider
public abstract Task<bool> ExistsAsync(BlobProviderExistsArgs args);
public abstract Task<Stream> GetOrNullAsync(BlobProviderGetArgs args);
public abstract Task<Stream?> GetOrNullAsync(BlobProviderGetArgs args);
protected virtual async Task<Stream?> TryCopyToMemoryStreamAsync(Stream? stream, CancellationToken cancellationToken = default)
{

@ -11,5 +11,5 @@ public interface IBlobProvider
Task<bool> ExistsAsync(BlobProviderExistsArgs args);
Task<Stream> GetOrNullAsync(BlobProviderGetArgs args);
Task<Stream?> GetOrNullAsync(BlobProviderGetArgs args);
}

Loading…
Cancel
Save