Skip to content

Commit

Permalink
update introspec logic to check for schemaversion w/signoff
Browse files Browse the repository at this point in the history
Signed-off-by: Jougan-0 <prasantmishra2018@gmail.com>
  • Loading branch information
Jougan-0 committed Nov 25, 2024
1 parent 084c49c commit d2dfe34
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions utils/detect_pattern_file_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"archive/tar"
"bytes"
"compress/gzip"
"encoding/json"
"io"
"regexp"
"strings"
Expand Down Expand Up @@ -31,12 +32,39 @@ func IdentifyInputType(data []byte) (string, error) {

// Check if the input is a Meshery design
func isMesheryDesign(data []byte) bool {
var mesheryPattern map[string]interface{}
if err := yaml.Unmarshal(data, &mesheryPattern); err != nil {
var tempMap map[string]interface{}

// Try unmarshaling as JSON; if it fails, try YAML
if err := json.Unmarshal(data, &tempMap); err != nil {
var yamlMap map[string]interface{}
if yaml.Unmarshal(data, &yamlMap) != nil {
return false
}

// Convert YAML to JSON format
yamlToJSON, err := json.Marshal(yamlMap)
if err != nil {
return false
}

// Unmarshal JSON back into tempMap
if json.Unmarshal(yamlToJSON, &tempMap) != nil {
return false
}
}

// Check for schemaVersion key
schemaVersion, exists := tempMap["schemaVersion"].(string)
if !exists {
return false
}
_, exists := mesheryPattern["services"]
return exists

// Validate schemaVersion for Meshery Design
if strings.HasPrefix(schemaVersion, "designs.meshery.io") {
return true
}

return false
}

// Check if the input is a Docker Compose file
Expand Down

0 comments on commit d2dfe34

Please sign in to comment.