github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/core/watcher/secretbackends.go (about)

     1  // Copyright 2023 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package watcher
     5  
     6  import (
     7  	"fmt"
     8  	"time"
     9  )
    10  
    11  // SecretBackendRotateChange describes changes to a secret backend
    12  // rotation trigger.
    13  type SecretBackendRotateChange struct {
    14  	ID              string
    15  	Name            string
    16  	NextTriggerTime time.Time
    17  }
    18  
    19  func (s SecretBackendRotateChange) GoString() string {
    20  	whenMsg := "never"
    21  	if !s.NextTriggerTime.IsZero() {
    22  		interval := s.NextTriggerTime.Sub(time.Now())
    23  		if interval < 0 {
    24  			whenMsg = fmt.Sprintf("%v ago at %s", -interval, s.NextTriggerTime.Format(time.RFC3339))
    25  		} else {
    26  			whenMsg = fmt.Sprintf("in %v at %s", interval, s.NextTriggerTime.Format(time.RFC3339))
    27  		}
    28  	}
    29  	return fmt.Sprintf("%s token rotate: %s", s.Name, whenMsg)
    30  }
    31  
    32  // SecretBackendRotateChannel is a change channel as described in the CoreWatcher docs.
    33  type SecretBackendRotateChannel <-chan []SecretBackendRotateChange
    34  
    35  // SecretBackendRotateWatcher conveniently ties a SecretBackendRotateChannel to the
    36  // worker.Worker that represents its validity.
    37  type SecretBackendRotateWatcher interface {
    38  	CoreWatcher
    39  	Changes() SecretBackendRotateChannel
    40  }