summaryrefslogtreecommitdiffstats
path: root/src/dkv/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/dkv/api')
-rw-r--r--src/dkv/api/endpointViews.go8
-rw-r--r--src/dkv/api/endpointViews_fake.go4
-rw-r--r--src/dkv/api/endpointViews_test.go2
-rw-r--r--src/dkv/api/initialise.go16
-rw-r--r--src/dkv/api/propertiesReader.go5
5 files changed, 29 insertions, 6 deletions
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