Merge "Use httptest instead of http in unit tests"
[multicloud/k8s.git] / src / k8splugin / api / api.go
1 /*
2 Copyright 2018 Intel Corporation.
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6     http://www.apache.org/licenses/LICENSE-2.0
7 Unless required by applicable law or agreed to in writing, software
8 distributed under the License is distributed on an "AS IS" BASIS,
9 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 See the License for the specific language governing permissions and
11 limitations under the License.
12 */
13
14 package api
15
16 import (
17         "k8splugin/internal/rb"
18
19         "github.com/gorilla/mux"
20 )
21
22 // NewRouter creates a router instance that serves the VNFInstance web methods
23 func NewRouter(kubeconfig string, defClient rb.DefinitionManager,
24         profileClient rb.ProfileManager) *mux.Router {
25         router := mux.NewRouter()
26
27         vnfInstanceHandler := router.PathPrefix("/v1/vnf_instances").Subrouter()
28         vnfInstanceHandler.HandleFunc("/", CreateHandler).Methods("POST").Name("VNFCreation")
29         vnfInstanceHandler.HandleFunc("/{cloudRegionID}/{namespace}", ListHandler).Methods("GET")
30         vnfInstanceHandler.HandleFunc("/{cloudRegionID}/{namespace}/{externalVNFID}", DeleteHandler).Methods("DELETE")
31         vnfInstanceHandler.HandleFunc("/{cloudRegionID}/{namespace}/{externalVNFID}", GetHandler).Methods("GET")
32
33         //rbd is resource bundle definition
34         if defClient == nil {
35                 defClient = rb.NewDefinitionClient()
36         }
37         defHandler := rbDefinitionHandler{client: defClient}
38         resRouter := router.PathPrefix("/v1/rb").Subrouter()
39         resRouter.HandleFunc("/definition", defHandler.createHandler).Methods("POST")
40         resRouter.HandleFunc("/definition/{rbdID}/content", defHandler.uploadHandler).Methods("POST")
41         resRouter.HandleFunc("/definition", defHandler.listHandler).Methods("GET")
42         resRouter.HandleFunc("/definition/{rbdID}", defHandler.getHandler).Methods("GET")
43         resRouter.HandleFunc("/definition/{rbdID}", defHandler.deleteHandler).Methods("DELETE")
44
45         //rbp is resource bundle profile
46         if profileClient == nil {
47                 profileClient = rb.NewProfileClient()
48         }
49         profileHandler := rbProfileHandler{client: profileClient}
50         resRouter.HandleFunc("/profile", profileHandler.createHandler).Methods("POST")
51         resRouter.HandleFunc("/profile/{rbpID}/content", profileHandler.uploadHandler).Methods("POST")
52         resRouter.HandleFunc("/profile/help", profileHandler.helpHandler).Methods("GET")
53         resRouter.HandleFunc("/profile", profileHandler.listHandler).Methods("GET")
54         resRouter.HandleFunc("/profile/{rbpID}", profileHandler.getHandler).Methods("GET")
55         resRouter.HandleFunc("/profile/{rbpID}", profileHandler.deleteHandler).Methods("DELETE")
56
57         // (TODO): Fix update method
58         // vnfInstanceHandler.HandleFunc("/{vnfInstanceId}", UpdateHandler).Methods("PUT")
59
60         return router
61 }