Skip to content

feat: add PolicyCheck callback to CopyOptions#1189

Merged
TerryHowe merged 2 commits into
oras-project:mainfrom
TerryHowe:feat/copy-policy-check
Jun 15, 2026
Merged

feat: add PolicyCheck callback to CopyOptions#1189
TerryHowe merged 2 commits into
oras-project:mainfrom
TerryHowe:feat/copy-policy-check

Conversation

@TerryHowe

Copy link
Copy Markdown
Member

What

Adds an optional PolicyCheck callback to CopyOptions:

PolicyCheck func(ctx context.Context, srcRef string) error

Copy invokes it once with the source reference before any I/O. A non-nil return aborts the copy and the error is wrapped via %w (policy check failed for %s: %w).

When PolicyCheck is nil the behavior is unchanged.

Why

Lets callers plug in policy enforcement (e.g., containers-policy.json signature/identity checks) without the root oras package taking a build-time dependency on the policy package. Keeps the oras <-> registry/remote/policy boundary clean.

Part of the v3 PR-by-PR breakdown (PR 17: feat/copy-policy-check). Self-contained; no new package deps.

(Note: prs.md lists content_test.go, example_test.go, and example_copy_test.go under this PR, but those diffs in feat/everything are actually repo.Registry.PlainHTTP / NewCredentialFunc renames that belong to PR 13. They are intentionally excluded here so this PR stays scoped to PolicyCheck.)

Test plan

  • go build -mod=mod ./...
  • go test -mod=mod -run TestCopy_PolicyCheck -v . — PASS for rejected, allowed, no policy subtests
  • go test -mod=mod -run Copy . — full Copy test family passes

Add an optional PolicyCheck callback on CopyOptions, invoked with the
source reference at the start of Copy. A non-nil return aborts the copy
with the policy error wrapped via %w.

This lets callers plug in policy enforcement (e.g.,
containers-policy.json) without the root oras package taking a
dependency on the policy package.

Signed-off-by: Terry Howe <terrylhowe@gmail.com>
@codecov

codecov Bot commented May 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.10%. Comparing base (702345e) to head (3c0b7f8).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1189   +/-   ##
=======================================
  Coverage   83.09%   83.10%           
=======================================
  Files          82       82           
  Lines        5743     5746    +3     
=======================================
+ Hits         4772     4775    +3     
  Misses        600      600           
  Partials      371      371           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TerryHowe TerryHowe added v3 Things belongs to version 3.x keep open labels May 24, 2026
@TerryHowe TerryHowe added this to the v3.0.0 milestone May 24, 2026

@sabre1041 sabre1041 left a comment

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.

LGTM

@TerryHowe
TerryHowe merged commit 20a12c9 into oras-project:main Jun 15, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

keep open v3 Things belongs to version 3.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants