Skip to content

Commit

Permalink
#94: adds SSL to webserver.go
Browse files Browse the repository at this point in the history
  • Loading branch information
aetaric committed Sep 30, 2024
1 parent 86d55c1 commit d5532b1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions checkrr.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ stats: # These will slow down the runtime substantually, but... DATA
token: "HEC Token" # this is the HEC token for your input. Configure it to force ingestion into a metrics index
webserver:
port: 8585
tls: false
certs:
cert: "/path/to/cert.pem"
key: "/path/to/privkey.pem"
baseurl: "/"
trustedproxies:
- 127.0.0.1
14 changes: 12 additions & 2 deletions webserver/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ var checkrrInstance *check.Checkrr
type Webserver struct {
Port int
BaseURL BaseURL
tls bool
cert string
key string
data chan []string
trustedProxies []string
DB *bolt.DB
Expand All @@ -55,7 +58,10 @@ func (b BaseURL) String() string {
}

func (w *Webserver) FromConfig(conf *viper.Viper, c chan []string, checkrr *check.Checkrr) {
w.Port = conf.GetInt("Port")
w.Port = conf.GetInt("port")
w.tls = conf.GetBool("tls")
w.key = conf.Sub("certs").GetString("key")
w.cert = conf.Sub("certs").GetString("cert")
w.BaseURL = BaseURL(conf.GetString("baseurl")).EnforceTrailingSlash()
baseurl = w.BaseURL
if conf.GetStringSlice("trustedproxies") != nil {
Expand Down Expand Up @@ -113,7 +119,11 @@ func createServer(w *Webserver) *gin.Engine {
api.GET("/schedule", getSchedule)
api.POST("/run", runCheckrr)

router.Run(fmt.Sprintf(":%v", w.Port))
if w.tls {
router.RunTLS(fmt.Sprintf(":%v", w.Port), w.cert, w.key)
} else {
router.Run(fmt.Sprintf(":%v", w.Port))
}
return router
}

Expand Down

0 comments on commit d5532b1

Please sign in to comment.