Signed-off-by: Jonathan Collinge <jonathancollinge@live.com>
This commit is contained in:
Jonathan Collinge 2025-05-11 09:16:05 +01:00
parent c529962a9d
commit 6427592335
No known key found for this signature in database
GPG Key ID: BF9B59005264DD95
2 changed files with 13 additions and 5 deletions

View File

@ -33,6 +33,14 @@ import (
"github.com/dapr/kit/logger"
)
var (
// ErrTrustAnchorsClosed is returned when an operation is performed on closed trust anchors.
ErrTrustAnchorsClosed = errors.New("trust anchors is closed")
// ErrFailedToReadTrustAnchorsFile is returned when the trust anchors file cannot be read.
ErrFailedToReadTrustAnchorsFile = errors.New("failed to read trust anchors file")
)
type OptionsFile struct {
Log logger.Logger
CAPath string
@ -145,7 +153,7 @@ func (f *file) Run(ctx context.Context) error {
f.log.Info("Trust anchors file changed, reloading trust anchors")
if err = f.updateAnchors(ctx); err != nil {
return fmt.Errorf("failed to read trust anchors file '%s': %v", f.caPath, err)
return fmt.Errorf("%w: '%s': %v", ErrFailedToReadTrustAnchorsFile, f.caPath, err)
}
}
}
@ -158,7 +166,7 @@ func (f *file) CurrentTrustAnchors(ctx context.Context) ([]byte, error) {
case <-ctx.Done():
return nil, ctx.Err()
case <-f.closeCh:
return nil, errors.New("trust anchors is closed")
return nil, ErrTrustAnchorsClosed
case <-f.readyCh:
}
@ -219,7 +227,7 @@ func (f *file) updateAnchors(ctx context.Context) error {
func (f *file) GetX509BundleForTrustDomain(_ spiffeid.TrustDomain) (*x509bundle.Bundle, error) {
select {
case <-f.closeCh:
return nil, errors.New("trust anchors is closed")
return nil, ErrTrustAnchorsClosed
case <-f.readyCh:
}
@ -232,7 +240,7 @@ func (f *file) GetX509BundleForTrustDomain(_ spiffeid.TrustDomain) (*x509bundle.
func (f *file) GetJWTBundleForTrustDomain(_ spiffeid.TrustDomain) (*jwtbundle.Bundle, error) {
select {
case <-f.closeCh:
return nil, errors.New("trust anchors is closed")
return nil, ErrTrustAnchorsClosed
case <-f.readyCh:
}

View File

@ -86,7 +86,7 @@ func (s *static) GetX509BundleForTrustDomain(spiffeid.TrustDomain) (*x509bundle.
return s.x509Bundle, nil
}
func (s *static) GetJWTBundleForTrustDomain(td spiffeid.TrustDomain) (*jwtbundle.Bundle, error) {
func (s *static) GetJWTBundleForTrustDomain(_ spiffeid.TrustDomain) (*jwtbundle.Bundle, error) {
return s.jwtBundle, nil
}