2017-08-30 03:24:12 +02:00
|
|
|
// Copyright 2017, Pulumi Corporation. All rights reserved.
|
|
|
|
|
2017-08-23 01:56:15 +02:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/pulumi/pulumi-fabric/pkg/tokens"
|
|
|
|
)
|
|
|
|
|
2017-08-31 23:31:33 +02:00
|
|
|
func (eng *Engine) SetConfig(envName string, key tokens.ModuleMember, value string) error {
|
2017-08-23 19:58:35 +02:00
|
|
|
info, err := eng.initEnvCmdName(tokens.QName(envName), "")
|
2017-08-23 01:56:15 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-08-31 23:31:33 +02:00
|
|
|
config := info.Target.Config
|
2017-08-23 01:56:15 +02:00
|
|
|
if config == nil {
|
2017-08-31 23:31:33 +02:00
|
|
|
config = make(map[tokens.ModuleMember]string)
|
2017-08-23 01:56:15 +02:00
|
|
|
info.Target.Config = config
|
|
|
|
}
|
|
|
|
|
2017-08-30 03:24:12 +02:00
|
|
|
config[key] = value
|
2017-08-23 01:56:15 +02:00
|
|
|
|
2017-08-30 03:25:50 +02:00
|
|
|
if err = eng.Environment.SaveEnvironment(info.Target, info.Snapshot); err != nil {
|
2017-08-31 19:28:20 +02:00
|
|
|
return errors.Wrap(err, "could not save configuration value")
|
2017-08-23 01:56:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2017-08-25 19:51:39 +02:00
|
|
|
|
|
|
|
// 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
|
2017-08-31 23:31:33 +02:00
|
|
|
func (eng *Engine) ReplaceConfig(envName string, newConfig map[tokens.ModuleMember]string) error {
|
2017-08-25 19:51:39 +02:00
|
|
|
info, err := eng.initEnvCmdName(tokens.QName(envName), "")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-08-31 23:31:33 +02:00
|
|
|
config := make(map[tokens.ModuleMember]string)
|
2017-08-30 03:24:12 +02:00
|
|
|
for key, v := range newConfig {
|
|
|
|
config[key] = v
|
2017-08-25 19:51:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
info.Target.Config = config
|
|
|
|
|
2017-08-30 03:25:50 +02:00
|
|
|
if err = eng.Environment.SaveEnvironment(info.Target, info.Snapshot); err != nil {
|
2017-08-31 19:28:20 +02:00
|
|
|
return errors.Wrap(err, "could not save configuration value")
|
2017-08-25 19:51:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|