mirror of
https://github.com/openziti/zrok.git
synced 2025-01-03 20:49:13 +01:00
need to assert environment metadata when modifying the environment (#369)
This commit is contained in:
parent
1c8ab67bf1
commit
48cfaada20
@ -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
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user