2023-07-11 21:47:13 +02:00
|
|
|
package environment
|
|
|
|
|
|
|
|
import (
|
2023-07-12 22:18:13 +02:00
|
|
|
"github.com/openziti/zrok/environment/env_core"
|
2023-07-14 15:42:06 +02:00
|
|
|
"github.com/openziti/zrok/environment/env_v0_3"
|
2023-07-14 20:30:35 +02:00
|
|
|
"github.com/openziti/zrok/environment/env_v0_4"
|
2023-07-12 23:22:24 +02:00
|
|
|
"github.com/pkg/errors"
|
2023-07-11 21:47:13 +02:00
|
|
|
)
|
|
|
|
|
2023-07-14 20:30:35 +02:00
|
|
|
func LoadRoot() (env_core.Root, error) {
|
|
|
|
if assert, err := env_v0_4.Assert(); assert && err == nil {
|
|
|
|
return env_v0_4.Load()
|
|
|
|
} else if assert, err := env_v0_3.Assert(); assert && err == nil {
|
2023-07-14 16:51:35 +02:00
|
|
|
return env_v0_3.Load()
|
|
|
|
} else {
|
2023-08-01 00:00:06 +02:00
|
|
|
return env_v0_4.Default()
|
2023-07-14 16:51:35 +02:00
|
|
|
}
|
2023-07-11 21:47:13 +02:00
|
|
|
}
|
|
|
|
|
2023-07-14 20:30:35 +02:00
|
|
|
func IsLatest(r env_core.Root) bool {
|
|
|
|
if r == nil {
|
|
|
|
return false
|
2023-07-12 23:22:24 +02:00
|
|
|
}
|
2023-07-14 20:30:35 +02:00
|
|
|
if r.Metadata() == nil {
|
|
|
|
return false
|
2023-07-12 23:22:24 +02:00
|
|
|
}
|
2023-07-14 20:30:35 +02:00
|
|
|
if r.Metadata().V == env_v0_4.V {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
2023-07-12 23:22:24 +02:00
|
|
|
}
|
|
|
|
|
2023-07-14 20:30:35 +02:00
|
|
|
func UpdateRoot(r env_core.Root) (env_core.Root, error) {
|
|
|
|
newR, err := env_v0_4.Update(r)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "unable to update environment")
|
|
|
|
}
|
|
|
|
return newR, nil
|
2023-07-11 21:47:13 +02:00
|
|
|
}
|