From e87394fea173469196f1e792426672edf8138191 Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Tue, 22 Jun 2021 12:54:17 +0200 Subject: [PATCH] distro: method for detecting manifest version Small helper method for distro.Manifest that can detect the schema version of the Manifest. --- internal/distro/distro.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/internal/distro/distro.go b/internal/distro/distro.go index bca2fa042..1b6630f11 100644 --- a/internal/distro/distro.go +++ b/internal/distro/distro.go @@ -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 {