summaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorTyler Cipriani <tcipriani@wikimedia.org>2018-11-02 09:40:58 -0600
committerTyler Cipriani <tcipriani@wikimedia.org>2018-12-10 17:33:15 -0700
commit56e830f6417fe1ebda1bdc2cf7810dcccd9a7da6 (patch)
treea081badcc905a516c3421f9534555fe916b961e3 /config
parent6597c943b6af809cc30e80070ad42953cab05dc4 (diff)
downloadblubber-56e830f6417fe1ebda1bdc2cf7810dcccd9a7da6.tar.gz
Use JSON as canonical config format
Uses the github.com/ghodss/yaml library to convert YAML to JSON before unmarshaling for the purposes of supporting YAML and JSON input while converting to only support JSON internally. Bug: T207694 Change-Id: I00668014907e9ea54917f5d5067cac08d0668053
Diffstat (limited to 'config')
-rw-r--r--config/apt.go2
-rw-r--r--config/apt_test.go2
-rw-r--r--config/artifacts.go6
-rw-r--r--config/artifacts_test.go8
-rw-r--r--config/builder.go4
-rw-r--r--config/builder_test.go2
-rw-r--r--config/common.go16
-rw-r--r--config/common_test.go2
-rw-r--r--config/config.go6
-rw-r--r--config/config_test.go2
-rw-r--r--config/flag.go9
-rw-r--r--config/flag_test.go2
-rw-r--r--config/lives.go4
-rw-r--r--config/lives_test.go4
-rw-r--r--config/node.go4
-rw-r--r--config/node_test.go2
-rw-r--r--config/policy.go39
-rw-r--r--config/policy_test.go6
-rw-r--r--config/python.go4
-rw-r--r--config/python_test.go6
-rw-r--r--config/reader.go49
-rw-r--r--config/reader_test.go20
-rw-r--r--config/runs.go6
-rw-r--r--config/runs_test.go2
-rw-r--r--config/user.go6
-rw-r--r--config/validation.go6
-rw-r--r--config/variant.go8
-rw-r--r--config/variant_test.go14
-rw-r--r--config/version.go2
-rw-r--r--config/version_test.go2
30 files changed, 136 insertions, 109 deletions
diff --git a/config/apt.go b/config/apt.go
index 34a0d4a..b31239a 100644
--- a/config/apt.go
+++ b/config/apt.go
@@ -8,7 +8,7 @@ import (
// existing APT sources.
//
type AptConfig struct {
- Packages []string `yaml:"packages" validate:"dive,debianpackage"`
+ Packages []string `json:"packages" validate:"dive,debianpackage"`
}
// Merge takes another AptConfig and combines the packages declared within
diff --git a/config/apt_test.go b/config/apt_test.go
index 1bff48e..9704c67 100644
--- a/config/apt_test.go
+++ b/config/apt_test.go
@@ -11,7 +11,7 @@ import (
)
func TestAptConfigYAML(t *testing.T) {
- cfg, err := config.ReadConfig([]byte(`---
+ cfg, err := config.ReadYAMLConfig([]byte(`---
version: v3
apt:
packages:
diff --git a/config/artifacts.go b/config/artifacts.go
index 982f8ab..32cdfff 100644
--- a/config/artifacts.go
+++ b/config/artifacts.go
@@ -15,9 +15,9 @@ import (
// VariantConfig.Copies.
//
type ArtifactsConfig struct {
- From string `yaml:"from" validate:"required,variantref"` // source variant from which to copy
- Source string `yaml:"source" validate:"required"` // source variant path from which to copy
- Destination string `yaml:"destination" validate:"required"` // destination path within current variant
+ From string `json:"from" validate:"required,variantref"` // source variant from which to copy
+ Source string `json:"source" validate:"required"` // source variant path from which to copy
+ Destination string `json:"destination" validate:"required"` // destination path within current variant
}
// InstructionsForPhase injects instructions into the given build phase that
diff --git a/config/artifacts_test.go b/config/artifacts_test.go
index 44dd89c..465d5ea 100644
--- a/config/artifacts_test.go
+++ b/config/artifacts_test.go
@@ -10,7 +10,7 @@ import (
)
func TestArtifactsConfigYAML(t *testing.T) {
- cfg, err := config.ReadConfig([]byte(`---
+ cfg, err := config.ReadYAMLConfig([]byte(`---
version: v3
base: foo
variants:
@@ -79,7 +79,7 @@ func TestArtifactsConfigInstructions(t *testing.T) {
func TestArtifactsConfigValidation(t *testing.T) {
t.Run("from", func(t *testing.T) {
t.Run("ok", func(t *testing.T) {
- _, err := config.ReadConfig([]byte(`---
+ _, err := config.ReadYAMLConfig([]byte(`---
version: v3
variants:
build: {}
@@ -93,7 +93,7 @@ func TestArtifactsConfigValidation(t *testing.T) {
})
t.Run("missing", func(t *testing.T) {
- _, err := config.ReadConfig([]byte(`---
+ _, err := config.ReadYAMLConfig([]byte(`---
version: v3
variants:
build: {}
@@ -111,7 +111,7 @@ func TestArtifactsConfigValidation(t *testing.T) {
})
t.Run("bad", func(t *testing.T) {
- _, err := config.ReadConfig([]byte(`---
+ _, err := config.ReadYAMLConfig([]byte(`---
version: v3
variants:
build: {}
diff --git a/config/builder.go b/config/builder.go
index c2e95b2..0f92d24 100644
--- a/config/builder.go
+++ b/config/builder.go
@@ -8,8 +8,8 @@ import (
// build command and the files required to successfully execute the command.
//
type BuilderConfig struct {
- Command []string `yaml:"command"`
- Requirements []string `yaml:"requirements"`
+ Command []string `json:"command"`
+ Requirements []string `json:"requirements"`
}
// Merge takes another BuilderConfig and merges its fields into this one's,
diff --git a/config/builder_test.go b/config/builder_test.go
index 0785f7a..b8e95f5 100644
--- a/config/builder_test.go
+++ b/config/builder_test.go
@@ -10,7 +10,7 @@ import (
)
func TestBuilderConfigYAML(t *testing.T) {
- cfg, err := config.ReadConfig([]byte(`---
+ cfg, err := config.ReadYAMLConfig([]byte(`---
version: v3
base: foo
builder:
diff --git a/config/common.go b/config/common.go
index 90c9c5b..5421830 100644
--- a/config/common.go
+++ b/config/common.go
@@ -8,14 +8,14 @@ import (
// and each configured variant.
//
type CommonConfig struct {
- Base string `yaml:"base" validate:"omitempty,baseimage"` // name/path to base image
- Apt AptConfig `yaml:"apt"` // APT related
- Node NodeConfig `yaml:"node"` // Node related
- Python PythonConfig `yaml:"python"` // Python related
- Builder BuilderConfig `yaml:"builder"` // Builder related
- Lives LivesConfig `yaml:"lives"` // application owner/dir
- Runs RunsConfig `yaml:"runs"` // runtime environment
- EntryPoint []string `yaml:"entrypoint"` // entry-point executable
+ Base string `json:"base" validate:"omitempty,baseimage"` // name/path to base image
+ Apt AptConfig `json:"apt"` // APT related
+ Node NodeConfig `json:"node"` // Node related
+ Python PythonConfig `json:"python"` // Python related
+ Builder BuilderConfig `json:"builder"` // Builder related
+ Lives LivesConfig `json:"lives"` // application owner/dir
+ Runs RunsConfig `json:"runs"` // runtime environment
+ EntryPoint []string `json:"entrypoint"` // entry-point executable
}
// Merge takes another CommonConfig and merges its fields this one's.
diff --git a/config/common_test.go b/config/common_test.go
index d22bcff..5ea3b35 100644
--- a/config/common_test.go
+++ b/config/common_test.go
@@ -9,7 +9,7 @@ import (
)
func TestCommonConfigYAML(t *testing.T) {
- cfg, err := config.ReadConfig([]byte(`---
+ cfg, err := config.ReadYAMLConfig([]byte(`---
version: v3
base: fooimage
entrypoint: ["/bin/foo"]
diff --git a/config/config.go b/config/config.go
index 695759f..8fa6844 100644
--- a/config/config.go
+++ b/config/config.go
@@ -7,7 +7,7 @@ package config
// Config holds the root fields of a Blubber configuration.
//
type Config struct {
- CommonConfig `yaml:",inline"`
- Variants map[string]VariantConfig `yaml:"variants" validate:"variants,dive"`
- VersionConfig `yaml:",inline"`
+ CommonConfig `json:",inline"`
+ Variants map[string]VariantConfig `json:"variants" validate:"variants,dive"`
+ VersionConfig `json:",inline"`
}
diff --git a/config/config_test.go b/config/config_test.go
index 45151bc..8b6e28c 100644
--- a/config/config_test.go
+++ b/config/config_test.go
@@ -9,7 +9,7 @@ import (
)
func TestConfigYAML(t *testing.T) {
- cfg, err := config.ReadConfig([]byte(`---
+ cfg, err := config.ReadYAMLConfig([]byte(`---
version: v3
variants:
foo: {}`))
diff --git a/config/flag.go b/config/flag.go
index 6fb9e72..01fa6dd 100644
--- a/config/flag.go
+++ b/config/flag.go
@@ -1,4 +1,5 @@
package config
+import "strconv"
// Flag represents a nullable boolean value that is considered null until
// either parsed from YAML or merged in from another Flag value.
@@ -8,11 +9,13 @@ type Flag struct {
set bool
}
-// UnmarshalYAML implements yaml.Unmarshaler to parse the underlying boolean
+// UnmarshalJSON implements json.Unmarshaler to parse the underlying boolean
// value and detect that the Flag should no longer be considered null.
//
-func (flag *Flag) UnmarshalYAML(unmarshal func(interface{}) error) error {
- if err := unmarshal(&flag.True); err != nil {
+func (flag *Flag) UnmarshalJSON(unmarshal []byte) error {
+ var err error
+ flag.True, err = strconv.ParseBool(string(unmarshal))
+ if err != nil {
return err
}
diff --git a/config/flag_test.go b/config/flag_test.go
index b70174d..bb77027 100644
--- a/config/flag_test.go
+++ b/config/flag_test.go
@@ -9,7 +9,7 @@ import (
)
func TestFlagMerge(t *testing.T) {
- cfg, err := config.ReadConfig([]byte(`---
+ cfg, err := config.ReadYAMLConfig([]byte(`---
version: v3
base: foo
runs: { insecurely: true }
diff --git a/config/lives.go b/config/lives.go
index 0e45247..3be4eb5 100644
--- a/config/lives.go
+++ b/config/lives.go
@@ -13,8 +13,8 @@ const LocalLibPrefix = "/opt/lib"
// installed dependencies and application files.
//
type LivesConfig struct {
- In string `yaml:"in" validate:"omitempty,abspath"` // application directory
- UserConfig `yaml:",inline"`
+ In string `json:"in" validate:"omitempty,abspath"` // application directory
+ UserConfig `json:",inline"`
}
// Merge takes another LivesConfig and overwrites this struct's fields.
diff --git a/config/lives_test.go b/config/lives_test.go
index 2220652..db76fce 100644
--- a/config/lives_test.go
+++ b/config/lives_test.go
@@ -10,7 +10,7 @@ import (
)
func TestLivesConfigYAML(t *testing.T) {
- cfg, err := config.ReadConfig([]byte(`---
+ cfg, err := config.ReadYAMLConfig([]byte(`---
version: v3
base: foo
lives:
@@ -39,7 +39,7 @@ func TestLivesConfigYAML(t *testing.T) {
}
func TestLivesConfigDefaults(t *testing.T) {
- cfg, err := config.ReadConfig([]byte(`---
+ cfg, err := config.ReadYAMLConfig([]byte(`---
version: v3
base: foo`))
diff --git a/config/node.go b/config/node.go
index a6a22ea..d15cf89 100644
--- a/config/node.go
+++ b/config/node.go
@@ -8,8 +8,8 @@ import (
// whether/how to install NPM packages.
//
type NodeConfig struct {
- Requirements []string `yaml:"requirements"` // install requirements from given files
- Env string `yaml:"env" validate:"omitempty,nodeenv"` // environment name ("production" install)
+ Requirements []string `json:"requirements"` // install requirements from given files
+ Env string `json:"env" validate:"omitempty,nodeenv"` // environment name ("production" install)
}
// Merge takes another NodeConfig and merges its fields into this one's,
diff --git a/config/node_test.go b/config/node_test.go
index ef29ee5..9267474 100644
--- a/config/node_test.go
+++ b/config/node_test.go
@@ -10,7 +10,7 @@ import (
)
func TestNodeConfigYAML(t *testing.T) {
- cfg, err := config.ReadConfig([]byte(`---
+ cfg, err := config.ReadYAMLConfig([]byte(`---
version: v3
base: foo
node:
diff --git a/config/policy.go b/config/policy.go
index f143f1a..ade4e71 100644
--- a/config/policy.go
+++ b/config/policy.go
@@ -2,19 +2,20 @@ package config
import (
"errors"
+ "encoding/json"
"fmt"
"io/ioutil"
"reflect"
"strings"
"github.com/utahta/go-openuri"
- "gopkg.in/yaml.v2"
+ "github.com/ghodss/yaml"
)
// Policy validates a number of rules against a given configuration.
//
type Policy struct {
- Enforcements []Enforcement `yaml:"enforcements"`
+ Enforcements []Enforcement `json:"enforcements"`
}
// Validate checks the given config against all policy enforcements.
@@ -23,7 +24,7 @@ func (pol Policy) Validate(config Config) error {
validate := newValidator()
for _, enforcement := range pol.Enforcements {
- cfg, err := ResolveYAMLPath(enforcement.Path, config)
+ cfg, err := ResolveJSONPath(enforcement.Path, config)
if err != nil {
// If the path resolved nothing, there's nothing to enforce
@@ -52,16 +53,26 @@ func (pol Policy) Validate(config Config) error {
// Enforcement represents a policy rule and config path on which to apply it.
//
type Enforcement struct {
- Path string `yaml:"path"`
- Rule string `yaml:"rule"`
+ Path string `json:"path"`
+ Rule string `json:"rule"`
}
-// ReadPolicy unmarshals the given YAML bytes into a new Policy struct.
+// ReadYAMLPolicy converts YAML input to JSON and returns a new Policy struct.
+//
+func ReadYAMLPolicy(data []byte) (*Policy, error) {
+ jsonData, err := yaml.YAMLToJSON(data)
+ if err != nil {
+ return nil, err
+ }
+
+ return ReadPolicy(jsonData)
+}
+
+// ReadPolicy unmarshals the given YAML/json bytes into a new Policy struct.
//
func ReadPolicy(data []byte) (*Policy, error) {
var policy Policy
-
- err := yaml.Unmarshal(data, &policy)
+ err := json.Unmarshal(data, &policy)
if err != nil {
return nil, err
@@ -88,13 +99,13 @@ func ReadPolicyFromURI(uri string) (*Policy, error) {
return nil, err
}
- return ReadPolicy(data)
+ return ReadYAMLPolicy(data)
}
-// ResolveYAMLPath returns the config value found at the given YAML-ish
+// ResolveJSONPath returns the config value found at the given JSON-ish
// namespace/path (e.g. "variants.production.runs.as").
//
-func ResolveYAMLPath(path string, cfg interface{}) (interface{}, error) {
+func ResolveJSONPath(path string, cfg interface{}) (interface{}, error) {
parts := strings.SplitN(path, ".", 2)
name := parts[0]
@@ -107,12 +118,12 @@ func ResolveYAMLPath(path string, cfg interface{}) (interface{}, error) {
case reflect.Struct:
for i := 0; i < t.NumField(); i++ {
if t.Field(i).Anonymous {
- if subsubcfg, err := ResolveYAMLPath(path, v.Field(i).Interface()); err == nil {
+ if subsubcfg, err := ResolveJSONPath(path, v.Field(i).Interface()); err == nil {
return subsubcfg, nil
}
}
- if name == resolveYAMLTagName(t.Field(i)) {
+ if name == resolveJSONTagName(t.Field(i)) {
subcfg = v.Field(i).Interface()
break
}
@@ -134,7 +145,7 @@ func ResolveYAMLPath(path string, cfg interface{}) (interface{}, error) {
}
if len(parts) > 1 {
- return ResolveYAMLPath(parts[1], subcfg)
+ return ResolveJSONPath(parts[1], subcfg)
}
return subcfg, nil
diff --git a/config/policy_test.go b/config/policy_test.go
index 09d838c..95eb655 100644
--- a/config/policy_test.go
+++ b/config/policy_test.go
@@ -9,7 +9,7 @@ import (
)
func TestPolicyRead(t *testing.T) {
- policy, err := config.ReadPolicy([]byte(`---
+ policy, err := config.ReadYAMLPolicy([]byte(`---
enforcements:
- path: variants.production.runs.as
rule: ne=root
@@ -94,7 +94,7 @@ func TestEnforcementOnFlag(t *testing.T) {
}
-func TestResolveYAMLPath(t *testing.T) {
+func TestResolveJSONPath(t *testing.T) {
cfg := config.Config{
Variants: map[string]config.VariantConfig{
"foo": config.VariantConfig{
@@ -109,7 +109,7 @@ func TestResolveYAMLPath(t *testing.T) {
},
}
- val, err := config.ResolveYAMLPath("variants.foo.runs.as", cfg)
+ val, err := config.ResolveJSONPath("variants.foo.runs.as", cfg)
if assert.NoError(t, err) {
assert.Equal(t, "root", val)
diff --git a/config/python.go b/config/python.go
index c2927e3..9329f6e 100644
--- a/config/python.go
+++ b/config/python.go
@@ -20,8 +20,8 @@ const PythonSiteBin = PythonSitePackages + "/bin"
// dependencies via PIP.
//
type PythonConfig struct {
- Version string `yaml:"version"` // Python binary to use when installing dependencies
- Requirements []string `yaml:"requirements"` // install requirements from given files
+ Version string `json:"version"` // Python binary to use when installing dependencies
+ Requirements []string `json:"requirements"` // install requirements from given files
}
// Merge takes another PythonConfig and merges its fields into this one's,
diff --git a/config/python_test.go b/config/python_test.go
index 3ece2e5..02d6259 100644
--- a/config/python_test.go
+++ b/config/python_test.go
@@ -10,7 +10,7 @@ import (
)
func TestPythonConfigYAMLMerge(t *testing.T) {
- cfg, err := config.ReadConfig([]byte(`---
+ cfg, err := config.ReadYAMLConfig([]byte(`---
version: v3
base: foo
python:
@@ -36,7 +36,7 @@ func TestPythonConfigYAMLMerge(t *testing.T) {
}
func TestPythonConfigYAMLMergeEmpty(t *testing.T) {
- cfg, err := config.ReadConfig([]byte(`---
+ cfg, err := config.ReadYAMLConfig([]byte(`---
version: v3
base: foo
python:
@@ -58,7 +58,7 @@ func TestPythonConfigYAMLMergeEmpty(t *testing.T) {
}
func TestPythonConfigYAMLDoNotMergeNil(t *testing.T) {
- cfg, err := config.ReadConfig([]byte(`---
+ cfg, err := config.ReadYAMLConfig([]byte(`---
version: v3
base: foo
python:
diff --git a/config/reader.go b/config/reader.go
index 4386aa7..4dddfdc 100644
--- a/config/reader.go
+++ b/config/reader.go
@@ -1,26 +1,29 @@
package config
import (
+ "bytes"
"errors"
+ "encoding/json"
"fmt"
"io/ioutil"
- "gopkg.in/yaml.v2"
+ "github.com/ghodss/yaml"
)
// DefaultConfig contains YAML that is applied before the user's
// configuration.
//
-const DefaultConfig = `---
-lives:
- in: /srv/app
- as: somebody
- uid: 65533
- gid: 65533
-runs:
- as: runuser
- uid: 900
- gid: 900`
+const DefaultConfig = `{
+"lives": {
+ "in": "/srv/app",
+ "as": "somebody",
+ "uid": 65533,
+ "gid": 65533
+},
+"runs": {
+ "as": "runuser",
+ "uid": 900,
+ "gid": 900}}`
// ResolveIncludes iterates over and recurses through a given variant's
// includes to build a flat slice of variant names in the correct order by
@@ -87,6 +90,16 @@ func ExpandVariant(config *Config, name string) (*VariantConfig, error) {
return expanded, nil
}
+// ReadYAMLConfig converts YAML bytes to json and returns new Config struct.
+//
+func ReadYAMLConfig(data []byte) (*Config, error) {
+ jsonData, err := yaml.YAMLToJSON(data)
+ if err != nil {
+ return nil, err
+ }
+
+ return ReadConfig(jsonData)
+}
// ReadConfig unmarshals the given YAML bytes into a new Config struct.
//
@@ -96,8 +109,8 @@ func ReadConfig(data []byte) (*Config, error) {
config Config
)
- // Unmarshal (un-strictly) config version first for pre-validation
- err := yaml.Unmarshal(data, &version)
+ // Unmarshal config version first for pre-validation
+ err := json.Unmarshal(data, &version)
if err != nil {
return nil, err
@@ -108,10 +121,12 @@ func ReadConfig(data []byte) (*Config, error) {
}
// Unmarshal the default config
- yaml.Unmarshal([]byte(DefaultConfig), &config)
+ json.Unmarshal([]byte(DefaultConfig), &config)
- // And finally strictly unmarshal the entire user-provided config
- err = yaml.UnmarshalStrict(data, &config)
+ // And finally strictly decode the entire user-provided config
+ dec := json.NewDecoder(bytes.NewReader(data))
+ dec.DisallowUnknownFields()
+ err = dec.Decode(&config)
if err != nil {
return nil, err
@@ -132,5 +147,5 @@ func ReadConfigFile(path string) (*Config, error) {
return nil, err
}
- return ReadConfig(data)
+ return ReadYAMLConfig(data)
}
diff --git a/config/reader_test.go b/config/reader_test.go
index 1a7d529..0c1f1ed 100644
--- a/config/reader_test.go
+++ b/config/reader_test.go
@@ -10,7 +10,7 @@ import (
)
func ExampleResolveIncludes() {
- cfg, _ := config.ReadConfig([]byte(`---
+ cfg, _ := config.ReadYAMLConfig([]byte(`---
version: v3
variants:
varA: { includes: [varB, varC] }
@@ -27,8 +27,8 @@ func ExampleResolveIncludes() {
// Output: [varF varD varE varB varC varA]
}
-func TestReadConfigErrorsOnUnknownYAML(t *testing.T) {
- _, err := config.ReadConfig([]byte(`---
+func TestReadYAMLConfigErrorsOnUnknownYAML(t *testing.T) {
+ _, err := config.ReadYAMLConfig([]byte(`---
version: v3
newphone: whodis
variants:
@@ -36,13 +36,11 @@ func TestReadConfigErrorsOnUnknownYAML(t *testing.T) {
assert.EqualError(t,
err,
- "yaml: unmarshal errors:\n"+
- " line 2: field newphone not found in struct config.Config",
- )
+ `json: unknown field "newphone"`)
}
-func TestReadConfigValidateVersionBeforeStrictUnmarshal(t *testing.T) {
- _, err := config.ReadConfig([]byte(`---
+func TestReadYAMLConfigValidateVersionBeforeStrictUnmarshal(t *testing.T) {
+ _, err := config.ReadYAMLConfig([]byte(`---
version: foo
newphone: whodis
variants:
@@ -56,7 +54,7 @@ func TestReadConfigValidateVersionBeforeStrictUnmarshal(t *testing.T) {
}
func TestResolveIncludesPreventsInfiniteRecursion(t *testing.T) {
- cfg, err := config.ReadConfig([]byte(`---
+ cfg, err := config.ReadYAMLConfig([]byte(`---
version: v3
variants:
varA: { includes: [varB] }
@@ -70,7 +68,7 @@ func TestResolveIncludesPreventsInfiniteRecursion(t *testing.T) {
}
func TestMultiLevelIncludes(t *testing.T) {
- cfg, err := config.ReadConfig([]byte(`---
+ cfg, err := config.ReadYAMLConfig([]byte(`---
version: v3
base: foo-slim
variants:
@@ -102,7 +100,7 @@ func TestMultiLevelIncludes(t *testing.T) {
}
func TestMultiIncludes(t *testing.T) {
- cfg, err := config.ReadConfig([]byte(`---
+ cfg, err := config.ReadYAMLConfig([]byte(`---
version: v3
variants:
mammal:
diff --git a/config/runs.go b/config/runs.go
index 9657303..35b7efb 100644
--- a/config/runs.go
+++ b/config/runs.go
@@ -8,9 +8,9 @@ import (
// runtime environment.
//
type RunsConfig struct {
- UserConfig `yaml:",inline"`
- Insecurely Flag `yaml:"insecurely"` // runs user owns application files
- Environment map[string]string `yaml:"environment" validate:"envvars"` // environment variables
+ UserConfig `json:",inline"`
+ Insecurely Flag `json:"insecurely"` // runs user owns application files
+ Environment map[string]string `json:"environment" validate:"envvars"` // environment variables
}
// Merge takes another RunsConfig and overwrites this struct's fields. All
diff --git a/config/runs_test.go b/config/runs_test.go
index 8d685c7..74f7158 100644
--- a/config/runs_test.go
+++ b/config/runs_test.go
@@ -10,7 +10,7 @@ import (
)
func TestRunsConfigYAML(t *testing.T) {
- cfg, err := config.ReadConfig([]byte(`---
+ cfg, err := config.ReadYAMLConfig([]byte(`---
version: v3
base: foo
runs:
diff --git a/config/user.go b/config/user.go
index f42fbf7..b43161a 100644
--- a/config/user.go
+++ b/config/user.go
@@ -3,9 +3,9 @@ package config
// UserConfig holds configuration fields related to a user account.
//
type UserConfig struct {
- As string `yaml:"as" validate:"omitempty,username"` // user name
- UID uint `yaml:"uid"` // user ID
- GID uint `yaml:"gid"` // group ID
+ As string `json:"as" validate:"omitempty,username"` // user name
+ UID uint `json:"uid"` // user ID
+ GID uint `json:"gid"` // group ID
}
// Merge takes another UserConfig and overwrites this struct's fields.
diff --git a/config/validation.go b/config/validation.go
index 2529e00..26c447e 100644
--- a/config/validation.go
+++ b/config/validation.go
@@ -71,7 +71,7 @@ const rootCfgCtx ctxKey = iota
func newValidator() *validator.Validate {
validate := validator.New()
- validate.RegisterTagNameFunc(resolveYAMLTagName)
+ validate.RegisterTagNameFunc(resolveJSONTagName)
for name, tags := range validatorAliases {
validate.RegisterAlias(name, tags)
@@ -207,6 +207,6 @@ func isVariantReference(ctx context.Context, fl validator.FieldLevel) bool {
return false
}
-func resolveYAMLTagName(field reflect.StructField) string {
- return strings.SplitN(field.Tag.Get("yaml"), ",", 2)[0]
+func resolveJSONTagName(field reflect.StructField) string {
+ return strings.SplitN(field.Tag.Get("json"), ",", 2)[0]
}
diff --git a/config/variant.go b/config/variant.go
index cc4d802..8d6b7bc 100644
--- a/config/variant.go
+++ b/config/variant.go
@@ -7,10 +7,10 @@ import (
// VariantConfig holds configuration fields for each defined build variant.
//
type VariantConfig struct {
- Includes []string `yaml:"includes" validate:"dive,variantref"` // other variants
- Copies string `yaml:"copies" validate:"omitempty,variantref"` // copy artifacts from variant
- Artifacts []ArtifactsConfig `yaml:"artifacts" validate:"dive"` // artifact configuration
- CommonConfig `yaml:",inline"`
+ Includes []string `json:"includes" validate:"dive,variantref"` // other variants
+ Copies string `json:"copies" validate:"omitempty,variantref"` // copy artifacts from variant
+ Artifacts []ArtifactsConfig `json:"artifacts" validate:"dive"` // artifact configuration
+ CommonConfig `json:",inline"`
}
// Merge takes another VariantConfig and overwrites this struct's fields.
diff --git a/config/variant_test.go b/config/variant_test.go
index b073654..9916185 100644
--- a/config/variant_test.go
+++ b/config/variant_test.go
@@ -11,7 +11,7 @@ import (
)
func TestVariantConfigYAML(t *testing.T) {
- cfg, err := config.ReadConfig([]byte(`---
+ cfg, err := config.ReadYAMLConfig([]byte(`---
version: v3
base: foo
variants:
@@ -202,7 +202,7 @@ func TestVariantConfigInstructions(t *testing.T) {
func TestVariantConfigValidation(t *testing.T) {
t.Run("includes", func(t *testing.T) {
t.Run("ok", func(t *testing.T) {
- _, err := config.ReadConfig([]byte(`---
+ _, err := config.ReadYAMLConfig([]byte(`---
version: v3
variants:
build: {}
@@ -212,7 +212,7 @@ func TestVariantConfigValidation(t *testing.T) {
})
t.Run("optional", func(t *testing.T) {
- _, err := config.ReadConfig([]byte(`---
+ _, err := config.ReadYAMLConfig([]byte(`---
version: v3
variants:
build: {}
@@ -222,7 +222,7 @@ func TestVariantConfigValidation(t *testing.T) {
})
t.Run("bad", func(t *testing.T) {
- _, err := config.ReadConfig([]byte(`---
+ _, err := config.ReadYAMLConfig([]byte(`---
version: v3
variants:
build: {}
@@ -242,7 +242,7 @@ func TestVariantConfigValidation(t *testing.T) {
t.Run("copies", func(t *testing.T) {
t.Run("ok", func(t *testing.T) {
- _, err := config.ReadConfig([]byte(`---
+ _, err := config.ReadYAMLConfig([]byte(`---
version: v3
variants:
build: {}
@@ -252,7 +252,7 @@ func TestVariantConfigValidation(t *testing.T) {
})
t.Run("optional", func(t *testing.T) {
- _, err := config.ReadConfig([]byte(`---
+ _, err := config.ReadYAMLConfig([]byte(`---
version: v3
variants:
build: {}
@@ -262,7 +262,7 @@ func TestVariantConfigValidation(t *testing.T) {
})
t.Run("bad", func(t *testing.T) {
- _, err := config.ReadConfig([]byte(`---
+ _, err := config.ReadYAMLConfig([]byte(`---
version: v3
variants:
build: {}
diff --git a/config/version.go b/config/version.go
index 0a41fca..b0e3589 100644
--- a/config/version.go
+++ b/config/version.go
@@ -8,5 +8,5 @@ const CurrentVersion string = "v3"
// config version independent from an entire Config struct.
//
type VersionConfig struct {
- Version string `yaml:"version" validate:"required,currentversion"`
+ Version string `json:"version" validate:"required,currentversion"`
}
diff --git a/config/version_test.go b/config/version_test.go
index 3b25d5e..bf2b0fc 100644
--- a/config/version_test.go
+++ b/config/version_test.go
@@ -9,7 +9,7 @@ import (
)
func TestVersionConfigYAML(t *testing.T) {
- cfg, err := config.ReadConfig([]byte(`---
+ cfg, err := config.ReadYAMLConfig([]byte(`---
version: v3
variants:
foo: {}`))