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

Function extractNameFromMetadata

app/cli/pkg/action/util.go:105–138  ·  view source on GitHub ↗

extractNameFromMetadata attempts to extract the name from metadata.name.

(content []byte)

Source from the content-addressed store, hash-verified

103
104// extractNameFromMetadata attempts to extract the name from metadata.name.
105func extractNameFromMetadata(content []byte) (string, error) {
106 if len(content) == 0 {
107 return "", nil
108 }
109
110 // Identify the format
111 format, err := unmarshal.IdentifyFormat(content)
112 if err != nil {
113 return "", err
114 }
115
116 // Convert to JSON for consistent unmarshaling
117 var jsonData []byte
118 switch format {
119 case unmarshal.RawFormatJSON:
120 jsonData = content
121 case unmarshal.RawFormatYAML:
122 jsonData, err = unmarshal.LoadJSONBytes(content, ".yaml")
123 if err != nil {
124 return "", err
125 }
126 default:
127 return "", fmt.Errorf("unsupported format: %s", format)
128 }
129
130 // Unmarshal just the metadata field
131 var schema metadataWithName
132 if err := json.Unmarshal(jsonData, &schema); err != nil {
133 // Not a v2 schema or invalid format
134 return "", nil
135 }
136
137 return schema.Metadata.Name, nil
138}

Callers 1

ValidateAndExtractNameFunction · 0.85

Calls 2

IdentifyFormatFunction · 0.92
LoadJSONBytesFunction · 0.92

Tested by

no test coverage detected