talos/pkg/userdata/version.go
Brad Beam a5d31d97ff
feat: Validate userdata (#593)
* feat: Validate userdata

Signed-off-by: Brad Beam <brad.beam@talos-systems.com>
2019-05-02 13:10:16 -05:00

28 lines
762 B
Go

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package userdata
import (
"github.com/hashicorp/go-multierror"
"golang.org/x/xerrors"
)
// Version represents the config file version
type Version string
// Validate triggers the specified validation checks to run
func (v Version) Validate() error {
var result *multierror.Error
if v == "" {
result = multierror.Append(result, xerrors.Errorf("[%s] %q: %w", "version", "", ErrRequiredSection))
}
if v != "1" {
result = multierror.Append(result, xerrors.Errorf("[%s] %q: %w", "version", v, ErrInvalidVersion))
}
return result.ErrorOrNil()
}