Skip to content

feat(cli): add apply command#2804

Merged
Piskoo merged 6 commits into
chainloop-dev:mainfrom
Piskoo:pfm-4754
Mar 3, 2026
Merged

feat(cli): add apply command#2804
Piskoo merged 6 commits into
chainloop-dev:mainfrom
Piskoo:pfm-4754

Conversation

@Piskoo

@Piskoo Piskoo commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

Adds a chainloop apply -f <file|dir> command that applies contracts from YAML files or directories.

All succeeded

$ chainloop apply -f ./contracts
WRN API contacted in insecure mode
INF 2 contracts applied

1 failed

$ chainloop apply -f ./contracts
WRN API contacted in insecure mode
ERR parsing file /home/ubuntu/Desktop/contracts/contract2.yml: missing 'metadata.name' field in YAML document of kind "Contract"
exit status 1

Closes #2803

Piskoo added 2 commits March 2, 2026 14:31
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
@Piskoo Piskoo marked this pull request as ready for review March 2, 2026 13:57

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2 issues found across 4 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="app/cli/pkg/action/apply.go">

<violation number="1" location="app/cli/pkg/action/apply.go:122">
P1: Bug: All `Describe` errors are treated as "not found", causing incorrect fallthrough to `Create`. If the server returns a permission error, network timeout, or internal error, the code will silently attempt to create a new contract instead of reporting the failure. You should check for the specific gRPC `NotFound` status code before falling through to Create.</violation>

<violation number="2" location="app/cli/pkg/action/apply.go:214">
P2: Missing validation: `metadata.name` is not checked for empty. If a YAML document omits the `name` field, the code will attempt to create/update a contract with an empty name, leading to a confusing downstream error.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread app/cli/pkg/action/apply.go Outdated
Comment thread app/cli/pkg/action/apply.go
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
Comment thread app/cli/pkg/action/apply.go
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 10 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="app/controlplane/internal/service/workflowcontract.go">

<violation number="1" location="app/controlplane/internal/service/workflowcontract.go:294">
P1: The creation path in `Apply` bypasses the RBAC project-scope enforcement that the `Create` method has. When RBAC is enabled, `Create` requires a project reference (`rbacEnabled(ctx) && !req.ProjectReference.IsSet()`), but `Apply` skips this check entirely and never sets `ProjectID` in `WorkflowContractCreateOpts`. This creates an authorization bypass where users can create global contracts through `Apply` even when the system requires project-scoped contracts.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread app/controlplane/internal/service/workflowcontract.go
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
@jiparis jiparis self-requested a review March 2, 2026 15:26
Comment thread app/cli/cmd/apply.go
var filePath string

cmd := &cobra.Command{
Use: "apply",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since OSS only supports declarative workflow contracts, I think this command should be placed in chainloop wf contract apply.

@Piskoo Piskoo Mar 2, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We already have wf contract apply, this one is there to expose generic apply for all resources in chainloop, it will be extended in CLI EE. We can refactor wf contract apply in a separate task so it uses the new endpoint, although if we do that, we will lose the capability scoping contracts per project. We don't support projects in the schema

@jiparis jiparis self-requested a review March 2, 2026 15:27

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="app/cli/pkg/action/apply.go">

<violation number="1" location="app/cli/pkg/action/apply.go:75">
P2: The `Error` field on `ApplyResult` is now dead code. Since both error paths early-return from `Run()` instead of populating `result.Error`, no result will ever have a non-nil `Error`. The caller in `cmd/apply.go` has an unreachable `r.Error != nil` branch (lines 48-57) as a consequence. Either remove the `Error` field and the dead caller logic, or restore the accumulate-and-continue pattern if partial failure reporting is desired.

(Based on your team's feedback about removing unused code, methods, and variables.) [FEEDBACK_USED]</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread app/cli/pkg/action/apply.go
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
@Piskoo Piskoo merged commit f165f77 into chainloop-dev:main Mar 3, 2026
15 checks passed
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.

Add chainloop apply command

3 participants