feat(docs): document WithPolicyFrom re-wrap helper#323
Conversation
Adds a tdf.mdx section for sdk.WithPolicyFrom, the option-builder helper landing as part of DSPX-2603. The function returns a TDFOption that binds the source TDF's policy (attribute FQNs) to a new TDF being created — useful in re-wrap pipelines where the policy should carry forward without callers handling base64+JSON manifest encoding. Demo output of the /docs-drift skill — example block is mined verbatim from the function's godoc, no inference. Section placed after IsValidTdf since both are re-wrap-flavored helpers. Skill's name-only sniff proposed a new with-policy-from.mdx file; placement overridden manually to match the existing tdf.mdx structure. Not for merge until the underlying sdk.WithPolicyFrom function lands in opentdf/platform. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Mary Dickson <mary.dickson@virtru.com>
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 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 |
There was a problem hiding this comment.
Code Review
This pull request adds documentation for the WithPolicyFrom function in the Go SDK, which allows binding a source TDF's policy to a new TDF. Feedback was provided regarding an inconsistency in the documentation concerning the Init(ctx) requirement for Reader.DataAttributes. Additionally, the example code contains a logic error where a return statement is missing after a validation check, and the SDK client variable naming is inconsistent with the rest of the document.
|
|
||
| | Parameter | Required | Description | | ||
| |-----------|----------|-------------| | ||
| | `r` | Required | An initialized `*sdk.Reader`, typically returned by [`LoadTDF`](#loadtdf). Must have `Init(ctx)` called before being passed here — `Reader.DataAttributes` requires the policy field to be parsed. | |
There was a problem hiding this comment.
This parameter description states that Init(ctx) must be called because Reader.DataAttributes requires the policy field to be parsed. However, the existing documentation and examples for DataAttributes() (lines 903-917) do not mention this requirement, and the example there shows the method being called without a preceding Init(). This inconsistency should be resolved to avoid confusing users—either by updating the DataAttributes documentation or by clarifying why Init is specifically required in this context.
| if ok, _ := sdk.IsValidTdf(file); !ok { | ||
| // pass through unchanged | ||
| } | ||
| reader, _ := s.LoadTDF(file) | ||
| _ = reader.Init(ctx) | ||
| _, _ = s.CreateTDF(out, transformed, sdk.WithPolicyFrom(reader)) |
There was a problem hiding this comment.
The example code contains a logic error and a naming inconsistency:
- The
ifblock forIsValidTdfis missing areturnstatement. Without it, the code would proceed to callLoadTDFeven if the validation fails, which contradicts the "pass through unchanged" comment. - The variable
sis used for the SDK client, but the rest of this document consistently usesclient(e.g., lines 52, 63, 71, 234, 401).
if ok, _ := sdk.IsValidTdf(file); !ok {
return // pass through unchanged
}
reader, _ := client.LoadTDF(file)
_ = reader.Init(ctx)
_, _ = client.CreateTDF(out, transformed, sdk.WithPolicyFrom(reader))
|
❌ Surge preview build failed — no preview was deployed. Check the workflow logs for details. Once the build passes, the preview will be at: https://opentdf-docs-pr-323.surge.sh Common cause: If the build failed on vendored YAML validation, run the following locally and commit the result: |
Summary
Adds a
tdf.mdxsection forsdk.WithPolicyFrom, a newTDFOptionbuilder that binds the source TDF's policy — its attribute value FQNs — to a new TDF being created. Targets re-wrap pipelines where the source policy should carry forward without callers handling the manifest's base64 + JSON encoding themselves.Call site is a single line, matching the existing
With*option-builder idiom:Companion PR
Documents the function landing in opentdf/platform#3476. Draft until that PR merges — the example references a symbol that doesn't exist in the SDK yet.
How this was drafted
Generated by the docs-drift skill mining the function's godoc example block verbatim. No example code was invented; the snippet shown is exactly what the function's author wrote in the godoc.
Test plan
tdf.mdxafterIsValidTdf, beforeBulkDecrypt)🤖 Generated with Claude Code