// updateSettings fetches the service config from luci-config and then stores
// the new config into the datastore.
500634
func updateSettings(c context.Context) error {
	// Load the settings from luci-config.
	cs := cfgclient.CurrentServiceConfigSet(c)
	lucicfg := GetConfigService(c)
	cfg, err := lucicfg.GetConfig(c, cs, "settings.cfg", false)
	if err != nil {
		return errors.Annotate(err, "loading settings.cfg from luci-config").Err()
	}

	// Do the revision check & swap in a datastore transaction.
	return datastore.RunInTransaction(c, func(c context.Context) error {
		oldSettings := Settings{}
		err := datastore.Get(c, &oldSettings)
		switch err {
		case datastore.ErrNoSuchEntity:
			// This might be the first time this has run, so a warning here is ok.
			logging.WithError(err).Warningf(c, "no existing service config")
		case nil:
			// Continue
		default:
			return errors.Annotate(err, "loading existing config").Err()
		}
		// Check to see if we need to update
		if oldSettings.Revision == cfg.Revision {
			logging.Debugf(c, "revisions matched (%s), no need to update", cfg.Revision)
			return nil
		}
		newSettings := Settings{Revision: cfg.Revision}
		if err := proto.UnmarshalText(cfg.Content, &newSettings.Settings); err != nil {
			return errors.Annotate(err, "unmarshalling proto").Err()
		}
		ctx := &validation.Context{Context: c}
		ctx.SetFile("settings.cfg")
		validateSettings(ctx, &newSettings.Settings)
		if err := ctx.Finalize(); err != nil {
			return errors.Annotate(err, "validating settings").Err()
		}
		return datastore.Put(c, &newSettings)
	}, nil)
}
1177388
func (s *PresetSettings) SetContainerSettings(v *ContainerSettings) *PresetSettings {
	s.ContainerSettings = v
	return s
}
372367
func (s *UpdatePresetInput) SetSettings(v *PresetSettings) *UpdatePresetInput {
	s.Settings = v
	return s
}
473888
func (c ItemChanges) CurrentSettings(defaults charm.Settings) map[string]interface{} {
	result := make(map[string]interface{})
	for _, change := range c {
		key := change.Key

		switch {
		case change.IsModification() && reflect.DeepEqual(change.OldValue, change.NewValue):
			// These are placeholders that we do not apply.
			// See comment in ApplyDeltaSource, above.
		case change.IsDeletion():
			result[key] = defaults[key]
		default:
			result[key] = change.NewValue
		}
	}
	return result
}
706425
func (a *Archivist) loadSettings(c context.Context, project types.ProjectName) (*Settings, error) {
	if a.SettingsLoader == nil {
		panic("no settings loader configured")
	}

	st, err := a.SettingsLoader(c, project)
	switch {
	case err != nil:
		return nil, err

	case st.GSBase.Bucket() == "":
		log.Fields{
			log.ErrorKey: err,
			"gsBase":     st.GSBase,
		}.Errorf(c, "Invalid storage base.")
		return nil, errors.New("invalid storage base")

	case st.GSStagingBase.Bucket() == "":
		log.Fields{
			log.ErrorKey:    err,
			"gsStagingBase": st.GSStagingBase,
		}.Errorf(c, "Invalid storage staging base.")
		return nil, errors.New("invalid storage staging base")

	default:
		return st, nil
	}
}
926523
func GetSettings(c context.Context) *config.Settings {
	settings := config.Settings{
		Buildbot: &config.Settings_Buildbot{},
	}

	msg, err := GetCurrentServiceConfig(c)
	if err != nil {
		// The service config does not exist, just return an empty config
		// and complain loudly in the logs.
		logging.WithError(err).Errorf(c,
			"Encountered error while loading service config, using empty config.")
		return &settings
	}

	err = proto.Unmarshal(msg.Data, &settings)
	if err != nil {
		// The service config is broken, just return an empty config
		// and complain loudly in the logs.
		logging.WithError(err).Errorf(c,
			"Encountered error while unmarshalling service config, using empty config.")
		// Zero out the message just incase something got written in.
		settings = config.Settings{Buildbot: &config.Settings_Buildbot{}}
	}

	return &settings
}
192639
func (m *MemoryStorage) UpdateSetting(c context.Context, key string, value json.RawMessage, who, why string) error {
	m.lock.Lock()
	defer m.lock.Unlock()
	if m.values == nil {
		m.values = make(map[string]*json.RawMessage, 1)
	}
	cpy := append(json.RawMessage(nil), value...)
	m.values[key] = &cpy
	return nil
}
76819
func (s *CreateEnvironmentInput) SetOptionSettings(v []*ConfigurationOptionSetting) *CreateEnvironmentInput {
	s.OptionSettings = v
	return s
}
1190794
func (cfg *ubuntuCloudConfig) updateProxySettings(proxySettings proxy.Settings) {
	// Write out the apt proxy settings
	if (proxySettings != proxy.Settings{}) {
		filename := config.AptProxyConfigFile
		cfg.AddBootCmd(fmt.Sprintf(
			`printf '%%s\n' %s > %s`,
			utils.ShQuote(cfg.paccmder.ProxyConfigContents(proxySettings)),
			filename))
	}
}
143872
func (c *Conn) UpdateSetting(args map[string]interface{}, filter_indices ...string) (ClusterStateResponse, error) {
	var url string
	var retval ClusterStateResponse

	url = "/_cluster/state"

	body, err := c.DoCommand("GET", url, args, nil)
	if err != nil {
		return retval, err
	}
	if err == nil {
		// marshall into json
		jsonErr := json.Unmarshal(body, &retval)
		if jsonErr != nil {
			return retval, jsonErr
		}
	}
	return retval, err
}
167406
func (_m *FacadeInterface) UpdateServiceConfig(ctx datastore.Context, fileID string, conf servicedefinition.ConfigFile) error {
	ret := _m.Called(ctx, fileID, conf)

	var r0 error
	if rf, ok := ret.Get(0).(func(datastore.Context, string, servicedefinition.ConfigFile) error); ok {
		r0 = rf(ctx, fileID, conf)
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
1086625
func GetSettings(c context.Context) *Settings {
	if s, ok := c.Value(contextKey(0)).(*Settings); ok && s != nil {
		return s
	}
	return nil
}
560251
func (s *CreatePresetInput) SetSettings(v *PresetSettings) *CreatePresetInput {
	s.Settings = v
	return s
}
413400
func (s *ListAccountSettingsOutput) SetSettings(v []*Setting) *ListAccountSettingsOutput {
	s.Settings = v
	return s
}
766190
func (s *CreateJobInput) SetSettings(v *JobSettings) *CreateJobInput {
	s.Settings = v
	return s
}
822507
func (s *ClusterStateService) FlatSettings(flatSettings bool) *ClusterStateService {
	s.flatSettings = &flatSettings
	return s
}
280442
func (c *Client) UpdateCacheSetting(i *UpdateCacheSettingInput) (*CacheSetting, error) {
	if i.Service == "" {
		return nil, ErrMissingService
	}

	if i.Version == 0 {
		return nil, ErrMissingVersion
	}

	if i.Name == "" {
		return nil, ErrMissingName
	}

	path := fmt.Sprintf("/service/%s/version/%d/cache_settings/%s", i.Service, i.Version, i.Name)
	resp, err := c.PutForm(path, i, nil)
	if err != nil {
		return nil, err
	}

	var cs *CacheSetting
	if err := decodeJSON(&cs, resp.Body); err != nil {
		return nil, err
	}
	return cs, nil
}