From 10b17da590fc43622c6080815f65fbbb2721b640 Mon Sep 17 00:00:00 2001 From: enyinna1234 Date: Fri, 14 Feb 2020 08:41:49 -0800 Subject: Add Distributed Cloud Manager This handles RESTful API CRUD operations for logical clouds, CLuster, User Permissions, Quota, and Key Value pairs. See: https://wiki.onap.org/x/tAiVB Issue-ID: MULTICLOUD-996 Signed-off-by: Enyinna Ochulor Change-Id: I654a304cd682f762c02cfd92b4483d1edea63fca --- src/Makefile | 4 + src/dcm/Makefile | 37 +++ src/dcm/api/api.go | 148 ++++++++++++ src/dcm/api/clusterHandler.go | 162 +++++++++++++ src/dcm/api/keyValueHandler.go | 161 +++++++++++++ src/dcm/api/logicalCloudHandler.go | 170 +++++++++++++ src/dcm/api/quotaHandler.go | 162 +++++++++++++ src/dcm/api/userPermissionsHandler.go | 162 +++++++++++++ src/dcm/cmd/main.go | 71 ++++++ src/dcm/go.mod | 11 + src/dcm/go.sum | 372 +++++++++++++++++++++++++++++ src/dcm/pkg/module/cluster.go | 205 ++++++++++++++++ src/dcm/pkg/module/cluster_test.go | 115 +++++++++ src/dcm/pkg/module/keyvalue.go | 205 ++++++++++++++++ src/dcm/pkg/module/keyvalue_test.go | 115 +++++++++ src/dcm/pkg/module/logicalcloud.go | 291 ++++++++++++++++++++++ src/dcm/pkg/module/logicalcloud_test.go | 157 ++++++++++++ src/dcm/pkg/module/module.go | 39 +++ src/dcm/pkg/module/quota.go | 222 +++++++++++++++++ src/dcm/pkg/module/quota_test.go | 115 +++++++++ src/dcm/pkg/module/userpermissions.go | 193 +++++++++++++++ src/dcm/pkg/module/userpermissions_test.go | 110 +++++++++ 22 files changed, 3227 insertions(+) create mode 100644 src/dcm/Makefile create mode 100644 src/dcm/api/api.go create mode 100644 src/dcm/api/clusterHandler.go create mode 100644 src/dcm/api/keyValueHandler.go create mode 100644 src/dcm/api/logicalCloudHandler.go create mode 100644 src/dcm/api/quotaHandler.go create mode 100644 src/dcm/api/userPermissionsHandler.go create mode 100644 src/dcm/cmd/main.go create mode 100644 src/dcm/go.mod create mode 100644 src/dcm/go.sum create mode 100644 src/dcm/pkg/module/cluster.go create mode 100644 src/dcm/pkg/module/cluster_test.go create mode 100644 src/dcm/pkg/module/keyvalue.go create mode 100644 src/dcm/pkg/module/keyvalue_test.go create mode 100644 src/dcm/pkg/module/logicalcloud.go create mode 100644 src/dcm/pkg/module/logicalcloud_test.go create mode 100644 src/dcm/pkg/module/module.go create mode 100644 src/dcm/pkg/module/quota.go create mode 100644 src/dcm/pkg/module/quota_test.go create mode 100644 src/dcm/pkg/module/userpermissions.go create mode 100644 src/dcm/pkg/module/userpermissions_test.go diff --git a/src/Makefile b/src/Makefile index 8d3bba43..36a981a9 100644 --- a/src/Makefile +++ b/src/Makefile @@ -3,21 +3,25 @@ build: $(MAKE) -C k8splugin build $(MAKE) -C orchestrator build $(MAKE) -C ncm build + $(MAKE) -C dcm build deploy: $(MAKE) -C monitor deploy $(MAKE) -C k8splugin deploy $(MAKE) -C orchestrator deploy $(MAKE) -C ncm deploy + $(MAKE) -C dcm deploy all: $(MAKE) -C monitor all $(MAKE) -C k8splugin all $(MAKE) -C orchestrator all $(MAKE) -C ncm all + $(MAKE) -C dcm all clean: $(MAKE) -C monitor clean $(MAKE) -C k8splugin clean $(MAKE) -C orchestrator clean $(MAKE) -C ncm clean + $(MAKE) -C dcm clean diff --git a/src/dcm/Makefile b/src/dcm/Makefile new file mode 100644 index 00000000..62b82a5f --- /dev/null +++ b/src/dcm/Makefile @@ -0,0 +1,37 @@ +# SPDX-license-identifier: Apache-2.0 +############################################################################## +# Copyright (c) 2020 Intel Corporation +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +export GO111MODULE=on + +all: clean + CGO_ENABLED=1 GOOS=linux GOARCH=amd64 + @go build -tags netgo -o ./dcm ./cmd/main.go + +# The following is done this way as each patch on CI runs build and each merge runs deploy. So for build we don't need to build binary and hence +# no need to create a static binary with additional flags. However, for generating binary, additional build flags are necessary. This if used with +# mock plugin errors out for unit tests. So the seperation avoids the error. + +build: clean test cover +deploy: build + +.PHONY: test +test: clean + @go test -race ./... + +format: + @go fmt ./... + +clean: + @find . -name "*so" -delete + @rm -f dcm coverage.html coverage.out + +.PHONY: cover +cover: + @go test -race ./... -coverprofile=coverage.out + @go tool cover -html=coverage.out -o coverage.html diff --git a/src/dcm/api/api.go b/src/dcm/api/api.go new file mode 100644 index 00000000..d050a5ba --- /dev/null +++ b/src/dcm/api/api.go @@ -0,0 +1,148 @@ +/* +Copyright 2020 Intel Corporation. +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 ( + + "github.com/onap/multicloud-k8s/src/dcm/pkg/module" + + "github.com/gorilla/mux" +) + +// NewRouter creates a router that registers the various urls that are +// supported + +func NewRouter( + logicalCloudClient module.LogicalCloudManager, + clusterClient module.ClusterManager, + userPermissionClient module.UserPermissionManager, + quotaClient module.QuotaManager, + keyValueClient module.KeyValueManager) *mux.Router { + + router := mux.NewRouter() + + // Set up Logical Cloud handler routes + if logicalCloudClient == nil { + logicalCloudClient = module.NewLogicalCloudClient() + } + logicalCloudHandler := logicalCloudHandler{client: logicalCloudClient} + lcRouter := router.PathPrefix("/v2/projects/{project-name}").Subrouter() + lcRouter.HandleFunc( + "/logical-clouds", + logicalCloudHandler.createHandler).Methods("POST") + lcRouter.HandleFunc( + "/logical-clouds", + logicalCloudHandler.getHandler).Methods("GET") + lcRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}", + logicalCloudHandler.getHandler).Methods("GET") + lcRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}", + logicalCloudHandler.deleteHandler).Methods("DELETE") + lcRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}", + logicalCloudHandler.updateHandler).Methods("PUT") + lcRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/apply", + logicalCloudHandler.applyHandler).Methods("POST") + // To Do + // get kubeconfig + /*lcRouter.HandleFunc( + "/logical-clouds/{name}/kubeconfig?cluster-reference={cluster}", + logicalCloudHandler.getConfigHandler).Methods("GET") + //get status + lcRouter.HandleFunc( + "/logical-clouds/{name}/cluster-references/", + logicalCloudHandler.associateHandler).Methods("GET")*/ + + // Set up Cluster API + if clusterClient == nil { + clusterClient = module.NewClusterClient() + } + clusterHandler := clusterHandler{client: clusterClient} + clusterRouter := router.PathPrefix("/v2/projects/{project-name}").Subrouter() + clusterRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/cluster-references", + clusterHandler.createHandler).Methods("POST") + clusterRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/cluster-references", + clusterHandler.getHandler).Methods("GET") + clusterRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/cluster-references/{cluster-reference}", + clusterHandler.getHandler).Methods("GET") + clusterRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/cluster-references/{cluster-reference}", + clusterHandler.updateHandler).Methods("PUT") + clusterRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/cluster-references/{cluster-reference}", + clusterHandler.deleteHandler).Methods("DELETE") + + // Set up User Permission API + if userPermissionClient == nil { + userPermissionClient = module.NewUserPermissionClient() + } + userPermissionHandler := userPermissionHandler{client: userPermissionClient} + upRouter := router.PathPrefix("/v2/projects/{project-name}").Subrouter() + upRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/user-permissions", + userPermissionHandler.createHandler).Methods("POST") + upRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/user-permissions/{permission-name}", + userPermissionHandler.getHandler).Methods("GET") + upRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/user-permissions/{permission-name}", + userPermissionHandler.updateHandler).Methods("PUT") + upRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/user-permissions/{permission-name}", + userPermissionHandler.deleteHandler).Methods("DELETE") + + // Set up Quota API + if quotaClient == nil { + quotaClient = module.NewQuotaClient() + } + quotaHandler := quotaHandler{client: quotaClient} + quotaRouter := router.PathPrefix("/v2/projects/{project-name}").Subrouter() + quotaRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/cluster-quotas", + quotaHandler.createHandler).Methods("POST") + quotaRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/cluster-quotas/{quota-name}", + quotaHandler.getHandler).Methods("GET") + quotaRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/cluster-quotas/{quota-name}", + quotaHandler.updateHandler).Methods("PUT") + quotaRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/cluster-quotas/{quota-name}", + quotaHandler.deleteHandler).Methods("DELETE") + + // Set up Key Value API + if keyValueClient == nil { + keyValueClient = module.NewKeyValueClient() + } + keyValueHandler := keyValueHandler{client: keyValueClient} + kvRouter := router.PathPrefix("/v2/projects/{project-name}").Subrouter() + kvRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/kv-pairs", + keyValueHandler.createHandler).Methods("POST") + kvRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/kv-pairs/{kv-pair-name}", + keyValueHandler.getHandler).Methods("GET") + kvRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/kv-pairs/{kv-pair-name}", + keyValueHandler.updateHandler).Methods("PUT") + kvRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/kv-pairs/{kv-pair-name}", + keyValueHandler.deleteHandler).Methods("DELETE") + return router +} diff --git a/src/dcm/api/clusterHandler.go b/src/dcm/api/clusterHandler.go new file mode 100644 index 00000000..3e483f06 --- /dev/null +++ b/src/dcm/api/clusterHandler.go @@ -0,0 +1,162 @@ +/* +* Copyright 2020 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 ( + "encoding/json" + "net/http" + "io" + "github.com/onap/multicloud-k8s/src/dcm/pkg/module" + + "github.com/gorilla/mux" +) + + +// clusterHandler is used to store backend implementations objects +type clusterHandler struct { + client module.ClusterManager +} + +// CreateHandler handles creation of the cluster reference entry in the database + +func (h clusterHandler) createHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + project := vars["project-name"] + logicalCloud := vars["logical-cloud-name"] + var v module.Cluster + + err := json.NewDecoder(r.Body).Decode(&v) + switch { + case err == io.EOF: + http.Error(w, "Empty body", http.StatusBadRequest) + return + case err != nil: + http.Error(w, err.Error(), http.StatusUnprocessableEntity) + return + } + + // Cluster Reference Name is required. + if v.MetaData.ClusterReference == "" { + http.Error(w, "Missing name in POST request", http.StatusBadRequest) + return + } + + ret, err := h.client.CreateCluster(project, logicalCloud, v) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + err = json.NewEncoder(w).Encode(ret) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } +} + +// getHandler handle GET operations on a particular name +// Returns a Cluster Reference +func (h clusterHandler) getHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + project := vars["project-name"] + logicalCloud := vars["logical-cloud-name"] + name := vars["cluster-reference"] + var ret interface{} + var err error + + if len(name) == 0 { + ret, err = h.client.GetAllClusters(project, logicalCloud) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + } else { + ret, err = h.client.GetCluster(project, logicalCloud, name) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + err = json.NewEncoder(w).Encode(ret) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } +} + +// UpdateHandler handles Update operations on a particular cluster reference +func (h clusterHandler) updateHandler(w http.ResponseWriter, r *http.Request) { + var v module.Cluster + vars := mux.Vars(r) + project := vars["project-name"] + logicalCloud := vars["logical-cloud-name"] + name := vars["cluster-reference"] + + err := json.NewDecoder(r.Body).Decode(&v) + switch { + case err == io.EOF: + http.Error(w, "Empty body", http.StatusBadRequest) + return + case err != nil: + http.Error(w, err.Error(), http.StatusUnprocessableEntity) + return + } + +// Name is required. + if v.MetaData.ClusterReference == "" { + http.Error(w, "Missing name in PUT request", http.StatusBadRequest) + return + } + + ret, err := h.client.UpdateCluster(project, logicalCloud, name, v) + if err != nil { + http.Error(w, err.Error(), + http.StatusInternalServerError) + return + } + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + err = json.NewEncoder(w).Encode(ret) + if err != nil { + http.Error(w, err.Error(), + http.StatusInternalServerError) + return + } +} + +//deleteHandler handles DELETE operations on a particular record +func (h clusterHandler) deleteHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + project := vars["project-name"] + logicalCloud := vars["logical-cloud-name"] + name := vars["cluster-reference"] + + err := h.client.DeleteCluster(project, logicalCloud, name) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + w.WriteHeader(http.StatusNoContent) +} diff --git a/src/dcm/api/keyValueHandler.go b/src/dcm/api/keyValueHandler.go new file mode 100644 index 00000000..57df6556 --- /dev/null +++ b/src/dcm/api/keyValueHandler.go @@ -0,0 +1,161 @@ +/* +* Copyright 2020 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 ( + "encoding/json" + "net/http" + "io" + "github.com/onap/multicloud-k8s/src/dcm/pkg/module" + "github.com/gorilla/mux" +) + + +// keyValueHandler is used to store backend implementations objects +type keyValueHandler struct { + client module.KeyValueManager +} + +// CreateHandler handles creation of the key value entry in the database + +func (h keyValueHandler) createHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + project := vars["project-name"] + logicalCloud := vars["logical-cloud-name"] + var v module.KeyValue + + err := json.NewDecoder(r.Body).Decode(&v) + switch { + case err == io.EOF: + http.Error(w, "Empty body", http.StatusBadRequest) + return + case err != nil: + http.Error(w, err.Error(), http.StatusUnprocessableEntity) + return + } + + // Key Value Name is required. + if v.MetaData.KeyValueName == "" { + http.Error(w, "Missing name in POST request", http.StatusBadRequest) + return + } + + ret, err := h.client.CreateKVPair(project, logicalCloud, v) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + err = json.NewEncoder(w).Encode(ret) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } +} + +// getHandler handle GET operations on a particular name +// Returns a Key Value +func (h keyValueHandler) getHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + project := vars["project-name"] + logicalCloud := vars["logical-cloud-name"] + name := vars["kv-pair-name"] + var ret interface{} + var err error + + if len(name) == 0 { + ret, err = h.client.GetAllKVPairs(project, logicalCloud) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + } else { + ret, err = h.client.GetKVPair(project, logicalCloud, name) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + err = json.NewEncoder(w).Encode(ret) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } +} + +// UpdateHandler handles Update operations on a particular Key Value +func (h keyValueHandler) updateHandler(w http.ResponseWriter, r *http.Request) { + var v module.KeyValue + vars := mux.Vars(r) + project := vars["project-name"] + logicalCloud := vars["logical-cloud-name"] + name := vars["kv-pair-name"] + + err := json.NewDecoder(r.Body).Decode(&v) + switch { + case err == io.EOF: + http.Error(w, "Empty body", http.StatusBadRequest) + return + case err != nil: + http.Error(w, err.Error(), http.StatusUnprocessableEntity) + return + } + + // Name is required. + if v.MetaData.KeyValueName == "" { + http.Error(w, "Missing name in PUT request", http.StatusBadRequest) + return + } + + ret, err := h.client.UpdateKVPair(project, logicalCloud, name, v) + if err != nil { + http.Error(w, err.Error(), + http.StatusInternalServerError) + return + } + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + err = json.NewEncoder(w).Encode(ret) + if err != nil { + http.Error(w, err.Error(), + http.StatusInternalServerError) + return + } +} + +//deleteHandler handles DELETE operations on a particular record +func (h keyValueHandler) deleteHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + project := vars["project-name"] + logicalCloud := vars["logical-cloud-name"] + name := vars["kv-pair-name"] + + err := h.client.DeleteKVPair(project, logicalCloud, name) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + w.WriteHeader(http.StatusNoContent) +} diff --git a/src/dcm/api/logicalCloudHandler.go b/src/dcm/api/logicalCloudHandler.go new file mode 100644 index 00000000..7df0ae2e --- /dev/null +++ b/src/dcm/api/logicalCloudHandler.go @@ -0,0 +1,170 @@ +/* +* Copyright 2020 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 ( + "encoding/json" + "net/http" + "io" + "github.com/onap/multicloud-k8s/src/dcm/pkg/module" + "github.com/gorilla/mux" +) + + +// logicalCloudHandler is used to store backend implementations objects +type logicalCloudHandler struct { + client module.LogicalCloudManager +} + +// CreateHandler handles creation of the logical cloud entry in the database + +func (h logicalCloudHandler) createHandler(w http.ResponseWriter, r *http.Request) { + + vars := mux.Vars(r) + project := vars["project-name"] + var v module.LogicalCloud + + err := json.NewDecoder(r.Body).Decode(&v) + switch { + case err == io.EOF: + http.Error(w, "Empty body", http.StatusBadRequest) + return + case err != nil: + http.Error(w, err.Error(), http.StatusUnprocessableEntity) + return + } + + // Logical Cloud Name is required. + if v.MetaData.LogicalCloudName == "" { + http.Error(w, "Missing name in POST request", http.StatusBadRequest) + return + } + + ret, err := h.client.Create(project, v) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + err = json.NewEncoder(w).Encode(ret) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } +} + +// getHandler handle GET operations on a particular name +// Returns a Logical Cloud +func (h logicalCloudHandler) getHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + project := vars["project-name"] + name := vars["logical-cloud-name"] + var ret interface{} + var err error + + if len(name) == 0 { + ret, err = h.client.GetAll(project) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + } else { + ret, err = h.client.Get(project, name) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + err = json.NewEncoder(w).Encode(ret) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } +} + +// UpdateHandler handles Update operations on a particular logical cloud +func (h logicalCloudHandler) updateHandler(w http.ResponseWriter, r *http.Request) { + var v module.LogicalCloud + vars := mux.Vars(r) + project := vars["project-name"] + name := vars["logical-cloud-name"] + + err := json.NewDecoder(r.Body).Decode(&v) + switch { + case err == io.EOF: + http.Error(w, "Empty body", http.StatusBadRequest) + return + case err != nil: + http.Error(w, err.Error(), http.StatusUnprocessableEntity) + return + } + + if v.MetaData.LogicalCloudName == "" { + http.Error(w, "Missing name in PUT request", http.StatusBadRequest) + return + } + + ret, err := h.client.Update(project, name, v) + if err != nil { + http.Error(w, err.Error(), + http.StatusInternalServerError) + return + } + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + err = json.NewEncoder(w).Encode(ret) + if err != nil { + http.Error(w, err.Error(), + http.StatusInternalServerError) + return + } +} + +func (h logicalCloudHandler) deleteHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + project := vars["project-name"] + name := vars["logical-cloud-name"] + + err := h.client.Delete(project, name) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + w.WriteHeader(http.StatusNoContent) +} + +func (h logicalCloudHandler) applyHandler(w http.ResponseWriter, r *http.Request) { + /*vars := mux.Vars(r) + project := vars["project-name"] + name := vars["logical-cloud-name"]*/ + /*ret, err := h.client.Get(project, name) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + }*/ + + // Do Some Work + // someApplyFunction(project, name, ret) +} diff --git a/src/dcm/api/quotaHandler.go b/src/dcm/api/quotaHandler.go new file mode 100644 index 00000000..bca5206a --- /dev/null +++ b/src/dcm/api/quotaHandler.go @@ -0,0 +1,162 @@ +/* +* Copyright 2020 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 ( + "encoding/json" + "net/http" + "io" + "github.com/onap/multicloud-k8s/src/dcm/pkg/module" + + "github.com/gorilla/mux" +) + + +// quotaHandler is used to store backend implementations objects +type quotaHandler struct { + client module.QuotaManager +} + +// CreateHandler handles creation of the quota entry in the database + +func (h quotaHandler) createHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + project := vars["project-name"] + logicalCloud := vars["logical-cloud-name"] + var v module.Quota + + err := json.NewDecoder(r.Body).Decode(&v) + switch { + case err == io.EOF: + http.Error(w, "Empty body", http.StatusBadRequest) + return + case err != nil: + http.Error(w, err.Error(), http.StatusUnprocessableEntity) + return + } + + // Quota Name is required. + if v.MetaData.QuotaName == "" { + http.Error(w, "Missing name in POST request", http.StatusBadRequest) + return + } + + ret, err := h.client.CreateQuota(project, logicalCloud, v) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + err = json.NewEncoder(w).Encode(ret) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } +} + +// getHandler handle GET operations on a particular name +// Returns a quota +func (h quotaHandler) getHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + project := vars["project-name"] + logicalCloud := vars["logical-cloud-name"] + name := vars["quota-name"] + var ret interface{} + var err error + + if len(name) == 0 { + ret, err = h.client.GetAllQuotas(project, logicalCloud) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + } else { + ret, err = h.client.GetQuota(project, logicalCloud, name) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + err = json.NewEncoder(w).Encode(ret) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } +} + +// UpdateHandler handles Update operations on a particular quota +func (h quotaHandler) updateHandler(w http.ResponseWriter, r *http.Request) { + var v module.Quota + vars := mux.Vars(r) + project := vars["project-name"] + logicalCloud := vars["logical-cloud-name"] + name := vars["quota-name"] + + err := json.NewDecoder(r.Body).Decode(&v) + switch { + case err == io.EOF: + http.Error(w, "Empty body", http.StatusBadRequest) + return + case err != nil: + http.Error(w, err.Error(), http.StatusUnprocessableEntity) + return + } + + // Name is required. + if v.MetaData.QuotaName == "" { + http.Error(w, "Missing name in PUT request", http.StatusBadRequest) + return + } + + ret, err := h.client.UpdateQuota(project, logicalCloud, name, v) + if err != nil { + http.Error(w, err.Error(), + http.StatusInternalServerError) + return + } + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + err = json.NewEncoder(w).Encode(ret) + if err != nil { + http.Error(w, err.Error(), + http.StatusInternalServerError) + return + } +} + +//deleteHandler handles DELETE operations on a particular record +func (h quotaHandler) deleteHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + project := vars["project-name"] + logicalCloud := vars["logical-cloud-name"] + name := vars["quota-name"] + + err := h.client.DeleteQuota(project, logicalCloud, name) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + w.WriteHeader(http.StatusNoContent) +} diff --git a/src/dcm/api/userPermissionsHandler.go b/src/dcm/api/userPermissionsHandler.go new file mode 100644 index 00000000..48ab3d8e --- /dev/null +++ b/src/dcm/api/userPermissionsHandler.go @@ -0,0 +1,162 @@ +/* +* Copyright 2020 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 ( + "encoding/json" + "net/http" + "io" + "github.com/onap/multicloud-k8s/src/dcm/pkg/module" + "github.com/gorilla/mux" +) + + +// userPermissionHandler is used to store backend implementations objects +type userPermissionHandler struct { + client module.UserPermissionManager +} + +// CreateHandler handles creation of the user permission entry in the database + +func (h userPermissionHandler) createHandler(w http.ResponseWriter, r *http.Request) { + + vars := mux.Vars(r) + project := vars["project-name"] + logicalCloud := vars["logical-cloud-name"] + var v module.UserPermission + + err := json.NewDecoder(r.Body).Decode(&v) + switch { + case err == io.EOF: + http.Error(w, "Empty body", http.StatusBadRequest) + return + case err != nil: + http.Error(w, err.Error(), http.StatusUnprocessableEntity) + return + } + + // User-Permission Name is required. + if v.UserPermissionName == "" { + http.Error(w, "Missing name in POST request", http.StatusBadRequest) + return + } + + ret, err := h.client.CreateUserPerm(project, logicalCloud, v) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + err = json.NewEncoder(w).Encode(ret) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } +} + +// getHandler handle GET operations on a particular name +// Returns a User Permission +func (h userPermissionHandler) getHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + project := vars["project-name"] + logicalCloud := vars["logical-cloud-name"] + name := vars["permission-name"] + var ret interface{} + var err error + + if len(name) == 0 { + ret, err = h.client.GetAllUserPerms(project, logicalCloud) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + } else { + ret, err = h.client.GetAllUserPerms(project, logicalCloud) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + err = json.NewEncoder(w).Encode(ret) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } +} + +// UpdateHandler handles Update operations on a particular user permission +func (h userPermissionHandler) updateHandler(w http.ResponseWriter, r *http.Request) { + var v module.UserPermission + vars := mux.Vars(r) + project := vars["project-name"] + logicalCloud := vars["logical-cloud-name"] + name := vars["permission-name"] + + err := json.NewDecoder(r.Body).Decode(&v) + switch { + case err == io.EOF: + http.Error(w, "Empty body", http.StatusBadRequest) + return + case err != nil: + http.Error(w, err.Error(), http.StatusUnprocessableEntity) + return + } + + // Name is required. + if v.UserPermissionName == "" { + http.Error(w, "Missing name in PUT request", http.StatusBadRequest) + return + } + + ret, err := h.client.UpdateUserPerm(project, logicalCloud, name, v) + if err != nil { + http.Error(w, err.Error(), + http.StatusInternalServerError) + return + } + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + err = json.NewEncoder(w).Encode(ret) + if err != nil { + http.Error(w, err.Error(), + http.StatusInternalServerError) + return + } +} + +//deleteHandler handles DELETE operations on a particular record +func (h userPermissionHandler) deleteHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + project := vars["project-name"] + logicalCloud := vars["logical-cloud-name"] + name := vars["permission-name"] + + err := h.client.DeleteUserPerm(project, logicalCloud, name) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + w.WriteHeader(http.StatusNoContent) +} diff --git a/src/dcm/cmd/main.go b/src/dcm/cmd/main.go new file mode 100644 index 00000000..d8c13d2e --- /dev/null +++ b/src/dcm/cmd/main.go @@ -0,0 +1,71 @@ +/* +Copyright 2020 Intel Corporation. +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 main + +import ( + "context" + "log" + "math/rand" + "net/http" + "os" + "os/signal" + "time" + + "github.com/onap/multicloud-k8s/src/dcm/api" + "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/auth" + "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/config" + "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/db" + + "github.com/gorilla/handlers" +) + +func main() { + + rand.Seed(time.Now().UnixNano()) + + err := db.InitializeDatabaseConnection("mco") + if err != nil { + log.Println("Unable to initialize database connection...") + log.Println(err) + log.Fatalln("Exiting...") + } + + httpRouter := api.NewRouter(nil, nil, nil, nil, nil) + loggedRouter := handlers.LoggingHandler(os.Stdout, httpRouter) + log.Println("Starting Distributed Cloud Manager API") + + httpServer := &http.Server{ + Handler: loggedRouter, + Addr: ":" + config.GetConfiguration().ServicePort, + } + + connectionsClose := make(chan struct{}) + go func() { + c := make(chan os.Signal, 1) + signal.Notify(c, os.Interrupt) + <-c + httpServer.Shutdown(context.Background()) + close(connectionsClose) + }() + + tlsConfig, err := auth.GetTLSConfig("ca.cert", "server.cert", "server.key") + if err != nil { + log.Println("Error Getting TLS Configuration. Starting without TLS...") + log.Fatal(httpServer.ListenAndServe()) + } else { + httpServer.TLSConfig = tlsConfig + + err = httpServer.ListenAndServeTLS("", "") + } +} diff --git a/src/dcm/go.mod b/src/dcm/go.mod new file mode 100644 index 00000000..994f919a --- /dev/null +++ b/src/dcm/go.mod @@ -0,0 +1,11 @@ +module github.com/onap/multicloud-k8s/src/dcm + +go 1.12 + +require ( + github.com/gorilla/handlers v1.4.2 + github.com/gorilla/mux v1.7.4 + github.com/onap/multicloud-k8s/src/orchestrator v0.0.0-20200309182120-42c5cef605d1 + github.com/pkg/errors v0.9.1 + github.com/stretchr/testify v1.4.0 +) diff --git a/src/dcm/go.sum b/src/dcm/go.sum new file mode 100644 index 00000000..e09ed0e2 --- /dev/null +++ b/src/dcm/go.sum @@ -0,0 +1,372 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= +github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI= +github.com/Azure/go-autorest/autorest/adal v0.5.0/go.mod h1:8Z9fGy2MpX0PvDjB1pEgQTmVqjGhiHBW7RJJEciWzS0= +github.com/Azure/go-autorest/autorest/date v0.1.0/go.mod h1:plvfp3oPSKwf2DNjlBjWF/7vwR+cUD/ELuzDCXwHUVA= +github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= +github.com/Azure/go-autorest/autorest/mocks v0.2.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= +github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc= +github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= +github.com/DataDog/datadog-go v2.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= +github.com/MakeNowJust/heredoc v0.0.0-20171113091838-e9091a26100e/go.mod h1:64YHyfSL2R96J44Nlwm39UHepQbyR5q10x7iYa1ks2E= +github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= +github.com/Masterminds/sprig v2.17.1+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o= +github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= +github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= +github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= +github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= +github.com/aokoli/goutils v1.1.0/go.mod h1:SijmP0QR8LtwsmDs8Yii5Z/S4trXFGFC2oO5g9DP+DQ= +github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= +github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= +github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878/go.mod h1:3AMJUQhVx52RsWOnlkpikZr01T/yAVN2gn0861vByNg= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/chai2010/gettext-go v0.0.0-20170215093142-bf70f2a70fb1/go.mod h1:/iP1qXHoty45bqomnu2LM+VVyAEdWN+vtSHGlQgyxbw= +github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag= +github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/coreos/bbolt v1.3.3/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= +github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/etcd v3.3.12+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= +github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= +github.com/cyphar/filepath-securejoin v0.2.2/go.mod h1:FpkQEhXnPnOthhzymB7CGsFk2G9VLXONKD9G7QGMM+4= +github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/docker/distribution v2.7.0+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= +github.com/docker/docker v0.7.3-0.20190912223608-ad718029b705/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/engine v0.0.0-20190620014054-c513a4c6c298/go.mod h1:3CPr2caMgTHxxIAZgEMd3uLYPDlRvPqCpyeRf6ncPcY= +github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM= +github.com/docker/spdystream v0.0.0-20181023171402-6480d4af844c/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM= +github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= +github.com/elazarl/goproxy v0.0.0-20190911111923-ecfe977594f1/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM= +github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2/go.mod h1:gNh8nYJoAm43RfaxurUnxr+N1PwuFV3ZMl/efxlIlY8= +github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= +github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= +github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= +github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= +github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d/go.mod h1:ZZMPRZwes7CROmyNKgQzC3XPs6L/G2EJLHddWejkmf4= +github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/ghodss/yaml v0.0.0-20180820084758-c7ce16629ff4/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= +github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+35s3my2LFTysnkMfxsJBAMHj/DoqoB9knIWoYG/Vk0= +github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg= +github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9/go.mod h1:W3Z9FmVs9qj+KR4zFKmDPGiLdk1D9Rlm7cyMvf57TTg= +github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc= +github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501/go.mod h1:J8+jY1nAiCcj+friV/PDoE1/3eeccG9LYBs0tYvLOWc= +github.com/go-openapi/spec v0.19.2/go.mod h1:sCxk3jxKgioEJikev4fgkNmwS+3kuYdJtcsZsD5zxMY= +github.com/go-openapi/spec v0.19.3/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8Lj9mJglo= +github.com/go-openapi/swag v0.0.0-20160704191624-1d0bd113de87/go.mod h1:DXUve3Dpr1UfpPtxFw+EFuQ41HhCWZfha5jSVRG7C7I= +github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= +github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= +github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= +github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= +github.com/gobuffalo/logger v1.0.0/go.mod h1:2zbswyIUa45I+c+FLXuWl9zSWEiVuthsk8ze5s8JvPs= +github.com/gobuffalo/packd v0.3.0/go.mod h1:zC7QkmNkYVGKPw4tHpBQ+ml7W/3tIebgeo1b36chA3Q= +github.com/gobuffalo/packr v1.30.1/go.mod h1:ljMyFO2EcrnzsHsN99cvbq055Y9OhRrIaviy289eRuk= +github.com/gobuffalo/packr/v2 v2.5.1/go.mod h1:8f9c96ITobJlPzI44jj+4tHnEKNt0xXWSVlXRN9X1Iw= +github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= +github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20181024230925-c65c006176ff/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY= +github.com/googleapis/gnostic v0.2.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY= +github.com/gophercloud/gophercloud v0.1.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8= +github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= +github.com/gorilla/handlers v1.3.0/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ= +github.com/gorilla/handlers v1.4.2 h1:0QniY0USkHQ1RGCLfKxeNHK9bkDHGRYGNDFBCS+YARg= +github.com/gorilla/handlers v1.4.2/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ= +github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= +github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc= +github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= +github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gregjones/httpcache v0.0.0-20170728041850-787624de3eb7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= +github.com/gregjones/httpcache v0.0.0-20181110185634-c63ab54fda8f/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= +github.com/grpc-ecosystem/go-grpc-middleware v1.1.0/go.mod h1:f5nM7jw/oeRSadq3xCzHAvxcr8HZnzsqU6ILg/0NiiE= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= +github.com/grpc-ecosystem/grpc-gateway v1.11.1/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/hashicorp/consul v1.4.0/go.mod h1:mFrjN1mfidgJfYP1xrJCF+AfRhr6Eaqhb2+sfyn/OOI= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= +github.com/hashicorp/go-msgpack v0.5.5/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= +github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= +github.com/hashicorp/go-rootcerts v0.0.0-20160503143440-6bb64b370b90/go.mod h1:o4zcYY1e0GEZI6eSEr+43QDYmuGglw1qSO6qdHUHCgg= +github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= +github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/hashicorp/memberlist v0.1.5/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= +github.com/hashicorp/serf v0.8.1/go.mod h1:h/Ru6tmZazX7WO/GDmwdpS975F019L4t5ng5IgwbNrE= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4= +github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks= +github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= +github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/karrick/godirwalk v1.10.12/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE= +github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= +github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180320133207-05fbef0ca5da/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= +github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= +github.com/onap/multicloud-k8s/src/k8splugin v0.0.0-20191115005109-f168ebb73d8d/go.mod h1:EnQd/vQGZR1/55IihaHxiux4ZUig/zfXZux7bfmU0S8= +github.com/onap/multicloud-k8s/src/orchestrator v0.0.0-20200309182120-42c5cef605d1 h1:rhEsWSmTf0JF+U0xwI7KFnMnsU7IjMHN7JphRKpolhQ= +github.com/onap/multicloud-k8s/src/orchestrator v0.0.0-20200309182120-42c5cef605d1/go.mod h1:tAKrUVGJa0hwzIcE1e09B5CtcI9ZXlL7ZMQiw4dXEhQ= +github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= +github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= +github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= +github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= +github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= +github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc= +github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rubenv/sql-migrate v0.0.0-20190902133344-8926f37f0bc1/go.mod h1:WS0rl9eEliYI8DPnr3TOwz4439pay+qNgzJoVya/DmY= +github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= +github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48= +github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= +github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/technosophos/moniker v0.0.0-20180509230615-a5dbd03a2245/go.mod h1:O1c8HleITsZqzNZDjSNzirUGsMT0oGu9LhHKoJrqO+A= +github.com/tidwall/pretty v0.0.0-20180105212114-65a9db5fad51/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= +github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= +github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= +github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= +github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c h1:u40Z8hqBAAQyv+vATcGgV0YCnDjqSL7/q/JyPhhJSPk= +github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I= +github.com/xdg/stringprep v1.0.0 h1:d9X0esnoa3dFsV0FG35rAT0RIhYFlPq7MiP+DW89La0= +github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +github.com/xlab/handysort v0.0.0-20150421192137-fb3537ed64a1/go.mod h1:QcJo0QPSfTONNIgpN5RA8prR7fF8nkF6cTWTcNerRO8= +github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0= +go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.etcd.io/etcd v3.3.12+incompatible/go.mod h1:yaeTdrJi5lOmYerz05bd8+V7KubZs8YSFZfzsF9A6aI= +go.mongodb.org/mongo-driver v1.0.0 h1:KxPRDyfB2xXnDE2My8acoOWBQkfv3tz0SaWTRZjJR0c= +go.mongodb.org/mongo-driver v1.0.0/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4 h1:ydJNl0ENAG67pFbB+9tfhiL2pYqLhfoaZFw/cjLhY4A= +golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190812203447-cdfb69ac37fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 h1:k7pJ2yAPLPgbskkFdhRCsA77k2fySZ1zf2zCjvQCiIM= +golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190209173611-3b5209105503/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190515120540-06a5c4944438/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20181011042414-1f849cf54d09/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190624180213-70d37148ca0c/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/gorp.v1 v1.7.2/go.mod h1:Wo3h+DBQZIxATwftsglhdD/62zRFPhGhTiu5jUJmCaw= +gopkg.in/inf.v0 v0.9.0/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= +gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= +gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= +gopkg.in/square/go-jose.v2 v2.2.2/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +k8s.io/api v0.0.0-20190831074750-7364b6bdad65/go.mod h1:u09ZxrpPFcoUNEQM2GsqT/KpglKAtXdEcK+tSMilQ3Q= +k8s.io/apiextensions-apiserver v0.0.0-20190409022649-727a075fdec8/go.mod h1:IxkesAMoaCRoLrPJdZNZUQp9NfZnzqaVzLhb2VEQzXE= +k8s.io/apimachinery v0.0.0-20190831074630-461753078381/go.mod h1:nL6pwRT8NgfF8TT68DBI8uEePRt89cSvoXUVqbkWHq4= +k8s.io/apiserver v0.0.0-20190409021813-1ec86e4da56c/go.mod h1:6bqaTSOSJavUIXUtfaR9Os9JtTCm8ZqH2SUl2S60C4w= +k8s.io/cli-runtime v0.0.0-20190913085402-777c64e2902f/go.mod h1:TtjkdmxYMLASzYbE8E7AUr/ZrXMcmXLnDLRY4sVWspw= +k8s.io/client-go v0.0.0-20190831074946-3fe2abece89e/go.mod h1:hAiMqq+tCk9hxFvWr2DoRiVyCYEGpni4eOcGCQLOEfM= +k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s= +k8s.io/cloud-provider v0.0.0-20190409023720-1bc0c81fa51d/go.mod h1:LlIffnLBu+GG7d4ppPzC8UnA1Ex8S+ntmSRVsnr7Xy4= +k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= +k8s.io/helm v2.14.3+incompatible/go.mod h1:LZzlS4LQBHfciFOurYBFkCMTaZ0D1l+p0teMg7TSULI= +k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= +k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= +k8s.io/klog v0.4.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I= +k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I= +k8s.io/kube-openapi v0.0.0-20190816220812-743ec37842bf/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E= +k8s.io/kubernetes v1.14.1/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk= +k8s.io/utils v0.0.0-20190801114015-581e00157fb1/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew= +k8s.io/utils v0.0.0-20190907131718-3d4f5b7dea0b/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew= +sigs.k8s.io/kustomize v2.0.3+incompatible/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5QeXV4WCbnt/PEpU= +sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI= +sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= +vbom.ml/util v0.0.0-20180919145318-efcd4e0f9787/go.mod h1:so/NYdZXCz+E3ZpW0uAoCj6uzU2+8OWDFv/HxUSs7kI= diff --git a/src/dcm/pkg/module/cluster.go b/src/dcm/pkg/module/cluster.go new file mode 100644 index 00000000..38848990 --- /dev/null +++ b/src/dcm/pkg/module/cluster.go @@ -0,0 +1,205 @@ +/* +* Copyright 2020 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 module + +import ( + pkgerrors "github.com/pkg/errors" +) + +// Cluster contains the parameters needed for a Cluster +type Cluster struct { + MetaData ClusterMeta `json:"metadata"` + Specification ClusterSpec `json:"spec"` +} + +type ClusterMeta struct { + ClusterReference string `json:"name"` + Description string `json:"description"` + UserData1 string `json:"userData1"` + UserData2 string `json:"userData2"` +} + +type ClusterSpec struct { + ClusterProvider string `json:"cluster-provider"` + ClusterName string `json:"cluster-name"` + LoadBalancerIP string `json:"loadbalancer-ip"` +} + + +type ClusterKey struct { + Project string `json:"project"` + LogicalCloudName string `json:"logical-cloud-name"` + ClusterReference string `json:"clname"` +} + +// ClusterManager is an interface that exposes the connection +// functionality +type ClusterManager interface { + CreateCluster(project, logicalCloud string, c Cluster) (Cluster, error) + GetCluster(project, logicalCloud, name string) (Cluster, error) + GetAllClusters(project, logicalCloud string) ([]Cluster, error) + DeleteCluster(project, logicalCloud, name string) error + UpdateCluster(project, logicalCloud, name string, c Cluster) (Cluster, error) +} + +// ClusterClient implements the ClusterManager +// It will also be used to maintain some localized state +type ClusterClient struct { + storeName string + tagMeta string + util Utility +} + +// ClusterClient returns an instance of the ClusterClient +// which implements the ClusterManager +func NewClusterClient() *ClusterClient { + service := DBService{} + return &ClusterClient{ + storeName: "orchestrator", + tagMeta: "cluster", + util: service, + } +} + +// Create entry for the cluster reference resource in the database +func (v *ClusterClient) CreateCluster(project, logicalCloud string, c Cluster) (Cluster, error) { + + //Construct key consisting of name + key := ClusterKey{ + Project: project, + LogicalCloudName: logicalCloud, + ClusterReference: c.MetaData.ClusterReference, + } + + //Check if project exists + err := v.util.CheckProject(project) + if err != nil { + return Cluster{}, pkgerrors.New("Unable to find the project") + } + //check if logical cloud exists + err = v.util.CheckLogicalCloud(project, logicalCloud) + if err != nil { + return Cluster{}, pkgerrors.New("Unable to find the logical cloud") + } + //Check if this Cluster reference already exists + _, err = v.GetCluster(project, logicalCloud, c.MetaData.ClusterReference) + if err == nil { + return Cluster{}, pkgerrors.New("Cluster reference already exists") + } + + err = v.util.DBInsert(v.storeName, key, nil, v.tagMeta, c) + if err != nil { + return Cluster{}, pkgerrors.Wrap(err, "Creating DB Entry") + } + + return c, nil +} + +// Get returns Cluster for corresponding cluster reference +func (v *ClusterClient) GetCluster(project, logicalCloud, clusterReference string)(Cluster, error) { + + //Construct the composite key to select the entry + key := ClusterKey{ + Project: project, + LogicalCloudName: logicalCloud, + ClusterReference: clusterReference, + } + + value, err := v.util.DBFind(v.storeName, key, v.tagMeta) + if err != nil { + return Cluster{}, pkgerrors.Wrap(err, "Get Cluster reference") + } + + //value is a byte array + if value != nil { + cl := Cluster{} + err = v.util.DBUnmarshal(value[0], &cl) + if err != nil { + return Cluster{}, pkgerrors.Wrap(err, "Unmarshaling value") + } + return cl, nil + } + + return Cluster{}, pkgerrors.New("Error getting Cluster") +} + + +// GetAll returns all cluster references in the logical cloud +func (v *ClusterClient) GetAllClusters(project, logicalCloud string)([]Cluster, error) { + //Construct the composite key to select clusters + key := ClusterKey{ + Project: project, + LogicalCloudName: logicalCloud, + ClusterReference: "", + } + var resp []Cluster + values, err := v.util.DBFind(v.storeName, key, v.tagMeta) + if err != nil { + return []Cluster{}, pkgerrors.Wrap(err, "Get All Cluster references") + } + + for _, value := range values { + cl := Cluster{} + err = v.util.DBUnmarshal(value, &cl) + if err != nil { + return []Cluster{}, pkgerrors.Wrap(err, "Unmarshaling values") + } + resp = append(resp, cl) + } + + return resp, nil +} + +// Delete the Cluster reference entry from database +func (v *ClusterClient) DeleteCluster(project, logicalCloud, clusterReference string) error { + //Construct the composite key to select the entry + key := ClusterKey{ + Project: project, + LogicalCloudName: logicalCloud, + ClusterReference: clusterReference, + } + err := v.util.DBRemove(v.storeName, key) + if err != nil { + return pkgerrors.Wrap(err, "Delete Cluster Reference") + } + return nil +} + +// Update an entry for the Cluster reference in the database +func (v *ClusterClient) UpdateCluster(project, logicalCloud, clusterReference string, c Cluster) (Cluster, error) { + + key := ClusterKey{ + Project: project, + LogicalCloudName: logicalCloud, + ClusterReference: clusterReference, + } + + //Check for name mismatch in cluster reference + if c.MetaData.ClusterReference != clusterReference { + return Cluster{}, pkgerrors.New("Update Error - Cluster reference mismatch") + } + //Check if this Cluster reference exists + _, err := v.GetCluster(project, logicalCloud, clusterReference) + if err != nil { + return Cluster{}, pkgerrors.New("Update Error - Cluster reference doesn't exist") + } + err = v.util.DBInsert(v.storeName, key, nil, v.tagMeta, c) + if err != nil { + return Cluster{}, pkgerrors.Wrap(err, "Updating DB Entry") + } + return c, nil +} diff --git a/src/dcm/pkg/module/cluster_test.go b/src/dcm/pkg/module/cluster_test.go new file mode 100644 index 00000000..d42935db --- /dev/null +++ b/src/dcm/pkg/module/cluster_test.go @@ -0,0 +1,115 @@ +package module + +import ( + "testing" + + "github.com/pkg/errors" + +) + + +func TestCreateCluster(t *testing.T) { + + mData := ClusterMeta{ + ClusterReference: "test_cluster", + } + + cl := Cluster { + MetaData: mData, + } + data1 := [][]byte{} + + + key := ClusterKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + ClusterReference: "test_cluster", + } + myMocks := new(mockValues) + // just to get an error value + err1 := errors.New("math: square root of negative number") + + myMocks.On("CheckProject", "test_project").Return(nil) + myMocks.On("CheckLogicalCloud", "test_project", "test_asdf").Return(nil) + myMocks.On("DBInsert", "test_dcm", key, nil, "test_meta", cl).Return(nil) + myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, err1) + + clClient := ClusterClient{"test_dcm", "test_meta", myMocks} + _, err := clClient.CreateCluster("test_project", "test_asdf", cl) + if err != nil { + t.Errorf("Some error occured!") + } +} + +func TestGetCluster(t *testing.T) { + key := ClusterKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + ClusterReference: "test_cluster", + } + + data1 := [][]byte{ + []byte("abc"), + } + + data2 := []byte("abc") + + myMocks := new(mockValues) + + myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, nil) + myMocks.On("DBUnmarshal", data2).Return(nil) + clClient := ClusterClient{"test_dcm", "test_meta", myMocks} + _, err := clClient.GetCluster("test_project", "test_asdf", "test_cluster") + if err != nil { + t.Errorf("Some error occured!") + } +} + +func TestDeleteCluster(t *testing.T) { + + key := ClusterKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + ClusterReference: "test_cluster", + } + + myMocks := new(mockValues) + + myMocks.On("DBRemove", "test_dcm", key).Return(nil) + + clClient := ClusterClient{"test_dcm", "test_meta", myMocks} + err := clClient.DeleteCluster("test_project", "test_asdf", "test_cluster") + if err != nil { + t.Errorf("Some error occured!") + } + +} + +func TestUpdateCluster(t *testing.T) { + key := ClusterKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + ClusterReference: "test_cluster", + } + mData := ClusterMeta{ + ClusterReference: "test_cluster", + } + cl := Cluster{ + MetaData: mData, + } + data1 := [][]byte{ + []byte("abc"), + } + data2 := []byte("abc") + + myMocks := new(mockValues) + + myMocks.On("DBInsert", "test_dcm", key, nil, "test_meta", cl).Return(nil) + myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, nil) + myMocks.On("DBUnmarshal", data2).Return(nil) + clClient := ClusterClient{"test_dcm", "test_meta", myMocks} + _, err := clClient.UpdateCluster("test_project", "test_asdf", "test_cluster", cl) + if err != nil { + t.Errorf("Some error occured!") + } +} diff --git a/src/dcm/pkg/module/keyvalue.go b/src/dcm/pkg/module/keyvalue.go new file mode 100644 index 00000000..4e3e0fab --- /dev/null +++ b/src/dcm/pkg/module/keyvalue.go @@ -0,0 +1,205 @@ +/* +* Copyright 2020 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 module + +import ( + pkgerrors "github.com/pkg/errors" +) + +// KeyValue contains the parameters needed for a key value +type KeyValue struct { + MetaData KVMetaDataList `json:"metadata"` + Specification KVSpec `json:"spec"` +} + + +// MetaData contains the parameters needed for metadata +type KVMetaDataList struct { + KeyValueName string `json:"name"` + Description string `json:"description"` + UserData1 string `json:"userData1"` + UserData2 string `json:"userData2"` +} + +// Spec contains the parameters needed for spec +type KVSpec struct { + Kv []map[string]interface{} `json:"kv"` +} + +// KeyValueKey is the key structure that is used in the database +type KeyValueKey struct { + Project string `json:"project"` + LogicalCloudName string `json:"logical-cloud-name"` + KeyValueName string `json:"kvname"` +} + +// KeyValueManager is an interface that exposes the connection +// functionality +type KeyValueManager interface { + CreateKVPair(project, logicalCloud string, c KeyValue) (KeyValue, error) + GetKVPair(project, logicalCloud, name string) (KeyValue, error) + GetAllKVPairs(project, logicalCloud string) ([]KeyValue, error) + DeleteKVPair(project, logicalCloud, name string) error + UpdateKVPair(project, logicalCloud, name string, c KeyValue) (KeyValue, error) +} + +// KeyValueClient implements the KeyValueManager +// It will also be used to maintain some localized state +type KeyValueClient struct { + storeName string + tagMeta string + util Utility +} + +// KeyValueClient returns an instance of the KeyValueClient +// which implements the KeyValueManager +func NewKeyValueClient() *KeyValueClient { + service := DBService{} + return &KeyValueClient{ + storeName: "orchestrator", + tagMeta: "keyvalue", + util: service, + } +} + +// Create entry for the key value resource in the database +func (v *KeyValueClient) CreateKVPair(project, logicalCloud string, c KeyValue) (KeyValue, error) { + + //Construct key consisting of name + key := KeyValueKey{ + Project: project, + LogicalCloudName: logicalCloud, + KeyValueName: c.MetaData.KeyValueName, + } + + //Check if project exist + err := v.util.CheckProject(project) + if err != nil { + return KeyValue{}, pkgerrors.New("Unable to find the project") + } + //check if logical cloud exists + err = v.util.CheckLogicalCloud(project, logicalCloud) + if err != nil { + return KeyValue{}, pkgerrors.New("Unable to find the logical cloud") + } + //Check if this Key Value already exists + _, err = v.GetKVPair(project, logicalCloud, c.MetaData.KeyValueName) + if err == nil { + return KeyValue{}, pkgerrors.New("Key Value already exists") + } + + err = v.util.DBInsert(v.storeName, key, nil, v.tagMeta, c) + if err != nil { + return KeyValue{}, pkgerrors.Wrap(err, "Creating DB Entry") + } + + return c, nil +} + +// Get returns Key Value for correspondin name +func (v *KeyValueClient) GetKVPair(project, logicalCloud, kvPairName string) (KeyValue, error) { + + //Construct the composite key to select the entry + key := KeyValueKey{ + Project: project, + LogicalCloudName: logicalCloud, + KeyValueName: kvPairName, + } + value, err := v.util.DBFind(v.storeName, key, v.tagMeta) + if err != nil { + return KeyValue{}, pkgerrors.Wrap(err, "Get Key Value") + } + + //value is a byte array + if value != nil { + kv := KeyValue{} + err = v.util.DBUnmarshal(value[0], &kv) + if err != nil { + return KeyValue{}, pkgerrors.Wrap(err, "Unmarshaling value") + } + return kv, nil + } + + return KeyValue{}, pkgerrors.New("Error getting Key Value") +} + +// Get All lists all key value pairs +func (v *KeyValueClient) GetAllKVPairs(project, logicalCloud string) ([]KeyValue, error) { + + //Construct the composite key to select the entry + key := KeyValueKey{ + Project: project, + LogicalCloudName: logicalCloud, + KeyValueName: "", + } + var resp []KeyValue + values, err := v.util.DBFind(v.storeName, key, v.tagMeta) + if err != nil { + return []KeyValue{}, pkgerrors.Wrap(err, "Get Key Value") + } + + for _, value := range values { + kv := KeyValue{} + err = v.util.DBUnmarshal(value, &kv) + if err != nil { + return []KeyValue{}, pkgerrors.Wrap(err, "Unmarshaling value") + } + resp = append(resp, kv) + } + + return resp, nil +} + +// Delete the Key Value entry from database +func (v *KeyValueClient) DeleteKVPair(project, logicalCloud, kvPairName string) error { + + //Construct the composite key to select the entry + key := KeyValueKey{ + Project: project, + LogicalCloudName: logicalCloud, + KeyValueName: kvPairName, + } + err := v.util.DBRemove(v.storeName, key) + if err != nil { + return pkgerrors.Wrap(err, "Delete Key Value") + } + return nil +} + +// Update an entry for the Key Value in the database +func (v *KeyValueClient) UpdateKVPair(project, logicalCloud, kvPairName string, c KeyValue) (KeyValue, error) { + + key := KeyValueKey{ + Project: project, + LogicalCloudName: logicalCloud, + KeyValueName: kvPairName, + } + //Check if KV pair URl name is the same name in json + if c.MetaData.KeyValueName != kvPairName { + return KeyValue{}, pkgerrors.New("Update Error - KV pair name mismatch") + } + //Check if this Key Value exists + _, err := v.GetKVPair(project, logicalCloud, kvPairName) + if err != nil { + return KeyValue{}, pkgerrors.New("Update Error - Key Value Pair doesn't exist") + } + err = v.util.DBInsert(v.storeName, key, nil, v.tagMeta, c) + if err != nil { + return KeyValue{}, pkgerrors.Wrap(err, "Updating DB Entry") + } + return c, nil +} diff --git a/src/dcm/pkg/module/keyvalue_test.go b/src/dcm/pkg/module/keyvalue_test.go new file mode 100644 index 00000000..9faceda4 --- /dev/null +++ b/src/dcm/pkg/module/keyvalue_test.go @@ -0,0 +1,115 @@ +package module + +import ( + "testing" + + "github.com/pkg/errors" + +) + + +func TestCreateKVPair(t *testing.T) { + + mData := KVMetaDataList{ + KeyValueName: "test_kv_pair", + } + + kv := KeyValue { + MetaData: mData, + } + data1 := [][]byte{} + + + key := KeyValueKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + KeyValueName: "test_kv_pair", + } + myMocks := new(mockValues) + // just to get an error value + err1 := errors.New("math: square root of negative number") + + myMocks.On("CheckProject", "test_project").Return(nil) + myMocks.On("CheckLogicalCloud", "test_project", "test_asdf").Return(nil) + myMocks.On("DBInsert", "test_dcm", key, nil, "test_meta", kv).Return(nil) + myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, err1) + + kvClient := KeyValueClient{"test_dcm", "test_meta", myMocks} + _, err := kvClient.CreateKVPair("test_project", "test_asdf", kv) + if err != nil { + t.Errorf("Some error occured!") + } +} + +func TestGetKVPair(t *testing.T) { + key := KeyValueKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + KeyValueName: "test_kv_pair", + } + + data1 := [][]byte{ + []byte("abc"), + } + + data2 := []byte("abc") + + myMocks := new(mockValues) + + myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, nil) + myMocks.On("DBUnmarshal", data2).Return(nil) + kvClient := KeyValueClient{"test_dcm", "test_meta", myMocks} + _, err := kvClient.GetKVPair("test_project", "test_asdf", "test_kv_pair") + if err != nil { + t.Errorf("Some error occured!") + } +} + +func TestDeleteKVPair(t *testing.T) { + + key := KeyValueKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + KeyValueName: "test_kv_pair", + } + + myMocks := new(mockValues) + + myMocks.On("DBRemove", "test_dcm", key).Return(nil) + + kvClient := KeyValueClient{"test_dcm", "test_meta", myMocks} + err := kvClient.DeleteKVPair("test_project", "test_asdf", "test_kv_pair") + if err != nil { + t.Errorf("Some error occured!") + } + +} + +func TestUpdateKVPair(t *testing.T) { + key := KeyValueKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + KeyValueName: "test_kv_pair", + } + mData := KVMetaDataList{ + KeyValueName: "test_kv_pair", + } + kv := KeyValue{ + MetaData: mData, + } + data1 := [][]byte{ + []byte("abc"), + } + data2 := []byte("abc") + + myMocks := new(mockValues) + + myMocks.On("DBInsert", "test_dcm", key, nil, "test_meta", kv).Return(nil) + myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, nil) + myMocks.On("DBUnmarshal", data2).Return(nil) + kvClient := KeyValueClient{"test_dcm", "test_meta", myMocks} + _, err := kvClient.UpdateKVPair("test_project", "test_asdf", "test_kv_pair", kv) + if err != nil { + t.Errorf("Some error occured!") + } +} diff --git a/src/dcm/pkg/module/logicalcloud.go b/src/dcm/pkg/module/logicalcloud.go new file mode 100644 index 00000000..9fb1b6fb --- /dev/null +++ b/src/dcm/pkg/module/logicalcloud.go @@ -0,0 +1,291 @@ +/* +* Copyright 2020 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 module + +import ( + "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/db" + "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module" + + pkgerrors "github.com/pkg/errors" +) + +// LogicalCloud contains the parameters needed for a Logical Cloud +type LogicalCloud struct { + MetaData MetaDataList `json:"metadata"` + Specification Spec `json:"spec"` +} + + +// MetaData contains the parameters needed for metadata +type MetaDataList struct { + LogicalCloudName string `json:"name"` + Description string `json:"description"` + UserData1 string `json:"userData1"` + UserData2 string `json:"userData2"` +} + +// Spec contains the parameters needed for spec +type Spec struct { + NameSpace string `json:"namespace"` + User UserData `json:"user"` + +} + +// UserData contains the parameters needed for user +type UserData struct { + UserName string `json:"user-name"` + Type string `json:"type"` + UserPermissions []UserPerm `json:"user-permissions"` +} + +// UserPerm contains the parameters needed for user permissions +type UserPerm struct { + PermName string `json:"permission-name"` + APIGroups []string `json:"apiGroups"` + Resources []string `json:"resources"` + Verbs []string `json:"verbs"` +} + +// LogicalCloudKey is the key structure that is used in the database +type LogicalCloudKey struct { + Project string `json:"project"` + LogicalCloudName string `json:"logical-cloud-name"` +} + +// LogicalCloudManager is an interface that exposes the connection +// functionality +type LogicalCloudManager interface { + Create(project string, c LogicalCloud) (LogicalCloud, error) + Get(project, name string) (LogicalCloud, error) + GetAll(project string) ([]LogicalCloud, error) + Delete(project, name string) error + Update(project, name string, c LogicalCloud) (LogicalCloud, error) + +} + +// Interface facilitates unit testing by mocking functions +type Utility interface { + DBInsert(storeName string, key db.Key, query interface{}, meta string, c interface{}) error + DBFind(storeName string, key db.Key, meta string) ([][]byte, error) + DBUnmarshal(value []byte, out interface{}) error + DBRemove(storeName string, key db.Key) error + CheckProject(project string) error + CheckLogicalCloud(project, logicalCloud string) error +} + +// LogicalCloudClient implements the LogicalCloudManager +// It will also be used to maintain some localized state +type LogicalCloudClient struct { + storeName string + tagMeta string + util Utility +} + +// Added for unit testing; implements Utility interface +type DBService struct {} + +// LogicalCloudClient returns an instance of the LogicalCloudClient +// which implements the LogicalCloudManager +func NewLogicalCloudClient() *LogicalCloudClient { + service := DBService{} + return &LogicalCloudClient{ + storeName: "orchestrator", + tagMeta: "logicalcloud", + util: service, + } +} + +// Create entry for the logical cloud resource in the database +func (v *LogicalCloudClient) Create(project string, c LogicalCloud) (LogicalCloud, error) { + + //Construct key consisting of name + key := LogicalCloudKey{ + Project: project, + LogicalCloudName: c.MetaData.LogicalCloudName, + } + + //Check if project exists + err := v.util.CheckProject(project) + if err != nil { + return LogicalCloud{}, pkgerrors.New("Unable to find the project") + } + + //Check if this Logical Cloud already exists + _, err = v.Get(project, c.MetaData.LogicalCloudName) + if err == nil { + return LogicalCloud{}, pkgerrors.New("Logical Cloud already exists") + } + + err = v.util.DBInsert(v.storeName, key, nil, v.tagMeta, c) + if err != nil { + return LogicalCloud{}, pkgerrors.Wrap(err, "Creating DB Entry") + } + + return c, nil +} + +// Get returns Logical Cloud corresponding to logical cloud name +func (v *LogicalCloudClient) Get(project, logicalCloudName string) (LogicalCloud, error) { + + //Construct the composite key to select the entry + key := LogicalCloudKey{ + Project: project, + LogicalCloudName: logicalCloudName, + } + value, err := v.util.DBFind(v.storeName, key, v.tagMeta) + if err != nil { + return LogicalCloud{}, pkgerrors.Wrap(err, "Get Logical Cloud") + } + + //value is a byte array + if value != nil { + lc := LogicalCloud{} + err = v.util.DBUnmarshal(value[0], &lc) + if err != nil { + return LogicalCloud{}, pkgerrors.Wrap(err, "Unmarshaling value") + } + return lc, nil + } + + return LogicalCloud{}, pkgerrors.New("Error getting Logical Cloud") +} + +// GetAll returns Logical Clouds in the project +func (v *LogicalCloudClient) GetAll(project string) ([]LogicalCloud, error) { + + //Construct the composite key to select the entry + key := LogicalCloudKey{ + Project: project, + LogicalCloudName: "", + } + + var resp []LogicalCloud + values, err := v.util.DBFind(v.storeName, key, v.tagMeta) + if err != nil { + return []LogicalCloud{}, pkgerrors.Wrap(err, "Get Logical Clouds") + } + + for _, value := range values { + lc := LogicalCloud{} + err = v.util.DBUnmarshal(value, &lc) + if err != nil { + return []LogicalCloud{}, pkgerrors.Wrap(err, "Unmarshaling values") + } + resp = append(resp, lc) + } + + return resp, nil +} + +// Delete the Logical Cloud entry from database +func (v *LogicalCloudClient) Delete(project, logicalCloudName string) error { + + //Construct the composite key to select the entry + key := LogicalCloudKey{ + Project: project, + LogicalCloudName: logicalCloudName, + } + err := v.util.DBRemove(v.storeName, key) + if err != nil { + return pkgerrors.Wrap(err, "Delete Logical Cloud") + } + + return nil +} + +// Update an entry for the Logical Cloud in the database +func (v *LogicalCloudClient) Update(project, logicalCloudName string, c LogicalCloud) (LogicalCloud, error) { + + key := LogicalCloudKey{ + Project: project, + LogicalCloudName: logicalCloudName, + } + // Check for mismatch, logicalCloudName and payload logical cloud name + if c.MetaData.LogicalCloudName != logicalCloudName { + return LogicalCloud{}, pkgerrors.New("Update Error - Logical Cloud name mismatch") + } + //Check if this Logical Cloud exists + _, err := v.Get(project, logicalCloudName) + if err != nil { + return LogicalCloud{}, pkgerrors.New("Update Error - Logical Cloud doesn't exist") + } + err = v.util.DBInsert(v.storeName, key, nil, v.tagMeta, c) + if err != nil { + return LogicalCloud{}, pkgerrors.Wrap(err, "Updating DB Entry") + } + return c, nil +} + +func (d DBService) DBInsert(storeName string, key db.Key, query interface{}, meta string, c interface{}) error { + + err := db.DBconn.Insert(storeName, key, nil, meta, c) + if err != nil { + return pkgerrors.Wrap(err, "Creating DB Entry") + } + + return nil +} + +func (d DBService) DBFind(storeName string, key db.Key, meta string) ([][]byte, error) { + + value, err := db.DBconn.Find(storeName, key, meta) + if err != nil { + return [][]byte{}, pkgerrors.Wrap(err, "Get Resource") + } + + return value, nil +} + +func (d DBService) DBUnmarshal(value []byte, out interface{}) error { + + err := db.DBconn.Unmarshal(value, out) + if err != nil { + return pkgerrors.Wrap(err, "Unmarshaling Value") + } + + return nil +} + +func (d DBService) DBRemove(storeName string, key db.Key) error { + + err := db.DBconn.Remove(storeName, key) + if err != nil { + return pkgerrors.Wrap(err, "Delete Resource") + } + + return nil +} + +func (d DBService) CheckProject(project string) error { + // Check if project exists + _, err := module.NewProjectClient().GetProject(project) + if err != nil { + return pkgerrors.New("Unable to find the project") + } + + return nil +} + +func (d DBService) CheckLogicalCloud(project, logicalCloud string) error { + // Check if logical cloud exists + _, err := NewLogicalCloudClient().Get(project, logicalCloud) + if err != nil { + return pkgerrors.New("Unable to find the logical cloud") + } + + return nil +} diff --git a/src/dcm/pkg/module/logicalcloud_test.go b/src/dcm/pkg/module/logicalcloud_test.go new file mode 100644 index 00000000..882cc292 --- /dev/null +++ b/src/dcm/pkg/module/logicalcloud_test.go @@ -0,0 +1,157 @@ +package module + +import ( + "fmt" + "testing" + + "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/db" + "github.com/stretchr/testify/mock" + "github.com/pkg/errors" + +) + +type mockValues struct { + mock.Mock +} + +func (m *mockValues) DBInsert(name string, key db.Key, query interface {}, meta string, c interface {}) error{ + fmt.Println("Mocked Insert operation in Mongo") + args := m.Called(name, key, nil, meta, c) + + return args.Error(0) +} + +func (m *mockValues) DBFind(name string, key db.Key, meta string) ([][]byte, error) { + fmt.Println("Mocked Mongo DB Find Operation") + args := m.Called(name, key, meta) + + return args.Get(0).([][]byte), args.Error(1) +} + +func (m *mockValues) DBUnmarshal(value []byte, out interface{}) error { + fmt.Println("Mocked Mongo DB Unmarshal Operation") + args := m.Called(value) + + return args.Error(0) +} + +func (m *mockValues) DBRemove(name string, key db.Key) error { + fmt.Println("Mocked Mongo DB Remove operation") + args := m.Called(name, key) + + return args.Error(0) +} + +func (m *mockValues) CheckProject(project string) error { + fmt.Println("Mocked Check Project exists") + args := m.Called(project) + + return args.Error(0) +} + +func (m *mockValues) CheckLogicalCloud(project, logicalCloud string) error { + fmt.Println("Mocked Check Logical Cloud exists") + args := m.Called(project, logicalCloud) + + return args.Error(0) +} + +func TestCreateLogicalCloud(t *testing.T) { + + mData := MetaDataList{ + LogicalCloudName: "test_asdf", + } + + lc := LogicalCloud { + MetaData: mData, + } + data1 := [][]byte{} + + key := LogicalCloudKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + } + myMocks := new(mockValues) + // just to get an error value + err1 := errors.New("math: square root of negative number") + + myMocks.On("CheckProject", "test_project").Return(nil) + myMocks.On("DBInsert", "test_dcm", key, nil, "test_meta", lc).Return(nil) + myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, err1) + + lcClient := LogicalCloudClient{"test_dcm", "test_meta", myMocks} + _, err := lcClient.Create("test_project", lc) + if err != nil { + t.Errorf("Some error occured!") + } +} + +func TestGetLogicalCloud(t *testing.T) { + key := LogicalCloudKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + } + + data1 := [][]byte{ + []byte("abc"), + } + + data2 := []byte("abc") + + myMocks := new(mockValues) + + myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, nil) + myMocks.On("DBUnmarshal", data2).Return(nil) + lcClient := LogicalCloudClient{"test_dcm", "test_meta", myMocks} + _, err := lcClient.Get("test_project", "test_asdf") + if err != nil { + t.Errorf("Some error occured!") + } +} + +func TestDeleteLogicalCloud(t *testing.T) { + + key := LogicalCloudKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + } + + myMocks := new(mockValues) + + myMocks.On("DBRemove", "test_dcm", key).Return(nil) + + lcClient := LogicalCloudClient{"test_dcm", "test_meta", myMocks} + err := lcClient.Delete("test_project", "test_asdf") + if err != nil { + t.Errorf("Some error occured!") + } + +} + +func TestUpdateLogicalCloud(t *testing.T) { + key := LogicalCloudKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + } + mData := MetaDataList{ + LogicalCloudName: "test_asdf", + } + lc := LogicalCloud{ + MetaData: mData, + } + data1 := [][]byte{ + []byte("abc"), + } + data2 := []byte("abc") + + myMocks := new(mockValues) + + myMocks.On("DBInsert", "test_dcm", key, nil, "test_meta", lc).Return(nil) + myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, nil) + myMocks.On("DBUnmarshal", data2).Return(nil) + lcClient := LogicalCloudClient{"test_dcm", "test_meta", myMocks} + _, err := lcClient.Update("test_project", "test_asdf", lc) + if err != nil { + t.Errorf("Some error occured!") + } +} diff --git a/src/dcm/pkg/module/module.go b/src/dcm/pkg/module/module.go new file mode 100644 index 00000000..293f6dd5 --- /dev/null +++ b/src/dcm/pkg/module/module.go @@ -0,0 +1,39 @@ +/* + * Copyright 2020 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 module + +// Client for using the services in the orchestrator +type Client struct { + LogicalCloud *LogicalCloudClient + Cluster *ClusterClient + Quota *QuotaClient + UserPermission *UserPermissionClient + KeyValue *KeyValueClient + // Add Clients for API's here +} + +// NewClient creates a new client for using the services +func NewClient() *Client { + c := &Client{} + c.LogicalCloud = NewLogicalCloudClient() + c.Cluster = NewClusterClient() + c.Quota = NewQuotaClient() + c.UserPermission = NewUserPermissionClient() + c.KeyValue = NewKeyValueClient() + // Add Client API handlers here + return c +} diff --git a/src/dcm/pkg/module/quota.go b/src/dcm/pkg/module/quota.go new file mode 100644 index 00000000..1a7012f6 --- /dev/null +++ b/src/dcm/pkg/module/quota.go @@ -0,0 +1,222 @@ +/* +* Copyright 2020 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 module + +import ( + pkgerrors "github.com/pkg/errors" +) + +// Quota contains the parameters needed for a Quota +type Quota struct { + MetaData QMetaDataList `json:"metadata"` + Specification QSpec `json:"spec"` +} + + +// MetaData contains the parameters needed for metadata +type QMetaDataList struct { + QuotaName string `json:"name"` + Description string `json:"description"` +} + +// Spec contains the parameters needed for spec +type QSpec struct { + LimitsCPU string `json:"limits.cpu"` + LimitsMemory string `json:"limits.memory"` + RequestsCPU string `json:"requests.cpu"` + RequestsMemory string `json:"requests.memory"` + RequestsStorage string `json:"requests.storage"` + LimitsEphemeralStorage string `json:"limits.ephemeral.storage"` + PersistentVolumeClaims string `json:"persistentvolumeclaims"` + Pods string `json:"pods"` + ConfigMaps string `json:"configmaps"` + ReplicationControllers string `json:"replicationcontrollers"` + ResourceQuotas string `json:"resourcequotas"` + Services string `json:"services"` + ServicesLoadBalancers string `json:"services.loadbalancers"` + ServicesNodePorts string `json:"services.nodeports"` + Secrets string `json:"secrets"` + CountReplicationControllers string `json:"count/replicationcontrollers"` + CountDeploymentsApps string `json:"count/deployments.apps"` + CountReplicasetsApps string `json:"count/replicasets.apps"` + CountStatefulSets string `json:"count/statefulsets.apps"` + CountJobsBatch string `json:"count/jobs.batch"` + CountCronJobsBatch string `json:"count/cronjobs.batch"` + CountDeploymentsExtensions string `json:"count/deployments.extensions"` +} + +// QuotaKey is the key structure that is used in the database +type QuotaKey struct { + Project string `json:"project"` + LogicalCloudName string `json:"logical-cloud-name"` + QuotaName string `json:"qname"` +} + +// QuotaManager is an interface that exposes the connection +// functionality +type QuotaManager interface { + CreateQuota(project, logicalCloud string, c Quota) (Quota, error) + GetQuota(project, logicalCloud, name string) (Quota, error) + GetAllQuotas(project, logicalCloud string) ([]Quota, error) + DeleteQuota(project, logicalCloud, name string) error + UpdateQuota(project, logicalCloud, name string, c Quota) (Quota, error) +} + +// QuotaClient implements the QuotaManager +// It will also be used to maintain some localized state +type QuotaClient struct { + storeName string + tagMeta string + util Utility +} + +// QuotaClient returns an instance of the QuotaClient +// which implements the QuotaManager +func NewQuotaClient() *QuotaClient { + service := DBService{} + return &QuotaClient{ + storeName: "orchestrator", + tagMeta: "quota", + util: service, + } +} + +// Create entry for the quota resource in the database +func (v *QuotaClient) CreateQuota(project, logicalCloud string, c Quota) (Quota, error) { + + //Construct key consisting of name + key := QuotaKey{ + Project: project, + LogicalCloudName: logicalCloud, + QuotaName: c.MetaData.QuotaName, + } + + //Check if project exists + err := v.util.CheckProject(project) + if err != nil { + return Quota{}, pkgerrors.New("Unable to find the project") + } + //check if logical cloud exists + err = v.util.CheckLogicalCloud(project, logicalCloud) + if err != nil { + return Quota{}, pkgerrors.New("Unable to find the logical cloud") + } + //Check if this Quota already exists + _, err = v.GetQuota(project, logicalCloud, c.MetaData.QuotaName) + if err == nil { + return Quota{}, pkgerrors.New("Quota already exists") + } + + err = v.util.DBInsert(v.storeName, key, nil, v.tagMeta, c) + if err != nil { + return Quota{}, pkgerrors.Wrap(err, "Creating DB Entry") + } + + return c, nil +} + +// Get returns Quota for corresponding quota name +func (v *QuotaClient) GetQuota(project, logicalCloud, quotaName string) (Quota, error) { + + //Construct the composite key to select the entry + key := QuotaKey{ + Project: project, + LogicalCloudName: logicalCloud, + QuotaName: quotaName, + } + value, err := v.util.DBFind(v.storeName, key, v.tagMeta) + if err != nil { + return Quota{}, pkgerrors.Wrap(err, "Quota") + } + + //value is a byte array + if value != nil { + q := Quota{} + err = v.util.DBUnmarshal(value[0], &q) + if err != nil { + return Quota{}, pkgerrors.Wrap(err, "Unmarshaling value") + } + return q, nil + } + + return Quota{}, pkgerrors.New("Error getting Quota") +} + +// GetAll returns all cluster quotas in the logical cloud +func (v *QuotaClient) GetAllQuotas(project, logicalCloud string) ([]Quota, error) { + //Construct the composite key to select the entry + key := QuotaKey{ + Project: project, + LogicalCloudName: logicalCloud, + QuotaName: "", + } + var resp []Quota + values, err := v.util.DBFind(v.storeName, key, v.tagMeta) + if err != nil { + return []Quota{}, pkgerrors.Wrap(err, "Get All Quotas") + } + + for _, value := range values { + q := Quota{} + err = v.util.DBUnmarshal(value, &q) + if err != nil { + return []Quota{}, pkgerrors.Wrap(err, "Unmarshaling value") + } + resp = append(resp, q) + } + + return resp, nil +} + +// Delete the Quota entry from database +func (v *QuotaClient) DeleteQuota(project, logicalCloud, quotaName string) error { + //Construct the composite key to select the entry + key := QuotaKey{ + Project: project, + LogicalCloudName: logicalCloud, + QuotaName: quotaName, + } + err := v.util.DBRemove(v.storeName, key) + if err != nil { + return pkgerrors.Wrap(err, "Delete Quota") + } + return nil +} + +// Update an entry for the Quota in the database +func (v *QuotaClient) UpdateQuota(project, logicalCloud, quotaName string, c Quota) (Quota, error) { + + key := QuotaKey{ + Project: project, + LogicalCloudName: logicalCloud, + QuotaName: quotaName, + } + //Check quota URL name against the quota json name + if c.MetaData.QuotaName != quotaName { + return Quota{}, pkgerrors.New("Update Error - Quota name mismatch") + } + //Check if this Quota exists + _, err := v.GetQuota(project, logicalCloud, quotaName) + if err != nil { + return Quota{}, pkgerrors.New("Update Error - Quota doesn't exist") + } + err = v.util.DBInsert(v.storeName, key, nil, v.tagMeta, c) + if err != nil { + return Quota{}, pkgerrors.Wrap(err, "Updating DB Entry") + } + return c, nil +} diff --git a/src/dcm/pkg/module/quota_test.go b/src/dcm/pkg/module/quota_test.go new file mode 100644 index 00000000..87a60d71 --- /dev/null +++ b/src/dcm/pkg/module/quota_test.go @@ -0,0 +1,115 @@ +package module + +import ( + "testing" + + "github.com/pkg/errors" + +) + + +func TestCreateQuota(t *testing.T) { + + mData := QMetaDataList{ + QuotaName: "test_quota", + } + + q := Quota { + MetaData: mData, + } + data1 := [][]byte{} + + + key := QuotaKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + QuotaName: "test_quota", + } + myMocks := new(mockValues) + // just to get an error value + err1 := errors.New("math: square root of negative number") + + myMocks.On("CheckProject", "test_project").Return(nil) + myMocks.On("CheckLogicalCloud", "test_project", "test_asdf").Return(nil) + myMocks.On("DBInsert", "test_dcm", key, nil, "test_meta", q).Return(nil) + myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, err1) + + qClient := QuotaClient{"test_dcm", "test_meta", myMocks} + _, err := qClient.CreateQuota("test_project", "test_asdf", q) + if err != nil { + t.Errorf("Some error occured!") + } +} + +func TestGetQuota(t *testing.T) { + key := QuotaKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + QuotaName: "test_quota", + } + + data1 := [][]byte{ + []byte("abc"), + } + + data2 := []byte("abc") + + myMocks := new(mockValues) + + myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, nil) + myMocks.On("DBUnmarshal", data2).Return(nil) + qClient := QuotaClient{"test_dcm", "test_meta", myMocks} + _, err := qClient.GetQuota("test_project", "test_asdf", "test_quota") + if err != nil { + t.Errorf("Some error occured!") + } +} + +func TestDeleteQuota(t *testing.T) { + + key := QuotaKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + QuotaName: "test_quota", + } + + myMocks := new(mockValues) + + myMocks.On("DBRemove", "test_dcm", key).Return(nil) + + qClient := QuotaClient{"test_dcm", "test_meta", myMocks} + err := qClient.DeleteQuota("test_project", "test_asdf", "test_quota") + if err != nil { + t.Errorf("Some error occured!") + } + +} + +func TestUpdateQuota(t *testing.T) { + key := QuotaKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + QuotaName: "test_quota", + } + mData := QMetaDataList{ + QuotaName: "test_quota", + } + q := Quota{ + MetaData: mData, + } + data1 := [][]byte{ + []byte("abc"), + } + data2 := []byte("abc") + + myMocks := new(mockValues) + + myMocks.On("DBInsert", "test_dcm", key, nil, "test_meta", q).Return(nil) + myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, nil) + myMocks.On("DBUnmarshal", data2).Return(nil) + qClient := QuotaClient{"test_dcm", "test_meta", myMocks} + _, err := qClient.UpdateQuota("test_project", "test_asdf", "test_quota", q) + if err != nil { + t.Errorf("Some error occured!") + } +} diff --git a/src/dcm/pkg/module/userpermissions.go b/src/dcm/pkg/module/userpermissions.go new file mode 100644 index 00000000..cf961a65 --- /dev/null +++ b/src/dcm/pkg/module/userpermissions.go @@ -0,0 +1,193 @@ +/* +* Copyright 2020 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 module + +import ( + pkgerrors "github.com/pkg/errors" +) + +// UserPermission contains the parameters needed for a user permission +type UserPermission struct { + UserPermissionName string `json:"name"` + APIGroups []string `json:"apiGroups"` + Resources []string `json:"resources"` + Verbs []string `json:"verbs"` +} + +// UserPermissionKey is the key structure that is used in the database +type UserPermissionKey struct { + Project string `json:"project"` + LogicalCloudName string `json:"logical-cloud-name"` + UserPermissionName string `json:"upname"` +} + +// UserPermissionManager is an interface that exposes the connection +// functionality +type UserPermissionManager interface { + CreateUserPerm(project, logicalCloud string, c UserPermission) (UserPermission, error) + GetUserPerm(project, logicalCloud, name string) (UserPermission, error) + GetAllUserPerms(project, logicalCloud string) ([]UserPermission, error) + DeleteUserPerm(project, logicalCloud, name string) error + UpdateUserPerm(project, logicalCloud, name string, c UserPermission) (UserPermission, error) +} + +// UserPermissionClient implements the UserPermissionManager +// It will also be used to maintain some localized state +type UserPermissionClient struct { + storeName string + tagMeta string + util Utility +} + +// UserPermissionClient returns an instance of the UserPermissionClient +// which implements the UserPermissionManager +func NewUserPermissionClient() *UserPermissionClient { + service := DBService{} + return &UserPermissionClient{ + storeName: "orchestrator", + tagMeta: "userpermission", + util: service, + } +} + +// Create entry for the User Permission resource in the database +func (v *UserPermissionClient) CreateUserPerm(project, logicalCloud string, c UserPermission) (UserPermission, error) { + + //Construct key consisting of name + key := UserPermissionKey { + Project: project, + LogicalCloudName: logicalCloud, + UserPermissionName: c.UserPermissionName, + } + + //Check if project exists + err := v.util.CheckProject(project) + if err != nil { + return UserPermission{}, pkgerrors.New("Unable to find the project") + } + //check if logical cloud exists + err = v.util.CheckLogicalCloud(project, logicalCloud) + if err != nil { + return UserPermission{}, pkgerrors.New("Unable to find the logical cloud") + } + + //Check if this User Permission already exists + _, err = v.GetUserPerm(project, logicalCloud, c.UserPermissionName) + if err == nil { + return UserPermission{}, pkgerrors.New("User Permission already exists") + } + + err = v.util.DBInsert(v.storeName, key, nil, v.tagMeta, c) + if err != nil { + return UserPermission{}, pkgerrors.Wrap(err, "Creating DB Entry") + } + + return c, nil +} + +// Get returns User Permission for corresponding name +func (v *UserPermissionClient) GetUserPerm(project, logicalCloud, userPermName string) (UserPermission, error) { + + //Construct the composite key to select the entry + key := UserPermissionKey{ + Project: project, + LogicalCloudName: logicalCloud, + UserPermissionName: userPermName, + } + + value, err := v.util.DBFind(v.storeName, key, v.tagMeta) + if err != nil { + return UserPermission{}, pkgerrors.Wrap(err, "Get User Permission") + } + + //value is a byte array + if value != nil { + up := UserPermission{} + err = v.util.DBUnmarshal(value[0], &up) + if err != nil { + return UserPermission{}, pkgerrors.Wrap(err, "Unmarshaling value") + } + return up, nil + } + + return UserPermission{}, pkgerrors.New("Error getting User Permission") +} + +// GetAll lists all user permissions +func (v *UserPermissionClient) GetAllUserPerms(project, logicalCloud string) ([]UserPermission, error) { + //Construct the composite key to select the entry + key := UserPermissionKey { + Project: project, + LogicalCloudName: logicalCloud, + UserPermissionName: "", + } + var resp []UserPermission + values, err := v.util.DBFind(v.storeName, key, v.tagMeta) + if err != nil { + return []UserPermission{}, pkgerrors.Wrap(err, "Get All User Permissions") + } + + for _, value := range values { + up := UserPermission{} + err = v.util.DBUnmarshal(value, &up) + if err != nil { + return []UserPermission{}, pkgerrors.Wrap(err, "Unmarshaling value") + } + resp = append(resp, up) + } + return resp, nil +} +// Delete the User Permission entry from database +func (v *UserPermissionClient) DeleteUserPerm(project, logicalCloud, userPermName string) error { + //Construct the composite key to select the entry + key := UserPermissionKey{ + Project: project, + LogicalCloudName: logicalCloud, + UserPermissionName: userPermName, + } + err := v.util.DBRemove(v.storeName, key) + if err != nil { + return pkgerrors.Wrap(err, "Delete User Permission") + } + return nil +} + +// Update an entry for the User Permission in the database +func (v *UserPermissionClient) UpdateUserPerm(project, logicalCloud, userPermName string, c UserPermission) ( + UserPermission, error) { + + key := UserPermissionKey{ + Project: project, + LogicalCloudName: logicalCloud, + UserPermissionName: userPermName, + } + //Check for URL name and json permission name mismatch + if c.UserPermissionName != userPermName { + return UserPermission{}, pkgerrors.New("Update Error - Permission name mismatch") + } + //Check if this User Permission exists + _, err := v.GetUserPerm(project, logicalCloud, userPermName) + if err != nil { + return UserPermission{}, pkgerrors.New( + "Update Error - User Permission doesn't exist") + } + err = v.util.DBInsert(v.storeName, key, nil, v.tagMeta, c) + if err != nil { + return UserPermission{}, pkgerrors.Wrap(err, "Updating DB Entry") + } + return c, nil +} diff --git a/src/dcm/pkg/module/userpermissions_test.go b/src/dcm/pkg/module/userpermissions_test.go new file mode 100644 index 00000000..f134aa0f --- /dev/null +++ b/src/dcm/pkg/module/userpermissions_test.go @@ -0,0 +1,110 @@ +package module + +import ( + "testing" + + "github.com/pkg/errors" + +) + + +func TestCreateUserPerm(t *testing.T) { + + up := UserPermission { + UserPermissionName: "test_user_perm", + } + data1 := [][]byte{} + + // data2 := []byte("abc") + + key := UserPermissionKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + UserPermissionName: "test_user_perm", + } + myMocks := new(mockValues) + // just to get an error value + err1 := errors.New("math: square root of negative number") + + myMocks.On("CheckProject", "test_project").Return(nil) + myMocks.On("CheckLogicalCloud", "test_project", "test_asdf").Return(nil) + myMocks.On("DBInsert", "test_dcm", key, nil, "test_meta", up).Return(nil) + myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, err1) + // myMocks.On("DBUnmarshal", data2).Return(nil) + + upClient := UserPermissionClient{"test_dcm", "test_meta", myMocks} + _, err := upClient.CreateUserPerm("test_project", "test_asdf", up) + if err != nil { + t.Errorf("Some error occured!") + } +} + +func TestGetUserPerm(t *testing.T) { + key := UserPermissionKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + UserPermissionName: "test_user_perm", + } + + data1 := [][]byte{ + []byte("abc"), + } + + data2 := []byte("abc") + + myMocks := new(mockValues) + + myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, nil) + myMocks.On("DBUnmarshal", data2).Return(nil) + upClient := UserPermissionClient{"test_dcm", "test_meta", myMocks} + _, err := upClient.GetUserPerm("test_project", "test_asdf", "test_user_perm") + if err != nil { + t.Errorf("Some error occured!") + } +} + +func TestDeleteUserPerm(t *testing.T) { + + key := UserPermissionKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + UserPermissionName: "test_user_perm", + } + + myMocks := new(mockValues) + + myMocks.On("DBRemove", "test_dcm", key).Return(nil) + + upClient := UserPermissionClient{"test_dcm", "test_meta", myMocks} + err := upClient.DeleteUserPerm("test_project", "test_asdf", "test_user_perm") + if err != nil { + t.Errorf("Some error occured!") + } + +} + +func TestUpdateUserPerm(t *testing.T) { + key := UserPermissionKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + UserPermissionName: "test_user_perm", + } + up := UserPermission{ + UserPermissionName: "test_user_perm", + } + data1 := [][]byte{ + []byte("abc"), + } + data2 := []byte("abc") + + myMocks := new(mockValues) + + myMocks.On("DBInsert", "test_dcm", key, nil, "test_meta", up).Return(nil) + myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, nil) + myMocks.On("DBUnmarshal", data2).Return(nil) + upClient := UserPermissionClient{"test_dcm", "test_meta", myMocks} + _, err := upClient.UpdateUserPerm("test_project", "test_asdf", "test_user_perm", up) + if err != nil { + t.Errorf("Some error occured!") + } +} -- cgit 1.2.3-korg