// setupUserEnv prepares user subprocess environment.
967494
func (r *runner) setupUserEnv(ctx context.Context, args *pb.RunnerArgs, userAuth *authctx.Context, logdogServ *logdogServer, logdogNamespace string) (environ.Env, error) {
	ret := environ.System()
	userAuth.ExportIntoEnv(ret)
	if err := logdogServ.ExportIntoEnv(ret); err != nil {
		return environ.Env{}, err
	}
	ret.Set("LOGDOG_NAMESPACE", logdogNamespace)

	// Prepare user LUCI context.
	ctx, err := lucictx.Set(ctx, "luci_executable", map[string]string{
		"cache_dir": args.CacheDir,
	})
	if err != nil {
		return environ.Env{}, err
	}
	lctx, err := lucictx.ExportInto(ctx, args.WorkDir)
	if err != nil {
		return environ.Env{}, err
	}
	lctx.SetInEnviron(ret)

	// Prepare a user temp dir.
	// Note that we can't use workdir directly because some overzealous scripts
	// like to remove everything they find under TEMPDIR, and it breaks LUCI
	// runner internals that keep some files in workdir (in particular git and
	// gsutil configs setup by AuthContext).
	userTempDir := filepath.Join(args.WorkDir, "ut")
	if err := os.MkdirAll(userTempDir, 0700); err != nil {
		return environ.Env{}, errors.Annotate(err, "failed to create temp dir").Err()
	}
	for _, v := range []string{"TEMPDIR", "TMPDIR", "TEMP", "TMP", "MAC_CHROMIUM_TMPDIR"} {
		ret.Set(v, userTempDir)
	}

	return ret, nil
}
31499
func (f *Facade) CreateSystemUser(ctx datastore.Context) error {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.CreateSystemUser"))
	user, err := f.GetUser(ctx, SYSTEM_USER_NAME)
	if err != nil {
		plog.WithError(err).Warning("Default user not found; creating one.")

		// create the system user
		user := userdomain.User{}
		user.Name = SYSTEM_USER_NAME

		if err := f.AddUser(ctx, user); err != nil {
			return err
		}
	}

	// update the instance password
	password, err := utils.NewUUID36()
	if err != nil {
		return err
	}
	user.Name = SYSTEM_USER_NAME
	user.Password = password
	INSTANCE_PASSWORD = password
	return f.UpdateUser(ctx, user)
}
981177
func (s *VirtualMFADevice) SetUser(v *User) *VirtualMFADevice {
	s.User = v
	return s
}
546855
func (s *AdminCreateUserOutput) SetUser(v *UserType) *AdminCreateUserOutput {
	s.User = v
	return s
}
650457
func SetKeyEnv() (err error) {
	_key = os.Getenv("STRIPE_API_KEY")
	if _key == "" {
		err = errors.New("STRIPE_API_KEY not found in environment")
	}
	return
}
899945
func SetenvForFunction(envKey, envValue string, fn func()) error {
	revokeFn, err := RevokableSetenv(envKey, envValue)
	if err != nil {
		return err
	}

	fn()

	return revokeFn()
}
205476
func (cfg *cloudConfig) AddUser(user *User) {
	users, _ := cfg.attrs["users"].([]map[string]interface{})
	newUser := map[string]interface{}{
		"name":        user.Name,
		"lock_passwd": true,
	}
	if user.Groups != nil {
		newUser["groups"] = user.Groups
	}
	if user.Shell != "" {
		newUser["shell"] = user.Shell
	}
	if user.SSHAuthorizedKeys != "" {
		newUser["ssh-authorized-keys"] = annotateKeys(user.SSHAuthorizedKeys)
	}
	if user.Sudo != nil {
		newUser["sudo"] = user.Sudo
	}
	cfg.SetAttr("users", append(users, newUser))
}
522132
func SetupUser(process *service.TeleportProcess, username string, roles []services.Role) error {
	auth := process.GetAuthServer()
	teleUser, err := services.NewUser(username)
	if err != nil {
		return trace.Wrap(err)
	}
	if len(roles) == 0 {
		role := services.RoleForUser(teleUser)
		role.SetLogins(services.Allow, []string{username})

		// allow tests to forward agent, still needs to be passed in client
		roleOptions := role.GetOptions()
		roleOptions.ForwardAgent = services.NewBool(true)
		role.SetOptions(roleOptions)

		err = auth.UpsertRole(role)
		if err != nil {
			return trace.Wrap(err)
		}
		teleUser.AddRole(role.GetMetadata().Name)
		roles = append(roles, role)
	} else {
		for _, role := range roles {
			err := auth.UpsertRole(role)
			if err != nil {
				return trace.Wrap(err)
			}
			teleUser.AddRole(role.GetName())
		}
	}
	err = auth.UpsertUser(teleUser)
	if err != nil {
		return trace.Wrap(err)
	}
	return nil
}
1163688
func SetupUserCreds(tc *client.TeleportClient, proxyHost string, creds UserCreds) error {
	_, err := tc.AddKey(proxyHost, &creds.Key)
	if err != nil {
		return trace.Wrap(err)
	}
	err = tc.AddTrustedCA(creds.HostCA)
	if err != nil {
		return trace.Wrap(err)
	}
	return nil
}
445522
func SetUser(ctx context.Context, user string) context.Context {
	return context.WithValue(ctx, UserIdentityKey, user)
}
633313
func (s *ContainerProperties) SetUser(v string) *ContainerProperties {
	s.User = &v
	return s
}
1025962
func (g *Generator) addEnv(env, key string) {
	if idx, ok := g.envMap[key]; ok {
		// The ENV exists in the cache, so change its value in g.Config.Process.Env
		g.Config.Process.Env[idx] = env
	} else {
		// else the env doesn't exist, so add it and add it's index to g.envMap
		g.Config.Process.Env = append(g.Config.Process.Env, env)
		g.envMap[key] = len(g.Config.Process.Env) - 1
	}
}
1363013
func SetEnvVariable(key, value string) error {
	if strings.TrimSpace(value) == "" {
		return nil
	}
	err := os.Setenv(key, value)
	if err != nil {
		return fmt.Errorf("Failed to set: %s = %s. %s", key, value, err.Error())
	}
	return nil
}
38309
func (c *CommandLabels) SetEnv(v string) error {
	if err := json.Unmarshal([]byte(v), c); err != nil {
		return trace.Wrap(err, "can not parse Command Labels")
	}
	return nil
}
742271
func (o *Options) SetEnv(env *Env) {
	C.leveldb_options_set_env(o.Opt, env.Env)
}
1211415
func Setup(ctx *cli.Context, logdir string) error {
	// logging
	log.PrintOrigins(ctx.GlobalBool(debugFlag.Name))
	if logdir != "" {
		rfh, err := log.RotatingFileHandler(
			logdir,
			262144,
			log.JSONFormatOrderedEx(false, true),
		)
		if err != nil {
			return err
		}
		glogger.SetHandler(log.MultiHandler(ostream, rfh))
	}
	glogger.Verbosity(log.Lvl(ctx.GlobalInt(verbosityFlag.Name)))
	glogger.Vmodule(ctx.GlobalString(vmoduleFlag.Name))
	glogger.BacktraceAt(ctx.GlobalString(backtraceAtFlag.Name))
	log.Root().SetHandler(glogger)

	// profiling, tracing
	runtime.MemProfileRate = ctx.GlobalInt(memprofilerateFlag.Name)
	Handler.SetBlockProfileRate(ctx.GlobalInt(blockprofilerateFlag.Name))
	if traceFile := ctx.GlobalString(traceFlag.Name); traceFile != "" {
		if err := Handler.StartGoTrace(traceFile); err != nil {
			return err
		}
	}
	if cpuFile := ctx.GlobalString(cpuprofileFlag.Name); cpuFile != "" {
		if err := Handler.StartCPUProfile(cpuFile); err != nil {
			return err
		}
	}

	// pprof server
	if ctx.GlobalBool(pprofFlag.Name) {
		address := fmt.Sprintf("%s:%d", ctx.GlobalString(pprofAddrFlag.Name), ctx.GlobalInt(pprofPortFlag.Name))
		StartPProf(address)
	}
	return nil
}
563182
func (b *photonPersistentDiskMounter) SetUp(fsGroup *int64) error {
	return b.SetUpAt(b.GetPath(), fsGroup)
}