Skip to content

Code smell: AWS S3 client exposed publicly without encapsulation #1636

@thomhurst

Description

@thomhurst

Issue

Location: C:\git\ModularPipelines\src\ModularPipelines.AmazonWebServices\S3.cs (lines 10-15)

Problem:
The S3 class exposes the underlying AmazonS3Client directly through a public property. This violates encapsulation and allows callers to bypass any wrapper methods, logging, or future enhancements.

Current code:
public class S3
{
public AmazonS3Client Client { get; } // Publicly exposed!

public S3(AmazonS3Client client)
{
    Client = client;
}
// ... wrapper methods

}

Issues:

  1. Callers can use Client directly, bypassing wrapper methods
  2. Cannot add cross-cutting concerns (logging, metrics, validation) to all S3 operations
  3. No abstraction - tied directly to AWS SDK types
  4. Difficult to mock for testing

Risk: LOW - This is a design smell rather than a bug.

Suggested Fix:
Option 1: Make the client internal or private:
internal AmazonS3Client Client { get; }

Option 2: Extract an interface and hide the implementation:
public interface IS3
{
Task Bucket(PutBucketRequest request, CancellationToken token = default);
// ... other methods
}

Option 3: If public access is intentional, document it clearly:
///


/// The underlying AWS S3 client. Use for operations not yet wrapped by this class.
/// Note: Direct usage bypasses any framework-level logging or error handling.
///

public AmazonS3Client Client { get; }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions