distro: method for detecting manifest version

Small helper method for distro.Manifest that can detect the schema
version of the Manifest.
This commit is contained in:
Achilleas Koutsou 2021-06-22 12:54:17 +02:00 committed by Tom Gundersen
parent 72f0f7ffed
commit e87394fea1

View file

@ -131,6 +131,26 @@ func (m *Manifest) UnmarshalJSON(payload []byte) error {
return nil
}
type manifestVersion struct {
Version string `json:"version"`
}
func (m Manifest) Version() (string, error) {
mver := new(manifestVersion)
if err := json.Unmarshal(m, mver); err != nil {
return "", err
}
switch mver.Version {
case "":
return "1", nil
case "2":
return "2", nil
default:
return "", fmt.Errorf("Unsupported Manifest version %s", mver.Version)
}
}
func GetHostDistroName() (string, bool, bool, error) {
f, err := os.Open("/etc/os-release")
if err != nil {