feat: add ory validate opl - #456
Conversation
Closes #402. Adds a thin command over the already-wired `RelationshipAPI.CheckOplSyntax` SDK call, so that OPL files can be syntax-checked in CI/CD without the raw `curl` workaround. The command exits non-zero when the file has syntax errors. Errors are rendered compiler-style (`<source>:<line>:<column>: <message>`) on stderr for humans, and as the raw API result for the machine-readable formats. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012UL5u7KWLdu8hzNTNvYq5a
- an empty file is valid; the SDK rejects a zero-length body, so skip the call - use the nil-safe accessor for the result, which is nil on an empty response - always emit the `errors` key in machine-readable formats, so that CI scripts can rely on `jq '.errors | length'` - render the column only together with the line, so that a line-less position cannot be misread as a line number - treat an unknown `--format` as human-readable, matching cmdx itself - do not claim `update opl` validates through the same endpoint Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012UL5u7KWLdu8hzNTNvYq5a
📝 WalkthroughWalkthroughAdds a project-scoped SDK client and registers ChangesNamespace configuration validation
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant CLI
participant CommandHelper
participant RelationshipAPI
CLI->>CommandHelper: Create project API client
CommandHelper->>RelationshipAPI: Configure selected project endpoint
CLI->>RelationshipAPI: Check OPL syntax
RelationshipAPI-->>CLI: Return parse errors
CLI-->>CLI: Format output and set exit status
Possibly related PRs
Suggested reviewers: 🚥 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 |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
There is not really a point in making this a server call, as it is not dependent on any project config or other stuff. In fact, we want to remove the endpoint eventually. Ideally, this would run locally. The only problem with that is version drift between the server and the CLI, so it might pass the CI check but the server might still reject it as invalid. Do you have an idea how to solve this with local execution?
If you want to remove this endpoint in the future but keep the ability to validate OPL without also configuring Keto with that same OPL, version drift becomes a perpetual problem. The are ways to deal with that of course (versioning etc) but fundamentally that would require providing reasonable compatibility guarantees for OPL. I am not opposed to that, but at that point ory/keto#1860 becomes a Keto problem. In fact, what I think I will do is move ory/keto#1860 into ory/keto to find a design there, whether client- oder server-side. When the subcommand in keto exists, we'll import it in ory/cli. |
Adds
ory validate opl --file ./my-permissions.ts, a thin command over theRelationshipAPI.CheckOplSyntaxSDK call that was already vendored but unused.It replaces the raw
curlworkaround from the issue and exits non-zero onsyntax errors, so it can be used as a CI/CD check before
ory update opl.Details:
<source>:<line>:<column>: <message>) onstderr for the human-readable formats, so editors and CI log parsers pick up
the location. The machine-readable formats print the API result verbatim, with
the
errorskey always present so thatjq '.errors | length'works on thesuccess path too.
--file -reads from stdin, and errors are then reported againststdin.--quietsilences the success message but not the syntax errors.body, and a whitespace-only file — semantically identical — is valid).
The syntax check endpoint lives on the project's own API
(
<slug>.projects.oryapis.com) rather than the Console API, and there was noSDK-client helper for that host, so this also adds
CommandHelper.NewProjectAPIClient.Related Issue or Design Document
Closes ory/keto#1860.
Checklist
and signed the CLA.
introduces a new feature.
vulnerability. If this pull request addresses a security vulnerability, I
confirm that I got approval (please contact
security@ory.com) from the maintainers to push
the changes.
works.
appropriate).
Further comments
The command is mounted under the existing
ory validateparent (next tovalidate identity) rather than as a new top-levelory checkverb, assuggested in the issue —
validatealready exists and carries the samesemantics.
🤖 Generated with Claude Code
https://claude.ai/code/session_012UL5u7KWLdu8hzNTNvYq5a
Summary by CodeRabbit
New Features
validate oplto check project namespace configuration syntax.Tests