mirror of
https://github.com/hauler-dev/hauler.git
synced 2026-04-05 18:27:16 +00:00
* improved test coverage Signed-off-by: Adam Martin <adam.martin@ranchergovernment.com> * adjusted mapper_test for oddball oci files Signed-off-by: Adam Martin <adam.martin@ranchergovernment.com> --------- Signed-off-by: Adam Martin <adam.martin@ranchergovernment.com>
36 lines
890 B
Go
36 lines
890 B
Go
package content
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
"k8s.io/apimachinery/pkg/util/yaml"
|
|
|
|
v1 "hauler.dev/go/hauler/pkg/apis/hauler.cattle.io/v1"
|
|
)
|
|
|
|
func Load(data []byte) (schema.ObjectKind, error) {
|
|
var tm metav1.TypeMeta
|
|
if err := yaml.Unmarshal(data, &tm); err != nil {
|
|
return nil, fmt.Errorf("failed to parse manifest: %w", err)
|
|
}
|
|
|
|
if tm.APIVersion == "" {
|
|
return nil, fmt.Errorf("missing required manifest field [apiVersion]")
|
|
}
|
|
|
|
if tm.Kind == "" {
|
|
return nil, fmt.Errorf("missing required manifest field [kind]")
|
|
}
|
|
|
|
gv := tm.GroupVersionKind().GroupVersion()
|
|
// allow v1 content and collections
|
|
if gv != v1.ContentGroupVersion &&
|
|
gv != v1.CollectionGroupVersion {
|
|
return nil, fmt.Errorf("unrecognized content or collection [%s] with [kind=%s]", tm.APIVersion, tm.Kind)
|
|
}
|
|
|
|
return &tm, nil
|
|
}
|