diff options
-rwxr-xr-x | kud/hosting_providers/vagrant/installer.sh | 1 | ||||
-rwxr-xr-x | kud/tests/vFW/firewall | 2 | ||||
-rwxr-xr-x | kud/tests/vFW/packetgen | 2 | ||||
-rwxr-xr-x | kud/tests/vFW/sink | 2 | ||||
-rw-r--r-- | src/k8splugin/api/brokerhandler.go | 65 | ||||
-rw-r--r-- | src/k8splugin/api/brokerhandler_test.go | 30 |
6 files changed, 84 insertions, 18 deletions
diff --git a/kud/hosting_providers/vagrant/installer.sh b/kud/hosting_providers/vagrant/installer.sh index 0ea8930f..c37d2746 100755 --- a/kud/hosting_providers/vagrant/installer.sh +++ b/kud/hosting_providers/vagrant/installer.sh @@ -79,7 +79,6 @@ function _install_docker { echo "DOCKER_OPTS=\"-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --max-concurrent-downloads $max_concurrent_downloads \"" | sudo tee --append /etc/default/docker if [[ -z $(groups | grep docker) ]]; then sudo usermod -aG docker $USER - newgrp docker fi sudo systemctl restart docker diff --git a/kud/tests/vFW/firewall b/kud/tests/vFW/firewall index c839c4d6..f59dcaab 100755 --- a/kud/tests/vFW/firewall +++ b/kud/tests/vFW/firewall @@ -16,7 +16,7 @@ set -o errexit # install_dependencies() - Install required dependencies function install_dependencies { apt-get update - apt-get install -y -qq wget openjdk-8-jre bridge-utils net-tools bsdmainutils make gcc libcurl4-gnutls-dev + apt-get install -y -qq wget openjdk-8-jre bridge-utils net-tools bsdmainutils make gcc libcurl4-gnutls-dev unzip } # install_vpp() - Install VPP diff --git a/kud/tests/vFW/packetgen b/kud/tests/vFW/packetgen index c51cd9f8..fadedd4d 100755 --- a/kud/tests/vFW/packetgen +++ b/kud/tests/vFW/packetgen @@ -16,7 +16,7 @@ set -o errexit # install_dependencies() - Install required dependencies function install_dependencies { apt-get update - apt-get install -y -qq wget openjdk-8-jre bridge-utils net-tools bsdmainutils + apt-get install -y -qq wget openjdk-8-jre bridge-utils net-tools bsdmainutils unzip } # install_vpp() - Install VPP diff --git a/kud/tests/vFW/sink b/kud/tests/vFW/sink index ace3b389..e1913a51 100755 --- a/kud/tests/vFW/sink +++ b/kud/tests/vFW/sink @@ -16,7 +16,7 @@ set -o errexit # install_dependencies() - Install required dependencies function install_dependencies { apt-get update - apt install -y wget darkstat net-tools + apt install -y wget darkstat net-tools unzip # Configure and run Darkstat sed -i "s/START_DARKSTAT=.*/START_DARKSTAT=yes/g;s/INTERFACE=.*/INTERFACE=\"-i eth1\"/g" /etc/darkstat/init.cfg diff --git a/src/k8splugin/api/brokerhandler.go b/src/k8splugin/api/brokerhandler.go index 80ab643c..dca64788 100644 --- a/src/k8splugin/api/brokerhandler.go +++ b/src/k8splugin/api/brokerhandler.go @@ -16,6 +16,7 @@ package api import ( "encoding/json" "io" + "log" "net/http" "k8splugin/internal/app" @@ -56,6 +57,52 @@ type brokerGETResponse struct { WorkloadStatus string `json:"workload_status"` } +// getUserDirectiveValue parses the following kind of json +// "user_attributes": { +// "attributes": [ +// { +// "attribute_value": "foo", +// "attribute_name": "bar" +// }, +// { +// "attribute_value": "value2", +// "attribute_name": "name2" +// } +// ] +// } +func (b brokerRequest) getUserDirectiveValue(inp string) string { + attributes, ok := b.UserDirectives["attributes"].([]interface{}) + if !ok { + log.Println("Unable to cast attributes to []interface{}") + return "" + } + + for _, value := range attributes { + + attribute, ok := value.(map[string]interface{}) + if !ok { + log.Println("Unable to cast attribute to map[string]interface{}") + return "" + } + + attributename, ok := attribute["attribute_name"].(string) + if !ok { + log.Println("Unable to cast attribute_name to string") + return "" + } + if attributename == inp { + attributevalue, ok := attribute["attribute_value"].(string) + if !ok { + log.Println("Unable to cast attribute_value to string") + return "" + } + + return attributevalue + } + } + return "" +} + func (b brokerInstanceHandler) createHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) cloudRegion := vars["cloud-region"] @@ -77,29 +124,29 @@ func (b brokerInstanceHandler) createHandler(w http.ResponseWriter, r *http.Requ return } - rbName, ok := req.UserDirectives["definition-name"] - if !ok { + rbName := req.getUserDirectiveValue("definition-name") + if rbName == "" { http.Error(w, "definition-name is missing from user-directives", http.StatusBadRequest) return } - rbVersion, ok := req.UserDirectives["definition-version"] - if !ok { + rbVersion := req.getUserDirectiveValue("definition-version") + if rbVersion == "" { http.Error(w, "definition-version is missing from user-directives", http.StatusBadRequest) return } - profileName, ok := req.UserDirectives["profile-name"] - if !ok { + profileName := req.getUserDirectiveValue("profile-name") + if profileName == "" { http.Error(w, "profile-name is missing from user-directives", http.StatusBadRequest) return } // Setup the resource parameters for making the request var instReq app.InstanceRequest - instReq.RBName = rbName.(string) - instReq.RBVersion = rbVersion.(string) - instReq.ProfileName = profileName.(string) + instReq.RBName = rbName + instReq.RBVersion = rbVersion + instReq.ProfileName = profileName instReq.CloudRegion = cloudRegion resp, err := b.client.Create(instReq) diff --git a/src/k8splugin/api/brokerhandler_test.go b/src/k8splugin/api/brokerhandler_test.go index 16046634..e7ff08c4 100644 --- a/src/k8splugin/api/brokerhandler_test.go +++ b/src/k8splugin/api/brokerhandler_test.go @@ -52,8 +52,17 @@ func TestBrokerCreateHandler(t *testing.T) { input: bytes.NewBuffer([]byte(`{ "vf-module-model-customization-id": "84sdfkio938", "user_directives": { - "definition-name": "test-rbdef", - "definition-version": "v1" } + "attributes": [ + { + "attribute_name": "definition-name", + "attribute_value": "test-rbdef" + }, + { + "attribute_name": "definition-version", + "attribute_value": "v1" + } + ] + } }`)), expectedCode: http.StatusBadRequest, }, @@ -62,9 +71,20 @@ func TestBrokerCreateHandler(t *testing.T) { input: bytes.NewBuffer([]byte(`{ "vf-module-model-customization-id": "84sdfkio938", "user_directives": { - "definition-name": "test-rbdef", - "definition-version": "v1", - "profile-name": "profile1" + "attributes": [ + { + "attribute_name": "definition-name", + "attribute_value": "test-rbdef" + }, + { + "attribute_name": "definition-version", + "attribute_value": "v1" + }, + { + "attribute_name": "profile-name", + "attribute_value": "profile1" + } + ] } }`)), expected: brokerPOSTResponse{ |