diff --git a/cmd/root.go b/cmd/root.go index f281016..305f36e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -61,7 +61,7 @@ func init() { rootCmd.PersistentFlags().Bool("domain-subdir", false, "Use domain as sub-directory.") rootCmd.PersistentFlags().Bool("clean", true, "Clean destination folder before dumping content.") rootCmd.PersistentFlags().Bool("watch", false, "Enable watching changes.") - rootCmd.PersistentFlags().String("post-hook", "", "Execute a command only if changes occurs on the data source. (works only with the watch mode)") + rootCmd.PersistentFlags().String("post-hook", "", "Execute a command only if changes occurs on the data source.") } // initConfig reads in config file and ENV variables if set. diff --git a/docs/traefik-certs-dumper.md b/docs/traefik-certs-dumper.md index f2a73aa..94b420e 100644 --- a/docs/traefik-certs-dumper.md +++ b/docs/traefik-certs-dumper.md @@ -18,7 +18,7 @@ Dump Let's Encrypt certificates from Traefik. -h, --help help for traefik-certs-dumper --key-ext string The file extension of the generated private keys. (default ".key") --key-name string The file name (without extension) of the generated private keys. (default "privatekey") - --post-hook string Execute a command only if changes occurs on the data source. (works only with the watch mode) + --post-hook string Execute a command only if changes occurs on the data source. --watch Enable watching changes. ``` diff --git a/docs/traefik-certs-dumper_file.md b/docs/traefik-certs-dumper_file.md index d7be5a4..0801717 100644 --- a/docs/traefik-certs-dumper_file.md +++ b/docs/traefik-certs-dumper_file.md @@ -28,7 +28,7 @@ traefik-certs-dumper file [flags] --domain-subdir Use domain as sub-directory. --key-ext string The file extension of the generated private keys. (default ".key") --key-name string The file name (without extension) of the generated private keys. (default "privatekey") - --post-hook string Execute a command only if changes occurs on the data source. (works only with the watch mode) + --post-hook string Execute a command only if changes occurs on the data source. --watch Enable watching changes. ``` diff --git a/docs/traefik-certs-dumper_kv.md b/docs/traefik-certs-dumper_kv.md index ba510f0..d621cc2 100644 --- a/docs/traefik-certs-dumper_kv.md +++ b/docs/traefik-certs-dumper_kv.md @@ -34,7 +34,7 @@ Dump the content of a KV store. --domain-subdir Use domain as sub-directory. --key-ext string The file extension of the generated private keys. (default ".key") --key-name string The file name (without extension) of the generated private keys. (default "privatekey") - --post-hook string Execute a command only if changes occurs on the data source. (works only with the watch mode) + --post-hook string Execute a command only if changes occurs on the data source. --watch Enable watching changes. ``` diff --git a/docs/traefik-certs-dumper_kv_boltdb.md b/docs/traefik-certs-dumper_kv_boltdb.md index f2e774b..382607e 100644 --- a/docs/traefik-certs-dumper_kv_boltdb.md +++ b/docs/traefik-certs-dumper_kv_boltdb.md @@ -32,7 +32,7 @@ traefik-certs-dumper kv boltdb [flags] --key-ext string The file extension of the generated private keys. (default ".key") --key-name string The file name (without extension) of the generated private keys. (default "privatekey") --password string Password for connection. - --post-hook string Execute a command only if changes occurs on the data source. (works only with the watch mode) + --post-hook string Execute a command only if changes occurs on the data source. --prefix string Prefix used for KV store. (default "traefik") --tls Enable TLS encryption. --tls.ca string Root CA for certificate verification if TLS is enabled diff --git a/docs/traefik-certs-dumper_kv_consul.md b/docs/traefik-certs-dumper_kv_consul.md index 6fb0df0..b8897ed 100644 --- a/docs/traefik-certs-dumper_kv_consul.md +++ b/docs/traefik-certs-dumper_kv_consul.md @@ -31,7 +31,7 @@ traefik-certs-dumper kv consul [flags] --key-ext string The file extension of the generated private keys. (default ".key") --key-name string The file name (without extension) of the generated private keys. (default "privatekey") --password string Password for connection. - --post-hook string Execute a command only if changes occurs on the data source. (works only with the watch mode) + --post-hook string Execute a command only if changes occurs on the data source. --prefix string Prefix used for KV store. (default "traefik") --tls Enable TLS encryption. --tls.ca string Root CA for certificate verification if TLS is enabled diff --git a/docs/traefik-certs-dumper_kv_etcd.md b/docs/traefik-certs-dumper_kv_etcd.md index 878c3b8..efdfb8b 100644 --- a/docs/traefik-certs-dumper_kv_etcd.md +++ b/docs/traefik-certs-dumper_kv_etcd.md @@ -31,7 +31,7 @@ traefik-certs-dumper kv etcd [flags] --key-ext string The file extension of the generated private keys. (default ".key") --key-name string The file name (without extension) of the generated private keys. (default "privatekey") --password string Password for connection. - --post-hook string Execute a command only if changes occurs on the data source. (works only with the watch mode) + --post-hook string Execute a command only if changes occurs on the data source. --prefix string Prefix used for KV store. (default "traefik") --tls Enable TLS encryption. --tls.ca string Root CA for certificate verification if TLS is enabled diff --git a/docs/traefik-certs-dumper_kv_zookeeper.md b/docs/traefik-certs-dumper_kv_zookeeper.md index 1ffe529..14b9a75 100644 --- a/docs/traefik-certs-dumper_kv_zookeeper.md +++ b/docs/traefik-certs-dumper_kv_zookeeper.md @@ -30,7 +30,7 @@ traefik-certs-dumper kv zookeeper [flags] --key-ext string The file extension of the generated private keys. (default ".key") --key-name string The file name (without extension) of the generated private keys. (default "privatekey") --password string Password for connection. - --post-hook string Execute a command only if changes occurs on the data source. (works only with the watch mode) + --post-hook string Execute a command only if changes occurs on the data source. --prefix string Prefix used for KV store. (default "traefik") --tls Enable TLS encryption. --tls.ca string Root CA for certificate verification if TLS is enabled diff --git a/docs/traefik-certs-dumper_version.md b/docs/traefik-certs-dumper_version.md index 4d76473..b340186 100644 --- a/docs/traefik-certs-dumper_version.md +++ b/docs/traefik-certs-dumper_version.md @@ -27,7 +27,7 @@ traefik-certs-dumper version [flags] --domain-subdir Use domain as sub-directory. --key-ext string The file extension of the generated private keys. (default ".key") --key-name string The file name (without extension) of the generated private keys. (default "privatekey") - --post-hook string Execute a command only if changes occurs on the data source. (works only with the watch mode) + --post-hook string Execute a command only if changes occurs on the data source. --watch Enable watching changes. ``` diff --git a/dumper/file/file.go b/dumper/file/file.go index 33bbacc..c388ccb 100644 --- a/dumper/file/file.go +++ b/dumper/file/file.go @@ -33,7 +33,13 @@ func dump(acmeFile string, baseConfig *dumper.BaseConfig) error { return err } - return dumper.Dump(data, baseConfig) + err = dumper.Dump(data, baseConfig) + if err != nil { + return err + } + + hook.Exec(baseConfig.Hook) + return nil } func readFile(acmeFile string) (*dumper.StoredData, error) { @@ -127,8 +133,6 @@ func manageEvent(watcher *fsnotify.Watcher, event fsnotify.Event, acmeFile strin if isDebug() { log.Println("Dumped new certificate data.") } - - hook.Exec(baseConfig.Hook) } return hash, nil diff --git a/dumper/kv/kv.go b/dumper/kv/kv.go index 3714a60..52c69ca 100644 --- a/dumper/kv/kv.go +++ b/dumper/kv/kv.go @@ -61,8 +61,6 @@ func watch(kvStore store.Store, storeKey string, baseConfig *dumper.BaseConfig) if isDebug() { log.Println("Dumped new certificate data.") } - - hook.Exec(baseConfig.Hook) } } @@ -72,7 +70,13 @@ func dumpPair(pair *store.KVPair, baseConfig *dumper.BaseConfig) error { return err } - return dumper.Dump(data, baseConfig) + err = dumper.Dump(data, baseConfig) + if err != nil { + return err + } + + hook.Exec(baseConfig.Hook) + return nil } func getStoredDataFromGzip(pair *store.KVPair) (*dumper.StoredData, error) {