Skip to content

Commit

Permalink
misc: move Config to mutate/config.go
Browse files Browse the repository at this point in the history
  • Loading branch information
j4m3s-s committed Jan 5, 2022
1 parent c45820c commit fd3ea4d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
8 changes: 8 additions & 0 deletions config.example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
port: 8443
# change tlsdirpath path accordingly if you change this
tlskeypath: "/tls/key.pem"
ignoreimages:
- registry
- registry.example.com/toto/k8s-proxy-image-swapper
# change tlsdirpath path accordingly if you change this
tlscertpath: "/tls/cert.pem"
3 changes: 0 additions & 3 deletions config.example.yml

This file was deleted.

20 changes: 7 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,26 @@ func handleMutation(w http.ResponseWriter, r *http.Request) {
}
}

type Config struct {
TLSCertPath string `yaml:"tlscertpath"`
TLSKeyPath string `yaml:"tlskeypath"`
Port string `yaml:"port"`
}

func main() {
if len(os.Args) == 1 {
fmt.Errorf("Usage : %v $CONFIG_FILE_PATH", os.Args[0])
log.Fatalf("Usage : %v $CONFIG_FILE_PATH\n", os.Args[0])
return
}
configFile, err := os.Open(os.Args[1])
if err != nil {
fmt.Errorf("Error opening %v : %v", os.Args[1], err)
return
log.Fatalf("Error opening %v : %v\n", os.Args[1], err)
}
defer configFile.Close()

var config Config
var config m.Config
decoder := yaml.NewDecoder(configFile)
err = decoder.Decode(&config)
if err != nil {
fmt.Errorf("Error reading config : %v", err)
return
log.Fatalf("Error reading config : %v\n", err)
}

m.Configuration = config

log.Println("Starting server ...")

mux := http.NewServeMux()
Expand All @@ -83,7 +77,7 @@ func main() {
mux.HandleFunc("/mutate", handleMutation)

s := &http.Server{
Addr: config.Port,
Addr: ":" + config.Port,
Handler: mux,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
Expand Down
11 changes: 11 additions & 0 deletions mutate/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: Apache-2.0
package mutate

type Config struct {
TLSCertPath string `yaml:"tlscertpath"`
TLSKeyPath string `yaml:"tlskeypath"`
Port string `yaml:"port"`
IgnoreImages []string `yaml:"ignoreimages"`
}

var Configuration Config

0 comments on commit fd3ea4d

Please sign in to comment.