Skip to content

Commit 9e4addf

Browse files
committed
remove validation related to schema v2
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
1 parent 9d900f1 commit 9e4addf

3 files changed

Lines changed: 13 additions & 90 deletions

File tree

app/cli/cmd/workflow_contract_apply.go

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
)
2323

2424
func newWorkflowContractApplyCmd() *cobra.Command {
25-
var filePath, name, description, projectName string
25+
var contractPath, name, description, projectName string
2626
var contractName string
2727
var rawContract []byte
2828

@@ -32,18 +32,7 @@ func newWorkflowContractApplyCmd() *cobra.Command {
3232
Long: `Apply a contract from a file. This command will create the contract if it doesn't exist,
3333
or update it if it already exists.`,
3434
Example: ` # Apply a contract from file
35-
chainloop workflow contract apply --contract my-contract.yaml
36-
37-
# Apply to a specific project
38-
chainloop workflow contract apply --contract my-contract.yaml --project my-project`,
39-
PreRunE: func(_ *cobra.Command, _ []string) error {
40-
var err error
41-
rawContract, contractName, err = action.LoadSchemaAndExtractName(filePath, name)
42-
if err != nil {
43-
return err
44-
}
45-
return nil
46-
},
35+
chainloop workflow contract apply --contract my-contract.yaml --name my-contract --project my-project`,
4736
RunE: func(cmd *cobra.Command, _ []string) error {
4837
var desc *string
4938
if cmd.Flags().Changed("description") {
@@ -60,12 +49,13 @@ or update it if it already exists.`,
6049
},
6150
}
6251

63-
cmd.Flags().StringVarP(&filePath, "contract", "f", "", "workflow contract file path (optional)")
64-
cmd.Flags().StringVar(&name, "name", "", "contract name (required if no contract file provided)")
65-
cmd.Flags().StringVar(&description, "description", "", "contract description")
66-
cmd.Flags().StringVar(&projectName, "project", "", "project name to scope the contract")
52+
cmd.Flags().StringVar(&name, "name", "", "contract name")
53+
err := cmd.MarkFlagRequired("name")
54+
cobra.CheckErr(err)
6755

68-
cmd.MarkFlagsOneRequired("contract", "name")
56+
cmd.Flags().StringVarP(&contractPath, "contract", "f", "", "path or URL to the contract schema")
57+
cmd.Flags().StringVar(&description, "description", "", "description of the contract")
58+
cmd.Flags().StringVar(&projectName, "project", "", "project name used to scope the contract, if not set the contract will be created in the organization")
6959

7060
return cmd
7161
}

app/cli/documentation/cli-reference.mdx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3308,20 +3308,17 @@ Examples
33083308

33093309
```
33103310
Apply a contract from file
3311-
chainloop workflow contract apply --contract my-contract.yaml
3312-
3313-
Apply to a specific project
3314-
chainloop workflow contract apply --contract my-contract.yaml --project my-project
3311+
chainloop workflow contract apply --contract my-contract.yaml --name my-contract --project my-project
33153312
```
33163313

33173314
Options
33183315

33193316
```
3320-
-f, --contract string workflow contract file path (optional)
3321-
--description string contract description
3317+
-f, --contract string path or URL to the contract schema
3318+
--description string description of the contract
33223319
-h, --help help for apply
3323-
--name string contract name (required if no contract file provided)
3324-
--project string project name to scope the contract
3320+
--name string contract name
3321+
--project string project name used to scope the contract, if not set the contract will be created in the organization
33253322
```
33263323

33273324
Options inherited from parent commands

app/cli/pkg/action/util.go

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,12 @@
1616
package action
1717

1818
import (
19-
"encoding/json"
2019
"errors"
21-
"fmt"
2220
"io"
2321
"net/http"
2422
"os"
2523
"path/filepath"
2624
"strings"
27-
28-
"github.com/chainloop-dev/chainloop/app/controlplane/pkg/unmarshal"
2925
)
3026

3127
// LoadFileOrURL loads a file from a local path or a URL
@@ -51,63 +47,3 @@ func LoadFileOrURL(fileRef string) ([]byte, error) {
5147

5248
return os.ReadFile(filepath.Clean(fileRef))
5349
}
54-
55-
// SchemaBase represents the minimal structure of a schema with metadata containing a name
56-
type SchemaBase struct {
57-
Metadata struct {
58-
Name string `json:"name"`
59-
} `json:"metadata"`
60-
}
61-
62-
// ExtractNameFromRawSchema tries to extract the name from any schema with metadata
63-
func extractNameFromRawSchema(content []byte) (string, error) {
64-
// Identify format
65-
format, err := unmarshal.IdentifyFormat(content)
66-
if err != nil {
67-
return "", fmt.Errorf("failed to identify schema format: %w", err)
68-
}
69-
70-
// Convert to JSON for consistent parsing
71-
jsonData, err := unmarshal.LoadJSONBytes(content, "."+string(format))
72-
if err != nil {
73-
return "", fmt.Errorf("failed to convert to JSON: %w", err)
74-
}
75-
76-
// Unmarshal to extract name
77-
var schemaBase SchemaBase
78-
if err := json.Unmarshal(jsonData, &schemaBase); err != nil {
79-
// Unmarshalling error, don't fail, return empty name,
80-
return "", nil
81-
}
82-
83-
return schemaBase.Metadata.Name, nil
84-
}
85-
86-
// LoadSchemaAndExtractName loads a schema from file path and extracts name from metadata if available
87-
func LoadSchemaAndExtractName(filePath, explicitName string) ([]byte, string, error) {
88-
finalName := explicitName
89-
90-
if filePath != "" {
91-
rawSchema, err := LoadFileOrURL(filePath)
92-
if err != nil {
93-
return nil, "", fmt.Errorf("failed to load schema file: %w", err)
94-
}
95-
96-
// Extract name from the schema file content
97-
extractedName, err := extractNameFromRawSchema(rawSchema)
98-
if err != nil {
99-
return nil, "", err
100-
}
101-
102-
// Name is required
103-
if extractedName == "" && explicitName == "" {
104-
return nil, "", fmt.Errorf("name in schema not found, --name flag is required")
105-
} else if extractedName != "" {
106-
finalName = extractedName
107-
}
108-
109-
return rawSchema, finalName, nil
110-
}
111-
112-
return nil, finalName, nil
113-
}

0 commit comments

Comments
 (0)