We'd like to abstract out environment CRUD operations and I'd prefer not to have to bake in the conspect of a file name like thing in the abstraction. Since we were not really using this feature many places, let's just get rid of it.
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package engine
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
"github.com/pulumi/pulumi-fabric/pkg/resource"
|
|
"github.com/pulumi/pulumi-fabric/pkg/tokens"
|
|
)
|
|
|
|
func (eng *Engine) SetConfig(envName string, key string, value string) error {
|
|
info, err := eng.initEnvCmdName(tokens.QName(envName), "")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
config := info.Target.Config
|
|
|
|
if config == nil {
|
|
config = make(resource.ConfigMap)
|
|
info.Target.Config = config
|
|
}
|
|
|
|
config[tokens.Token(key)] = value
|
|
|
|
if !eng.saveEnv(info.Target, info.Snapshot, true) {
|
|
return errors.Errorf("could not save configuration value")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// ReplaceConfig sets the config for an environment to match `newConfig` and then saves
|
|
// the environment. Note that config values that were present in the old environment but are
|
|
// not present in `newConfig` will be removed from the environment
|
|
func (eng *Engine) ReplaceConfig(envName string, newConfig map[string]string) error {
|
|
info, err := eng.initEnvCmdName(tokens.QName(envName), "")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
config := make(resource.ConfigMap)
|
|
|
|
for k, v := range newConfig {
|
|
config[tokens.Token(k)] = v
|
|
}
|
|
|
|
info.Target.Config = config
|
|
|
|
if !eng.saveEnv(info.Target, info.Snapshot, true) {
|
|
return errors.Errorf("could not save configuration value")
|
|
}
|
|
|
|
return nil
|
|
}
|