11package registry
22
33import (
4+ "encoding/json"
45 "fmt"
56 "os"
67 "path/filepath"
78 "strconv"
89 "strings"
9- "encoding/json"
1010
1111 "github.com/meshery/meshkit/encoding"
1212 "github.com/meshery/meshkit/files"
1313 "github.com/meshery/meshkit/models/meshmodel/entity"
1414 "github.com/meshery/meshkit/utils"
1515 "github.com/meshery/meshkit/utils/csv"
1616 "github.com/meshery/meshkit/utils/manifests"
17+ "github.com/meshery/schemas"
1718 "github.com/meshery/schemas/models/v1alpha1/capability"
19+ corev1alpha1 "github.com/meshery/schemas/models/v1alpha1/core"
1820 schmeaVersion "github.com/meshery/schemas/models/v1beta1"
1921 "github.com/meshery/schemas/models/v1beta1/component"
20- "github.com/meshery/schemas"
2122)
2223
2324const (
@@ -123,7 +124,9 @@ func (c *ComponentCSV) UpdateCompDefinition(compDef *component.ComponentDefiniti
123124 if c .Capabilities != "" && c .Capabilities != "null" {
124125 err := encoding .Unmarshal ([]byte (c .Capabilities ), & capabilities )
125126 if err != nil {
126- Log .Error (err )
127+ if Log != nil {
128+ Log .Error (err )
129+ }
127130 defaultCapabilities , defaultErr := getMinimalUICapabilitiesFromSchema ()
128131 if defaultErr == nil {
129132 capabilities = defaultCapabilities
@@ -132,7 +135,9 @@ func (c *ComponentCSV) UpdateCompDefinition(compDef *component.ComponentDefiniti
132135 } else {
133136 defaultCapabilities , err := getMinimalUICapabilitiesFromSchema ()
134137 if err != nil {
135- Log .Error (err )
138+ if Log != nil {
139+ Log .Error (err )
140+ }
136141 } else {
137142 capabilities = defaultCapabilities
138143 }
@@ -176,7 +181,7 @@ func (c *ComponentCSV) UpdateCompDefinition(compDef *component.ComponentDefiniti
176181 for _ , key := range compStyleValues {
177182 if c .Shape != "" {
178183 shape := c .Shape
179- compDefStyles .Shape = (* component . ComponentDefinitionStylesShape )(& shape )
184+ compDefStyles .Shape = (* corev1alpha1 . Shape )(& shape )
180185 }
181186 if c .PrimaryColor != "" {
182187
@@ -210,8 +215,6 @@ func (c *ComponentCSV) UpdateCompDefinition(compDef *component.ComponentDefiniti
210215 return nil
211216}
212217
213-
214-
215218type ComponentCSVHelper struct {
216219 SpreadsheetID int64
217220 SpreadsheetURL string
@@ -465,43 +468,42 @@ func getSVGForComponent(model ModelCSV, component ComponentCSV) (colorSVG string
465468 return
466469}
467470
468-
469471func getMinimalUICapabilitiesFromSchema () ([]capability.Capability , error ) {
470- schema , err := schemas .Schemas .ReadFile ("schemas/constructs/v1beta1/component/component.json " )
471- if err != nil {
472- return nil , fmt .Errorf ("failed to read component schema: %v" , err )
473- }
474-
475- capabilitiesJSON , err := extractCapabilitiesJSONFromSchema (schema )
476- if err != nil {
477- return nil , fmt .Errorf ("failed to extract capabilities from schema: %v" , err )
478- }
479-
480- var allCapabilities []capability.Capability
481- if err := json .Unmarshal (capabilitiesJSON , & allCapabilities ); err != nil {
482- return nil , fmt .Errorf ("failed to unmarshal capabilities: %v" , err )
483- }
484-
485- if len (allCapabilities ) >= 3 {
486- return allCapabilities [len (allCapabilities )- 3 :], nil
487- }
488-
489- return nil , fmt .Errorf ("insufficient default capabilities in schema, found %d" , len (allCapabilities ))
472+ schema , err := schemas .Schemas .ReadFile ("schemas/constructs/v1beta1/component/component.yaml " )
473+ if err != nil {
474+ return nil , fmt .Errorf ("failed to read component schema: %v" , err )
475+ }
476+
477+ capabilitiesJSON , err := extractCapabilitiesJSONFromSchema (schema )
478+ if err != nil {
479+ return nil , fmt .Errorf ("failed to extract capabilities from schema: %v" , err )
480+ }
481+
482+ var allCapabilities []capability.Capability
483+ if err := json .Unmarshal (capabilitiesJSON , & allCapabilities ); err != nil {
484+ return nil , fmt .Errorf ("failed to unmarshal capabilities: %v" , err )
485+ }
486+
487+ if len (allCapabilities ) >= 3 {
488+ return allCapabilities [len (allCapabilities )- 3 :], nil
489+ }
490+
491+ return nil , fmt .Errorf ("insufficient default capabilities in schema, found %d" , len (allCapabilities ))
490492}
491493
492494func extractCapabilitiesJSONFromSchema (schema []byte ) ([]byte , error ) {
493- var schemaMap map [string ]interface {}
494- if err := json .Unmarshal (schema , & schemaMap ); err != nil {
495- return nil , err
496- }
497-
498- if properties , ok := schemaMap ["properties" ].(map [string ]interface {}); ok {
499- if capabilitiesSchema , ok := properties ["capabilities" ].(map [string ]interface {}); ok {
500- if defaultValue , ok := capabilitiesSchema ["default" ]; ok {
501- return json .Marshal (defaultValue )
502- }
503- }
504- }
505-
506- return nil , fmt .Errorf ("default capabilities not found in schema" )
507- }
495+ var schemaMap map [string ]interface {}
496+ if err := encoding .Unmarshal (schema , & schemaMap ); err != nil {
497+ return nil , err
498+ }
499+
500+ if properties , ok := schemaMap ["properties" ].(map [string ]interface {}); ok {
501+ if capabilitiesSchema , ok := properties ["capabilities" ].(map [string ]interface {}); ok {
502+ if defaultValue , ok := capabilitiesSchema ["default" ]; ok {
503+ return json .Marshal (defaultValue )
504+ }
505+ }
506+ }
507+
508+ return nil , fmt .Errorf ("default capabilities not found in schema" )
509+ }
0 commit comments