-
Notifications
You must be signed in to change notification settings - Fork 16
/
manager.go
88 lines (74 loc) · 2.83 KB
/
manager.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package bundlemanager
import (
"context"
"errors"
"time"
"github.com/HewlettPackard/galadriel/pkg/common/telemetry"
"github.com/HewlettPackard/galadriel/pkg/common/util"
"github.com/HewlettPackard/galadriel/pkg/harvester/galadrielclient"
"github.com/HewlettPackard/galadriel/pkg/harvester/integrity"
"github.com/HewlettPackard/galadriel/pkg/harvester/spireclient"
"github.com/sirupsen/logrus"
)
const (
defaultFederatedBundlesPollInterval = 2 * time.Minute
defaultSpireBundlesPollInterval = 1 * time.Minute
spireCallTimeout = 10 * time.Second
galadrielCallTimeout = 2 * time.Minute
)
// BundleManager is responsible for managing the synchronization and watching of bundles.
type BundleManager struct {
federatedBundlesSynchronizer *FederatedBundlesSynchronizer
spireBundleSynchronizer *SpireBundleSynchronizer
}
// Config holds the configuration for BundleManager.
type Config struct {
SpireClient spireclient.Client
GaladrielClient galadrielclient.Client
FederatedBundlesPollInterval time.Duration
SpireBundlePollInterval time.Duration
// BundleSigner is used to sign the bundle before uploading it to Galadriel Server.
BundleSigner integrity.Signer
// BundleVerifiers are used to verify the bundle received from the SPIRE Server.
BundleVerifiers []integrity.Verifier
Logger logrus.FieldLogger
}
// NewBundleManager creates a new BundleManager instance.
func NewBundleManager(c *Config) *BundleManager {
if c.FederatedBundlesPollInterval == 0 {
c.FederatedBundlesPollInterval = defaultFederatedBundlesPollInterval
}
if c.SpireBundlePollInterval == 0 {
c.SpireBundlePollInterval = defaultSpireBundlesPollInterval
}
spireBundleSync := NewSpireSynchronizer(&SpireSynchronizerConfig{
GaladrielClient: c.GaladrielClient,
SpireClient: c.SpireClient,
BundleSigner: c.BundleSigner,
SyncInterval: c.SpireBundlePollInterval,
Logger: c.Logger.WithField(telemetry.SubsystemName, telemetry.SpireBundleSynchronizer),
})
fedBundlesSync := NewFederatedBundlesSynchronizer(&FederatedBundlesSynchronizerConfig{
GaladrielClient: c.GaladrielClient,
SpireClient: c.SpireClient,
BundleVerifiers: c.BundleVerifiers,
SyncInterval: c.FederatedBundlesPollInterval,
Logger: c.Logger.WithField(telemetry.SubsystemName, telemetry.FederatedBundlesSynchronizer),
})
return &BundleManager{
federatedBundlesSynchronizer: fedBundlesSync,
spireBundleSynchronizer: spireBundleSync,
}
}
// Run runs the bundle synchronization processes.
func (bm *BundleManager) Run(ctx context.Context) error {
tasks := []func(ctx context.Context) error{
bm.federatedBundlesSynchronizer.StartSyncing,
bm.spireBundleSynchronizer.StartSyncing,
}
err := util.RunTasks(ctx, tasks...)
if errors.Is(err, context.Canceled) {
return nil
}
return err
}