2 // ========================LICENSE_START=================================
5 // Copyright (C) 2022: Nordix Foundation. All rights reserved.
6 // Copyright (C) 2023-2024 OpenInfra Foundation Europe. All rights reserved.
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
12 // http://www.apache.org/licenses/LICENSE-2.0
14 // Unless required by applicable law or agreed to in writing, software
15 // distributed under the License is distributed on an "AS IS" BASIS,
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 // See the License for the specific language governing permissions and
18 // limitations under the License.
19 // ========================LICENSE_END===================================
29 "github.com/labstack/echo/v4"
30 "helm.sh/helm/v3/pkg/cli"
31 log "github.com/sirupsen/logrus"
33 "oransc.org/nonrtric/capifcore/internal/helmmanagement"
34 config "oransc.org/nonrtric/capifcore/internal/config"
35 "oransc.org/nonrtric/capifcore/internal/keycloak"
37 "oransc.org/nonrtric/capifcore"
42 var helmManager helmmanagement.HelmManager
45 var port = flag.Int("port", 8090, "Port for CAPIF Core Function HTTP server")
46 var secPort = flag.Int("secPort", 4433, "Port for CAPIF Core Function HTTPS server")
47 flag.StringVar(&url, "chartMuseumUrl", "", "ChartMuseum URL")
48 flag.StringVar(&repoName, "repoName", "capifcore", "Repository name")
49 var logLevelStr = flag.String("loglevel", "Info", "Log level")
50 var certPath = flag.String("certPath", "certs/cert.pem", "Path for server certificate")
51 var keyPath = flag.String("keyPath", "certs/key.pem", "Path for server private key")
55 if loglevel, err := log.ParseLevel(*logLevelStr); err == nil {
56 log.SetLevel(loglevel)
60 helmManager = helmmanagement.NewHelmManager(cli.New())
61 err := helmManager.SetUpRepo(repoName, url)
63 log.Warnf("No Helm repo added due to: %s", err.Error())
66 // Read configuration file
67 cfg, err := config.ReadKeycloakConfigFile("configs")
69 log.Fatalf("Error loading configuration file\n: %s", err)
71 km := keycloak.NewKeycloakManager(cfg, &http.Client{})
74 capifcore.RegisterHandlers(eWeb, helmManager, km)
75 go startWebServer(eWeb, *port)
77 eHttpsWeb := echo.New()
78 capifcore.RegisterHandlers(eHttpsWeb, helmManager, km)
79 go startHttpsWebServer(eHttpsWeb, *secPort, *certPath, *keyPath)
81 log.Info("Server started and listening on port: ", *port)
85 func startWebServer(e *echo.Echo, port int) {
86 e.Logger.Fatal(e.Start(fmt.Sprintf("0.0.0.0:%d", port)))
89 func startHttpsWebServer(e *echo.Echo, port int, certPath string, keyPath string) {
90 e.Logger.Fatal(e.StartTLS(fmt.Sprintf("0.0.0.0:%d", port), certPath, keyPath))
93 func keepServerAlive() {
94 forever := make(chan int)