@@ -3,9 +3,9 @@ package ocm_cli
33import (
44 "context"
55 "fmt"
6- "gopkg.in/yaml.v3"
76 "os"
87 "os/exec"
8+ "sigs.k8s.io/yaml"
99)
1010
1111const (
@@ -19,16 +19,16 @@ const (
1919// The `args` parameter is a slice of strings representing the arguments to the command.
2020// The `ocmConfig` parameter is a string representing the path to the OCM configuration file. Passing `NoOcmConfig` indicates that no configuration file should be used.
2121func Execute (ctx context.Context , commands []string , args []string , ocmConfig string ) error {
22- var flags []string
23-
24- flags = append (flags , commands ... )
25- flags = append (flags , args ... )
22+ var ocmArgs []string
2623
2724 if ocmConfig != NoOcmConfig {
28- flags = append (flags , "--config" , ocmConfig )
25+ ocmArgs = append (ocmArgs , "--config" , ocmConfig )
2926 }
3027
31- cmd := exec .CommandContext (ctx , "ocm" , flags ... )
28+ ocmArgs = append (ocmArgs , commands ... )
29+ ocmArgs = append (ocmArgs , args ... )
30+
31+ cmd := exec .CommandContext (ctx , "ocm" , ocmArgs ... )
3232 cmd .Stdout = os .Stdout
3333 cmd .Stderr = os .Stderr
3434
@@ -52,43 +52,47 @@ type ComponentVersion struct {
5252// Component represents an OCM component with its name, version, references to other components, and resources.
5353type Component struct {
5454 // Name is the name of the component.
55- Name string `yaml :"name"`
55+ Name string `json :"name"`
5656 // Version is the version of the component.
57- Version string `yaml :"version"`
57+ Version string `json :"version"`
5858 // ComponentReferences is a list of references to other components that this component depends on.
5959 ComponentReferences []ComponentReference `yaml:"componentReferences"`
6060 // Resources is a list of resources associated with this component, including their names, versions, types, and access information.
61- Resources []Resource `yaml :"resources"`
61+ Resources []Resource `json :"resources"`
6262}
6363
6464// ComponentReference represents a reference to another component, including its name, version, and the name of the component it refers to.
6565type ComponentReference struct {
6666 // Name is the name of the component reference.
67- Name string `yaml :"name"`
67+ Name string `json :"name"`
6868 // Version is the version of the component reference.
69- Version string `yaml :"version"`
69+ Version string `json :"version"`
7070 // ComponentName is the name of the component that this reference points to.
71- ComponentName string `yaml :"componentName"`
71+ ComponentName string `json :"componentName"`
7272}
7373
7474// Resource represents a resource associated with a component, including its name, version, type, and access information.
7575type Resource struct {
7676 // Name is the name of the resource.
77- Name string `yaml :"name"`
77+ Name string `json :"name"`
7878 // Version is the version of the resource.
79- Version string `yaml :"version"`
79+ Version string `json :"version"`
8080 // Type is the content type of the resource.
81- Type string `yaml :"type"`
81+ Type string `json :"type"`
8282 // Access contains the information on how to access the resource.
83- Access Access `yaml :"access"`
83+ Access Access `json :"access"`
8484}
8585
8686// Access represents the access information for a resource, including the type of access.
8787type Access struct {
88- // Type is the content type of access to the resource.
89- Type string `yaml :"type"`
88+ // Type specifies the access type of the resource.
89+ Type string `json :"type"`
9090 // ImageReference is the reference to the image if the Type is "ociArtifact".
91- ImageReference string `yaml:"imageReference"`
91+ ImageReference * string `json:"imageReference"`
92+ // LocalReference specifies a component local access
93+ LocalReference * string `json:"localReference"`
94+ // MediaType is the media type of the resource
95+ MediaType * string `json:"mediaType"`
9296}
9397
9498// GetResource retrieves a resource by its name from the component version.
@@ -113,21 +117,18 @@ func (cv *ComponentVersion) GetComponentReference(name string) (*ComponentRefere
113117
114118// GetComponentVersion retrieves a component version by its reference using the OCM CLI.
115119func GetComponentVersion (ctx context.Context , componentReference string , ocmConfig string ) (* ComponentVersion , error ) {
116- flags := []string {
117- "get" ,
118- "componentversion" ,
119- "--output" , "yaml" ,
120- componentReference ,
121- }
120+ var ocmArgs []string
122121
123122 if ocmConfig != NoOcmConfig {
124- flags = append (flags , "--config" , ocmConfig )
123+ ocmArgs = append (ocmArgs , "--config" , ocmConfig )
125124 }
126125
127- cmd := exec .CommandContext (ctx , "ocm" , flags ... )
126+ ocmArgs = append (ocmArgs , "get" , "componentversion" , "--output" , "yaml" , componentReference )
127+
128+ cmd := exec .CommandContext (ctx , "ocm" , ocmArgs ... )
128129 out , err := cmd .CombinedOutput ()
129130 if err != nil {
130- return nil , fmt .Errorf ("error executing ocm command: %w" , err )
131+ return nil , fmt .Errorf ("error executing ocm command: %w, %q " , err , out )
131132 }
132133
133134 var cv ComponentVersion
0 commit comments