ExStorageService.BucketValidator (ex_storage_service v0.6.3)

Copy Markdown View Source

Validates S3 bucket names and filesystem path segments.

Enforces the same naming rules as AWS S3:

  • 3–63 characters
  • Lowercase letters, numbers, hyphens, dots only
  • Must start and end with a letter or number
  • Cannot be formatted as an IP address
  • Cannot contain consecutive dots or dot-hyphen/hyphen-dot sequences

Also rejects names that could escape the data root directory via path traversal.

Summary

Functions

Returns true if the bucket name is valid according to S3 rules and is safe to use as a filesystem directory name.

Returns a human-readable error message for an invalid bucket name, or :ok if the name is valid.

Functions

valid_bucket_name?(name)

@spec valid_bucket_name?(String.t()) :: boolean()

Returns true if the bucket name is valid according to S3 rules and is safe to use as a filesystem directory name.

Examples

iex> BucketValidator.valid_bucket_name?("my-bucket")
true

iex> BucketValidator.valid_bucket_name?("../escape")
false

iex> BucketValidator.valid_bucket_name?("192.168.1.1")
false

validate(name)

@spec validate(String.t()) :: :ok | {:error, String.t()}

Returns a human-readable error message for an invalid bucket name, or :ok if the name is valid.