diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | src/dkv/Gopkg.lock | 10 | ||||
-rw-r--r-- | src/dkv/Gopkg.toml | 12 | ||||
-rw-r--r-- | src/dkv/api/endpointViews.go | 8 | ||||
-rw-r--r-- | src/dkv/api/endpointViews_fake.go | 4 | ||||
-rw-r--r-- | src/dkv/api/endpointViews_test.go | 2 | ||||
-rw-r--r-- | src/dkv/api/initialise.go | 16 | ||||
-rw-r--r-- | src/dkv/api/propertiesReader.go | 5 | ||||
-rw-r--r-- | swagger.json | 2 |
9 files changed, 48 insertions, 13 deletions
@@ -7,3 +7,5 @@ bin/ pkg/ target/ src/github.com/ +.vscode +src/golang.org/
\ No newline at end of file diff --git a/src/dkv/Gopkg.lock b/src/dkv/Gopkg.lock index 97abfee..535922e 100644 --- a/src/dkv/Gopkg.lock +++ b/src/dkv/Gopkg.lock @@ -28,8 +28,8 @@ [[projects]] name = "github.com/hashicorp/consul" packages = ["api"] - revision = "48f3dd5642374d079f5a64359023fb8318eb81cc" - version = "v1.0.3" + revision = "9a494b5fb9c86180a5702e29c485df1507a47198" + version = "v1.0.6" [[projects]] branch = "master" @@ -52,8 +52,8 @@ [[projects]] name = "github.com/magiconair/properties" packages = ["."] - revision = "d419a98cdbed11a922bf76f257b7c4be79b50e73" - version = "v1.7.4" + revision = "c3beff4c2358b44d0493c7dda585e7db7ff28ae6" + version = "v1.7.6" [[projects]] branch = "master" @@ -76,6 +76,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "da4b4bdf45858b18ffddcdd32894f4af272104c2501a5334bf1d01abfa6d9a23" + inputs-digest = "000a855a3e5fca6c1f7b134951013777f7decbbde7be20af1e262da6005e874a" solver-name = "gps-cdcl" solver-version = 1 diff --git a/src/dkv/Gopkg.toml b/src/dkv/Gopkg.toml index 3f608e7..064b88e 100644 --- a/src/dkv/Gopkg.toml +++ b/src/dkv/Gopkg.toml @@ -26,16 +26,24 @@ [[constraint]] + name = "github.com/gorilla/handlers" + version = "1.3.0" + +[[constraint]] name = "github.com/gorilla/mux" version = "1.6.1" [[constraint]] name = "github.com/hashicorp/consul" - version = "1.0.3" + version = "1.0.6" [[constraint]] name = "github.com/magiconair/properties" - version = "1.7.4" + version = "1.7.6" + +[[constraint]] + name = "github.com/stretchr/testify" + version = "1.2.1" [prune] go-tests = true diff --git a/src/dkv/api/endpointViews.go b/src/dkv/api/endpointViews.go index 7d19a6a..8f77061 100644 --- a/src/dkv/api/endpointViews.go +++ b/src/dkv/api/endpointViews.go @@ -36,7 +36,8 @@ type ResponseGETSStruct struct { } type POSTBodyStruct struct { - Type *TypeStruct `json:"type"` + Domain string `json:"domain"` + Type *TypeStruct `json:"type"` } type TypeStruct struct { @@ -44,6 +45,9 @@ type TypeStruct struct { } func ValidateBody(body POSTBodyStruct) error { + if body.Domain == "" { + return errors.New("Domain not set. Please set domain in POST.") + } if body.Type == nil { return errors.New("Type not set. Recheck POST data.") } else if body.Type.FilePath == "" { @@ -88,7 +92,7 @@ func HandlePOST(w http.ResponseWriter, r *http.Request) { return } - err = KeyValues.WriteKVsToConsul() + err = KeyValues.WriteKVsToConsul(body.Domain) if err != nil { req := ResponseStringStruct{Response: string(err.Error())} diff --git a/src/dkv/api/endpointViews_fake.go b/src/dkv/api/endpointViews_fake.go index c147673..ecc6466 100644 --- a/src/dkv/api/endpointViews_fake.go +++ b/src/dkv/api/endpointViews_fake.go @@ -78,7 +78,7 @@ func (f *FakeKeyValues) ReadConfigs(body POSTBodyStruct) error { return nil } -func (f *FakeKeyValues) WriteKVsToConsul() error { +func (f *FakeKeyValues) WriteKVsToConsul(prefix string) error { return nil } @@ -91,6 +91,6 @@ func (f *FakeKeyValuesErr) ReadConfigs(body POSTBodyStruct) error { return errors.New("Internal Server Error") } -func (f *FakeKeyValuesErr) WriteKVsToConsul() error { +func (f *FakeKeyValuesErr) WriteKVsToConsul(prefix string) error { return errors.New("Internal Server Error") } diff --git a/src/dkv/api/endpointViews_test.go b/src/dkv/api/endpointViews_test.go index 1f7abf3..8e2799e 100644 --- a/src/dkv/api/endpointViews_test.go +++ b/src/dkv/api/endpointViews_test.go @@ -96,6 +96,7 @@ func TestHandlePOST(t *testing.T) { }() body := &POSTBodyStruct{ + Domain: "test", Type: &TypeStruct{ FilePath: "default", }, @@ -173,6 +174,7 @@ func TestHandlePOST_ConsulError(t *testing.T) { }() body := &POSTBodyStruct{ + Domain: "test", Type: &TypeStruct{ FilePath: "default", }, diff --git a/src/dkv/api/initialise.go b/src/dkv/api/initialise.go index f85c146..331c981 100644 --- a/src/dkv/api/initialise.go +++ b/src/dkv/api/initialise.go @@ -1,3 +1,19 @@ +/* + * Copyright 2018 Intel Corporation, Inc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package api import ( diff --git a/src/dkv/api/propertiesReader.go b/src/dkv/api/propertiesReader.go index a1c94bb..559c0fc 100644 --- a/src/dkv/api/propertiesReader.go +++ b/src/dkv/api/propertiesReader.go @@ -27,7 +27,7 @@ import ( ) type KeyValuesInterface interface { - WriteKVsToConsul() error + WriteKVsToConsul(string) error ReadConfigs(POSTBodyStruct) error PropertiesFilesToKV(string) error ReadMultipleProperties(string) error @@ -41,8 +41,9 @@ type KeyValuesStruct struct { var KeyValues KeyValuesInterface -func (kvStruct *KeyValuesStruct) WriteKVsToConsul() error { +func (kvStruct *KeyValuesStruct) WriteKVsToConsul(prefix string) error { for key, value := range kvStruct.kvs { + key = prefix + "." + key err := Consul.RequestPUT(key, value) if err != nil { return err diff --git a/swagger.json b/swagger.json index bb76c41..4430574 100644 --- a/swagger.json +++ b/swagger.json @@ -90,6 +90,8 @@ definitions: LoadRequest: type: "object" properties: + domain: + type: "string" type: $ref: "#/definitions/Type" Type: |