Files
threshold/internal/server/service_rotate_roots.go
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

36 lines
1.3 KiB
Go
Raw Normal View History

2022-06-20 18:20:17 -07:00
package server
import (
"context"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/nodeenrollment"
"github.com/hashicorp/nodeenrollment/rotation"
2022-09-08 13:19:21 -04:00
"github.com/hashicorp/nodeenrollment/types"
)
// RotateRoots is a domain service function that initiates a rotation of root certificates
// via a call to the nodenenrollment RotateRootCertificates function
// Accepts the nodeenrollment option, WithCertificateLifetime(time.Duration) to specify the lifetime
// of the generated cert(s)
2022-09-08 13:19:21 -04:00
func RotateRoots(ctx context.Context, workerAuthRepo *WorkerAuthRepositoryStorage, opt ...nodeenrollment.Option) (*types.RootCertificates, error) {
2022-06-20 18:20:17 -07:00
const op = "server.RotateRoots"
if workerAuthRepo == nil {
2022-09-08 13:19:21 -04:00
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing workerAuthRepo")
}
2022-09-08 13:19:21 -04:00
// Get current root certs so we can pass along the version
rootCerts := &types.RootCertificates{Id: CaId}
err := workerAuthRepo.Load(ctx, rootCerts)
if err != nil && err != nodeenrollment.ErrNotFound {
return nil, errors.Wrap(ctx, err, op)
}
opt = append(opt, nodeenrollment.WithState(rootCerts.GetState()))
roots, err := rotation.RotateRootCertificates(ctx, workerAuthRepo, opt...)
if err != nil {
2022-09-08 13:19:21 -04:00
return nil, errors.Wrap(ctx, err, op)
}
2022-09-08 13:19:21 -04:00
return roots, nil
}