From 47a447cb67a648e061f6c3dd905bb78fdc988545 Mon Sep 17 00:00:00 2001 From: Josh Curl Date: Sat, 26 Nov 2016 23:26:20 -0800 Subject: [PATCH 1/2] Add container to write_files schema --- config/schema.go | 1 + scripts/schema.json | 1 + 2 files changed, 2 insertions(+) diff --git a/config/schema.go b/config/schema.go index 022dd573..0876f1e7 100644 --- a/config/schema.go +++ b/config/schema.go @@ -63,6 +63,7 @@ var schema = `{ "properties": { "encoding": {"type": "string"}, + "container": {"type": "string"}, "content": {"type": "string"}, "owner": {"type": "string"}, "path": {"type": "string"}, diff --git a/scripts/schema.json b/scripts/schema.json index 4410b194..f16d88bb 100644 --- a/scripts/schema.json +++ b/scripts/schema.json @@ -61,6 +61,7 @@ "properties": { "encoding": {"type": "string"}, + "container": {"type": "string"}, "content": {"type": "string"}, "owner": {"type": "string"}, "path": {"type": "string"}, From f6ba07bf8b5e1a29998607a8a6d012668daf587a Mon Sep 17 00:00:00 2001 From: Josh Curl Date: Sat, 26 Nov 2016 23:27:42 -0800 Subject: [PATCH 2/2] Fix validation for list of maps --- config/validate.go | 10 +++++----- config/validate_test.go | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/config/validate.go b/config/validate.go index f7027137..42cb685b 100644 --- a/config/validate.go +++ b/config/validate.go @@ -6,23 +6,23 @@ import ( ) // TODO: use this function from libcompose -func convertKeysToStrings(item interface{}) interface{} { +func ConvertKeysToStrings(item interface{}) interface{} { switch typedDatas := item.(type) { case map[string]interface{}: for key, value := range typedDatas { - typedDatas[key] = convertKeysToStrings(value) + typedDatas[key] = ConvertKeysToStrings(value) } return typedDatas case map[interface{}]interface{}: newMap := make(map[string]interface{}) for key, value := range typedDatas { stringKey := key.(string) - newMap[stringKey] = convertKeysToStrings(value) + newMap[stringKey] = ConvertKeysToStrings(value) } return newMap case []interface{}: for i, value := range typedDatas { - typedDatas[i] = append(typedDatas, convertKeysToStrings(value)) + typedDatas[i] = ConvertKeysToStrings(value) } return typedDatas default: @@ -35,7 +35,7 @@ func Validate(bytes []byte) (*gojsonschema.Result, error) { if err := yaml.Unmarshal([]byte(bytes), &rawCfg); err != nil { return nil, err } - rawCfg = convertKeysToStrings(rawCfg).(map[string]interface{}) + rawCfg = ConvertKeysToStrings(rawCfg).(map[string]interface{}) loader := gojsonschema.NewGoLoader(rawCfg) schemaLoader := gojsonschema.NewStringLoader(schema) return gojsonschema.Validate(schemaLoader, loader) diff --git a/config/validate_test.go b/config/validate_test.go index 4cb8c935..ac82bde8 100644 --- a/config/validate_test.go +++ b/config/validate_test.go @@ -25,8 +25,19 @@ func testValidate(t *testing.T, cfg []byte, contains string) { func TestValidate(t *testing.T) { testValidate(t, []byte("{}"), "") testValidate(t, []byte(`rancher: - log: true -`), "") + log: true`), "") + testValidate(t, []byte(`write_files: +- container: console + path: /etc/rc.local + permissions: "0755" + owner: root + content: | + #!/bin/bash + wait-for-docker`), "") + testValidate(t, []byte(`rancher: + docker: + extra_args: ['--insecure-registry', 'my.registry.com']`), "") + testValidate(t, []byte("bad_key: {}"), "Additional property bad_key is not allowed") testValidate(t, []byte("rancher: []"), "rancher: Invalid type. Expected: object, given: array")