本文整理汇总了Golang中launchpad/net/juju-core/environs/config.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestEnvironConfigWithAdminSecret
func (s *StateSuite) TestEnvironConfigWithAdminSecret(c *C) {
attrs := map[string]interface{}{
"name": "test",
"type": "test",
"authorized-keys": "i-am-a-key",
"default-series": "precise",
"development": true,
"admin-secret": "foo",
"ca-cert": testing.CACert,
"ca-private-key": "",
}
cfg, err := config.New(attrs)
c.Assert(err, IsNil)
_, err = state.Initialize(state.TestingStateInfo(), cfg)
c.Assert(err, ErrorMatches, "admin-secret should never be written to the state")
delete(attrs, "admin-secret")
cfg, err = config.New(attrs)
st, err := state.Initialize(state.TestingStateInfo(), cfg)
c.Assert(err, IsNil)
st.Close()
cfg, err = cfg.Apply(map[string]interface{}{"admin-secret": "foo"})
err = s.State.SetEnvironConfig(cfg)
c.Assert(err, ErrorMatches, "admin-secret should never be written to the state")
}
示例2: TestEnvironConfig
func (s *StateSuite) TestEnvironConfig(c *C) {
initial := map[string]interface{}{
"name": "test",
"type": "test",
"authorized-keys": "i-am-a-key",
"default-series": "precise",
"development": true,
"firewall-mode": "",
"admin-secret": "",
"ca-cert": testing.CACert,
"ca-private-key": "",
"ssl-hostname-verification": true,
}
cfg, err := config.New(initial)
c.Assert(err, IsNil)
st, err := state.Initialize(state.TestingStateInfo(), cfg)
c.Assert(err, IsNil)
st.Close()
c.Assert(err, IsNil)
cfg, err = s.State.EnvironConfig()
c.Assert(err, IsNil)
current := cfg.AllAttrs()
c.Assert(current, DeepEquals, initial)
current["authorized-keys"] = "i-am-a-new-key"
cfg, err = config.New(current)
c.Assert(err, IsNil)
err = s.State.SetEnvironConfig(cfg)
c.Assert(err, IsNil)
cfg, err = s.State.EnvironConfig()
c.Assert(err, IsNil)
final := cfg.AllAttrs()
c.Assert(final, DeepEquals, current)
}
示例3: TestValidateRejectsChangingStorageContainer
func (*ConfigSuite) TestValidateRejectsChangingStorageContainer(c *C) {
attrs := makeAzureConfigMap(c)
newConfig, err := config.New(attrs)
c.Assert(err, IsNil)
provider := azureEnvironProvider{}
attrs["storage-container-name"] = "another name"
oldConfig, err := config.New(attrs)
c.Assert(err, IsNil)
_, err = provider.Validate(newConfig, oldConfig)
c.Check(err, ErrorMatches, ".*cannot change storage-container-name.*")
}
示例4: TestValidateAcceptsUnchangedConfig
func (*ConfigSuite) TestValidateAcceptsUnchangedConfig(c *C) {
attrs := makeAzureConfigMap(c)
provider := azureEnvironProvider{}
oldConfig, err := config.New(attrs)
c.Assert(err, IsNil)
newConfig, err := config.New(attrs)
c.Assert(err, IsNil)
result, err := provider.Validate(newConfig, oldConfig)
c.Assert(err, IsNil)
c.Check(result.Name(), Equals, attrs["name"])
}
示例5: TestValidateChecksConfigChanges
func (*ConfigSuite) TestValidateChecksConfigChanges(c *C) {
provider := azureEnvironProvider{}
oldAttrs := makeBaseConfigMap()
oldConfig, err := config.New(oldAttrs)
c.Assert(err, IsNil)
newAttrs := makeBaseConfigMap()
newAttrs["name"] = "different-name"
newConfig, err := config.New(newAttrs)
c.Assert(err, IsNil)
_, err = provider.Validate(newConfig, oldConfig)
c.Check(err, NotNil)
}
示例6: TestValidateParsesAzureConfig
func (*ConfigSuite) TestValidateParsesAzureConfig(c *C) {
managementSubscriptionId := "subscription-id"
certificate := "certificate content"
storageAccountName := "account-name"
storageAccountKey := "account-key"
storageContainerName := "container-name"
publicStorageAccountName := "public-account-name"
publicStorageContainerName := "public-container-name"
unknownFutureSetting := "preserved"
azureConfig := map[string]interface{}{
"management-subscription-id": managementSubscriptionId,
"management-certificate": certificate,
"storage-account-name": storageAccountName,
"storage-account-key": storageAccountKey,
"storage-container-name": storageContainerName,
"public-storage-account-name": publicStorageAccountName,
"public-storage-container-name": publicStorageContainerName,
"unknown-future-setting": unknownFutureSetting,
}
attrs := makeConfigMap(azureConfig)
provider := azureEnvironProvider{}
config, err := config.New(attrs)
c.Assert(err, IsNil)
azConfig, err := provider.newConfig(config)
c.Assert(err, IsNil)
c.Check(azConfig.Name(), Equals, attrs["name"])
c.Check(azConfig.ManagementSubscriptionId(), Equals, managementSubscriptionId)
c.Check(azConfig.ManagementCertificate(), Equals, certificate)
c.Check(azConfig.StorageAccountName(), Equals, storageAccountName)
c.Check(azConfig.StorageAccountKey(), Equals, storageAccountKey)
c.Check(azConfig.StorageContainerName(), Equals, storageContainerName)
c.Check(azConfig.PublicStorageAccountName(), Equals, publicStorageAccountName)
c.Check(azConfig.PublicStorageContainerName(), Equals, publicStorageContainerName)
c.Check(azConfig.UnknownAttrs()["unknown-future-setting"], Equals, unknownFutureSetting)
}
示例7: TestFirewallMode
func (*ConfigSuite) TestFirewallMode(c *C) {
for _, test := range firewallModeTests {
c.Logf("test firewall mode %q", test.configFirewallMode)
cfgMap := map[string]interface{}{
"name": "only",
"type": "dummy",
"state-server": true,
"authorized-keys": "none",
"ca-cert": testing.CACert,
"ca-private-key": "",
}
if test.configFirewallMode != "" {
cfgMap["firewall-mode"] = test.configFirewallMode
}
cfg, err := config.New(cfgMap)
if err != nil {
c.Assert(err, ErrorMatches, test.errorMsg)
continue
}
env, err := environs.New(cfg)
if err != nil {
c.Assert(err, ErrorMatches, test.errorMsg)
continue
}
firewallMode := env.Config().FirewallMode()
c.Assert(firewallMode, Equals, test.firewallMode)
}
}
示例8: TestBootstrapConfig
func (suite) TestBootstrapConfig(c *C) {
defer makeFakeHome(c, "bladaam").restore()
cfg, err := config.New(map[string]interface{}{
"name": "bladaam",
"type": "dummy",
"state-server": false,
"admin-secret": "highly",
"secret": "um",
"authorized-keys": "i-am-a-key",
"ca-cert": testing.CACert,
"ca-private-key": testing.CAKey,
})
c.Assert(err, IsNil)
provider, err := environs.Provider(cfg.Type())
c.Assert(err, IsNil)
tools := &state.Tools{
URL: "http://x",
Binary: version.MustParseBinary("1.2.3-foo-bar"),
}
cfg1, err := environs.BootstrapConfig(provider, cfg, tools)
c.Assert(err, IsNil)
expect := cfg.AllAttrs()
delete(expect, "secret")
expect["admin-secret"] = ""
expect["ca-private-key"] = ""
expect["agent-version"] = "1.2.3"
c.Assert(cfg1.AllAttrs(), DeepEquals, expect)
}
示例9: TestWatchEnvironConfig
func (s *StateSuite) TestWatchEnvironConfig(c *C) {
watcher := s.State.WatchEnvironConfig()
defer func() {
c.Assert(watcher.Stop(), IsNil)
}()
for i, test := range watchEnvironConfigTests {
c.Logf("test %d", i)
change, err := config.New(test)
c.Assert(err, IsNil)
if i == 0 {
st, err := state.Initialize(state.TestingStateInfo(), change)
c.Assert(err, IsNil)
st.Close()
} else {
err = s.State.SetEnvironConfig(change)
c.Assert(err, IsNil)
}
c.Assert(err, IsNil)
s.State.StartSync()
select {
case got, ok := <-watcher.Changes():
c.Assert(ok, Equals, true)
c.Assert(got.AllAttrs(), DeepEquals, change.AllAttrs())
case <-time.After(500 * time.Millisecond):
c.Fatalf("did not get change: %#v", test)
}
}
select {
case got := <-watcher.Changes():
c.Fatalf("got unexpected change: %#v", got)
case <-time.After(50 * time.Millisecond):
}
}
示例10: TestConfigAttrs
func (*ConfigSuite) TestConfigAttrs(c *gc.C) {
attrs := map[string]interface{}{
"type": "my-type",
"name": "my-name",
"authorized-keys": "my-keys",
"firewall-mode": string(config.FwDefault),
"admin-secret": "foo",
"unknown": "my-unknown",
"ca-private-key": "",
"ca-cert": caCert,
"ssl-hostname-verification": true,
}
cfg, err := config.New(attrs)
c.Assert(err, gc.IsNil)
// These attributes are added if not set.
attrs["development"] = false
attrs["default-series"] = config.DefaultSeries
// Default firewall mode is instance
attrs["firewall-mode"] = string(config.FwInstance)
c.Assert(cfg.AllAttrs(), gc.DeepEquals, attrs)
c.Assert(cfg.UnknownAttrs(), gc.DeepEquals, map[string]interface{}{"unknown": "my-unknown"})
newcfg, err := cfg.Apply(map[string]interface{}{
"name": "new-name",
"new-unknown": "my-new-unknown",
})
attrs["name"] = "new-name"
attrs["new-unknown"] = "my-new-unknown"
c.Assert(newcfg.AllAttrs(), gc.DeepEquals, attrs)
}
示例11: step
func (createServiceAndUnit) step(c *C, ctx *context) {
cfg, err := config.New(map[string]interface{}{
"name": "testenv",
"type": "dummy",
"default-series": "abominable",
"agent-version": "1.2.3",
"authorized-keys": "we-are-the-keys",
"ca-cert": coretesting.CACert,
"ca-private-key": "",
})
c.Assert(err, IsNil)
err = ctx.st.SetEnvironConfig(cfg)
c.Assert(err, IsNil)
sch, err := ctx.st.Charm(curl(0))
c.Assert(err, IsNil)
svc, err := ctx.st.AddService("u", sch)
c.Assert(err, IsNil)
unit, err := svc.AddUnit()
c.Assert(err, IsNil)
// Assign the unit to a provisioned machine to match expected state.
err = unit.AssignToNewMachine()
c.Assert(err, IsNil)
mid, err := unit.AssignedMachineId()
c.Assert(err, IsNil)
machine, err := ctx.st.Machine(mid)
c.Assert(err, IsNil)
err = machine.SetProvisioned("i-exist", "fake_nonce", nil)
c.Assert(err, IsNil)
ctx.svc = svc
ctx.unit = unit
}
示例12: TestConfigAttrs
func (*ConfigSuite) TestConfigAttrs(c *C) {
attrs := map[string]interface{}{
"type": "my-type",
"name": "my-name",
"authorized-keys": "my-keys",
"firewall-mode": string(config.FwDefault),
"default-series": version.Current.Series,
"admin-secret": "foo",
"unknown": "my-unknown",
"ca-private-key": "",
"ca-cert": caCert,
"ssl-hostname-verification": true,
}
cfg, err := config.New(attrs)
c.Assert(err, IsNil)
attrs["development"] = false // This attribute is added if not set.
c.Assert(cfg.AllAttrs(), DeepEquals, attrs)
c.Assert(cfg.UnknownAttrs(), DeepEquals, map[string]interface{}{"unknown": "my-unknown"})
newcfg, err := cfg.Apply(map[string]interface{}{
"name": "new-name",
"new-unknown": "my-new-unknown",
})
attrs["name"] = "new-name"
attrs["new-unknown"] = "my-new-unknown"
c.Assert(newcfg.AllAttrs(), DeepEquals, attrs)
}
示例13: BootstrapConfig
// BootstrapConfig returns a copy of the supplied configuration with
// secret attributes removed. If the resulting config is not suitable
// for bootstrapping an environment, an error is returned.
func BootstrapConfig(cfg *config.Config) (*config.Config, error) {
p, err := Provider(cfg.Type())
if err != nil {
return nil, err
}
secrets, err := p.SecretAttrs(cfg)
if err != nil {
return nil, err
}
m := cfg.AllAttrs()
for k := range secrets {
delete(m, k)
}
// We never want to push admin-secret or the root CA private key to the cloud.
delete(m, "admin-secret")
m["ca-private-key"] = ""
if cfg, err = config.New(m); err != nil {
return nil, err
}
if _, ok := cfg.AgentVersion(); !ok {
return nil, fmt.Errorf("environment configuration has no agent-version")
}
return cfg, nil
}
示例14: Run
// Run initializes state for an environment.
func (c *BootstrapCommand) Run(_ *cmd.Context) error {
if err := c.Conf.read("bootstrap"); err != nil {
return err
}
cfg, err := config.New(c.EnvConfig)
if err != nil {
return err
}
// There is no entity that's created at init time.
c.Conf.StateInfo.EntityName = ""
st, err := state.Initialize(c.Conf.StateInfo, cfg)
if err != nil {
return err
}
defer st.Close()
m, err := st.InjectMachine(state.InstanceId(c.InstanceId), state.JobManageEnviron)
if err != nil {
return err
}
if c.Conf.OldPassword != "" {
if err := m.SetMongoPassword(c.Conf.OldPassword); err != nil {
return err
}
if err := st.SetAdminMongoPassword(c.Conf.OldPassword); err != nil {
return err
}
}
return nil
}
示例15: loop
func (w *EnvironConfigWatcher) loop() (err error) {
sw := w.st.watchSettings(environGlobalKey)
defer sw.Stop()
out := w.out
out = nil
cfg := &config.Config{}
for {
select {
case <-w.st.watcher.Dead():
return watcher.MustErr(w.st.watcher)
case <-w.tomb.Dying():
return tomb.ErrDying
case settings, ok := <-sw.Changes():
if !ok {
return watcher.MustErr(sw)
}
cfg, err = config.New(settings.Map())
if err == nil {
out = w.out
} else {
out = nil
}
case out <- cfg:
out = nil
}
}
return nil
}