/
main.go
94 lines (81 loc) · 3.28 KB
/
main.go
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//(C) Copyright [2020] Hewlett Packard Enterprise Development LP
//
//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 (
"fmt"
"os"
"github.com/sirupsen/logrus"
"github.com/ODIM-Project/ODIM/lib-utilities/common"
"github.com/ODIM-Project/ODIM/lib-utilities/config"
"github.com/ODIM-Project/ODIM/lib-utilities/logs"
accountproto "github.com/ODIM-Project/ODIM/lib-utilities/proto/account"
authproto "github.com/ODIM-Project/ODIM/lib-utilities/proto/auth"
roleproto "github.com/ODIM-Project/ODIM/lib-utilities/proto/role"
sessionproto "github.com/ODIM-Project/ODIM/lib-utilities/proto/session"
"github.com/ODIM-Project/ODIM/lib-utilities/services"
"github.com/ODIM-Project/ODIM/svc-account-session/account"
"github.com/ODIM-Project/ODIM/svc-account-session/rpc"
)
func main() {
// setting up the logging framework
hostName := os.Getenv("HOST_NAME")
podName := os.Getenv("POD_NAME")
pid := os.Getpid()
logs.Adorn(logrus.Fields{
"host": hostName,
"procid": podName + fmt.Sprintf("_%d", pid),
})
// log should be initialized after Adorn is invoked
// as Adorn will assign new pointer to Log variable in logs package.
log := logs.Log
configWarnings, err := config.SetConfiguration()
if err != nil {
log.Logger.SetFormatter(&logs.SysLogFormatter{})
log.Fatal("Error while trying set up configuration: " + err.Error())
}
logs.SetFormatter(config.Data.LogFormat)
log.Logger.SetOutput(os.Stdout)
log.Logger.SetLevel(config.Data.LogLevel)
// verifying the uid of the user
if uid := os.Geteuid(); uid == 0 {
log.Fatal("AccountSession Service should not be run as the root user")
}
config.CollectCLArgs(&configWarnings)
for _, warning := range configWarnings {
log.Warn(warning)
}
if err := common.CheckDBConnection(); err != nil {
log.Fatal("Error while trying to check DB connection health: " + err.Error())
}
account.ConfigFilePath = os.Getenv("CONFIG_FILE_PATH")
if account.ConfigFilePath == "" {
log.Fatal("error: no value get the environment variable CONFIG_FILE_PATH")
}
errChan := make(chan error)
// TrackConfigFileChanges monitors the odim config changes using fsnotfiy
go account.TrackConfigFileChanges(errChan)
if err := services.InitializeService(services.AccountSession, errChan); err != nil {
log.Fatal("Error while trying to initialize the service: " + err.Error())
}
registerHandlers()
if err := services.ODIMService.Run(); err != nil {
log.Fatal("Failed to run a service: " + err.Error())
}
}
func registerHandlers() {
authproto.RegisterAuthorizationServer(services.ODIMService.Server(), new(rpc.Auth))
sessionproto.RegisterSessionServer(services.ODIMService.Server(), new(rpc.Session))
accountproto.RegisterAccountServer(services.ODIMService.Server(), new(rpc.Account))
roleproto.RegisterRolesServer(services.ODIMService.Server(), new(rpc.Role))
}