Skip to content

Commit a82f860

Browse files
marythoughtclaude
andauthored
chore(docs): add Resource constructor helpers and update examples (#301)
## 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>
1 parent 4362792 commit a82f860

4 files changed

Lines changed: 218 additions & 119 deletions

File tree

code_samples/authorization/get_decision.mdx

Lines changed: 14 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,16 @@ func main() {
3434

3535
// Get Decision using v2 API
3636
// Convenience constructors live in the authorization/v2 package:
37-
// ForClientID, ForEmail, ForUserName, ForToken, WithRequestToken
37+
// Entity: ForClientID, ForEmail, ForUserName, ForToken, WithRequestToken
38+
// Resource: ForAttributeValues, ForRegisteredResourceValueFqn
3839
decisionReq := &authorization.GetDecisionRequest{
3940
EntityIdentifier: authorization.ForClientID("opentdf"),
4041
Action: &policy.Action{
4142
Name: "decrypt",
4243
},
43-
Resource: &authorization.Resource{
44-
Resource: &authorization.Resource_AttributeValues_{
45-
AttributeValues: &authorization.Resource_AttributeValues{
46-
Fqns: []string{"https://opentdf.io/attr/role/value/developer"},
47-
},
48-
},
49-
},
44+
Resource: authorization.ForAttributeValues(
45+
"https://opentdf.io/attr/role/value/developer",
46+
),
5047
}
5148

5249
decision, err := client.AuthorizationV2.GetDecision(context.Background(), decisionReq)
@@ -141,7 +138,6 @@ import io.opentdf.platform.sdk.*;
141138
import java.util.concurrent.ExecutionException;
142139

143140
import io.opentdf.platform.authorization.*;
144-
import io.opentdf.platform.entity.*;
145141
import io.opentdf.platform.policy.*;
146142

147143
public class GetDecision {
@@ -158,28 +154,13 @@ public class GetDecision {
158154

159155
// Get Decision using v2 API
160156
GetDecisionRequest request = GetDecisionRequest.newBuilder()
161-
.setEntityIdentifier(
162-
EntityIdentifier.newBuilder()
163-
.setEntityChain(
164-
EntityChain.newBuilder()
165-
.addEntities(
166-
Entity.newBuilder()
167-
.setId("entity-1")
168-
.setClientId("opentdf")
169-
)
170-
)
171-
)
157+
.setEntityIdentifier(EntityIdentifiers.forClientId("opentdf"))
172158
.setAction(
173159
Action.newBuilder()
174160
.setName("decrypt")
175161
)
176-
.setResource(
177-
Resource.newBuilder()
178-
.setAttributeValues(
179-
Resource.AttributeValues.newBuilder()
180-
.addFqns("https://opentdf.io/attr/role/value/developer")
181-
)
182-
)
162+
.setResource(Resources.forAttributeValues(
163+
"https://opentdf.io/attr/role/value/developer"))
183164
.build();
184165

185166
GetDecisionResponse resp = sdk.getServices().authorization().getDecision(request).get();
@@ -202,6 +183,7 @@ public class GetDecision {
202183
import {
203184
Decision,
204185
} from "@opentdf/sdk/platform/authorization/v2/authorization_pb.js";
186+
import { EntityIdentifiers, Resources } from "@opentdf/sdk";
205187
import { platformConnect, PlatformClient } from "@opentdf/sdk/platform";
206188

207189
async function main() {
@@ -223,33 +205,11 @@ async function main() {
223205
// Get Decision using v2 API
224206
try {
225207
const response = await platformClient.v2.authorization.getDecision({
226-
entityIdentifier: {
227-
identifier: {
228-
case: "entityChain",
229-
value: {
230-
entities: [
231-
{
232-
ephemeralId: "entity-1",
233-
entityType: {
234-
case: "clientId",
235-
value: "opentdf",
236-
},
237-
},
238-
],
239-
},
240-
},
241-
},
242-
action: {
243-
name: "decrypt",
244-
},
245-
resource: {
246-
resource: {
247-
case: "attributeValues",
248-
value: {
249-
fqns: ["https://opentdf.io/attr/role/value/developer"],
250-
},
251-
},
252-
},
208+
entityIdentifier: EntityIdentifiers.forClientId("opentdf"),
209+
action: { name: "decrypt" },
210+
resource: Resources.forAttributeValues(
211+
"https://opentdf.io/attr/role/value/developer",
212+
),
253213
});
254214

255215
const decision = response.decision;

0 commit comments

Comments
 (0)