-
Couldn't load subscription status.
- Fork 37
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
feat(crafting-schema): add schema v2 support to cli #2467
Conversation
|
|
||
| cmd.Flags().StringVar(&name, "name", "", "contract name") | ||
| err := cmd.MarkFlagRequired("name") | ||
| cobra.CheckErr(err) |
There was a problem hiding this comment.
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 = { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mark as deprecated
3918cc5 to
39deb09
Compare
| } 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/chainloop-dev/chainloop/blob/main/app/controlplane/pkg/data/workflowcontract.go#L354
That is already the case currently
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
0dcd82f to
a2824ae
Compare
Summary
This PR adds support for contract schema v2 in CLI
workflow contractcreate,update, andapplyoperations.Note: The default contract body for
createwill be updated once v2 schema support is available everywhere.Changes
metadata.name, removing the need for the--nameflag.--nameflag ormetadata.namein the contract).