need to assert environment metadata when modifying the environment (#369)

This commit is contained in:
Michael Quigley 2023-07-14 09:57:40 -04:00
parent 1c8ab67bf1
commit 48cfaada20
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 22 additions and 0 deletions

View File

@ -27,6 +27,9 @@ func (r *Root) Config() *env_core.Config {
}
func (r *Root) SetConfig(cfg *env_core.Config) error {
if err := assertMetadata(); err != nil {
return err
}
if err := saveConfig(cfg); err != nil {
return err
}
@ -87,6 +90,9 @@ func (r *Root) Environment() *env_core.Environment {
}
func (r *Root) SetEnvironment(env *env_core.Environment) error {
if err := assertMetadata(); err != nil {
return err
}
if err := saveEnvironment(env); err != nil {
return err
}
@ -115,6 +121,9 @@ func (r *Root) ZitiIdentityFile(name string) (string, error) {
}
func (r *Root) SaveZitiIdentity(name, data string) error {
if err := assertMetadata(); err != nil {
return err
}
zif, err := r.ZitiIdentityFile(name)
if err != nil {
return err

View File

@ -65,6 +65,19 @@ func rootExists() (bool, error) {
return true, err
}
func assertMetadata() error {
exists, err := rootExists()
if err != nil {
return err
}
if !exists {
if err := writeMetadata(); err != nil {
return err
}
}
return nil
}
func loadMetadata() (*env_core.Metadata, error) {
mf, err := metadataFile()
if err != nil {