// StructuredGenerate outputs a secret object using the configured fields
960547
func (s SecretForDockerRegistryGeneratorV1) StructuredGenerate() (runtime.Object, error) {
	if err := s.validate(); err != nil {
		return nil, err
	}
	secret := &v1.Secret{}
	secret.Name = s.Name
	secret.Type = v1.SecretTypeDockerConfigJson
	secret.Data = map[string][]byte{}
	if len(s.FileSources) > 0 {
		if err := handleFromFileSources(secret, s.FileSources); err != nil {
			return nil, err
		}
	}
	if len(s.FileSources) == 0 {
		dockercfgJSONContent, err := handleDockerCfgJSONContent(s.Username, s.Password, s.Email, s.Server)
		if err != nil {
			return nil, err
		}
		secret.Data[v1.DockerConfigJsonKey] = dockercfgJSONContent
	}
	if s.AppendHash {
		h, err := hash.SecretHash(secret)
		if err != nil {
			return nil, err
		}
		secret.Name = fmt.Sprintf("%s-%s", secret.Name, h)
	}
	return secret, nil
}
1003926
func (s *HorizontalPodAutoscalerGeneratorV1) StructuredGenerate() (runtime.Object, error) {
	if err := s.validate(); err != nil {
		return nil, err
	}

	scaler := autoscalingv1.HorizontalPodAutoscaler{
		ObjectMeta: metav1.ObjectMeta{
			Name: s.Name,
		},
		Spec: autoscalingv1.HorizontalPodAutoscalerSpec{
			ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{
				Kind:       s.ScaleRefKind,
				Name:       s.ScaleRefName,
				APIVersion: s.ScaleRefAPIVersion,
			},
			MaxReplicas: s.MaxReplicas,
		},
	}

	if s.MinReplicas > 0 {
		v := int32(s.MinReplicas)
		scaler.Spec.MinReplicas = &v
	}
	if s.CPUPercent >= 0 {
		c := int32(s.CPUPercent)
		scaler.Spec.TargetCPUUtilizationPercentage = &c
	}

	return &scaler, nil
}
462177
func (g *Generator) MustGenerate(length, numDigits, numSymbols int, noUpper, allowRepeat bool) string {
	res, err := g.Generate(length, numDigits, numSymbols, noUpper, allowRepeat)
	if err != nil {
		panic(err)
	}
	return res
}
902820
func (mas MaterialAttributesSvn) GenerateGeneric() (ma map[string]interface{}) {
	ma = map[string]interface{}{
		"auto_update":        mas.AutoUpdate,
		"check_externals":    mas.CheckExternals,
		"destination":        mas.Destination,
		"encrypted_password": mas.EncryptedPassword,
		"invert_filter":      mas.InvertFilter,
		"name":               mas.Name,
		"password":           mas.Password,
		"url":                mas.URL,
		"username":           mas.Username,
	}

	if f := mas.Filter.GenerateGeneric(); f != nil {
		ma["filter"] = f
	}

	return
}
249418
func isGenerated(src []byte) bool {
	sc := bufio.NewScanner(bytes.NewReader(src))
	for sc.Scan() {
		b := sc.Bytes()
		if bytes.HasPrefix(b, genHdr) && bytes.HasSuffix(b, genFtr) && len(b) >= len(genHdr)+len(genFtr) {
			return true
		}
	}
	return false
}
1143663
func (s *PriorityClassV1Generator) StructuredGenerate() (runtime.Object, error) {
	return &scheduling.PriorityClass{
		ObjectMeta: metav1.ObjectMeta{
			Name: s.Name,
		},
		Value:         s.Value,
		GlobalDefault: s.GlobalDefault,
		Description:   s.Description,
	}, nil
}
269699
func (c *unstructuredConverter) ToUnstructured(obj interface{}) (map[string]interface{}, error) {
	var u map[string]interface{}
	var err error
	if unstr, ok := obj.(Unstructured); ok {
		u = unstr.UnstructuredContent()
	} else {
		t := reflect.TypeOf(obj)
		value := reflect.ValueOf(obj)
		if t.Kind() != reflect.Ptr || value.IsNil() {
			return nil, fmt.Errorf("ToUnstructured requires a non-nil pointer to an object, got %v", t)
		}
		u = map[string]interface{}{}
		err = toUnstructured(value.Elem(), reflect.ValueOf(&u).Elem())
	}
	if c.mismatchDetection {
		newUnstr := map[string]interface{}{}
		newErr := toUnstructuredViaJSON(obj, &newUnstr)
		if (err != nil) != (newErr != nil) {
			klog.Fatalf("ToUnstructured unexpected error for %v: error: %v; newErr: %v", obj, err, newErr)
		}
		if err == nil && !c.comparison.DeepEqual(u, newUnstr) {
			klog.Fatalf("ToUnstructured mismatch\nobj1: %#v\nobj2: %#v", u, newUnstr)
		}
	}
	if err != nil {
		return nil, err
	}
	return u, nil
}
540750
func (sd structDef) generate(dir string) error {
	// generate enums
	for _, f := range sd.Fields {
		if f.Enum != nil {
			if err := f.Enum.generate(dir); err != nil {
				return err
			}
		}
	}
	if sd.Enum != nil {
		return sd.Enum.generate(dir)
	}
	fileName := filepath.Join(dir, sd.Name+".go")
	return commons.GenerateFile(sd, structTemplateLocation, "struct_template", fileName, true)
}
552142
func Publicizer(att *design.AttributeDefinition, sourceField, targetField string, dereference bool, depth int, init bool) string {
	var publication string
	data := map[string]interface{}{
		"sourceField": sourceField,
		"targetField": targetField,
		"depth":       depth,
		"att":         att,
		"dereference": dereference,
		"init":        init,
	}
	switch {
	case att.Type.IsPrimitive():
		publication = RunTemplate(simplePublicizeT, data)
	case att.Type.IsObject():
		if _, ok := att.Type.(*design.MediaTypeDefinition); ok {
			publication = RunTemplate(recursivePublicizeT, data)
		} else if _, ok := att.Type.(*design.UserTypeDefinition); ok {
			publication = RunTemplate(recursivePublicizeT, data)
		} else {
			publication = RunTemplate(objectPublicizeT, data)
		}
	case att.Type.IsArray():
		// If the array element is primitive type, we can simply copy the elements over (i.e) []string
		if att.Type.HasAttributes() {
			data["elemType"] = att.Type.ToArray().ElemType
			publication = RunTemplate(arrayPublicizeT, data)
		} else {
			publication = RunTemplate(simplePublicizeT, data)
		}
	case att.Type.IsHash():
		if att.Type.HasAttributes() {
			h := att.Type.ToHash()
			data["keyType"] = h.KeyType
			data["elemType"] = h.ElemType
			publication = RunTemplate(hashPublicizeT, data)
		} else {
			publication = RunTemplate(simplePublicizeT, data)
		}
	}
	return publication
}
1239272
func (t *transformer) generateClient(protoPackage, serviceName string, iface *ast.InterfaceType) ([]ast.Decl, error) {
	// This function used to construct an AST. It was a lot of code.
	// Now it generates code via a template and parses back to AST.
	// Slower, but saner and easier to make changes.

	type Method struct {
		Name          string
		InputMessage  string
		OutputMessage string
	}
	methods := make([]Method, 0, len(iface.Methods.List))

	var buf bytes.Buffer
	toGoCode := func(n ast.Node) (string, error) {
		defer buf.Reset()
		err := format.Node(&buf, t.fset, n)
		if err != nil {
			return "", err
		}
		return buf.String(), nil
	}

	for _, m := range iface.Methods.List {
		signature, ok := m.Type.(*ast.FuncType)
		if !ok {
			return nil, fmt.Errorf("unexpected embedded interface in %sClient", serviceName)
		}

		inStructPtr := signature.Params.List[1].Type.(*ast.StarExpr)
		inStruct, err := toGoCode(inStructPtr.X)
		if err != nil {
			return nil, err
		}

		outStructPtr := signature.Results.List[0].Type.(*ast.StarExpr)
		outStruct, err := toGoCode(outStructPtr.X)
		if err != nil {
			return nil, err
		}

		methods = append(methods, Method{
			Name:          m.Names[0].Name,
			InputMessage:  inStruct,
			OutputMessage: outStruct,
		})
	}

	prpcSymbolPrefix := "prpc."
	if t.inPRPCPackage {
		prpcSymbolPrefix = ""
	}
	err := clientCodeTemplate.Execute(&buf, map[string]interface{}{
		"Service":          serviceName,
		"ProtoPkg":         protoPackage,
		"StructName":       firstLower(serviceName) + "PRPCClient",
		"Methods":          methods,
		"PRPCSymbolPrefix": prpcSymbolPrefix,
	})
	if err != nil {
		return nil, fmt.Errorf("client template execution: %s", err)
	}

	f, err := parser.ParseFile(t.fset, "", buf.String(), 0)
	if err != nil {
		return nil, fmt.Errorf("client template result parsing: %s. Code: %#v", err, buf.String())
	}
	return f.Decls, nil
}
948644
func (g *genConversion) generateFor(inType, outType *types.Type, sw *generator.SnippetWriter) {
	klog.V(5).Infof("generating %v -> %v", inType, outType)
	var f func(*types.Type, *types.Type, *generator.SnippetWriter)

	switch inType.Kind {
	case types.Builtin:
		f = g.doBuiltin
	case types.Map:
		f = g.doMap
	case types.Slice:
		f = g.doSlice
	case types.Struct:
		f = g.doStruct
	case types.Pointer:
		f = g.doPointer
	case types.Alias:
		f = g.doAlias
	default:
		f = g.doUnknown
	}

	f(inType, outType, sw)
}
783836
func CheckGeneratedNameError(strategy RESTCreateStrategy, err error, obj runtime.Object) error {
	if !errors.IsAlreadyExists(err) {
		return err
	}

	objectMeta, kind, kerr := objectMetaAndKind(strategy, obj)
	if kerr != nil {
		return kerr
	}

	if len(objectMeta.GetGenerateName()) == 0 {
		return err
	}

	return errors.NewServerTimeoutForKind(kind.GroupKind(), "POST", 0)
}
710973
func DefaultGenerators(cmdName string) map[string]generate.Generator {
	var generator map[string]generate.Generator
	switch cmdName {
	case "expose":
		generator = map[string]generate.Generator{
			ServiceV1GeneratorName: ServiceGeneratorV1{},
			ServiceV2GeneratorName: ServiceGeneratorV2{},
		}
	case "service-clusterip":
		generator = map[string]generate.Generator{
			ServiceClusterIPGeneratorV1Name: ServiceClusterIPGeneratorV1{},
		}
	case "service-nodeport":
		generator = map[string]generate.Generator{
			ServiceNodePortGeneratorV1Name: ServiceNodePortGeneratorV1{},
		}
	case "service-loadbalancer":
		generator = map[string]generate.Generator{
			ServiceLoadBalancerGeneratorV1Name: ServiceLoadBalancerGeneratorV1{},
		}
	case "deployment":
		// Create Deployment has only StructuredGenerators and no
		// param-based Generators.
		// The StructuredGenerators are as follows (as of 2018-03-16):
		// DeploymentBasicV1Beta1GeneratorName -> DeploymentBasicGeneratorV1
		// DeploymentBasicAppsV1Beta1GeneratorName -> DeploymentBasicAppsGeneratorV1Beta1
		// DeploymentBasicAppsV1GeneratorName -> DeploymentBasicAppsGeneratorV1
		generator = map[string]generate.Generator{}
	case "run":
		generator = map[string]generate.Generator{
			RunV1GeneratorName:                 BasicReplicationController{},
			RunPodV1GeneratorName:              BasicPod{},
			DeploymentV1Beta1GeneratorName:     DeploymentV1Beta1{},
			DeploymentAppsV1Beta1GeneratorName: DeploymentAppsV1Beta1{},
			DeploymentAppsV1GeneratorName:      DeploymentAppsV1{},
			JobV1GeneratorName:                 JobV1{},
			CronJobV2Alpha1GeneratorName:       CronJobV2Alpha1{},
			CronJobV1Beta1GeneratorName:        CronJobV1Beta1{},
		}
	case "namespace":
		generator = map[string]generate.Generator{
			NamespaceV1GeneratorName: NamespaceGeneratorV1{},
		}
	case "quota":
		generator = map[string]generate.Generator{
			ResourceQuotaV1GeneratorName: ResourceQuotaGeneratorV1{},
		}
	case "secret":
		generator = map[string]generate.Generator{
			SecretV1GeneratorName: SecretGeneratorV1{},
		}
	case "secret-for-docker-registry":
		generator = map[string]generate.Generator{
			SecretForDockerRegistryV1GeneratorName: SecretForDockerRegistryGeneratorV1{},
		}
	case "secret-for-tls":
		generator = map[string]generate.Generator{
			SecretForTLSV1GeneratorName: SecretForTLSGeneratorV1{},
		}
	}

	return generator
}
1159345
func (sid *Shortid) MustGenerate() string {
	id, err := sid.Generate()
	if err == nil {
		return id
	}
	panic(err)
}
903842
func handleGetGenerate(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
	return s.cfg.CPUMiner.IsMining(), nil
}
667396
func generateSecret(opts *Options) (*v1.Secret, error) {

	labels := generateLabels(map[string]string{"name": "tiller"})
	secret := &v1.Secret{
		Type: v1.SecretTypeOpaque,
		Data: make(map[string][]byte),
		ObjectMeta: metav1.ObjectMeta{
			Name:      secretName,
			Labels:    labels,
			Namespace: opts.Namespace,
		},
	}
	var err error
	if secret.Data["tls.key"], err = read(opts.TLSKeyFile); err != nil {
		return nil, err
	}
	if secret.Data["tls.crt"], err = read(opts.TLSCertFile); err != nil {
		return nil, err
	}
	if opts.VerifyTLS {
		if secret.Data["ca.crt"], err = read(opts.TLSCaCertFile); err != nil {
			return nil, err
		}
	}
	return secret, nil
}
495699
func (g *Generator) Generate() (_ []string, err error) {
	if g.API == nil {
		return nil, fmt.Errorf("missing API definition, make sure design is properly initialized")
	}

	go utils.Catch(nil, func() { g.Cleanup() })

	defer func() {
		if err != nil {
			g.Cleanup()
		}
	}()

	codegen.Reserved[g.Target] = true

	os.RemoveAll(g.OutDir)

	if err := os.MkdirAll(g.OutDir, 0755); err != nil {
		return nil, err
	}
	g.genfiles = []string{g.OutDir}
	if err := g.generateContexts(); err != nil {
		return nil, err
	}
	if err := g.generateControllers(); err != nil {
		return nil, err
	}
	if err := g.generateSecurity(); err != nil {
		return nil, err
	}
	if err := g.generateHrefs(); err != nil {
		return nil, err
	}
	if err := g.generateMediaTypes(); err != nil {
		return nil, err
	}
	if err := g.generateUserTypes(); err != nil {
		return nil, err
	}
	if !g.NoTest {
		if err := g.generateResourceTest(); err != nil {
			return nil, err
		}
	}

	return g.genfiles, nil
}