Skip to content

feat(docs): document WithPolicyFrom re-wrap helper#323

Draft
marythought wants to merge 1 commit into
mainfrom
demo/docs-drift-with-policy-from
Draft

feat(docs): document WithPolicyFrom re-wrap helper#323
marythought wants to merge 1 commit into
mainfrom
demo/docs-drift-with-policy-from

Conversation

@marythought
Copy link
Copy Markdown
Contributor

Summary

Adds a tdf.mdx section for sdk.WithPolicyFrom, a new TDFOption builder 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:

if ok, _ := sdk.IsValidTdf(file); !ok {
    return // pass through unchanged
}
reader, _ := s.LoadTDF(file)
_ = reader.Init(ctx)
_, _ = s.CreateTDF(out, transformed, sdk.WithPolicyFrom(reader))

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

🤖 Generated with Claude Code

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>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 18, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a6d27871-e38a-4d23-ad45-5516b7974017

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch demo/docs-drift-with-policy-from

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 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.

Comment thread docs/sdks/tdf.mdx

| 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. |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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.

Comment thread docs/sdks/tdf.mdx
Comment on lines +635 to +640
if ok, _ := sdk.IsValidTdf(file); !ok {
// pass through unchanged
}
reader, _ := s.LoadTDF(file)
_ = reader.Init(ctx)
_, _ = s.CreateTDF(out, transformed, sdk.WithPolicyFrom(reader))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The example code contains a logic error and a naming inconsistency:

  1. The if block for IsValidTdf is missing a return statement. Without it, the code would proceed to call LoadTDF even if the validation fails, which contradicts the "pass through unchanged" comment.
  2. The variable s is used for the SDK client, but the rest of this document consistently uses client (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))

@github-actions
Copy link
Copy Markdown
Contributor

❌ 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:

npm run update-vendored-yaml
git add specs/
git commit -m "chore(deps): update vendored OpenAPI specs"

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.

1 participant