MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / IdentifyFormat

Function IdentifyFormat

app/controlplane/pkg/unmarshal/unmarshal.go:112–125  ·  view source on GitHub ↗

IdentifyFormat does best effort to identify the format of the raw contract by going the unmarshalling path in the following order: json, yaml. NOTE that we are just validating the format, not the content using regular marshalling not even proto marshalling, that comes later once we know the format.

(raw []byte)

Source from the content-addressed store, hash-verified

110// not even proto marshalling, that comes later once we know the format.
111// CUE is intentionally not detected: it is no longer a supported contract format.
112func IdentifyFormat(raw []byte) (RawFormat, error) {
113 // json marshalling first
114 var sink any
115 if err := json.Unmarshal(raw, &sink); err == nil {
116 return RawFormatJSON, nil
117 }
118
119 // yaml marshalling last
120 if err := yaml.Unmarshal(raw, &sink); err == nil {
121 return RawFormatYAML, nil
122 }
123
124 return "", errors.New("format not found")
125}
126
127// LoadJSONBytes Extracts raw data in JSON format from different sources, i.e yaml or json files
128func LoadJSONBytes(rawData []byte, extension string) ([]byte, error) {

Callers 6

extractMetadataFunction · 0.92
extractOrgFunction · 0.92
extractNameFromMetadataFunction · 0.92
TestIdentifyFormatFunction · 0.85
TestCUEIsRejectedFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestIdentifyFormatFunction · 0.68
TestCUEIsRejectedFunction · 0.68