summaryrefslogtreecommitdiffstats
path: root/src/dkv/main.go
blob: ba8f9e94f93eb98e9704de596d42893b70ad90d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * Copyright 2018 Intel Corporation, Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package main

import (
	"dkv/api"
	"github.com/gorilla/handlers"
	"github.com/gorilla/mux"
	"log"
	"net/http"
	"os"
)

func main() {
	err := api.Initialise()
	if err != nil {
		log.Fatal(err)
	}
	router := mux.NewRouter()
	// Sevice Registration
	// Domain CRUD
	router.HandleFunc("/v1/register", api.HandleServiceCreate).Methods("POST")
	router.HandleFunc("/v1/register/{token}", api.HandleServiceGet).Methods("GET")
	router.HandleFunc("/v1/register/{token}", api.HandleServiceDelete).Methods("DELETE")
	// Subdomain CRUD
	router.HandleFunc("/v1/register/{token}/subdomain", api.HandleServiceSubdomainCreate).Methods("POST")
	// router.HandleFunc("/v1/register/{token}/subdomain", api.HandleServiceSubdomainGet).Methods("GET")
	router.HandleFunc("/v1/register/{token}/subdomain/{subdomain}", api.HandleServiceSubdomainDelete).Methods("DELETE")
	// Configuration CRUD
	router.HandleFunc("/v1/config", api.HandleConfigUpload).Methods("POST")
	router.HandleFunc("/v1/config/{token}/{filename}", api.HandleConfigGet).Methods("GET")
	router.HandleFunc("/v1/config/{token}/{subdomain}/{filename}", api.HandleConfigGet).Methods("GET")
	router.HandleFunc("/v1/config/{token}/{filename}", api.HandleConfigDelete).Methods("DELETE")
	router.HandleFunc("/v1/config/{token}/{subdomain}/{filename}", api.HandleConfigDelete).Methods("DELETE")
	router.HandleFunc("/v1/config/load", api.HandleConfigLoad).Methods("POST")
	// Load default configs
	router.HandleFunc("/v1/config/load-default", api.HandleDefaultConfigLoad).Methods("GET")
	// Direct Consul queries.
	router.HandleFunc("/v1/getconfig/{token}/{key}", api.HandleGET).Methods("GET")
	// TODO(sshank): Following methods should not be allowed for all users. Remove it or make sure
	// its accessible only by admin.
	router.HandleFunc("/v1/deleteconfig/{key}", api.HandleDELETE).Methods("DELETE")
	router.HandleFunc("/v1/getconfigs", api.HandleGETS).Methods("GET")

	loggedRouter := handlers.LoggingHandler(os.Stdout, router)
	log.Println("[INFO] Started Distributed KV Store server.")
	log.Fatal(http.ListenAndServe(":8080", loggedRouter))
}