// generate security related files
// it currently only supports itsyou.online oauth2
483503
func (c *Client) generateSecurity() error {
	for name, ss := range c.APIDef.SecuritySchemes {
		if v, ok := ss.Settings["accessTokenUri"]; ok {
			ctx := map[string]string{
				"ClientName": clientName(c.APIDef),
				"BaseURI":    fmt.Sprintf("%v", v),
			}
			filename := filepath.Join(c.Dir, "oauth2_client_"+name+".nim")
			if err := commons.GenerateFile(ctx, "./templates/nim/oauth2_client_nim.tmpl", "oauth2_client_nim", filename, true); err != nil {
				return err
			}
		}
	}
	return nil
}
634031
func Generate(password, algorithm string, saltLen, iter uint) (string, error) {
	a, ok := stringToHash[algorithm]
	if !ok {
		return "", fmt.Errorf("Unrecognized hash")
	}
	if !a.Available() {
		return "", fmt.Errorf("Hash algorithm not available: %s", algorithm)
	}
	salt := generateSalt(saltLen)
	hash := generateHash(a.New, salt, password, iter)
	i := strconv.FormatUint(uint64(iter), 10)
	return algorithm + "$" + string(salt) + "$" + i + "$" + hash, nil
}
790668
func (msg MultiServiceGenerator) Generate(req *api.GenerateServiceRequest) (*api.GenerateServiceResponse, error) {
	var (
		lock      sync.Mutex
		files     = make(map[string][]byte)
		usedPaths = make(map[string]string) // path -> plugin name
	)

	err := concurrent.Range(msg, func(_ int, sg ServiceGenerator) error {
		res, err := sg.Generate(req)
		if err != nil {
			return err
		}

		lock.Lock()
		defer lock.Unlock()

		pluginName := sg.Handle().Name()
		for path, contents := range res.Files {
			if takenBy, taken := usedPaths[path]; taken {
				return fmt.Errorf("plugin conflict: cannot write file %q for plugin %q: "+
					"plugin %q already wrote to that file", path, pluginName, takenBy)
			}

			usedPaths[path] = pluginName
			files[path] = contents
		}

		return nil
	})

	return &api.GenerateServiceResponse{Files: files}, err
}
357650
func (c *Client) Generate(numBlocks uint32) ([]*chainhash.Hash, error) {
	return c.GenerateAsync(numBlocks).Receive()
}
196329
func (g *Generator) generateUserTypes() (err error) {
	var (
		utFile string
		utWr   *UserTypesWriter
	)
	{
		utFile = filepath.Join(g.OutDir, "user_types.go")
		utWr, err = NewUserTypesWriter(utFile)
		if err != nil {
			return
		}
	}
	defer func() {
		utWr.Close()
		if err == nil {
			err = utWr.FormatCode()
		}
	}()
	title := fmt.Sprintf("%s: Application User Types", g.API.Context())
	imports := []*codegen.ImportSpec{
		codegen.SimpleImport("fmt"),
		codegen.SimpleImport("mime/multipart"),
		codegen.SimpleImport("time"),
		codegen.SimpleImport("unicode/utf8"),
		codegen.SimpleImport("github.com/goadesign/goa"),
		codegen.NewImport("uuid", "github.com/gofrs/uuid"),
	}
	for _, v := range g.API.Types {
		imports = codegen.AttributeImports(v.AttributeDefinition, imports, nil)
	}
	if err = utWr.WriteHeader(title, g.Target, imports); err != nil {
		return err
	}
	g.genfiles = append(g.genfiles, utFile)
	err = g.API.IterateUserTypes(func(t *design.UserTypeDefinition) error {
		return utWr.Execute(t)
	})
	return
}
1275320
func (ps *pythonSecurity) generate(dir string) error {
	filename := filepath.Join(dir, ps.FileName)
	return commons.GenerateFile(ps, ps.template, ps.templateName, filename, true)
}
1367223
func (c *LoginController) Generate(ctx *app.GenerateLoginContext) error {
	return proxy.RouteHTTPToPath(ctx, c.configuration.GetAuthServiceURL(), authservice.GenerateTokenPath())
}
399391
func Generate() (files []string, err error) {
	var (
		outDir, designPkg, appPkg, ver, res, pkg string
		force, regen                             bool
	)

	set := flag.NewFlagSet("controller", flag.PanicOnError)
	set.StringVar(&outDir, "out", "", "")
	set.StringVar(&designPkg, "design", "", "")
	set.StringVar(&appPkg, "app-pkg", "app", "")
	set.StringVar(&pkg, "pkg", "main", "")
	set.StringVar(&res, "res", "", "")
	set.StringVar(&ver, "version", "", "")
	set.BoolVar(&force, "force", false, "")
	set.BoolVar(&regen, "regen", false, "")
	set.Bool("notest", false, "")
	set.Parse(os.Args[1:])

	if err := codegen.CheckVersion(ver); err != nil {
		return nil, err
	}

	g := &Generator{OutDir: outDir, DesignPkg: designPkg, AppPkg: appPkg, Force: force, Regen: regen, API: design.Design, Pkg: pkg, Resource: res}

	return g.Generate()
}
554911
func HtdigestFileProvider(filename string) SecretProvider {
	hf := &HtdigestFile{File: File{Path: filename}}
	hf.Reload = func() { reloadHTDigest(hf) }
	return func(user, realm string) string {
		hf.ReloadIfNeeded()
		hf.mu.RLock()
		defer hf.mu.RUnlock()
		_, exists := hf.Users[realm]
		if !exists {
			return ""
		}
		digest, exists := hf.Users[realm][user]
		if !exists {
			return ""
		}
		return digest
	}
}
326959
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()
		}
	}()

	if g.Timeout == 0 {
		g.Timeout = 20 * time.Second
	}
	if g.Scheme == "" && len(g.API.Schemes) > 0 {
		g.Scheme = g.API.Schemes[0]
	}
	if g.Scheme == "" {
		g.Scheme = "http"
	}
	if g.Host == "" {
		g.Host = g.API.Host
	}
	if g.Host == "" {
		return nil, fmt.Errorf("missing host value, set it with --host")
	}

	g.OutDir = filepath.Join(g.OutDir, "js")
	if err := os.RemoveAll(g.OutDir); err != nil {
		return nil, err
	}
	if err := os.MkdirAll(g.OutDir, 0755); err != nil {
		return nil, err
	}
	g.genfiles = append(g.genfiles, g.OutDir)

	// Generate client.js
	exampleAction, err := g.generateJS(filepath.Join(g.OutDir, "client.js"))
	if err != nil {
		return
	}

	// Generate axios.html
	if err = g.generateAxiosJS(); err != nil {
		return
	}

	if exampleAction != nil && !g.NoExample {
		// Generate index.html
		if err = g.generateIndexHTML(filepath.Join(g.OutDir, "index.html"), exampleAction); err != nil {
			return
		}

		// Generate example
		if err = g.generateExample(); err != nil {
			return
		}
	}

	return g.genfiles, nil
}
757072
func GeneratePasswd(uid, gid uint32, rootfs, rundir string) (string, error) {
	// if UID exists inside of container rootfs /etc/passwd then
	// don't generate passwd
	if _, err := lookup.GetUser(rootfs, strconv.Itoa(int(uid))); err == nil {
		return "", nil
	}
	passwdFile := filepath.Join(rundir, "passwd")
	originPasswdFile, err := symlink.FollowSymlinkInScope(filepath.Join(rootfs, "/etc/passwd"), rootfs)
	if err != nil {
		return "", errors.Wrapf(err, "unable to follow symlinks to passwd file")
	}
	orig, err := ioutil.ReadFile(originPasswdFile)
	if err != nil {
		// If no /etc/passwd in container ignore and return
		if os.IsNotExist(err) {
			return "", nil
		}
		return "", errors.Wrapf(err, "unable to read passwd file %s", originPasswdFile)
	}

	pwd := fmt.Sprintf("%s%d:x:%d:%d:container user:%s:/bin/sh\n", orig, uid, uid, gid, "/")
	if err := ioutil.WriteFile(passwdFile, []byte(pwd), 0644); err != nil {
		return "", errors.Wrapf(err, "failed to create temporary passwd file")
	}
	return passwdFile, nil
}
242520
func (ch *CredHub) GenerateUser(name string, gen generate.User, overwrite Mode) (credentials.User, error) {
	var cred credentials.User
	err := ch.generateCredential(name, "user", gen, overwrite, &cred)
	return cred, err
}
1139739
func (priv *DSAPrivateKey) Generate(rand io.Reader) error {
	if err := dsa.GenerateParameters(&priv.PrivateKey.PublicKey.Parameters, rand, dsa.L1024N160); err != nil {
		return err
	}
	if err := dsa.GenerateKey(&priv.PrivateKey, rand); err != nil {
		return err
	}
	priv.DSAPublicKey.PublicKey = priv.PrivateKey.PublicKey
	return nil
}
281679
func Generate() (files []string, err error) {
	var outDir, ver string
	set := flag.NewFlagSet("app", flag.PanicOnError)
	set.StringVar(&outDir, "out", "", "")
	set.StringVar(&ver, "version", "", "")
	set.String("design", "", "")
	set.Parse(os.Args[1:])

	if err := codegen.CheckVersion(ver); err != nil {
		return nil, err
	}

	g := &Generator{OutDir: outDir, API: design.Design}

	return g.Generate()
}
1128993
func (ps *FlaskServer) Generate() error {
	// python classes and it's helper
	typesPath := filepath.Join(ps.targetDir, typesDir)

	if err := commons.GenerateFile(nil, "./templates/python/client_support.tmpl",
		"client_support", filepath.Join(typesPath, "client_support.py"), true); err != nil {
		return err
	}

	if ps.Gevent {
		if err := commons.GenerateFile(ps, "./templates/python/server_gevent.tmpl", "server_gevent", filepath.Join(ps.targetDir, "server.py"), true); err != nil {
			return err
		}

		if err := GeneratePythonCapnpClasses(ps.APIDef, typesPath); err != nil {
			return nil
		}
	} else {
		_, err := GenerateAllClasses(ps.APIDef, typesPath, ps.Gevent)
		if err != nil {
			return err
		}
	}

	// json schema
	if err := generateJSONSchema(ps.APIDef, filepath.Join(ps.targetDir, handlersDir)); err != nil {
		return err
	}

	// security scheme
	if err := generateServerSecurity(ps.APIDef.SecuritySchemes, ps.Template, ps.targetDir); err != nil {
		log.Errorf("failed to generate security scheme:%v", err)
		return err
	}

	// generate resources
	if err := generateResources(ps.ResourcesDef, ps.Template, ps.targetDir); err != nil {
		return err
	}

	// libraries
	if err := generateLibraries(ps.APIDef.Libraries, ps.targetDir); err != nil {
		return err
	}

	// requirements.txt file
	if err := commons.GenerateFile(nil, "./templates/python/requirements_python.tmpl", "requirements_python",
		filepath.Join(ps.targetDir, "requirements.txt"), true); err != nil {
		return err
	}

	// generate main
	if ps.WithMain {
		// generate HTML front page
		if err := commons.GenerateFile(ps, "./templates/index.html.tmpl", "index.html", filepath.Join(ps.targetDir, "index.html"), true); err != nil {
			return err
		}
		// main file
		if err := commons.GenerateFile(ps, "./templates/python/server_main_flask.tmpl", "server_main_flask", filepath.Join(ps.targetDir, "app.py"), true); err != nil {
			return err
		}
	}

	return generateEmptyInitPy(ps.targetDir)
}
405227
func GenerateFile(data interface{}, tmplFile, tmplName, filename string, override bool) error {
	if !override && isFileExist(filename) {
		log.Infof("file %v already exist and override=false, no need to regenerate", filename)
		return nil
	}

	if err := checkCreateDir(filepath.Dir(filename)); err != nil {
	}

	// pass Go function to template
	funcMap := template.FuncMap{
		"ToLower": strings.ToLower,
	}

	// all template files path is relative to current directory (./)
	// while go-bindata files exist in templates directory
	tmplFile = strings.Replace(tmplFile, "./", "", -1)

	byteData, err := templates.Asset(tmplFile)
	if err != nil {
		return err
	}

	t, err := template.New(tmplName).Funcs(funcMap).Parse(string(byteData))
	if err != nil {
		return err
	}

	f, err := os.Create(filename)
	if err != nil {
		return err
	}
	defer f.Close()

	log.Infof("generating file %v", filename)
	if err := t.ExecuteTemplate(f, tmplName, data); err != nil {
		return err
	}

	switch {
	case strings.HasSuffix(filename, ".go"):
		return runGoFmt(filename)
	case strings.HasSuffix(filename, ".py"):
		return runAutoPep8(filename)
	}
	return nil
}
75057
func Generate(w http.ResponseWriter, r *http.Request, opts ...GenerateOption) {
	o := &GenerateOptions{
		name:   XSRFCookieName,
		path:   "/",
		domain: "",
		maxAge: 0,
	}
	for _, opt := range opts {
		opt(o)
	}
	if !hasCookie(r, o.name) || o.force {
		http.SetCookie(w, &http.Cookie{
			Name:   o.name,
			Value:  newKey(),
			Path:   o.path,
			Domain: o.domain,
			Secure: r.TLS != nil,
			MaxAge: o.maxAge,
		})
	}
}