Skip to content

Conversation

@darkenpeng
Copy link

Summary

Add httpUri config descriptor that validates the URI scheme is http or https. This prevents runtime NullPointerException when invalid URIs (e.g., minio:9000 without scheme) are passed to AWS SDK.

Problem

When configuring endpointOverride with an invalid URI like minio:9000 (missing scheme), the config parsing succeeds but AWS SDK throws NPE at runtime.

Solution

  • Add httpUri descriptor that validates scheme is http or https
  • Provide clear error message at config time

Changes

  • descriptors/package.scala: Add httpUri descriptor with scheme validation
    • CommonAwsConfigSpec.scala: Add tests for valid/invalid endpoints

Fixes #626

@CLAassistant
Copy link

CLAassistant commented Jan 23, 2026

CLA assistant check
All committers have signed the CLA.

@darkenpeng
Copy link
Author

About the edge case discussion in #626
K8s proxy scenarios needing URI flexibility. I looked into this:

Use Case Endpoint Works?
LocalStack http://localhost:4566
MinIO http://minio:9000
K8s service http://my-proxy.namespace:8080
AWS https://s3.amazonaws.com

All real-world cases I could find use http:// or https://. Makes sense since AWS SDK communicates over HTTP(S).
Also, AWS SDK 2.x explicitly requires the scheme - it's an intentional breaking change from v1.x. The official docs always show full URLs with schemes too.

Add httpUri config descriptor that validates the URI scheme is http or https.
This prevents runtime NullPointerExceptions when invalid URIs
(e.g., 'minio:9000' without scheme) are passed to AWS SDK.

Changes:
- Add httpUri descriptor with scheme validation in descriptors/package.scala
- Update commonAwsConfig to use httpUri for endpointOverride
- Add tests for valid (http/https) and invalid (missing scheme) endpoints

Fixes zio#626

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@darkenpeng darkenpeng force-pushed the fix/626-endpoint-uri-validation branch from 8404bce to 40c9dbb Compare January 26, 2026 04:53
val httpUri: Config[URI] = Config.uri.mapAttempt { uri =>
val scheme = uri.getScheme
if (scheme == null || (!scheme.equalsIgnoreCase("http") && !scheme.equalsIgnoreCase("https"))) {
throw new IllegalArgumentException(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the type signature of mapAttempt. please?

I'm pretty sure it take a function URI => Either[String, A] and I'm pretty sure you're not supposed to throw

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick review! You're right — I've updated it to use mapOrFail with explicit Either instead.

Address review feedback - use explicit Either return instead of throwing
Copy link
Member

@guizmaii guizmaii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @darkenpeng :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Endpoint override type is not strict enough

3 participants