// NewFromSpec creates a configuration Generator from a given
// configuration.
//
// Deprecated: Replace with:
//
//   generator := Generator{Config: config}
358728
func NewFromSpec(config *rspec.Spec) Generator {
	envCache := map[string]int{}
	if config != nil && config.Process != nil {
		envCache = createEnvCacheMap(config.Process.Env)
	}

	return Generator{
		Config: config,
		envMap: envCache,
	}
}
313933
func cloneForSpec(specPtr *ForSpec) {
	clone(&specPtr.Expr)
	oldOuter := specPtr.Outer
	if oldOuter != nil {
		specPtr.Outer = new(ForSpec)
		*specPtr.Outer = *oldOuter
		cloneForSpec(specPtr.Outer)
	}
	for i := range specPtr.Conditions {
		clone(&specPtr.Conditions[i].Expr)
	}
}
535717
func (_m *VerifierFactory) VerifierFromConfig(configuration *common.ConfigEnvelope, channel string) (cluster.BlockVerifier, error) {
	ret := _m.Called(configuration, channel)

	var r0 cluster.BlockVerifier
	if rf, ok := ret.Get(0).(func(*common.ConfigEnvelope, string) cluster.BlockVerifier); ok {
		r0 = rf(configuration, channel)
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).(cluster.BlockVerifier)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(*common.ConfigEnvelope, string) error); ok {
		r1 = rf(configuration, channel)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
776952
func New() *Generator {
	g := new(Generator)
	g.Buffer = new(bytes.Buffer)
	g.Request = new(plugin.CodeGeneratorRequest)
	g.Response = new(plugin.CodeGeneratorResponse)
	g.Suffix = ".pb.go"
	g.writtenImports = make(map[string]bool)
	uniquePackageName = make(map[*descriptor.FileDescriptorProto]string)
	pkgNamesInUse = make(map[string][]*FileDescriptor)
	return g
}
513022
func NewFromFile(path string) (Generator, error) {
	cf, err := os.Open(path)
	if err != nil {
		if os.IsNotExist(err) {
			return Generator{}, fmt.Errorf("template configuration at %s not found", path)
		}
		return Generator{}, err
	}
	defer cf.Close()

	return NewFromTemplate(cf)
}
16058
func New(opts ...Option) *Configurator {
	c := &Configurator{
		knownTransports:       make(map[string]*compiledTransportSpec),
		knownPeerChoosers:     make(map[string]*compiledPeerChooserSpec),
		knownPeerLists:        make(map[string]*compiledPeerListSpec),
		knownPeerListUpdaters: make(map[string]*compiledPeerListUpdaterSpec),
		resolver:              os.LookupEnv,
	}

	for _, opt := range opts {
		opt(c)
	}

	return c
}
1065120
func functionNewArgs(g Generator, s *compile.ServiceSpec, f *compile.FunctionSpec) (string, error) {
	return g.TextTemplate(
		`
		<- $f := .Function ->
		<- $prefix := namePrefix .Service $f ->
		<- $params := newNamespace ->
		func(
			<- range $f.ArgsSpec>
				<- if .Required>
					<$params.NewName .Name> <typeReference .Type>,
				<- else>
					<$params.NewName .Name> <typeReferencePtr .Type>,
				<- end ->
			<end>
		) *<$prefix>Args {
			return &<$prefix>Args{
			<range $f.ArgsSpec>
				<- if .Required ->
					<goCase .Name>: <$params.Rotate .Name>,
				<- else ->
					<goCase .Name>: <$params.Rotate .Name>,
				<- end>
			<end>
			}
		}
		`,
		struct {
			Service  *compile.ServiceSpec
			Function *compile.FunctionSpec
		}{
			Service:  s,
			Function: f,
		},
		TemplateFunc("namePrefix", functionNamePrefix))
}
152869
func newConfig(cfg, old *config.Config) (*environConfig, error) {
	// Ensure that the provided config is valid.
	if err := config.Validate(cfg, old); err != nil {
		return nil, errors.Trace(err)
	}
	attrs, err := cfg.ValidateUnknownAttrs(configFields, configDefaults)
	if err != nil {
		return nil, errors.Trace(err)
	}

	if old != nil {
		// There's an old configuration. Validate it so that any
		// default values are correctly coerced for when we check
		// the old values later.
		oldEcfg, err := newConfig(old, nil)
		if err != nil {
			return nil, errors.Annotatef(err, "invalid base config")
		}
		for _, attr := range configImmutableFields {
			oldv, newv := oldEcfg.attrs[attr], attrs[attr]
			if oldv != newv {
				return nil, errors.Errorf(
					"%s: cannot change from %v to %v",
					attr, oldv, newv,
				)
			}
		}
	}

	ecfg := &environConfig{
		config: cfg,
		attrs:  attrs,
	}
	return ecfg, nil
}
1355506
func newGenerators(regexps []*syntax.Regexp, args *GeneratorArgs) ([]*internalGenerator, error) {
	generators := make([]*internalGenerator, len(regexps), len(regexps))
	var err error

	// create a generator for each alternate pattern
	for i, subR := range regexps {
		generators[i], err = newGenerator(subR, args)
		if err != nil {
			return nil, err
		}
	}

	return generators, nil
}
184760
func newExprIterFromGroup(g *Group, p *Pattern) *ExprIter {
	for elem := g.GetFirstElem(p.Operand); elem != nil; elem = elem.Next() {
		expr := elem.Value.(*GroupExpr)
		if !p.Operand.Match(GetOperand(expr.ExprNode)) {
			return nil
		}
		iter := newExprIterFromGroupExpr(expr, p)
		if iter != nil {
			iter.Group, iter.Element = g, elem
			return iter
		}
	}
	return nil
}
1346516
func (p *Plugin) InitSpec(execRoot string) (*specs.Spec, error) {
	return nil, errors.New("not supported")
}
891879
func NewGenerator(pkg, iface string) (*Generator, error) {
	p, err := importer.DefaultWithTestFiles().Import(pkg)
	if err != nil {
		return nil, err
	}
	obj := p.Scope().Lookup(iface)
	if obj == nil {
		return nil, fmt.Errorf("interface %s missing", iface)
	}
	if !types.IsInterface(obj.Type()) {
		return nil, fmt.Errorf("%s should be an interface, was %s", iface, obj.Type())
	}
	g := &Generator{
		ifaceName: iface,
		pkg:       p,
		iface:     obj.Type().Underlying().(*types.Interface).Complete(),
	}
	g.SetTemplate(defaultMockTemplate)
	return g, nil
}
1025482
func (c *configFactory) CreateFromConfig(policy schedulerapi.Policy) (*Config, error) {
	klog.V(2).Infof("Creating scheduler from configuration: %v", policy)

	// validate the policy configuration
	if err := validation.ValidatePolicy(policy); err != nil {
		return nil, err
	}

	predicateKeys := sets.NewString()
	if policy.Predicates == nil {
		klog.V(2).Infof("Using predicates from algorithm provider '%v'", DefaultProvider)
		provider, err := GetAlgorithmProvider(DefaultProvider)
		if err != nil {
			return nil, err
		}
		predicateKeys = provider.FitPredicateKeys
	} else {
		for _, predicate := range policy.Predicates {
			klog.V(2).Infof("Registering predicate: %s", predicate.Name)
			predicateKeys.Insert(RegisterCustomFitPredicate(predicate))
		}
	}

	priorityKeys := sets.NewString()
	if policy.Priorities == nil {
		klog.V(2).Infof("Using priorities from algorithm provider '%v'", DefaultProvider)
		provider, err := GetAlgorithmProvider(DefaultProvider)
		if err != nil {
			return nil, err
		}
		priorityKeys = provider.PriorityFunctionKeys
	} else {
		for _, priority := range policy.Priorities {
			klog.V(2).Infof("Registering priority: %s", priority.Name)
			priorityKeys.Insert(RegisterCustomPriorityFunction(priority))
		}
	}

	var extenders []algorithm.SchedulerExtender
	if len(policy.ExtenderConfigs) != 0 {
		ignoredExtendedResources := sets.NewString()
		for ii := range policy.ExtenderConfigs {
			klog.V(2).Infof("Creating extender with config %+v", policy.ExtenderConfigs[ii])
			extender, err := core.NewHTTPExtender(&policy.ExtenderConfigs[ii])
			if err != nil {
				return nil, err
			}
			extenders = append(extenders, extender)
			for _, r := range policy.ExtenderConfigs[ii].ManagedResources {
				if r.IgnoredByScheduler {
					ignoredExtendedResources.Insert(string(r.Name))
				}
			}
		}
		predicates.RegisterPredicateMetadataProducerWithExtendedResourceOptions(ignoredExtendedResources)
	}
	// Providing HardPodAffinitySymmetricWeight in the policy config is the new and preferred way of providing the value.
	// Give it higher precedence than scheduler CLI configuration when it is provided.
	if policy.HardPodAffinitySymmetricWeight != 0 {
		c.hardPodAffinitySymmetricWeight = policy.HardPodAffinitySymmetricWeight
	}
	// When AlwaysCheckAllPredicates is set to true, scheduler checks all the configured
	// predicates even after one or more of them fails.
	if policy.AlwaysCheckAllPredicates {
		c.alwaysCheckAllPredicates = policy.AlwaysCheckAllPredicates
	}

	return c.CreateFromKeys(predicateKeys, priorityKeys, extenders)
}
81375
func New(prog *loader.Program) *Generator {
	gen := &Generator{
		header:          "Code generated by github.com/gojuno/generator. DO NOT EDIT.",
		imports:         map[string]*importInfo{},
		templateFuncs:   map[string]interface{}{},
		body:            bytes.NewBuffer([]byte{}),
		typeConversions: map[string]string{},
		vars:            map[string]string{},
		typesPrefixes:   map[string]string{},

		Program: prog,
	}

	gen.AddTemplateFunc("signature", gen.FuncSignature)
	gen.AddTemplateFunc("params", gen.FuncParams)
	gen.AddTemplateFunc("results", gen.FuncResults)
	gen.AddTemplateFunc("new", gen.New)
	gen.AddTemplateFunc("typeOf", gen.TypeOf)
	gen.AddTemplateFunc("first", First)
	gen.AddTemplateFunc("last", Last)
	gen.AddTemplateFunc("mixedCaps", MixedCaps)

	return gen
}
1157809
func NewFrom(v Values) *Configuration {
	c := &Configuration{
		Os:        EnvironmentOf(mapFetcher(v.Os)),
		gitConfig: git.NewConfig("", ""),
		timestamp: time.Now(),
	}
	c.Git = &delayedEnvironment{
		callback: func() Environment {
			source := &git.ConfigurationSource{
				Lines: make([]string, 0, len(v.Git)),
			}

			for key, values := range v.Git {
				parts := strings.Split(key, ".")
				isCaseSensitive := len(parts) >= 3
				hasUpper := strings.IndexFunc(key, unicode.IsUpper) > -1

				// This branch should only ever trigger in
				// tests, and only if they'd be broken.
				if !isCaseSensitive && hasUpper {
					panic(fmt.Sprintf("key %q has uppercase, shouldn't", key))
				}
				for _, value := range values {
					fmt.Printf("Config: %s=%s\n", key, value)
					source.Lines = append(source.Lines, fmt.Sprintf("%s=%s", key, value))
				}
			}

			return c.readGitConfig(source)
		},
	}
	return c
}
1183509
func NewGenerator(options ...Option) *Generator {
	g := &Generator{}
	g.validator = codegen.NewValidator()

	for _, option := range options {
		option(g)
	}

	return g
}
1072026
func NewDefault(cfg config.Provider) *Fs {
	fs := &afero.OsFs{}
	return newFs(fs, cfg)
}