internal/osbuild: add ovf stage

This commit is contained in:
Sanne Raymaekers 2023-03-29 17:48:45 +02:00
parent 0292725ce4
commit 53fa47f104

View file

@ -0,0 +1,39 @@
package osbuild
import (
"fmt"
"regexp"
)
const vmdkRegex = "^[a-zA-Z0-9+_.-]*$"
type OVFStageOptions struct {
Vmdk string `json:"vmdk"`
}
func (OVFStageOptions) isStageOptions() {}
func (o OVFStageOptions) validate() error {
if o.Vmdk == "" {
return fmt.Errorf("'vmdk' option is empty")
}
exp := regexp.MustCompile(vmdkRegex)
if !exp.MatchString(o.Vmdk) {
return fmt.Errorf("'vmdk' name %q doesn't conform to schema (%s)", o.Vmdk, exp.String())
}
return nil
}
// Generates a file descriptor for an in-tree vmdk file
func NewOVFStage(options *OVFStageOptions) *Stage {
if err := options.validate(); err != nil {
panic(err)
}
return &Stage{
Type: "org.osbuild.ovf",
Options: options,
}
}