Skip to content

feat(sdk): add ergonomic Resource constructors for authorization#354

Merged
marythought merged 2 commits intomainfrom
DSPX-2815-resource-constructors
Apr 21, 2026
Merged

feat(sdk): add ergonomic Resource constructors for authorization#354
marythought merged 2 commits intomainfrom
DSPX-2815-resource-constructors

Conversation

@marythought
Copy link
Copy Markdown
Contributor

@marythought marythought commented Apr 21, 2026

Summary

Before:

Resource.newBuilder()
    .setAttributeValues(
        Resource.AttributeValues.newBuilder()
            .addFqns("https://example.com/attr/department/value/finance"))
    .build();

After:

Resources.forAttributeValues("https://example.com/attr/department/value/finance");

Example — GetDecision authorization call:

import io.opentdf.platform.sdk.EntityIdentifiers;
import io.opentdf.platform.sdk.Resources;

GetDecisionRequest request = GetDecisionRequest.newBuilder()
    .setEntityIdentifier(EntityIdentifiers.forEmail("user@company.com"))
    .setAction(Action.newBuilder().setName("decrypt"))
    .setResource(Resources.forAttributeValues(
        "https://company.com/attr/clearance/value/confidential",
        "https://company.com/attr/department/value/finance"))
    .build();

GetDecisionResponse resp = sdk.getServices()
    .authorization()
    .getDecision(request)
    .get();

Test plan

  • Unit tests for forAttributeValues (single, multiple, empty-string FQN, empty array throws)
  • Unit tests for forRegisteredResourceValueFqn (valid + empty string)
  • Null safety tests (null array, null element, null fqn all throw NPE)
  • Full SDK test suite passes (157 tests, 0 failures)
  • CI checks pass

🤖 Generated with Claude Code

Add Resources utility class with forAttributeValues and
forRegisteredResourceValueFqn helpers to reduce boilerplate when
building Resource objects for authorization calls.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Mary Dickson <mary.dickson@virtru.com>
@marythought marythought requested review from a team as code owners April 21, 2026 00:12
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 21, 2026

Warning

Rate limit exceeded

@marythought has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 59 minutes and 38 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 59 minutes and 38 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3f9b63cc-37e7-45ae-a2cd-42ec09e39bbc

📥 Commits

Reviewing files that changed from the base of the PR and between 2c55e31 and 4690691.

📒 Files selected for processing (2)
  • sdk/src/main/java/io/opentdf/platform/sdk/Resources.java
  • sdk/src/test/java/io/opentdf/platform/sdk/ResourcesTest.java
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch DSPX-2815-resource-constructors

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new Resources utility class in the Java SDK to simplify the creation of Resource protocol buffer objects. It includes static factory methods forAttributeValues and forRegisteredResourceValueFqn, along with comprehensive unit tests covering various input scenarios and error handling. I have no feedback to provide.

@github-actions
Copy link
Copy Markdown
Contributor

Update class-level Javadoc to reference EntityIdentifiers instead of
non-existent Go SDK helpers.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Mary Dickson <mary.dickson@virtru.com>
@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown
Contributor

@marythought
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 21, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@marythought marythought merged commit 9e05ca2 into main Apr 21, 2026
19 checks passed
@marythought marythought deleted the DSPX-2815-resource-constructors branch April 21, 2026 17:12
marythought pushed a commit that referenced this pull request Apr 22, 2026
🤖 I have created a release *beep* *boop*
---


<details><summary>0.14.0</summary>

##
[0.14.0](v0.13.0...v0.14.0)
(2026-04-21)


### Features

* **sdk:** add ergonomic Resource constructors for authorization
([#354](#354))
([9e05ca2](9e05ca2))


### Bug Fixes

* **ci:** allow release branch scopes in PR title validation
([#349](#349))
([8020a3b](8020a3b))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: opentdf-automation[bot] <149537512+opentdf-automation[bot]@users.noreply.github.com>
marythought added a commit to opentdf/docs that referenced this pull request Apr 24, 2026
## Summary

- Add `### Resource` section documenting helper functions for all 3 SDKs
(`ForAttributeValues`, `ForRegisteredResourceValueFqn`)
- Add `<SdkVersion>` annotations with minimum SDK versions: Go v0.17.0,
Java v0.14.0, JS v0.15.0
- Update GetDecision examples (Go, Java, JS) to use helpers instead of
verbose proto construction
- Update Type Reference Resource section with tabbed helper examples
- Add note about `ephemeralId` not being set by helpers (relevant for
GetDecisionBulk)

Based on #303 (SdkVersion component + EntityIdentifier annotations).

**Companion PRs (SDK implementations):**
- Go: opentdf/platform#3337
- Java: opentdf/java-sdk#354
- JavaScript: opentdf/web-sdk#921

## Test plan

- [ ] `npm run build` passes
- [ ] Visual review of rendered authorization page
- [ ] CI checks pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Documentation**
* Enhanced authorization docs with a new Resource section describing
attribute-value and registered-resource formats, plus language-specific
helper APIs and “without helpers” manual examples.
* Updated GetDecision/GetDecisionBulk/GetEntitlements parameter docs to
link entity/resource types and note Resource helper usage.
* Rewrote multi-language GetDecision samples (Go/Java/JavaScript) to use
Resource/Entity helper constructors.
* Added Go TDFObject type reference and minor Go example ctx
initialization updates.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Mary Dickson <mary.dickson@virtru.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

2 participants