// NewRolesController creates a roles controller.
340532
func NewRolesController(service *goa.Service, app application.Application) *RolesController {
	return &RolesController{
		Controller: service.NewController("RolesController"),
		app:        app,
	}
}
237158
func NewAuthWithRoles(authServer *AuthServer,
	checker services.AccessChecker,
	user services.User,
	sessions session.Service,
	alog events.IAuditLog) *AuthWithRoles {
	return &AuthWithRoles{
		authServer: authServer,
		checker:    checker,
		sessions:   sessions,
		user:       user,
		alog:       alog,
	}
}
183368
func NewCollaboratorsController(service *goa.Service, app application.Application, config collaboratorsConfiguration) *CollaboratorsController {
	return &CollaboratorsController{Controller: service.NewController("CollaboratorsController"), app: app, config: config}
}
39337
func (u *UserV2) SetRoles(roles []string) {
	u.Spec.Roles = utils.Deduplicate(roles)
}
509844
func NewOrganizationController(service *goa.Service, app application.Application) *OrganizationController {
	return &OrganizationController{Controller: service.NewController("OrganizationController"), app: app}
}
1110108
func NewFeaturesController(service *goa.Service, config FeaturesControllerConfiguration) *FeaturesController {
	return &FeaturesController{
		Controller: service.NewController("FeaturesController"),
		config:     config,
	}
}
577419
func NewFilterController(service *goa.Service, config FilterControllerConfiguration) *FilterController {
	return &FilterController{
		Controller: service.NewController("FilterController"),
		config:     config,
	}
}
541579
func NewRole(name RoleName, threshold int, keyIDs, paths []string) (*Role, error) {
	if IsDelegation(name) {
		if len(paths) == 0 {
			logrus.Debugf("role %s with no Paths will never be able to publish content until one or more are added", name)
		}
	}
	if threshold < 1 {
		return nil, ErrInvalidRole{Role: name}
	}
	if !ValidRole(name) {
		return nil, ErrInvalidRole{Role: name}
	}
	return &Role{
		RootRole: RootRole{
			KeyIDs:    keyIDs,
			Threshold: threshold,
		},
		Name:  name,
		Paths: paths,
	}, nil

}
751726
func NewController(config ControllerConfig) (*Controller, error) {
	c, err := newController(config, newResidentManager(config.Changes))
	return c, errors.Trace(err)
}
43836
func NewController(bk *buckets.Bucket) *Controller {
	// map of days to integers
	daynum := map[string]int{
		"mon": 1, // monday is the first day of the week
		"tue": 2,
		"wed": 3,
		"thu": 4,
		"fri": 5,
		"sat": 6,
		"sun": 7,
	}
	return &Controller{bk, daynum}
}
123805
func NewNamedusersController(service *goa.Service, app application.Application, config UsersControllerConfiguration, tenantService appservice.TenantService) *NamedusersController {
	return &NamedusersController{
		Controller:    service.NewController("NamedusersController"),
		app:           app,
		config:        config,
		tenantService: tenantService,
	}
}
1232868
func CreateUserAndRoleWithoutRoles(clt clt, username string, allowedLogins []string) (services.User, services.Role, error) {
	user, err := services.NewUser(username)
	if err != nil {
		return nil, nil, trace.Wrap(err)
	}

	role := services.RoleForUser(user)
	set := services.MakeRuleSet(role.GetRules(services.Allow))
	delete(set, services.KindRole)
	role.SetRules(services.Allow, set.Slice())
	role.SetLogins(services.Allow, []string{user.GetName()})
	err = clt.UpsertRole(role)
	if err != nil {
		return nil, nil, trace.Wrap(err)
	}

	user.AddRole(role.GetName())
	err = clt.UpsertUser(user)
	if err != nil {
		return nil, nil, trace.Wrap(err)
	}

	return user, role, nil
}
1345277
func NewNodeController(client kubernetes.Interface, dns dns.Context) (*NodeController, error) {
	scope, err := dns.CreateScope("node")
	if err != nil {
		return nil, fmt.Errorf("error building dns scope: %v", err)
	}
	c := &NodeController{
		client: client,
		scope:  scope,
	}

	return c, nil
}
294151
func NewResourceController(name string, dal DataAccessLayer) *ResourceController {
	return &ResourceController{
		Name: name,
		DAL:  dal,
	}
}
171391
func (s *roleLister) Roles(namespace string) RoleNamespaceLister {
	return roleNamespaceLister{indexer: s.indexer, namespace: namespace}
}
1281428
func NewController(options ControllerOptions) (*Controller, error) {
	c := &Controller{
		options: options,
	}
	c.closing = make(chan chan error)

	if len(options.ServicedEndpoint) <= 0 {
		return nil, ErrInvalidEndpoint
	}

	// Load keys
	keyshutdown := make(chan interface{})
	go func() {
		// This is a ridiculous shutdown pattern I'll follow for the sake of
		// not destabilizing the controller this late in a release.
		// TODO: Make this not stupid
		errc := <-c.closing
		close(keyshutdown)
		errc <- nil
	}()

	go auth.WatchDelegateKeyFile(containerDelegateKeyFile, keyshutdown)
	go auth.WatchTokenFile(containerTokenFile, keyshutdown)

	// Load the delegate keys and auth tokens first so there's no race btwn starting the watcher routines
	//    and making the first RPC call in getService()
	<-auth.WaitForDelegateKeys(nil)
	<-auth.WaitForAuthToken(nil)

	// get service
	instanceID, err := strconv.Atoi(options.Service.InstanceID)
	if err != nil {
		glog.Errorf("Invalid instance from instanceID:%s", options.Service.InstanceID)
		return c, fmt.Errorf("Invalid instance from instanceID:%s", options.Service.InstanceID)
	}
	service, tenantID, svcPath, err := getService(options.ServicedEndpoint, options.Service.ID, instanceID)
	if err != nil {
		glog.Errorf("%+v", err)
		glog.Errorf("Invalid service from serviceID:%s", options.Service.ID)
		return c, ErrInvalidService
	}
	c.healthChecks = service.HealthChecks
	c.tenantID = tenantID
	options.ServiceNamePath = svcPath

	if service.PIDFile != "" {
		if strings.HasPrefix(service.PIDFile, "exec ") {
			cmd := service.PIDFile[5:len(service.PIDFile)]
			out, err := exec.Command("sh", "-c", cmd).Output()
			if err != nil {
				glog.Errorf("Unable to run command '%s'", cmd)
			} else {
				c.PIDFile = strings.Trim(string(out), "\n ")
			}
		} else {
			c.PIDFile = service.PIDFile
		}
	}

	// create config files
	if err := setupConfigFiles(service); err != nil {
		glog.Errorf("Could not setup config files error:%s", err)
		return c, fmt.Errorf("container: invalid ConfigFiles error:%s", err)
	}

	// get host id
	c.hostID, err = getAgentHostID(options.ServicedEndpoint)
	if err != nil {
		glog.Errorf("Invalid hostID")
		return c, ErrInvalidHostID
	}

	if options.Logforwarder.Enabled && len(service.LogConfigs) > 0 {
		if err := setupLogstashFiles(c.hostID, options.HostIPs, options.ServiceNamePath, service,
			options.Service.InstanceID, options.Logforwarder); err != nil {
			glog.Errorf("Could not setup logstash files error:%s", err)
			return c, fmt.Errorf("container: invalid LogStashFiles error:%s", err)
		}

		logforwarder, exited, err := subprocess.New(time.Second,
			nil,
			options.Logforwarder.Path,
			"-e", // Log to stderr
			"-c", options.Logforwarder.ConfigFile)
		if err != nil {
			return nil, err
		}
		c.logforwarder = logforwarder
		c.logforwarderExited = exited
	}

	//build metric redirect url -- assumes 8444 is port mapped
	metricRedirect := options.Metric.RemoteEndoint
	if len(metricRedirect) == 0 {
		glog.V(1).Infof("container.Controller does not have metric forwarding")
	} else if !options.MetricForwarding {
		glog.V(1).Infof("Not forwarding metrics for this container (%v)", c.tenantID)
	} else {
		if len(c.tenantID) <= 0 {
			return nil, ErrInvalidTenantID
		}
		if len(c.hostID) <= 0 {
			return nil, ErrInvalidHostID
		}
		if len(options.Service.ID) <= 0 {
			return nil, ErrInvalidServiceID
		}

		metricRedirect += "?controlplane_tenant_id=" + c.tenantID
		metricRedirect += "&controlplane_service_id=" + options.Service.ID
		metricRedirect += "&controlplane_host_id=" + c.hostID
		metricRedirect += "&controlplane_instance_id=" + options.Service.InstanceID

		//build and serve the container metric forwarder
		forwarder, err := NewMetricForwarder(options.Metric.Address, metricRedirect)
		if err != nil {
			return c, err
		}
		c.metricForwarder = forwarder

		// setup network stats
		destination := fmt.Sprintf("http://localhost%s/api/metrics/store", options.Metric.Address)
		glog.Infof("pushing network stats to: %s", destination)
		go statReporter(destination, time.Second*15)
	}

	// Keep a copy of the service prerequisites in the Controller object.
	c.prereqs = service.Prereqs

	// set up the zookeeper client
	c.zkInfo, err = getAgentZkInfo(options.ServicedEndpoint)
	if err != nil {
		glog.Errorf("Invalid zk info: %v", err)
		return c, err
	}
	glog.Infof(" c.zkInfo: %+v", c.zkInfo)

	// endpoints are created at the root level (not pool aware)
	rootBasePath := ""
	zClient, err := coordclient.New("zookeeper", c.zkInfo.ZkDSN, rootBasePath, nil)
	if err != nil {
		glog.Errorf("failed create a new coordclient: %v", err)
		return c, err
	}

	zzk.InitializeLocalClient(zClient)

	// get endpoints
	opts := ContainerEndpointsOptions{
		HostID:               c.hostID,
		TenantID:             c.tenantID,
		InstanceID:           instanceID,
		IsShell:              os.Getenv("SERVICED_IS_SERVICE_SHELL") == "true",
		TCPMuxPort:           uint16(options.Mux.Port),
		UseTLS:               !options.Mux.DisableTLS,
		VirtualAddressSubnet: options.VirtualAddressSubnet,
	}
	c.endpoints, err = NewContainerEndpoints(service, opts)
	if err != nil {
		return c, err
	}

	// CC Rest API proxy
	c.ccApiProxy = newServicedApiProxy()

	// check command
	glog.Infof("command: %v [%d]", options.Service.Command, len(options.Service.Command))
	if len(options.Service.Command) < 1 {
		glog.Errorf("Invalid commandif ")
		return c, ErrInvalidCommand
	}

	return c, nil
}
236534
func NewUserController(service *goa.Service, db application.DB, config UserControllerConfiguration, httpOptions ...configuration.HTTPClientOption) *UserController {
	return &UserController{
		Controller:  service.NewController("UserController"),
		config:      config,
		db:          db,
		httpOptions: httpOptions,
	}
}