package agent import ( "os" "path/filepath" ) // 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 atomically stores the raw config bytes. func (c Cache) Write(raw []byte) error { if err := os.MkdirAll(filepath.Dir(c.Path), 0o755); err != nil { return err } tmp := c.Path + ".tmp" if err := os.WriteFile(tmp, raw, 0o600); err != nil { return err } return os.Rename(tmp, c.Path) } // 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) }