2 Copyright 2018 Intel Corporation.
3 Copyright © 2021 Samsung Electronics
4 Copyright © 2021 Orange
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
23 "github.com/onap/multicloud-k8s/src/k8splugin/internal/app"
24 log "github.com/onap/multicloud-k8s/src/k8splugin/internal/logutils"
27 // Used to store the backend implementation objects
28 // Also simplifies the mocking needed for unit testing
29 type queryHandler struct {
30 // Interface that implements the Instance operations
31 client app.QueryManager
34 // queryHandler retrieves information about specified resources for instance
35 func (i queryHandler) queryHandler(w http.ResponseWriter, r *http.Request) {
36 namespace := r.FormValue("Namespace")
37 cloudRegion := r.FormValue("CloudRegion")
38 apiVersion := r.FormValue("ApiVersion")
39 kind := r.FormValue("Kind")
40 name := r.FormValue("Name")
41 labels := r.FormValue("Labels")
42 if cloudRegion == "" {
43 http.Error(w, "Missing CloudRegion mandatory parameter", http.StatusBadRequest)
47 http.Error(w, "Missing ApiVersion mandatory parameter", http.StatusBadRequest)
51 http.Error(w, "Missing Kind mandatory parameter", http.StatusBadRequest)
54 // instance id is irrelevant here
55 resp, err := i.client.Query(namespace, cloudRegion, apiVersion, kind, name, labels, "query")
57 log.Error("Error getting Query results", log.Fields{
59 "cloudRegion": cloudRegion,
60 "namespace": namespace,
61 "apiVersion": apiVersion,
66 http.Error(w, err.Error(), http.StatusInternalServerError)
68 w.Header().Set("Content-Type", "application/json")
69 w.WriteHeader(http.StatusOK)
70 err = json.NewEncoder(w).Encode(resp)
72 log.Error("Error Marshaling Response", log.Fields{
76 http.Error(w, err.Error(), http.StatusInternalServerError)