Skip to content

Commit

Permalink
Merge pull request #618 from Jougan-0/updateIntrospec
Browse files Browse the repository at this point in the history
update introspec logic to check for schemaversion
  • Loading branch information
Jougan-0 authored Nov 25, 2024
2 parents 9c570ce + c4dea9f commit 023b146
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 023b146

Please sign in to comment.