Skip to content

Commit

Permalink
Merge pull request #57 from ferringb/master
Browse files Browse the repository at this point in the history
Add debug statement for command svcmgr, add `ensure --forceRegen`, cut v1.6.3
  • Loading branch information
cbroglie authored Jan 24, 2019
2 parents f748d88 + 190c156 commit 56b5f8e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
7 changes: 6 additions & 1 deletion cert/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,17 @@ func (spec *Spec) Lifespan() time.Duration {
}
if isTooOld(spec.Key.Path) || isTooOld(spec.Cert.Path) {
// This is necessary to essentially force cfssl to regenerate since it's not spec aware.
spec.tr.Provider.Certificate().NotAfter = specStat.ModTime()
spec.ResetLifespan()
return 0
}
return spec.tr.Lifespan()
}

// Reset the lifespan to force cfssl to regenerate
func (spec *Spec) ResetLifespan() {
spec.tr.Provider.Certificate().NotAfter = time.Time{}
}

// Certificate returns the x509.Certificate associated with the spec
// if one exists.
func (spec *Spec) Certificate() *x509.Certificate {
Expand Down
4 changes: 3 additions & 1 deletion cli/ensure.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

var ensureTolerance = 3
var enableActions = false
var forceRegen = false

var ensureCmd = &cobra.Command{
Use: "ensure",
Expand All @@ -31,7 +32,7 @@ func Ensure(cmd *cobra.Command, args []string) {
os.Exit(1)
}

err = mgr.MustCheckCerts(ensureTolerance, enableActions)
err = mgr.MustCheckCerts(ensureTolerance, enableActions, forceRegen)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed: %s\n", err)
os.Exit(1)
Expand All @@ -44,4 +45,5 @@ func init() {
RootCmd.AddCommand(ensureCmd)
ensureCmd.Flags().IntVarP(&ensureTolerance, "tries", "n", ensureTolerance, "number of times to retry refreshing a certificate")
ensureCmd.Flags().BoolVarP(&enableActions, "enableActions", "", enableActions, "if passed, run the certificates svcmgr actions; defaults to not running them")
ensureCmd.Flags().BoolVarP(&forceRegen, "forceRegen", "", forceRegen, "if passed, ignore TTL checks and force regeneration of all specs")
}
2 changes: 1 addition & 1 deletion cli/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/spf13/viper"
)

var currentVersion = "1.6.2"
var currentVersion = "1.6.3"

var versionCmd = &cobra.Command{
Use: "version",
Expand Down
8 changes: 7 additions & 1 deletion mgr/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func (m *Manager) CheckCertsSync() int {
// MustCheckCerts acts like CheckCerts, except it's synchronous and
// has a maxmimum number of failures that are tolerated. If tolerate
// is less than 1, it will be set to 1.
func (m *Manager) MustCheckCerts(tolerance int, enableActions bool) error {
func (m *Manager) MustCheckCerts(tolerance int, enableActions bool, forceRegen bool) error {
if tolerance < 1 {
tolerance = 1
}
Expand All @@ -344,6 +344,12 @@ func (m *Manager) MustCheckCerts(tolerance int, enableActions bool) error {
log.Errorf("manager: the CA for %s has changed, but the service couldn't be notified of the change", m.Certs[i])
}

if forceRegen {
log.Debugf("manager: forcing regeneration of spec %s", m.Certs[i])
m.Certs[i].ResetLifespan()
queue <- &queuedCert{cert: m.Certs[i]}
continue
}
if !m.Certs[i].Ready() && !m.Certs[i].IsQueued() {
queue <- &queuedCert{cert: m.Certs[i]}
continue
Expand Down
1 change: 1 addition & 0 deletions svcmgr/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func newCommandManager(action string, service string) (Manager, error) {
log.Warningf("svcmgr 'command': service '%s' for action '%s' doesn't do anything, ignoring", service, action)
}
if canCheckSyntax {
log.Debugf("svcmgr 'command': validating the action definition %s", action)
err := run(shellBinary, "-n", "-c", action)
if err != nil {
return nil, fmt.Errorf("svcmgr 'command': action '%s' failed bash -n -c parse checks: %s", action, err)
Expand Down

0 comments on commit 56b5f8e

Please sign in to comment.