feat(crafting-schema): add schema v2 support to cli#2467
feat(crafting-schema): add schema v2 support to cli#2467Piskoo merged 9 commits intochainloop-dev:mainfrom
Conversation
|
|
||
| cmd.Flags().StringVar(&name, "name", "", "contract name") | ||
| err := cmd.MarkFlagRequired("name") | ||
| cobra.CheckErr(err) |
| 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.
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.
This might be broken, because Schema is necessary for compatibility reasons.
There was a problem hiding this comment.
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.
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.
validate that exactly one item is present
| if _, err := uc.findAndValidatePolicy(att, token); err != nil { | ||
| return NewErrValidation(err) | ||
| switch { | ||
| case c.isV1Schema(): |
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.
This looks awkward. Data layer shouldn't call biz layer logic.
There was a problem hiding this comment.
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.
I see, let's address it in another PR then.
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).