Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ func buildConfig(coreConfig *configv1.CoreConfiguration, hclText string) (*Confi
type Plugin struct {
nodeattestorv1.UnsafeNodeAttestorServer
configv1.UnsafeConfigServer
config *Config
m sync.Mutex
ns NodeStore
config *Config
m sync.Mutex
NodeStore NodeStore
}

type NodeStore interface {
Expand Down Expand Up @@ -180,21 +180,24 @@ func (s *FileNodeStore) Validate(cfg *configv1.CoreConfiguration, hclCfg string)
}

func New(ns NodeStore) *Plugin {
return &Plugin{ns: ns}
return &Plugin{NodeStore: ns}
}

func NewFromConfig(config *Config) *Plugin {
return &Plugin{
config: config,
ns: &FileNodeStore{
NodeStore: &FileNodeStore{
caPath: config.CaPath,
hashPath: config.HashPath,
},
}
}

func (p *Plugin) Configure(ctx context.Context, req *configv1.ConfigureRequest) (*configv1.ConfigureResponse, error) {
cfg, err := p.ns.Configure(req.GetCoreConfiguration(), req.GetHclConfiguration())
p.m.Lock()
defer p.m.Unlock()

cfg, err := p.NodeStore.Configure(req.GetCoreConfiguration(), req.GetHclConfiguration())
if err != nil {
return nil, err
}
Expand All @@ -204,7 +207,10 @@ func (p *Plugin) Configure(ctx context.Context, req *configv1.ConfigureRequest)
}

func (p *Plugin) Validate(_ context.Context, req *configv1.ValidateRequest) (*configv1.ValidateResponse, error) {
err := p.ns.Validate(req.GetCoreConfiguration(), req.GetHclConfiguration())
p.m.Lock()
defer p.m.Unlock()

err := p.NodeStore.Validate(req.GetCoreConfiguration(), req.GetHclConfiguration())

var notes []string
if err != nil {
Expand Down Expand Up @@ -248,7 +254,7 @@ func (p *Plugin) Attest(stream nodeattestorv1.NodeAttestor_AttestServer) error {
return err
}

if err := p.ns.Attest(stream.Context(), ek); err != nil {
if err := p.NodeStore.Attest(stream.Context(), ek); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestNodeStore_Attest_Success(t *testing.T) {
}
p := NewFromConfig(config)

err = p.ns.Attest(context.Background(), ekWrapper)
err = p.NodeStore.Attest(context.Background(), ekWrapper)
assert.NoError(t, err, "NodeStore should validate the EK against the file on disk")
}

Expand All @@ -46,7 +46,7 @@ func TestNodeStore_Attest_Failure(t *testing.T) {
HashPath: t.TempDir(),
})

err := p.ns.Attest(context.Background(), ekWrapper)
err := p.NodeStore.Attest(context.Background(), ekWrapper)

assert.Error(t, err)
assert.Contains(t, err.Error(), "could not validate EK")
Expand Down