feat: add ory get opl - #451
Conversation
Ory Network does not inline the Ory Permission Language file in the
project config, it stores a pointer to it. `ory get permission-config`
therefore returns `{"namespaces":{"location":"https://...bin"}}` rather
than the namespaces themselves, and there was no way to read the file
back: `ory update opl` could write it, but nothing could retrieve it,
so the config was writable as code but not retrievable as code.
`ory get opl` resolves that location and writes the file to stdout, so
it can be redirected to disk and checked into version control. Reading
local files is disabled when resolving, because the location comes from
the API and must never make the CLI read from the developer's disk.
Projects still using legacy namespace definitions get a message
pointing at `ory get permission-config` instead of an unhelpful type
error.
Also corrects the `get permission-config` example, which advertised
inline namespaces that the command never returns for an OPL-based
project, and carried a stray character in the sample JSON.
Closes #321
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JYzGVwAKQ4ormxRHZg1eDu
Resolve the location with ory/x/fetcher restricted to http, https and base64 instead of osx with the file loader disabled. The fetcher checks the HTTP status code, so an expired storage link can no longer be written to stdout as if it were the OPL file; it honours the command context, so the download is cancellable; it redacts base64 payloads from error messages rather than dumping the whole file; and the scheme allowlist states the no-local-files rule positively. Read the permission service through the generated nil-safe accessor. `ProjectServices.Permission` is a pointer with omitempty, so a project without a permission service panicked — in `get permission-config` as well, which this branch already touched. Report the new error paths through cmdx.FailSilently so cobra does not append a usage dump and Execute does not print the message twice. An empty legacy namespace list is now reported as "nothing configured" rather than pointing at a command that would show an empty list. Tests: the local-file case now writes a real file first, so it fails if the scheme allowlist is removed; added remote-read and HTTP-error cases; and the live round-trip in TestUpdateNamespaceConfig asserts `get opl` returns byte-identical content to what `update opl` uploaded. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JYzGVwAKQ4ormxRHZg1eDu
📝 WalkthroughWalkthroughChangesProject OPL retrieval
Estimated code review effort: 3 (Moderate) | ~25 minutes Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant CLI as cloudx get opl
participant Project as Project permission service
participant Resolver as oplLocation
participant Fetcher as fetcher
CLI->>Project: load permission config
CLI->>Resolver: resolve namespaces.location
Resolver-->>CLI: return OPL location
CLI->>Fetcher: FetchBytes using allowed schemes
Fetcher-->>CLI: return OPL bytes
CLI-->>CLI: write bytes to stdout
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
The round-trip assertion was added to TestUpdateNamespaceConfig, which runs against the shared defaultProject and extraProject fixtures. Other tests in this package rewrite the permission config of those same projects in parallel — patch_permission_config_test.go replaces /namespaces with legacy definitions, and update_test.go replaces the permission config wholesale — so re-reading the project after writing it is racy. CI caught this: `get opl` reported "no Ory Permission Language file is configured for this project" for a project that had just been given one. Moved to its own test against a dedicated project, the same isolation TestUpdateProject and TestListProject already use, so nothing else can rewrite the config between the write and the read. TestUpdateNamespaceConfig goes back to asserting only on its own command output, which never depended on shared state. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JYzGVwAKQ4ormxRHZg1eDu
|
I think could cause problems when you import it again, will it not? Because the format is not the same? so "keto get project > config.yaml" and then "keto update project --from config.yaml" |
The round-trip test only covered update -> get: it uploaded a file and asserted `get opl` returned it. The direction that matters for checking the permission model into version control is the other one — taking `get opl` output and applying it again — and that was only inferred from the two commands both handling raw files, never exercised. The test now feeds `get opl` output straight back into `update opl` and reads it once more, so a disagreement about the file format, or any stray wrapping or trailing newline that would accumulate over repeated round-trips, fails the test. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JYzGVwAKQ4ormxRHZg1eDu
This change does not touch This change only adds I've added a test that verifies Does that make sense? |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cmd/cloudx/project/get_namespace_config.go`:
- Around line 80-83: Replace the .CommandPath placeholder in the Example help
text with the literal command invocation, using “$ ory get opl --project ...” so
Cobra displays the intended command directly in default help output.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: cd580244-4eed-4822-a541-1d057a05f03e
📒 Files selected for processing (5)
cmd/cloudx/get.gocmd/cloudx/project/get_namespace_config.gocmd/cloudx/project/get_namespace_config_live_test.gocmd/cloudx/project/get_namespace_config_test.gocmd/cloudx/project/get_permission_config.go
Closes #321
Problem
Ory Network does not inline the Ory Permission Language file in the project config — it stores a pointer to it. So
ory get permission-configreturns:{"limit":{},"namespaces":{"location":"https://storage.googleapis.com/bac-gcs-production/xxxxx.bin"}}The reporter's complaint was accurate on two counts:
ory update opl --file ...could write it, but nothing could retrieve it — the permission config was writable as code but not retrievable as code, which breaks the gitops round-trip.{"namespaces":[{"name":"files","id":1}]}, which the command never returns for an OPL-based project, and carried a stray1in the sample JSON.Fix
ory get oplresolves the location and writes the file to stdout, so it can be redirected to disk and checked into version control:The
get permission-configexample now shows what the command actually returns, and points atory get oplfor the file itself.Resolution goes through
ory/x/fetcherrestricted tohttp,httpsandbase64— the same fetcherupdate_namespace_config_test.goalready uses. That choice matters for four reasons:err == nilfrom a plain reader, soory get opl > namespaces.tswould have written<Error><Code>AccessDenied</Code>...into the file and exited 0 — the user commits an error page as their permission model.cmd.Context().base64://payloads are redacted from errors.ory update oplstores the location asbase64://<whole file>; without redaction a decode failure dumps a multi-kilobyte blob to stderr.Two further fixes found in review:
ProjectServices.Permissionis a pointer withomitempty, so a project without a permission service panicked — including in the pre-existingget permission-config, which this branch already touched."namespaces": []) now reports "nothing configured" rather than sending the user to a command that would show them an empty list.Tests
TestOPLLocationcovers location extraction: OPL pointer, legacy list, empty legacy list, missing/null/empty location, nil config.TestOPLLocationIsReadablepins the loader contract — remote reads work, HTTP error responses are not mistaken for the file (httptest 403 with a GCS-style body), and a real local file is refused. The local-file case writes the file first; the earlier version asserted against a non-existent path and would have passed with the allowlist removed.TestUpdateNamespaceConfiggains a round-trip: the OPL uploaded byupdate opl/patchmust come back byte-identical fromget opl, for both project-selection modes. This ran against live staging and passes, so the resolve-and-fetch path is verified end to end and not just at the unit level.🤖 Generated with Claude Code
https://claude.ai/code/session_01JYzGVwAKQ4ormxRHZg1eDu
Summary by CodeRabbit
New Features
cloudx get oplto retrieve a project’s Ory Permission Language (OPL) file.Improvements