Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

@Piskoo
Copy link
Collaborator

@Piskoo Piskoo commented Oct 14, 2025
edited
Loading

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
Member

@migmartri migmartri Oct 17, 2025

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
Member

@migmartri migmartri Oct 17, 2025

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
Member

@migmartri migmartri Oct 17, 2025

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
Member

@migmartri migmartri Oct 17, 2025

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
Member

@migmartri migmartri Oct 17, 2025

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
Member

@migmartri migmartri Oct 17, 2025

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
Member

@migmartri migmartri Oct 17, 2025

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
} 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
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
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
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.

Piskoo reacted with thumbs up emoji
Copy link
Member

@jiparis jiparis left a comment
edited
Loading

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.

Piskoo added 9 commits October 28, 2025 12:06
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

Reviewers

@migmartri migmartri migmartri left review comments

@jiparis jiparis jiparis approved these changes

@javirln javirln Awaiting requested review from javirln

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /