// ReadSettings returns the local settings of each given set of // relation/unit. func (u *UniterAPIV3) ReadSettings(args params.RelationUnits) (params.SettingsResults, error) { result := params.SettingsResults{ Results: make([]params.SettingsResult, len(args.RelationUnits)), } canAccess, err := u.accessUnit() if err != nil { return params.SettingsResults{}, err } for i, arg := range args.RelationUnits { unit, err := names.ParseUnitTag(arg.Unit) if err != nil { result.Results[i].Error = common.ServerError(common.ErrPerm) continue } relUnit, err := u.getRelationUnit(canAccess, arg.Relation, unit) if err == nil { var settings *state.Settings settings, err = relUnit.Settings() if err == nil { result.Results[i].Settings, err = convertRelationSettings(settings.Map()) } } result.Results[i].Error = common.ServerError(err) } return result, nil }
// UpdateSettings persists all changes made to the local settings of // all given pairs of relation and unit. Keys with empty values are // considered a signal to delete these values. func (u *UniterAPIV3) UpdateSettings(args params.RelationUnitsSettings) (params.ErrorResults, error) { result := params.ErrorResults{ Results: make([]params.ErrorResult, len(args.RelationUnits)), } canAccess, err := u.accessUnit() if err != nil { return params.ErrorResults{}, err } for i, arg := range args.RelationUnits { unit, err := names.ParseUnitTag(arg.Unit) if err != nil { result.Results[i].Error = common.ServerError(common.ErrPerm) continue } relUnit, err := u.getRelationUnit(canAccess, arg.Relation, unit) if err == nil { var settings *state.Settings settings, err = relUnit.Settings() if err == nil { for k, v := range arg.Settings { if v == "" { settings.Delete(k) } else { settings.Set(k, v) } } _, err = settings.Write() } } result.Results[i].Error = common.ServerError(err) } return result, nil }