// From Aurora Docs:
// Add a Value constraint
// name - Mesos slave attribute that the constraint is matched against.
// If negated = true , treat this as a 'not' - to avoid specific values.
// Values - list of values we look for in attribute name
332754
func (j *AuroraJob) AddValueConstraint(name string, negated bool, values ...string) Job {
	j.jobConfig.TaskConfig.Constraints = append(j.jobConfig.TaskConfig.Constraints,
		&aurora.Constraint{
			Name: name,
			Constraint: &aurora.TaskConstraint{
				Value: &aurora.ValueConstraint{
					Negated: negated,
					Values:  values,
				},
				Limit: nil,
			},
		})

	return j
}
1195706
func unmarshalTableOrValue(cfg *Config, rv reflect.Value, av interface{}) error {
	if (rv.Kind() != reflect.Ptr && rv.Kind() != reflect.Map) || rv.IsNil() {
		return &invalidUnmarshalError{rv.Type()}
	}
	rv = indirect(rv)

	switch av.(type) {
	case *ast.KeyValue, *ast.Table, []*ast.Table:
		if err := unmarshalField(cfg, rv, av); err != nil {
			return lineError(fieldLineNumber(av), err)
		}
		return nil
	case ast.Value:
		return setValue(cfg, rv, av.(ast.Value))
	default:
		panic(fmt.Sprintf("BUG: unhandled AST node type %T", av))
	}
}
1073826
func (a *Attributes) Value(name string) (string, bool, error) {
	attr, ok := a.Attrs[name]
	return attr, ok, nil
}
637233
func unmarshallMaterialAttributesDependency(mad *MaterialAttributesDependency, i map[string]interface{}) {
	for key, value := range i {
		if value == nil {
			continue
		}
		switch key {
		case "name":
			mad.Name = value.(string)
		case "pipeline":
			mad.Pipeline = value.(string)
		case "stage":
			mad.Stage = value.(string)
		case "auto_update":
			mad.AutoUpdate = value.(bool)
		}
	}
}
117618
func (c *Client) AddValueDescriptor(v contract.ValueDescriptor) (id string, err error) {
	conn := c.Pool.Get()
	defer conn.Close()

	if v.Id != "" {
		_, err = uuid.Parse(v.Id)
		if err != nil {
			return "", db.ErrInvalidObjectId
		}
	}
	return addValue(conn, v)
}
213196
func convertConstraints(cons constraints.Value) url.Values {
	params := url.Values{}
	if cons.Arch != nil {
		// Note: Juju and MAAS use the same architecture names.
		// MAAS also accepts a subarchitecture (e.g. "highbank"
		// for ARM), which defaults to "generic" if unspecified.
		params.Add("arch", *cons.Arch)
	}
	if cons.CpuCores != nil {
		params.Add("cpu_count", fmt.Sprintf("%d", *cons.CpuCores))
	}
	if cons.Mem != nil {
		params.Add("mem", fmt.Sprintf("%d", *cons.Mem))
	}
	convertTagsToParams(params, cons.Tags)
	if cons.CpuPower != nil {
		logger.Warningf("ignoring unsupported constraint 'cpu-power'")
	}
	return params
}
445095
func dataForTableConstraints(schemas []*model.DBInfo) [][]types.Datum {
	var rows [][]types.Datum
	for _, schema := range schemas {
		for _, tbl := range schema.Tables {
			if tbl.PKIsHandle {
				record := types.MakeDatums(
					catalogVal,           // CONSTRAINT_CATALOG
					schema.Name.O,        // CONSTRAINT_SCHEMA
					mysql.PrimaryKeyName, // CONSTRAINT_NAME
					schema.Name.O,        // TABLE_SCHEMA
					tbl.Name.O,           // TABLE_NAME
					primaryKeyType,       // CONSTRAINT_TYPE
				)
				rows = append(rows, record)
			}

			for _, idx := range tbl.Indices {
				var cname, ctype string
				if idx.Primary {
					cname = mysql.PrimaryKeyName
					ctype = primaryKeyType
				} else if idx.Unique {
					cname = idx.Name.O
					ctype = uniqueKeyType
				} else {
					// The index has no constriant.
					continue
				}
				record := types.MakeDatums(
					catalogVal,    // CONSTRAINT_CATALOG
					schema.Name.O, // CONSTRAINT_SCHEMA
					cname,         // CONSTRAINT_NAME
					schema.Name.O, // TABLE_SCHEMA
					tbl.Name.O,    // TABLE_NAME
					ctype,         // CONSTRAINT_TYPE
				)
				rows = append(rows, record)
			}
		}
	}
	return rows
}
515275
func (r *Application) AddConstraint(constraints ...string) *Application {
	if r.Constraints == nil {
		r.EmptyConstraints()
	}

	c := *r.Constraints
	c = append(c, constraints)
	r.Constraints = &c

	return r
}
361717
func (st *State) defaultInheritedConfig(cloudName string) func() (attrValues, error) {
	return func() (attrValues, error) {
		var defaults = make(map[string]interface{})
		for k, v := range config.ConfigDefaults() {
			defaults[k] = v
		}
		providerDefaults, err := st.environsProviderConfigSchemaSource(cloudName)
		if errors.IsNotImplemented(err) {
			return defaults, nil
		} else if err != nil {
			return nil, errors.Trace(err)
		}
		fields := schema.FieldMap(providerDefaults.ConfigSchema(), providerDefaults.ConfigDefaults())
		if coercedAttrs, err := fields.Coerce(defaults, nil); err != nil {
			return nil, errors.Trace(err)
		} else {
			for k, v := range coercedAttrs.(map[string]interface{}) {
				defaults[k] = v
			}
		}
		return defaults, nil
	}
}
804590
func coalesceValues(c *chart.Chart, v map[string]interface{}) (map[string]interface{}, error) {
	// If there are no values in the chart, we just return the given values
	if c.Values == nil || c.Values.Raw == "" {
		return v, nil
	}

	nv, err := ReadValues([]byte(c.Values.Raw))
	if err != nil {
		// On error, we return just the overridden values.
		// FIXME: We should log this error. It indicates that the YAML data
		// did not parse.
		return v, fmt.Errorf("Error: Reading chart '%s' default values (%s): %s", c.Metadata.Name, c.Values.Raw, err)
	}

	for key, val := range nv {
		if value, ok := v[key]; ok {
			if value == nil {
				// When the YAML value is null, we remove the value's key.
				// This allows Helm's various sources of values (value files or --set) to
				// remove incompatible keys from any previous chart, file, or set values.
				delete(v, key)
			} else if dest, ok := value.(map[string]interface{}); ok {
				// if v[key] is a table, merge nv's val table into v[key].
				src, ok := val.(map[string]interface{})
				if !ok {
					log.Printf("Warning: Building values map for chart '%s'. Skipped value (%+v) for '%s', as it is not a table.", c.Metadata.Name, src, key)
					continue
				}
				// Because v has higher precedence than nv, dest values override src
				// values.
				coalesceTables(dest, src, c.Metadata.Name)
			}
		} else {
			// If the key is not in v, copy it from nv.
			v[key] = val
		}
	}
	return v, nil
}
279979
func (r *realisClient) SetQuota(role string, cpu *float64, ramMb *int64, diskMb *int64) (*aurora.Response, error) {
	ramRes := aurora.NewResource()
	ramRes.RamMb = ramMb
	cpuRes := aurora.NewResource()
	cpuRes.NumCpus = cpu
	diskRes := aurora.NewResource()
	diskRes.DiskMb = diskMb
	quota := aurora.NewResourceAggregate()
	quota.Resources = []*aurora.Resource{cpuRes, ramRes, diskRes}
	resp, retryErr := r.thriftCallWithRetries(func() (*aurora.Response, error) {
		return r.adminClient.SetQuota(nil, role, quota)
	})

	if retryErr != nil {
		return resp, errors.Wrap(retryErr, "Unable to set role quota")
	}
	return resp, retryErr

}
346111
func (c *ConfigDataNode) UnmarshalJSON(data []byte) error {
	t := map[string]interface{}{}
	c.table = map[string]ctypes.ConfigValue{}
	dec := json.NewDecoder(bytes.NewReader(data))
	dec.UseNumber()
	if err := dec.Decode(&t); err != nil {
		return err
	}

	for k, i := range t {
		switch t := i.(type) {
		case string:
			c.table[k] = ctypes.ConfigValueStr{Value: t}
		case bool:
			c.table[k] = ctypes.ConfigValueBool{Value: t}
		case json.Number:
			if v, err := t.Int64(); err == nil {
				c.table[k] = ctypes.ConfigValueInt{Value: int(v)}
				continue
			}
			if v, err := t.Float64(); err == nil {
				c.table[k] = ctypes.ConfigValueFloat{Value: v}
				continue
			}
		default:
			return fmt.Errorf("Error Unmarshalling JSON ConfigDataNode. Key: %v Type: %v is unsupported.", k, t)
		}
	}
	c.mutex = new(sync.Mutex)
	return nil
}
301828
func (model *Model) modelConfigValues(modelCfg attrValues) (config.ConfigValues, error) {
	resultValues := make(attrValues)
	for k, v := range modelCfg {
		resultValues[k] = v
	}

	// Read all of the current inherited config values so
	// we can dynamically reflect the origin of the model config.
	rspec, err := model.st.regionSpec()
	if err != nil {
		return nil, errors.Trace(err)
	}
	configSources := modelConfigSources(model.st, rspec)
	sourceNames := make([]string, 0, len(configSources))
	sourceAttrs := make([]attrValues, 0, len(configSources))
	for _, src := range configSources {
		sourceNames = append(sourceNames, src.name)
		cfg, err := src.sourceFunc()
		if errors.IsNotFound(err) {
			continue
		}
		if err != nil {
			return nil, errors.Annotatef(err, "reading %s settings", src.name)
		}
		sourceAttrs = append(sourceAttrs, cfg)

		// If no modelCfg was passed in, we'll accumulate data
		// for the inherited values instead.
		if len(modelCfg) == 0 {
			for k, v := range cfg {
				resultValues[k] = v
			}
		}
	}

	// Figure out the source of each config attribute based
	// on the current model values and the inherited values.
	result := make(config.ConfigValues)
	for attr, val := range resultValues {
		// Find the source of config for which the model
		// value matches. If there's a match, the last match
		// in the search order will be the source of config.
		// If there's no match, the source is the model.
		source := config.JujuModelConfigSource
		n := len(sourceAttrs)
		for i := range sourceAttrs {
			if sourceAttrs[n-i-1][attr] == val {
				source = sourceNames[n-i-1]
				break
			}
		}
		result[attr] = config.ConfigValue{
			Value:  val,
			Source: source,
		}
	}
	return result, nil
}
1164887
func (o *SAMLConnectorV2) MapAttributes(assertionInfo saml2.AssertionInfo) []string {
	var roles []string
	for _, mapping := range o.Spec.AttributesToRoles {
		for _, attr := range assertionInfo.Values {
			if attr.Name != mapping.Name {
				continue
			}
		mappingLoop:
			for _, value := range attr.Values {
				for _, role := range mapping.Roles {
					outRole, err := utils.ReplaceRegexp(mapping.Value, role, value.Value)
					switch {
					case err != nil:
						if !trace.IsNotFound(err) {
							log.Debugf("Failed to match expression %v, replace with: %v input: %v, err: %v", mapping.Value, role, value.Value, err)
						}
						// if value input did not match, no need to apply
						// to all roles
						continue mappingLoop
					case outRole == "":
						// skip empty role matches
					case outRole != "":
						roles = append(roles, outRole)
					}
				}
			}
		}
	}
	return utils.Deduplicate(roles)
}
261763
func (mem *memNamedMapping) Put(name string, value interface{}) {
	mem.putNameToIdxSync(name, value)
	mem.publishAddToChannel(name, value)
}
1283969
func unmarshal(v reflect.Value, valuer func(name string) interface{}) error {
	if v.Kind() == reflect.Ptr {
		v = v.Elem()
	}
	t := v.Type()
	for i, num := 0, t.NumField(); i < num; i++ {
		var (
			f    = v.Field(i)
			sf   = t.Field(i)
			name = sf.Tag.Get("option") // todo: support default value
		)

		if sf.PkgPath != "" {
			continue
		}

		if name == "" {
			name = texts.Rename(sf.Name, texts.Lower)
		}
		opt := valuer(name)
		if opt == nil {
			// todo: read default value with option tag?
			continue
		}

		if err := unmarshalValue(f, opt); err != nil {
			return err
		}
	}
	return nil
}
1256098
func joinNames(useNil bool, atts ...*design.AttributeDefinition) string {
	var elems []string
	for _, att := range atts {
		if att == nil {
			continue
		}
		obj := att.Type.ToObject()
		var names, optNames []string

		keys := make([]string, len(obj))
		i := 0
		for n := range obj {
			keys[i] = n
			i++
		}
		sort.Strings(keys)

		for _, n := range keys {
			a := obj[n]
			field := fmt.Sprintf("cmd.%s", codegen.Goify(n, true))
			if !a.Type.IsArray() && !att.IsRequired(n) && !att.IsNonZero(n) {
				if useNil {
					field = flagTypeVal(a, n, field)
				} else {
					field = "&" + field
				}
			} else if a.Type.IsArray() {
				field = flagTypeArrayVal(a, field)
			} else {
				field = flagRequiredTypeVal(a, field)
			}
			if att.IsRequired(n) {
				names = append(names, field)
			} else {
				optNames = append(optNames, field)
			}
		}
		elems = append(elems, names...)
		elems = append(elems, optNames...)
	}
	return strings.Join(elems, ", ")
}