Update status check endpoint 
[multicloud/k8s.git] / src / k8splugin / cmd / main.go
1 /*
2 Copyright 2018 Intel Corporation.
3 Copyright © 2021 Samsung Electronics
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7     http://www.apache.org/licenses/LICENSE-2.0
8 Unless required by applicable law or agreed to in writing, software
9 distributed under the License is distributed on an "AS IS" BASIS,
10 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 See the License for the specific language governing permissions and
12 limitations under the License.
13 */
14
15 package main
16
17 import (
18         "context"
19         "github.com/onap/multicloud-k8s/src/k8splugin/internal/utils"
20         "log"
21         "math/rand"
22         "net/http"
23         "os"
24         "os/signal"
25         "time"
26
27         "github.com/onap/multicloud-k8s/src/k8splugin/api"
28         "github.com/onap/multicloud-k8s/src/k8splugin/internal/auth"
29         "github.com/onap/multicloud-k8s/src/k8splugin/internal/config"
30
31         "github.com/gorilla/handlers"
32 )
33
34 func main() {
35
36         err := utils.CheckInitialSettings()
37         if err != nil {
38                 log.Fatal(err)
39         }
40
41         rand.Seed(time.Now().UnixNano())
42
43         httpRouter := api.NewRouter(nil, nil, nil, nil, nil, nil, nil, nil)
44         loggedRouter := handlers.LoggingHandler(os.Stdout, httpRouter)
45         log.Println("Starting Kubernetes Multicloud API")
46
47         httpServer := &http.Server{
48                 Handler: loggedRouter,
49                 Addr:    ":" + config.GetConfiguration().ServicePort,
50         }
51
52         connectionsClose := make(chan struct{})
53         go func() {
54                 c := make(chan os.Signal, 1)
55                 signal.Notify(c, os.Interrupt)
56                 <-c
57                 httpServer.Shutdown(context.Background())
58                 close(connectionsClose)
59         }()
60
61         tlsConfig, err := auth.GetTLSConfig("ca.cert", "server.cert", "server.key")
62         if err != nil {
63                 log.Println("Error Getting TLS Configuration. Starting without TLS...")
64                 log.Fatal(httpServer.ListenAndServe())
65         } else {
66                 httpServer.TLSConfig = tlsConfig
67                 // empty strings because tlsconfig already has this information
68                 err = httpServer.ListenAndServeTLS("", "")
69         }
70 }