Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand coordinator store interface #1237

Merged
merged 2 commits into from
Mar 3, 2025
Merged
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
7 changes: 7 additions & 0 deletions coordinator/history/aferostore.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,10 @@ func (s *AferoStore) CompareAndSwap(key string, oldVal, newVal []byte) error {
}
return s.fs.WriteFile(key, newVal, 0o644)
}

// Watch watches for changes to the value of key.
//
// Not implemented for AferoStore.
func (s *AferoStore) Watch(_ string) (<-chan []byte, func(), error) {
return nil, func() {}, nil
}
18 changes: 9 additions & 9 deletions coordinator/history/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,11 @@ import (
"fmt"
"hash"
"os"

"github.com/spf13/afero"
)

const (
// HashSize is the number of octets in hashes used by this package.
HashSize = sha256.Size

histPath = "/mnt/state/history"
)

// History is the history of the Coordinator.
Expand All @@ -30,13 +26,12 @@ type History struct {
hashFun func() hash.Hash
}

// New creates a new History backed by the default filesystem store.
// New creates a new History backed by the configured store.
func New() (*History, error) {
osFS := afero.NewOsFs()
if err := osFS.MkdirAll(histPath, 0o755); err != nil {
return nil, fmt.Errorf("creating history directory: %w", err)
store, err := NewStore()
if err != nil {
return nil, fmt.Errorf("creating history store: %w", err)
}
store := NewAferoStore(&afero.Afero{Fs: afero.NewBasePathFs(osFS, histPath)})
return NewWithStore(store), nil
}

Expand Down Expand Up @@ -251,4 +246,9 @@ type Store interface {
// If the current value is not equal to oldVal, an error must be returned. The comparison must
// treat a nil slice the same as an empty slice.
CompareAndSwap(key string, oldVal, newVal []byte) error

// Watch watches for changes to the value of key.
//
// If the value of key changes, the new value is sent on the channel.
Watch(key string) (ch <-chan []byte, cancel func(), err error)
}
25 changes: 25 additions & 0 deletions coordinator/history/store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2025 Edgeless Systems GmbH
// SPDX-License-Identifier: AGPL-3.0-only

//go:build !enterprise

package history

import (
"fmt"

"github.com/spf13/afero"
)

const (
histPath = "/mnt/state/history"
)

// NewStore creates a new AferoStore backed by the default filesystem store.
func NewStore() (*AferoStore, error) {
osFS := afero.NewOsFs()
if err := osFS.MkdirAll(histPath, 0o755); err != nil {
return nil, fmt.Errorf("creating history directory: %w", err)
}
return NewAferoStore(&afero.Afero{Fs: afero.NewBasePathFs(osFS, histPath)}), nil
}