It watches ACME certs, detects new files, syncs them to your other servers, and bounces them.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
cert-bouncer/main.go

60 lines
1020 B

package main
import (
"github.com/fsnotify/fsnotify"
"flag"
"log"
"os"
"encoding/json"
)
type Cert struct {
PrivateKey string
PublicKey string
Owner string
}
type Config struct {
Source Cert
Target Cert
Reload string
}
func LoadConfig(path string) Config {
var config Config
config_data, err := os.ReadFile(path)
if err != nil {
log.Fatal("invalid config path %s: %v", path, err)
}
err = json.Unmarshal(config_data, &config)
if err != nil {
log.Fatal(err, "json format error")
}
return config
}
func ParseOpts() Config {
var config_file string
flag.StringVar(&config_file, "config", "cert-bouncer.json", ".json config to use.")
flag.Parse()
return LoadConfig(config_file)
}
func main() {
config := ParseOpts()
watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Fatal(err, "Can't watch files.")
}
err = watcher.Add(config.Source.PrivateKey)
if err != nil {
log.Fatalf("can't watch %s: %v", err, config.Source.PrivateKey)
}
}