Skip to content

feat(crafting-schema): add schema v2 support to cli#2467

Merged
Piskoo merged 9 commits into
chainloop-dev:mainfrom
Piskoo:feat-use-contract-v2-for-contract-operations
Oct 28, 2025
Merged

feat(crafting-schema): add schema v2 support to cli#2467
Piskoo merged 9 commits into
chainloop-dev:mainfrom
Piskoo:feat-use-contract-v2-for-contract-operations

Conversation

@Piskoo

@Piskoo Piskoo commented Oct 14, 2025

Copy link
Copy Markdown
Contributor

Summary

This PR adds support for contract schema v2 in CLI workflow contract create, update, and apply operations.

Note: The default contract body for create will be updated once v2 schema support is available everywhere.

Changes

  • CLI can now create and update contracts using v2 schema format:
  apiVersion: ...
  kind: ...
  metadata:
    name: ...
  spec:
    ...
  • Contract name can now be extracted from the v2 field metadata.name, removing the need for the --name flag.
  • Validation ensures only one name source is provided (either --name flag or metadata.name in the contract).


cmd.Flags().StringVar(&name, "name", "", "contract name")
err := cmd.MarkFlagRequired("name")
cobra.CheckErr(err)

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.

missing validation

message: "must contain only lowercase letters, numbers, and hyphens."
expression: "this.name == '' || this.name.matches('^[a-z0-9]([-a-z0-9]*[a-z0-9])?$')"
};
option (buf.validate.message).cel = {

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.

this validation doesnt mean much in legacy format

return nil, fmt.Errorf("failed to unmarshal raw body: %w", err)
}
contract.Schema = schema
contract.Schema = parsedContract.Schema

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.

This might be broken, because Schema is necessary for compatibility reasons.

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.

Old CLIs must keep working with new contracts

}
contract.Schema = schema
contract.Schema = parsedContract.Schema
contract.Schemav2 = parsedContract.Schemav2

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.

This second option we don't want it.

}

// extractContractName extracts the contract name from v2 metadata or returns the fallback name
func extractContractName(rawContract []byte, name string) (string, error) {

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.

validate that exactly one item is present

if _, err := uc.findAndValidatePolicy(att, token); err != nil {
return NewErrValidation(err)
switch {
case c.isV1Schema():

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.

mark as deprecated

@Piskoo Piskoo marked this pull request as draft October 20, 2025 07:08
@Piskoo Piskoo force-pushed the feat-use-contract-v2-for-contract-operations branch from 3918cc5 to 39deb09 Compare October 21, 2025 11:53
@Piskoo Piskoo marked this pull request as ready for review October 22, 2025 08:16
Comment thread app/controlplane/pkg/biz/workflowcontract.go
} else if len(w.Body) == 0 {
schema := &schemav1.CraftingSchema{}
err := unmarshal.FromRaw(w.RawBody, w.RawBodyFormat, schema, false)
parsedContract, err := biz.UnmarshalAndValidateRawContract(w.RawBody, w.RawBodyFormat)

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.

This looks awkward. Data layer shouldn't call biz layer logic.

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.

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.

I see, let's address it in another PR then.

@jiparis jiparis left a comment

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.

I've been testing this locally with different server/client version combinations without any issue.

Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
@Piskoo Piskoo force-pushed the feat-use-contract-v2-for-contract-operations branch from 0dcd82f to a2824ae Compare October 28, 2025 11:06
@Piskoo Piskoo merged commit f355374 into chainloop-dev:main Oct 28, 2025
13 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.

3 participants