func loadFromYAML()

in terraformer/pkg/terraformer/compiler.go [238:268]


func loadFromYAML(in []byte) (*terraformerv1.AppRoleDefinition, error) {
	// Decode as YAML any object
	var specBody interface{}
	if err := yaml.Unmarshal(in, &specBody); err != nil {
		return nil, fmt.Errorf("unable to decode YAML input: %w", err)
	}

	// Convert map[interface{}]interface{} to a JSON serializable struct
	specBody, err := convertMapStringInterface(specBody)
	if err != nil {
		return nil, err
	}

	// Marshal as json
	jsonData, err := json.Marshal(specBody)
	if err != nil {
		return nil, fmt.Errorf("unable to marshal to JSON: %w", err)
	}

	// Initialize empty definition object
	def := terraformerv1.AppRoleDefinition{}
	def.Reset()

	// Deserialize JSON with JSONPB wrapper
	if err := protojson.Unmarshal(jsonData, &def); err != nil {
		return nil, fmt.Errorf("unable to decode with ProtoJSON: %w", err)
	}

	// No error
	return &def, nil
}