This repository has been archived by the owner on Jan 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
main.go
99 lines (82 loc) · 2.81 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
// Copyright 2016 CoreOS, 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 (
"flag"
"os"
"os/signal"
"syscall"
log "github.com/Sirupsen/logrus"
"github.com/eclipse/che-jwtproxy"
"github.com/eclipse/che-jwtproxy/config"
_ "github.com/eclipse/che-jwtproxy/jwt/claims/static"
_ "github.com/eclipse/che-jwtproxy/jwt/keyserver/keyregistry"
_ "github.com/eclipse/che-jwtproxy/jwt/keyserver/keyregistry/keycache/memory"
_ "github.com/eclipse/che-jwtproxy/jwt/keyserver/preshared"
_ "github.com/eclipse/che-jwtproxy/jwt/noncestorage/local"
_ "github.com/eclipse/che-jwtproxy/jwt/noncestorage/void"
_ "github.com/eclipse/che-jwtproxy/jwt/privatekey/autogenerated"
_ "github.com/eclipse/che-jwtproxy/jwt/privatekey/preshared"
)
func main() {
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
flagConfigPath := flag.String("config", "", "Load configuration from the specified yaml file.")
flagLogLevel := flag.String("log-level", "info", "Define the logging level.")
flag.Parse()
// Load configuration.
config, err := config.Load(*flagConfigPath)
if err != nil {
flag.Usage()
log.Fatalf("Failed to load configuration: %s", err)
}
// Initialize logging system.
level, err := log.ParseLevel(*flagLogLevel)
if err != nil {
log.Fatalf("Failed to parse the log level: %s", err)
}
log.SetLevel(level)
// Run proxies until SIGINT/SIGTERM is received and then shutdown gracefully.
run(config)
}
func run(config *config.Config) {
// Nothing to run? Abort.
var verifierEnabled bool
for _, verifierCfg := range config.VerifierProxies {
if verifierCfg.Enabled {
verifierEnabled = true
break
}
}
if !verifierEnabled && !config.SignerProxy.Enabled {
log.Error("No proxy is enabled. Terminating.")
return
}
// Create shutdown channel and make it listen to SIGINT and SIGTERM.
shutdown := make(chan os.Signal)
signal.Notify(shutdown, syscall.SIGINT, syscall.SIGTERM)
// Run proxies.
stopper, abort := jwtproxy.RunProxies(config)
// Wait for stop signal.
select {
case <-shutdown:
log.Info("Received stop signal. Stopping gracefully...")
case aborted := <-abort:
log.Error(aborted)
}
stopped := stopper.Stop()
// Restore the original behavior in case we need to force shutdown.
signal.Reset(syscall.SIGINT, syscall.SIGTERM)
// Wait for everything to stop.
<-stopped
}