Skip to content

Commit

Permalink
Check for magic cloud-config comment before yaml
Browse files Browse the repository at this point in the history
Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
  • Loading branch information
afbjorklund committed Apr 9, 2024
1 parent 3184d67 commit 2d45b03
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/cidata/schema.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cidata

import (
"bytes"
_ "embed"
"fmt"
"strings"

"github.com/santhosh-tekuri/jsonschema/v5"
Expand All @@ -15,6 +17,9 @@ const schemaURL = "https://raw.githubusercontent.com/canonical/cloud-init/main/c
var schemaText string

func validateCloudConfig(userData []byte) error {
if !bytes.HasPrefix(userData, []byte("#cloud-config")) {
return fmt.Errorf("missing #cloud-config")
}
var m interface{}
err := yaml.Unmarshal(userData, &m)
if err != nil {
Expand Down

0 comments on commit 2d45b03

Please sign in to comment.