chitralverma opened a new pull request, #9330:
URL: https://github.com/apache/opendal/pull/9330
# Which issue does this PR close?
Closes #9312.
Refs #9261, #9262.
# Rationale for this change
`ServiceConfig.configMap()` merged the entries of `S3.assumeRoleSessionTags`
and `HdfsNative.options` into the top-level options. Core never received either
map, and a tag such as `Region` competed with `region` (#9312). Since #9262,
core reads a map-valued option from a JSON object string.
I measured the issue's reproduction on main (`4ae8e6122`, full native build,
JDK 21). `configMap()` returned `{Region=eu-west-1, access_key_id=AKIDEXAMPLE,
bucket=b, disable_config_load=true, region=us-east-1,
secret_access_key=secret}`. Over 5 JVMs with 16 `AsyncOperator.of(cfg)` +
`presignRead` calls each, 32 of 80 URLs were signed for `eu-west-1`. On this
branch, `configMap()` contains
`assume_role_session_tags={"Region":"eu-west-1"}` and no `Region` key, and 48
of 48 URLs over 3 JVMs were signed for `us-east-1`.
# What changes are included in this PR?
- `make_populate_map` (`dev/src/generate/java.rs`) emits `map.put("<key>",
ConfigJson.encodeObject(<field>))` for map fields. The `putAll` branch is
removed.
- The new package-private `ConfigJson` encodes a `Map<String, String>` as a
JSON object. It sorts keys with `String.compareTo`, and it escapes `"`, `\`,
and U+0000–U+001F as RFC 8259 requires. A null value becomes `null`, which core
rejects with `ConfigInvalid` naming `assume_role_session_tags`. A null key
throws `NullPointerException`. An empty map becomes `{}`, and an unset field
has no entry. The encoder is hand-written for three reasons. The binding has no
runtime dependencies (lombok is `provided`, the rest are `test`), the JDK has
no JSON encoder, and a JNI call into `serde_json` would make the pure-Java
`configMap()` load the native library.
- The regenerated `ServiceConfig.java` changes two `configMap()` lines. The
`configMap()` Javadoc now says that a map field becomes one JSON entry and is
not flattened into top-level entries.
- `bindings/java/upgrade.md` gets an *Unreleased* entry for callers who read
`configMap()` directly.
- `pom.xml` adds `jackson-databind` 2.22.4 with `test` scope, so the
round-trip test decodes the JSON independently of `ConfigJson`. The runtime
dependencies are unchanged.
- `ServiceConfigMapFieldTest` has 10 tests.
`sessionTagsRoundTripAlongsideRegion` decodes `assume_role_session_tags` with
Jackson and checks that it is exactly `{Region=eu-west-1}` while `region` stays
`us-east-1`. The other tests pin exact literals for both fields, key order and
case, escaping, `{}` versus unset, and null values and keys, and check operator
construction with escaped tags. Each test fails under at least one scratch
mutation:
- Restoring main's generator (`putAll`) and regenerating fails 9 tests:
all except `coreAcceptsEncodedTags`, which also passes on main because main
drops the tags.
- Lowercasing keys in the encoder fails
`sessionTagsRoundTripAlongsideRegion`, `mapEntriesDoNotBecomeServiceOptions`,
`s3SessionTagsBecomeOneJsonEntry`, `hdfsNativeOptionsBecomeOneJsonEntry`, and
`keysAreSortedAndKeepTheirCase`.
- Dropping `"`/`\` escaping, or the `\u00XX` escape, fails
`jsonEscapesQuotesBackslashesAndControlCharacters` and `coreAcceptsEncodedTags`.
- Dropping the `\n` short form fails
`jsonEscapesQuotesBackslashesAndControlCharacters`.
- Iterating the input map instead of a `TreeMap` fails
`keysAreSortedAndKeepTheirCase` and
`jsonEscapesQuotesBackslashesAndControlCharacters`.
- Encoding an empty map as `""` fails `emptyMapIsExplicitAndNullIsOmitted`.
- Throwing on null values fails `coreRejectsNullTagValue`.
- Accepting null keys fails `nullTagKeyIsRejected`.
# Are there any user-facing changes?
Yes. `configMap()` returns one JSON object string per map field, under
`assume_role_session_tags` or `options`, instead of flattening the map's
entries into top-level entries. A null map omits the option, and an empty map
gives `{}`. S3 session tags now reach STS `AssumeRole` when `roleArn` is set.
`HdfsNative.options` now reaches the client in native builds with
`services-hdfs-native`. No signatures change: `javap -p -s` of `ServiceConfig`,
`ServiceConfig$S3`, `ServiceConfig$S3$S3Builder`, `ServiceConfig$HdfsNative`,
and `ServiceConfig$HdfsNative$HdfsNativeBuilder` matches main, and `ConfigJson`
is package-private.
# Breaking changes
Affected packages: bindings/java
Migration:
- `ServiceConfig.configMap()` now returns each map-valued field
(`S3.assumeRoleSessionTags`, `HdfsNative.options`) as one entry whose value is
a JSON object string, instead of merging the field's entries into the top-level
options. Code that read those entries from `configMap()` should read the field
instead.
- If you relied on a merged entry to set a service option, set that option
directly on the builder or in the `Operator.of(String, Map)` map.
- S3 session tags now reach STS `AssumeRole` when `roleArn` is set. The
role's trust policy must allow `sts:TagSession`, or `AssumeRole` fails. If it
does not, leave `assumeRoleSessionTags` unset. See `bindings/java/upgrade.md`
under *Unreleased*.
# AI Usage Statement
- Harness: Claude Code (in T3 Code)
- Model: Claude Opus 5.5 (`claude-opus-5-5`)
- Effort: max (planning), high (implementation), xhigh (orchestration and
review)
- Role: Planned the change, reproduced the bug in Java, implemented the
generator change, encoder, tests, and upgrade note, ran the checks above, and
drafted this description. The author reviewed them. S3 session tags were not
tested against AWS STS. The `sts:TagSession` requirement comes from the AWS IAM
session-tags documentation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]