feat(sdk): add shorthand enum constants for policy types#3408
feat(sdk): add shorthand enum constants for policy types#3408marythought merged 3 commits intomainfrom
Conversation
Add readable constant aliases for verbose proto enum names using the source-file codegen pattern (ADR DSPX-2594). Developers can now write: condition.Operator = policy.OperatorIn group.BooleanOperator = policy.BooleanAnd attr.Rule = policy.RuleHierarchy Instead of: condition.Operator = policy.SubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_IN Constants covered: - OperatorIn, OperatorNotIn, OperatorInContains (SubjectMappingOperatorEnum) - BooleanAnd, BooleanOr (ConditionBooleanTypeEnum) - RuleAllOf, RuleAnyOf, RuleHierarchy (AttributeRuleTypeEnum) - StateActive, StateInactive, StateAny (ActiveStateEnum) Resolves: #3338 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Note Gemini is unable to generate a summary for this pull request due to the file types involved not being currently supported. |
📝 WalkthroughWalkthroughThe changes add a code generator configuration to automatically produce a public enum aliases file ( Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Update Go code samples to use the new policy.OperatorIn, policy.BooleanAnd, policy.RuleAnyOf shorthand constants instead of verbose proto enum names. Companion to opentdf/platform#3408. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
The new enums_test.go in protocol/go/internal/policy/ imports github.com/stretchr/testify, which needs to be in the module's go.mod. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use stdlib testing patterns consistent with the existing authorization/v2 helper tests. No new dependencies needed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
X-Test Failure Report |
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
|
|
📝 Companion docs PR: opentdf/docs#308 — updates Go SDK code samples to use shorthand enum constants. |
Update Go code samples to use the new policy.OperatorIn, policy.BooleanAnd, policy.RuleAnyOf shorthand constants instead of verbose proto enum names. Companion to opentdf/platform#3408. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…928) Re-export SubjectMappingOperatorEnum, ConditionBooleanTypeEnum, AttributeRuleTypeEnum, and ActiveStateEnum from the main @opentdf/sdk entry point so users can import them directly instead of reaching into generated proto paths. Companion to opentdf/platform#3408 (Go SDK) and opentdf/java-sdk#357 (Java SDK). Signed-off-by: Mary Dickson <mary.dickson@virtru.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
## Summary - Add `PolicyEnums` utility class with readable constant aliases for verbose protobuf enum names so developers can write `PolicyEnums.OPERATOR_IN` instead of `SubjectMappingOperatorEnum.SUBJECT_MAPPING_OPERATOR_ENUM_IN` - Update all examples to use the new shorthand constants via static imports - Companion to opentdf/platform#3408 (Go SDK equivalent) ### Constants added | Shorthand | Full proto name | |---|---| | `OPERATOR_IN` | `SUBJECT_MAPPING_OPERATOR_ENUM_IN` | | `OPERATOR_NOT_IN` | `SUBJECT_MAPPING_OPERATOR_ENUM_NOT_IN` | | `OPERATOR_IN_CONTAINS` | `SUBJECT_MAPPING_OPERATOR_ENUM_IN_CONTAINS` | | `BOOLEAN_AND` | `CONDITION_BOOLEAN_TYPE_ENUM_AND` | | `BOOLEAN_OR` | `CONDITION_BOOLEAN_TYPE_ENUM_OR` | | `RULE_ALL_OF` | `ATTRIBUTE_RULE_TYPE_ENUM_ALL_OF` | | `RULE_ANY_OF` | `ATTRIBUTE_RULE_TYPE_ENUM_ANY_OF` | | `RULE_HIERARCHY` | `ATTRIBUTE_RULE_TYPE_ENUM_HIERARCHY` | | `STATE_ACTIVE` | `ACTIVE_STATE_ENUM_ACTIVE` | | `STATE_INACTIVE` | `ACTIVE_STATE_ENUM_INACTIVE` | | `STATE_ANY` | `ACTIVE_STATE_ENUM_ANY` | ### Before / After ```java // Before ConditionGroup.newBuilder() .setBooleanOperator(ConditionBooleanTypeEnum.CONDITION_BOOLEAN_TYPE_ENUM_AND) .addConditions(Condition.newBuilder() .setOperator(SubjectMappingOperatorEnum.SUBJECT_MAPPING_OPERATOR_ENUM_IN)); // After import static io.opentdf.platform.sdk.PolicyEnums.*; ConditionGroup.newBuilder() .setBooleanOperator(BOOLEAN_AND) .addConditions(Condition.newBuilder() .setOperator(OPERATOR_IN)); ``` ## Test plan - [x] `mvn compile` passes (full project including examples) - [x] `mvn test -Dtest=PolicyEnumsTest` — 4 tests, all pass - [ ] CI passes 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Introduced simplified static constants for policy configuration, making attribute rules, operators, and boolean conditions more readable and intuitive to use. * **Documentation** * Updated example code to demonstrate the new simplified policy constants. * **Tests** * Added test coverage validating the new policy configuration constants. <!-- 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>
Update Go code samples to use the new policy.OperatorIn, policy.BooleanAnd, policy.RuleAnyOf shorthand constants instead of verbose proto enum names. Companion to opentdf/platform#3408. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
## Summary - Update Go SDK code samples to use the new shorthand enum constants (`policy.OperatorIn`, `policy.BooleanAnd`, `policy.RuleAnyOf`) instead of verbose proto enum names - Update JS SDK imports to use barrel exports from `@opentdf/sdk` instead of deep proto paths (`@opentdf/sdk/platform/policy/objects_pb.js`) - Update JS SDK examples to use enum values (`ConditionBooleanTypeEnum.AND`) instead of string literals (`'CONDITION_BOOLEAN_TYPE_ENUM_AND'`) - Update Java SDK inline examples in policy.mdx to use `PolicyEnums` shorthand constants - Add `SdkVersion` badges with `NEXT` placeholders — replace with actual versions once SDK releases ship ### Companion PRs | SDK | PR | Status | |---|---|---| | Go | opentdf/platform#3408 | Open | | Java | opentdf/java-sdk#357 | Open | | JavaScript | opentdf/web-sdk#928 | Open | ### Note on Java code samples The `code_samples/java/` files are pulled from the java-sdk repo at build time via `docusaurus-plugin-remote-content`. They will update automatically once `javaSdkVersion` is bumped in `docusaurus.config.ts` after the java-sdk release containing opentdf/java-sdk#357. ## Test plan - [x] `npm run build` passes - [ ] Surge preview renders correctly - [ ] Replace `NEXT` version placeholders after SDK releases 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Updated policy and quickstart code examples for Go, Java, and JavaScript to use simplified SDK enum constants for clearer, more idiomatic samples. * Switched JavaScript examples to use package entry-point imports instead of generated-module paths. * Added SDK version markers to code samples to show explicit language/version context and improve consistency. <!-- 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>
Summary
policy.OperatorIninstead ofpolicy.SubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_INprotocol/go/internal/policy/with full IDE support, copied into thepolicypackage at build timeConstants added
policy.OperatorInSubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_INpolicy.OperatorNotInSubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_NOT_INpolicy.OperatorInContainsSubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_IN_CONTAINSpolicy.BooleanAndConditionBooleanTypeEnum_CONDITION_BOOLEAN_TYPE_ENUM_ANDpolicy.BooleanOrConditionBooleanTypeEnum_CONDITION_BOOLEAN_TYPE_ENUM_ORpolicy.RuleAllOfAttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_ALL_OFpolicy.RuleAnyOfAttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_ANY_OFpolicy.RuleHierarchyAttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_HIERARCHYpolicy.StateActivecommon.ActiveStateEnum_ACTIVE_STATE_ENUM_ACTIVEpolicy.StateInactivecommon.ActiveStateEnum_ACTIVE_STATE_ENUM_INACTIVEpolicy.StateAnycommon.ActiveStateEnum_ACTIVE_STATE_ENUM_ANYBefore / After
Resolves #3338
Test plan
go test ./protocol/go/internal/policy/...go vet ./protocol/go/policy/...cd protocol/codegen && go run .🤖 Generated with Claude Code