Skip to content

Commit

Permalink
Rework TLS options into its own struct (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhollinger authored Oct 19, 2021
1 parent 63f545d commit 3e98fbd
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ config.yml
*.exe
*.bin
webhook-go
webhook.yml
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ server:
user: puppet
password: puppet
port: 4000
tls:
enabled: false
certificate: "/path/to/tls/certificate"
key: "/path/to/tls/key"
chatops:
enabled: false
r10k:
Expand Down Expand Up @@ -69,19 +73,24 @@ Type: int64
Description: Port to run the server on. Optional.
Default: `4000`

#### `tls_enabled`
#### `tls`

Type: struct
Description: Struct containing server TLS options

##### `enabled`

Type: bool
Description: Enforces TLS with http server
Default: `false`

#### `tls_certificate`
##### `certificate`

Type: string
Description: Full path to certificate file. Optional.
Default: `nil`

#### `tls_key`
##### `key`

Type: string
Description: Full path to key file. Optional.
Expand Down
16 changes: 9 additions & 7 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ var config Config

type Config struct {
Server struct {
Protected bool `yaml:"protected"`
User string `yaml:"user"`
Password string `yaml:"password"`
Port string `yaml:"port,int"`
TLSEnabled bool `mapstructure:"tls_enabled"`
TLSCert string `mapstructure:"tls_certificate"`
TLSKey string `mapstructure:"tls_key"`
Protected bool `yaml:"protected"`
User string `yaml:"user"`
Password string `yaml:"password"`
Port string `yaml:"port,int"`
TLS struct {
Enabled bool `yaml:"enabled"`
Certificate string `yaml:"certificate"`
Key string `yaml:"key"`
} `yaml:"tls"`
} `yaml:"server"`
ChatOps struct {
Enabled bool `yaml:"enabled"`
Expand Down
4 changes: 2 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
func Init() {
config := config.GetConfig().Server
r := NewRouter()
if config.TLSEnabled {
r.RunTLS(":" + config.Port, config.TLSCert, config.TLSKey)
if config.TLS.Enabled {
r.RunTLS(":"+config.Port, config.TLS.Certificate, config.TLS.Key)
} else {
r.Run(":" + config.Port)
}
Expand Down
4 changes: 4 additions & 0 deletions webhook.yml → webhook.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ server:
user: puppet
password: puppet
port: 4000
tls:
enabled: false
certificate: ""
key: ""
chatops:
enabled: false
r10k:
Expand Down

0 comments on commit 3e98fbd

Please sign in to comment.