// CharmArchiveURL returns the URL, corresponding to the charm archive // (bundle) in the provider storage for each given charm URL, along // with the DisableSSLHostnameVerification flag. func (u *UniterAPI) CharmArchiveURL(args params.CharmURLs) (params.CharmArchiveURLResults, error) { result := params.CharmArchiveURLResults{ Results: make([]params.CharmArchiveURLResult, len(args.URLs)), } // Get the SSL hostname verification environment setting. envConfig, err := u.st.EnvironConfig() if err != nil { return result, err } // SSLHostnameVerification defaults to true, so we need to // invert that, for backwards-compatibility (older versions // will have DisableSSLHostnameVerification: false by default). disableSSLHostnameVerification := !envConfig.SSLHostnameVerification() for i, arg := range args.URLs { curl, err := charm.ParseURL(arg.URL) if err != nil { err = common.ErrPerm } else { var sch *state.Charm sch, err = u.st.Charm(curl) if errors.IsNotFound(err) { err = common.ErrPerm } if err == nil { result.Results[i].Result = sch.BundleURL().String() result.Results[i].DisableSSLHostnameVerification = disableSSLHostnameVerification } } result.Results[i].Error = common.ServerError(err) } return result, nil }
// parseSettingsCompatible parses setting strings in a way that is // compatible with the behavior before this CL based on the issue // http://pad.lv/1194945. Until then setting an option to an empty // string caused it to reset to the default value. We now allow // empty strings as actual values, but we want to preserve the API // behavior. func parseSettingsCompatible(ch *state.Charm, settings map[string]string) (charm.Settings, error) { setSettings := map[string]string{} unsetSettings := charm.Settings{} // Split settings into those which set and those which unset a value. for name, value := range settings { if value == "" { unsetSettings[name] = nil continue } setSettings[name] = value } // Validate the settings. changes, err := ch.Config().ParseSettingsStrings(setSettings) if err != nil { return nil, err } // Validate the unsettings and merge them into the changes. unsetSettings, err = ch.Config().ValidateSettings(unsetSettings) if err != nil { return nil, err } for name := range unsetSettings { changes[name] = nil } return changes, nil }
func assertCustomCharm(c *gc.C, ch *state.Charm, series string, meta *charm.Meta, config *charm.Config, revision int) { // Check Charm interface method results. c.Assert(ch.Meta(), gc.DeepEquals, meta) c.Assert(ch.Config(), gc.DeepEquals, config) c.Assert(ch.Revision(), gc.DeepEquals, revision) // Test URL matches charm and expected series. url := ch.URL() c.Assert(url.Series, gc.Equals, series) c.Assert(url.Revision, gc.Equals, ch.Revision()) // Ignore the BundleURL and BundleSHA256 methods, they're irrelevant. }
func (s *ServiceSuite) TestSetCharmConfig(c *gc.C) { charms := map[string]*state.Charm{ stringConfig: s.AddConfigCharm(c, "wordpress", stringConfig, 1), emptyConfig: s.AddConfigCharm(c, "wordpress", emptyConfig, 2), floatConfig: s.AddConfigCharm(c, "wordpress", floatConfig, 3), newStringConfig: s.AddConfigCharm(c, "wordpress", newStringConfig, 4), } for i, t := range setCharmConfigTests { c.Logf("test %d: %s", i, t.summary) origCh := charms[t.startconfig] svc := s.AddTestingService(c, "wordpress", origCh) err := svc.UpdateConfigSettings(t.startvalues) c.Assert(err, gc.IsNil) newCh := charms[t.endconfig] err = svc.SetCharm(newCh, false) var expectVals charm.Settings var expectCh *state.Charm if t.err != "" { c.Assert(err, gc.ErrorMatches, t.err) expectCh = origCh expectVals = t.startvalues } else { c.Assert(err, gc.IsNil) expectCh = newCh expectVals = t.endvalues } sch, _, err := svc.Charm() c.Assert(err, gc.IsNil) c.Assert(sch.URL(), gc.DeepEquals, expectCh.URL()) settings, err := svc.ConfigSettings() c.Assert(err, gc.IsNil) if len(expectVals) == 0 { c.Assert(settings, gc.HasLen, 0) } else { c.Assert(settings, gc.DeepEquals, expectVals) } err = svc.Destroy() c.Assert(err, gc.IsNil) } }
// CharmArchiveSha256 returns the SHA256 digest of the charm archive // (bundle) data for each charm url in the given parameters. func (u *UniterAPI) CharmArchiveSha256(args params.CharmURLs) (params.StringResults, error) { result := params.StringResults{ Results: make([]params.StringResult, len(args.URLs)), } for i, arg := range args.URLs { curl, err := charm.ParseURL(arg.URL) if err != nil { err = common.ErrPerm } else { var sch *state.Charm sch, err = u.st.Charm(curl) if errors.IsNotFound(err) { err = common.ErrPerm } if err == nil { result.Results[i].Result = sch.BundleSha256() } } result.Results[i].Error = common.ServerError(err) } return result, nil }
func assertCharm(c *gc.C, bun charm.Bundle, sch *state.Charm) { actual := bun.(*corecharm.Bundle) c.Assert(actual.Revision(), gc.Equals, sch.Revision()) c.Assert(actual.Meta(), gc.DeepEquals, sch.Meta()) c.Assert(actual.Config(), gc.DeepEquals, sch.Config()) }
func assertStandardCharm(c *gc.C, ch *state.Charm, series string) { chd := testing.Charms.Dir(ch.Meta().Name) assertCustomCharm(c, ch, series, chd.Meta(), chd.Config(), chd.Revision()) }