fix: execute post-hook command even without watch option enabled

This commit is contained in:
Aurelien Derouineau 2019-06-18 04:18:03 +00:00
parent 28e4c55785
commit 448bfd7f6d
11 changed files with 23 additions and 15 deletions

View File

@ -61,7 +61,7 @@ func init() {
rootCmd.PersistentFlags().Bool("domain-subdir", false, "Use domain as sub-directory.") 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("clean", true, "Clean destination folder before dumping content.")
rootCmd.PersistentFlags().Bool("watch", false, "Enable watching changes.") 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. // initConfig reads in config file and ENV variables if set.

View File

@ -18,7 +18,7 @@ Dump Let's Encrypt certificates from Traefik.
-h, --help help for traefik-certs-dumper -h, --help help for traefik-certs-dumper
--key-ext string The file extension of the generated private keys. (default ".key") --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") --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. --watch Enable watching changes.
``` ```

View File

@ -28,7 +28,7 @@ traefik-certs-dumper file [flags]
--domain-subdir Use domain as sub-directory. --domain-subdir Use domain as sub-directory.
--key-ext string The file extension of the generated private keys. (default ".key") --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") --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. --watch Enable watching changes.
``` ```

View File

@ -34,7 +34,7 @@ Dump the content of a KV store.
--domain-subdir Use domain as sub-directory. --domain-subdir Use domain as sub-directory.
--key-ext string The file extension of the generated private keys. (default ".key") --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") --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. --watch Enable watching changes.
``` ```

View File

@ -32,7 +32,7 @@ traefik-certs-dumper kv boltdb [flags]
--key-ext string The file extension of the generated private keys. (default ".key") --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") --key-name string The file name (without extension) of the generated private keys. (default "privatekey")
--password string Password for connection. --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") --prefix string Prefix used for KV store. (default "traefik")
--tls Enable TLS encryption. --tls Enable TLS encryption.
--tls.ca string Root CA for certificate verification if TLS is enabled --tls.ca string Root CA for certificate verification if TLS is enabled

View File

@ -31,7 +31,7 @@ traefik-certs-dumper kv consul [flags]
--key-ext string The file extension of the generated private keys. (default ".key") --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") --key-name string The file name (without extension) of the generated private keys. (default "privatekey")
--password string Password for connection. --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") --prefix string Prefix used for KV store. (default "traefik")
--tls Enable TLS encryption. --tls Enable TLS encryption.
--tls.ca string Root CA for certificate verification if TLS is enabled --tls.ca string Root CA for certificate verification if TLS is enabled

View File

@ -31,7 +31,7 @@ traefik-certs-dumper kv etcd [flags]
--key-ext string The file extension of the generated private keys. (default ".key") --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") --key-name string The file name (without extension) of the generated private keys. (default "privatekey")
--password string Password for connection. --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") --prefix string Prefix used for KV store. (default "traefik")
--tls Enable TLS encryption. --tls Enable TLS encryption.
--tls.ca string Root CA for certificate verification if TLS is enabled --tls.ca string Root CA for certificate verification if TLS is enabled

View File

@ -30,7 +30,7 @@ traefik-certs-dumper kv zookeeper [flags]
--key-ext string The file extension of the generated private keys. (default ".key") --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") --key-name string The file name (without extension) of the generated private keys. (default "privatekey")
--password string Password for connection. --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") --prefix string Prefix used for KV store. (default "traefik")
--tls Enable TLS encryption. --tls Enable TLS encryption.
--tls.ca string Root CA for certificate verification if TLS is enabled --tls.ca string Root CA for certificate verification if TLS is enabled

View File

@ -27,7 +27,7 @@ traefik-certs-dumper version [flags]
--domain-subdir Use domain as sub-directory. --domain-subdir Use domain as sub-directory.
--key-ext string The file extension of the generated private keys. (default ".key") --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") --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. --watch Enable watching changes.
``` ```

View File

@ -33,7 +33,13 @@ func dump(acmeFile string, baseConfig *dumper.BaseConfig) error {
return err 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) { func readFile(acmeFile string) (*dumper.StoredData, error) {
@ -127,8 +133,6 @@ func manageEvent(watcher *fsnotify.Watcher, event fsnotify.Event, acmeFile strin
if isDebug() { if isDebug() {
log.Println("Dumped new certificate data.") log.Println("Dumped new certificate data.")
} }
hook.Exec(baseConfig.Hook)
} }
return hash, nil return hash, nil

View File

@ -61,8 +61,6 @@ func watch(kvStore store.Store, storeKey string, baseConfig *dumper.BaseConfig)
if isDebug() { if isDebug() {
log.Println("Dumped new certificate data.") 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 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) { func getStoredDataFromGzip(pair *store.KVPair) (*dumper.StoredData, error) {