31 lines
678 B
Go
31 lines
678 B
Go
package agent
|
|
|
|
import (
|
|
"os"
|
|
|
|
"git.unkin.net/unkin/tomswall/internal/tryapply"
|
|
)
|
|
|
|
// Cache persists the last known-good rendered config to disk so the agent can
|
|
// keep applying it when the control plane is unreachable (never fail closed).
|
|
type Cache struct {
|
|
Path string
|
|
}
|
|
|
|
// Write durably stores the raw config bytes.
|
|
func (c Cache) Write(raw []byte) error {
|
|
return tryapply.WriteFile(c.Path, raw)
|
|
}
|
|
|
|
// Read returns the cached config, or (nil, nil) when no cache exists yet.
|
|
func (c Cache) Read() (*RenderedConfig, error) {
|
|
raw, err := os.ReadFile(c.Path)
|
|
if os.IsNotExist(err) {
|
|
return nil, nil
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return ParseRendered(raw)
|
|
}
|