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

[Nullable Context] Enable on S3Storage #6951

Merged
merged 4 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
2 changes: 1 addition & 1 deletion src/Extensions/S3Storage/LoggingEventIds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal static class LoggingEventIdsExtensions
{
public static EventId EventId(this LoggingEventIds enumVal)
{
string name = Enum.GetName(typeof(LoggingEventIds), enumVal);
string? name = Enum.GetName(typeof(LoggingEventIds), enumVal);
int id = enumVal.Id();
return new EventId(id, name);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Extensions/S3Storage/LoggingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ namespace Microsoft.Diagnostics.Monitoring.Extension.S3Storage
{
public static class LoggingExtensions
{
private static readonly Action<ILogger, string, Exception> _egressProviderInvokeStreamAction =
private static readonly Action<ILogger, string, Exception?> _egressProviderInvokeStreamAction =
LoggerMessage.Define<string>(
eventId: LoggingEventIds.EgressProviderInvokeStreamAction.EventId(),
logLevel: LogLevel.Debug,
formatString: Strings.LogFormatString_EgressProviderInvokeStreamAction);

private static readonly Action<ILogger, string, string, Exception> _egressProviderSavedStream =
private static readonly Action<ILogger, string, string, Exception?> _egressProviderSavedStream =
LoggerMessage.Define<string, string>(
eventId: LoggingEventIds.EgressProviderSavedStream.EventId(),
logLevel: LogLevel.Debug,
Expand Down
4 changes: 2 additions & 2 deletions src/Extensions/S3Storage/MultiPartUploadStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal sealed class MultiPartUploadStream : Stream
{
private readonly byte[] _buffer;
private int _offset;
private readonly string _bucketName;
private readonly string? _bucketName;
private readonly string _objectKey;
private readonly string _uploadId;
private readonly IS3Storage _client;
Expand All @@ -27,7 +27,7 @@ internal sealed class MultiPartUploadStream : Stream
public const int MinimumSize = 5 * 1024 * 1024; // the minimum size of an upload part (except for the last part)
private readonly int _bufferSize;

public MultiPartUploadStream(IS3Storage client, string bucketName, string objectKey, string uploadId, int? bufferSize)
public MultiPartUploadStream(IS3Storage client, string? bucketName, string objectKey, string uploadId, int? bufferSize)
ashyuuu marked this conversation as resolved.
Show resolved Hide resolved
{
_bufferSize = Math.Max(bufferSize ?? 0, MinimumSize);
_buffer = ArrayPool<byte>.Shared.Rent(_bufferSize);
Expand Down
8 changes: 4 additions & 4 deletions src/Extensions/S3Storage/S3Storage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ namespace Microsoft.Diagnostics.Monitoring.Extension.S3Storage
internal sealed class S3Storage : IS3Storage
{
private readonly IAmazonS3 _s3Client;
private readonly string _bucketName;
private readonly string? _bucketName;
private readonly string _objectId;
private readonly string _contentType;
private readonly bool _useKmsEncryption;
private readonly string _kmsEncryptionKey;
private readonly string? _kmsEncryptionKey;

public S3Storage(IAmazonS3 client, string bucketName, string objectId, string contentType, bool useKmsEncryption, string kmsEncryptionKey)
public S3Storage(IAmazonS3 client, string? bucketName, string objectId, string contentType, bool useKmsEncryption, string? kmsEncryptionKey)
{
_s3Client = client;
_bucketName = bucketName;
Expand All @@ -38,7 +38,7 @@ public S3Storage(IAmazonS3 client, string bucketName, string objectId, string co

public static async Task<IS3Storage> CreateAsync(S3StorageEgressProviderOptions options, EgressArtifactSettings settings, CancellationToken cancellationToken)
{
AWSCredentials awsCredentials = null;
AWSCredentials? awsCredentials = null;
AmazonS3Config configuration = new();
// use the specified access key and the secrets taken from configuration
if (!string.IsNullOrEmpty(options.AccessKeyId) && !string.IsNullOrEmpty(options.SecretAccessKey))
Expand Down
1 change: 1 addition & 0 deletions src/Extensions/S3Storage/S3Storage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<PackageTags>Diagnostic</PackageTags>
<PackageReleaseNotes>$(Description)</PackageReleaseNotes>
<AssemblyName>dotnet-monitor-egress-s3storage</AssemblyName>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/Extensions/S3Storage/S3StorageEgressProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public S3StorageEgressProvider(ILogger<S3StorageEgressProvider> logger)
EgressArtifactSettings artifactSettings,
CancellationToken token)
{
IS3Storage client = null;
string uploadId = null;
IS3Storage? client = null;
string? uploadId = null;
bool uploadDone = false;
try
{
Expand Down Expand Up @@ -70,7 +70,7 @@ public S3StorageEgressProvider(ILogger<S3StorageEgressProvider> logger)
}
catch (AmazonS3Exception e)
{
if (uploadId != null && !uploadDone)
if (client != null && uploadId != null && !uploadDone)
await client.AbortMultipartUploadAsync(uploadId, token);
throw CreateException(e.Message);
}
Expand Down
16 changes: 8 additions & 8 deletions src/Extensions/S3Storage/S3StorageEgressProviderOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,38 @@ internal sealed partial class S3StorageEgressProviderOptions
[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_S3StorageEgressProviderOptions_Endpoint))]
public string Endpoint { get; set; }
public string? Endpoint { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_S3StorageEgressProviderOptions_BucketName))]
[Required(AllowEmptyStrings = false)]
public string BucketName { get; set; }
public string BucketName { get; set; } = string.Empty;

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_S3StorageEgressProviderOptions_RegionName))]
public string RegionName { get; set; }
public string? RegionName { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_S3StorageEgressProviderOptions_AccessKeyId))]
public string AccessKeyId { get; set; }
public string? AccessKeyId { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_S3StorageEgressProviderOptions_SecretAccessKey))]
public string SecretAccessKey { get; set; }
public string? SecretAccessKey { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_S3StorageEgressProviderOptions_AWSProfileName))]
public string AwsProfileName { get; set; }
public string? AwsProfileName { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_S3StorageEgressProviderOptions_AWSProfilePath))]
public string AwsProfilePath { get; set; }
public string? AwsProfilePath { get; set; }

[Display(
ResourceType = typeof(OptionsDisplayStrings),
Expand All @@ -72,6 +72,6 @@ internal sealed partial class S3StorageEgressProviderOptions
[Display(
ResourceType = typeof(OptionsDisplayStrings),
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_S3StorageEgressProviderOptions_KmsEncryptionKey))]
public string KmsEncryptionKey { get; set; }
public string? KmsEncryptionKey { get; set; }
}
}
Loading