-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
executable file
·124 lines (105 loc) · 3.41 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package main
import (
"flag"
"net/http"
"os"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
"hpc_exporter/api"
"hpc_exporter/conf"
"github.com/gorilla/mux"
)
var (
addr = flag.String(
"listen-address",
":9110",
"The address to listen on for HTTP requests.",
)
logLevel = flag.String(
"log-level",
"error",
"Log level of the Application.",
)
introspection_endpoint = flag.String(
"introspection-endpoint",
"",
"Introspection endpoint to check JWT (Keycloak).",
)
introspection_client = flag.String(
"introspection-client",
"",
"Introspection client.",
)
introspection_secret = flag.String(
"introspection-secret",
"",
"Introspection client secret.",
)
vault_secret_uploader_address = flag.String(
"vault-secret-uploader-address",
"",
"Vault login endpoint.",
)
)
func main() {
flag.Parse()
// Parse and set log lovel
level, err := log.ParseLevel(*logLevel)
if err == nil {
log.SetLevel(level)
} else {
log.SetLevel(log.WarnLevel)
log.Warnf("Log level %s not recognized, setting 'warn' as default.")
}
security_config := conf.NewSecurityConf()
if *introspection_endpoint == "" {
security_config.Introspection_endpoint = os.Getenv("OIDC_INTROSPECTION_ENDPOINT")
if len(security_config.Introspection_endpoint) == 0 {
log.Fatal("No introspection endpoint given. Provide argument --introspection-endpoint or set environment variable OIDC_INTROSPECTION_ENDPOINT")
}
} else {
security_config.Introspection_endpoint = *introspection_endpoint
}
if *introspection_client == "" {
security_config.Introspection_client = os.Getenv("OIDC_INTROSPECTION_CLIENT")
if len(security_config.Introspection_client) == 0 {
security_config.Introspection_client = "sodalite-ide"
}
} else {
security_config.Introspection_client = *introspection_client
}
if *introspection_secret == "" {
security_config.Introspection_secret = os.Getenv("OIDC_CLIENT_SECRET")
if len(security_config.Introspection_secret) == 0 {
log.Fatal("No introspection secret given. Provide argument --introspection-secret or set environment variable OIDC_CLIENT_SECRET")
}
} else {
security_config.Introspection_secret = *introspection_secret
}
if *vault_secret_uploader_address == "" {
security_config.Vault_secret_uploader_address = os.Getenv("VAULT_SECRET_UPLOADER_ADDRESS")
if len(security_config.Vault_secret_uploader_address) == 0 {
log.Fatal("No vault-secret-uploader address given. Provide argument --vault-secret-uploader-address or set environment variable VAULT_SECRET_UPLOADER_ADDRESS")
}
} else {
security_config.Vault_secret_uploader_address = *vault_secret_uploader_address
}
collectorStore := api.NewCollectorStore(security_config)
// Expose the registered metrics via HTTP.
log.Infof("Starting Server: %s", *addr)
router := mux.NewRouter()
router.Handle("/metrics", promhttp.Handler())
router.HandleFunc("/collector", collectorStore.CreateHandler).Methods("POST")
router.HandleFunc("/collector", collectorStore.DeleteHandler).Methods("DELETE")
router.HandleFunc("/job", collectorStore.AddJobHandler).Methods("POST")
router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>Multi-Tenant HPC Exporter</title></head>
<body>
<h1>HPC Exporter</h1>
<p><a href="/metrics">Metrics</a></p>
</body>
</html>`))
}).Methods("GET")
log.Debug(http.ListenAndServe(*addr, router))
}