// Setup configures a simple collection object based on a given
// StaticCollectionConfig proto that has all the necessary information
196973
func (sc *SimpleCollection) Setup(collectionConfig *common.StaticCollectionConfig, deserializer msp.IdentityDeserializer) error {
	if collectionConfig == nil {
		return errors.New("Nil config passed to collection setup")
	}
	sc.conf = *collectionConfig
	sc.name = collectionConfig.GetName()

	// get the access signature policy envelope
	collectionPolicyConfig := collectionConfig.GetMemberOrgsPolicy()
	if collectionPolicyConfig == nil {
		return errors.New("Collection config policy is nil")
	}
	accessPolicyEnvelope := collectionPolicyConfig.GetSignaturePolicy()
	if accessPolicyEnvelope == nil {
		return errors.New("Collection config access policy is nil")
	}

	err := sc.setupAccessPolicy(collectionPolicyConfig, deserializer)
	if err != nil {
		return err
	}

	// get member org MSP IDs from the envelope
	for _, principal := range accessPolicyEnvelope.Identities {
		switch principal.PrincipalClassification {
		case m.MSPPrincipal_ROLE:
			// Principal contains the msp role
			mspRole := &m.MSPRole{}
			err := proto.Unmarshal(principal.Principal, mspRole)
			if err != nil {
				return errors.Wrap(err, "Could not unmarshal MSPRole from principal")
			}
			sc.memberOrgs = append(sc.memberOrgs, mspRole.MspIdentifier)
		case m.MSPPrincipal_IDENTITY:
			principalId, err := deserializer.DeserializeIdentity(principal.Principal)
			if err != nil {
				return errors.Wrap(err, "Invalid identity principal, not a certificate")
			}
			sc.memberOrgs = append(sc.memberOrgs, principalId.GetMSPIdentifier())
		case m.MSPPrincipal_ORGANIZATION_UNIT:
			OU := &m.OrganizationUnit{}
			err := proto.Unmarshal(principal.Principal, OU)
			if err != nil {
				return errors.Wrap(err, "Could not unmarshal OrganizationUnit from principal")
			}
			sc.memberOrgs = append(sc.memberOrgs, OU.MspIdentifier)
		default:
			return errors.New(fmt.Sprintf("Invalid principal type %d", int32(principal.PrincipalClassification)))
		}
	}

	return nil
}
749223
func (cephfsVolume *cephfsMounter) SetUp(fsGroup *int64) error {
	return cephfsVolume.SetUpAt(cephfsVolume.GetPath(), fsGroup)
}
1116141
func (c *Client) Setup() error {
	if c.IsSetup() {
		return nil
	}
	if runtime.GOOS == "windows" {
		return c.setupWindows()
	}
	return c.setupUnix()
}
381482
func setup(c *caddy.Controller) error {
	httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler {
		return PoolHandler{Next: next, refreshLauncher: &sync.Once{}}
	})

	return nil
}
262503
func setup(c *caddy.Controller) error {
	ctx := log.LoggerNewContext(context.Background())

	pfsso, err := buildPfssoHandler(ctx)

	if err != nil {
		return err
	}

	// Declare all pfconfig resources that will be necessary
	pfconfigdriver.PfconfigPool.AddRefreshable(ctx, &firewallsso.Firewalls)
	pfconfigdriver.PfconfigPool.AddStruct(ctx, &pfconfigdriver.Config.Interfaces.ManagementNetwork)

	httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler {
		pfsso.Next = next
		return pfsso
	})

	return nil
}
366809
func Setup(conf config.Config) error {
	getDownlinkDataDelay = conf.NetworkServer.GetDownlinkDataDelay
	disableMACCommands = conf.NetworkServer.NetworkSettings.DisableMACCommands

	return nil
}
1118480
func (o *Organizer) Setup(f func()) {
	o.setup = append(o.setup, f)
}
984255
func setup(ctx *cli.Context) (err error) {
	setting.Debug = ctx.GlobalBool("debug")
	log.NonColor = ctx.GlobalBool("noterm")
	log.Verbose = ctx.Bool("verbose")

	log.Info("App Version: %s", ctx.App.Version)

	setting.HomeDir, err = base.HomeDir()
	if err != nil {
		return fmt.Errorf("Fail to get home directory: %v", err)
	}
	setting.HomeDir = strings.Replace(setting.HomeDir, "\\", "/", -1)

	setting.InstallRepoPath = path.Join(setting.HomeDir, ".gopm/repos")
	if runtime.GOOS == "windows" {
		setting.IsWindows = true
	}
	os.MkdirAll(setting.InstallRepoPath, os.ModePerm)
	log.Info("Local repository path: %s", setting.InstallRepoPath)

	if !setting.LibraryMode || len(setting.WorkDir) == 0 {
		setting.WorkDir, err = os.Getwd()
		if err != nil {
			return fmt.Errorf("Fail to get work directory: %v", err)
		}
		setting.WorkDir = strings.Replace(setting.WorkDir, "\\", "/", -1)
	}
	setting.DefaultGopmfile = path.Join(setting.WorkDir, setting.GOPMFILE)
	setting.DefaultVendor = path.Join(setting.WorkDir, setting.VENDOR)
	setting.DefaultVendorSrc = path.Join(setting.DefaultVendor, "src")

	if !ctx.Bool("remote") {
		if ctx.Bool("local") {
			// gf, _, _, err := genGopmfile(ctx)
			// if err != nil {
			// 	return err
			// }
			// setting.InstallGopath = gf.MustValue("project", "local_gopath")
			// if ctx.Command.Name != "gen" {
			// 	if com.IsDir(setting.InstallGopath) {
			// 		log.Log("Indicated local GOPATH: %s", setting.InstallGopath)
			// 		setting.InstallGopath += "/src"
			// 	} else {
			// 		if setting.LibraryMode {
			// 			return fmt.Errorf("Local GOPATH does not exist or is not a directory: %s",
			// 				setting.InstallGopath)
			// 		}
			// 		log.Error("", "Invalid local GOPATH path")
			// 		log.Error("", "Local GOPATH does not exist or is not a directory:")
			// 		log.Error("", "\t"+setting.InstallGopath)
			// 		log.Help("Try 'go help gopath' to get more information")
			// 	}
			// }

		} else {
			// Get GOPATH.
			setting.InstallGopath = base.GetGOPATHs()[0]
			if base.IsDir(setting.InstallGopath) {
				log.Info("Indicated GOPATH: %s", setting.InstallGopath)
				setting.InstallGopath += "/src"
				setting.HasGOPATHSetting = true
			} else {
				if ctx.Bool("gopath") {
					return fmt.Errorf("Local GOPATH does not exist or is not a directory: %s",
						setting.InstallGopath)
				} else {
					// It's OK that no GOPATH setting
					// when user does not specify to use.
					log.Warn("No GOPATH setting available")
				}
			}
		}
	}

	setting.ConfigFile = path.Join(setting.HomeDir, ".gopm/data/gopm.ini")
	if err = setting.LoadConfig(); err != nil {
		return err
	}

	setting.PkgNameListFile = path.Join(setting.HomeDir, ".gopm/data/pkgname.list")
	if err = setting.LoadPkgNameList(); err != nil {
		return err
	}

	setting.LocalNodesFile = path.Join(setting.HomeDir, ".gopm/data/localnodes.list")
	if err = setting.LoadLocalNodes(); err != nil {
		return err
	}
	return nil
}
313688
func Setup(allowPrivileged bool, privilegedSources PrivilegedSources, perConnectionBytesPerSec int64) {
	Initialize(Capabilities{
		AllowPrivileged:                        allowPrivileged,
		PrivilegedSources:                      privilegedSources,
		PerConnectionBandwidthLimitBytesPerSec: perConnectionBytesPerSec,
	})
}
51816
func (mgr *mspManagerImpl) Setup(msps []MSP) error {
	if mgr.up {
		mspLogger.Infof("MSP manager already up")
		return nil
	}

	mspLogger.Debugf("Setting up the MSP manager (%d msps)", len(msps))

	// create the map that assigns MSP IDs to their manager instance - once
	mgr.mspsMap = make(map[string]MSP)

	// create the map that sorts MSPs by their provider types
	mgr.mspsByProviders = make(map[ProviderType][]MSP)

	for _, msp := range msps {
		// add the MSP to the map of active MSPs
		mspID, err := msp.GetIdentifier()
		if err != nil {
			return errors.WithMessage(err, "could not extract msp identifier")
		}
		mgr.mspsMap[mspID] = msp
		providerType := msp.GetType()
		mgr.mspsByProviders[providerType] = append(mgr.mspsByProviders[providerType], msp)
	}

	mgr.up = true

	mspLogger.Debugf("MSP manager setup complete, setup %d msps", len(msps))

	return nil
}
456830
func Setup(conf config.Config) error {
	nsConfig := conf.NetworkServer.NetworkSettings
	rxWindow = nsConfig.RXWindow
	downlinkTXPower = nsConfig.DownlinkTXPower

	return nil
}
596481
func (c *Config) Setup(serviceName string) (opentracing.Tracer, io.Closer, error) {
	collector, err := zipkin.NewHTTPCollector(c.HTTPEndpoint)
	if err != nil {
		return nil, nil, err
	}

	recorder := zipkin.NewRecorder(collector, c.Debug, "0.0.0.0:0", serviceName)

	tracer, err := zipkin.NewTracer(
		recorder,
		zipkin.ClientServerSameSpan(c.SameSpan),
		zipkin.TraceID128Bit(c.ID128Bit),
		zipkin.DebugMode(c.Debug),
		zipkin.WithSampler(zipkin.NewBoundarySampler(c.SampleRate, time.Now().Unix())),
	)
	if err != nil {
		return nil, nil, err
	}

	// Without this, child spans are getting the NOOP tracer
	opentracing.SetGlobalTracer(tracer)

	log.WithoutContext().Debug("Zipkin tracer configured")

	return tracer, collector, nil
}
842737
func (mounter *quobyteMounter) SetUp(fsGroup *int64) error {
	pluginDir := mounter.plugin.host.GetPluginDir(utilstrings.EscapeQualifiedName(quobytePluginName))
	return mounter.SetUpAt(pluginDir, fsGroup)
}
1039334
func (r *RetryableSetup) Setup() (interface{}, error) {
	r.init()

	var created interface{}
	for cur := 0; cur < r.RetryCount; cur++ {

		// リソース作成
		target, err := r.createResource()
		if err != nil {
			return nil, err
		}
		id := target.GetID()

		// コピー待ち
		if r.AsyncWaitForCopy != nil {
			// コピー待ち、Failedになった場合はリソース削除
			state, err := r.waitForCopyWithCleanup(id)
			if err != nil {
				return nil, err
			}
			if state != nil {
				created = state
			}
		} else {
			created = target
		}

		// 起動前の設定など
		if err := r.provisionBeforeUp(id, created); err != nil {
			return nil, err
		}

		// 起動待ち
		if err := r.waitForUp(id, created); err != nil {
			return nil, err
		}

		if created != nil {
			break
		}
	}

	if created == nil {
		return nil, MaxRetryCountExceededError(fmt.Errorf("max retry count exceeded"))
	}
	return created, nil
}
354359
func (j *JSON) Setup() error {
	r, err := j.gen()
	if err != nil {
		return err
	}

	dec := json.NewDecoder(r)
	j.values = make(map[string]interface{})

	return dec.Decode(&j.values)
}
643103
func Setup(ganeshaConfig string, gracePeriod uint) error {
	// Start rpcbind if it is not started yet
	cmd := exec.Command("/usr/sbin/rpcinfo", "127.0.0.1")
	if err := cmd.Run(); err != nil {
		cmd = exec.Command("/usr/sbin/rpcbind", "-w")
		if out, err := cmd.CombinedOutput(); err != nil {
			return fmt.Errorf("Starting rpcbind failed with error: %v, output: %s", err, out)
		}
	}

	cmd = exec.Command("/usr/sbin/rpc.statd")
	if out, err := cmd.CombinedOutput(); err != nil {
		return fmt.Errorf("rpc.statd failed with error: %v, output: %s", err, out)
	}

	// Start dbus, needed for ganesha dynamic exports
	cmd = exec.Command("dbus-daemon", "--system")
	if out, err := cmd.CombinedOutput(); err != nil {
		return fmt.Errorf("dbus-daemon failed with error: %v, output: %s", err, out)
	}

	err := setRlimitNOFILE()
	if err != nil {
		glog.Warningf("Error setting RLIMIT_NOFILE, there may be 'Too many open files' errors later: %v", err)
	}

	// Use defaultGaneshaConfigContents if the ganeshaConfig doesn't exist yet
	if _, err = os.Stat(ganeshaConfig); os.IsNotExist(err) {
		err = ioutil.WriteFile(ganeshaConfig, defaultGaneshaConfigContents, 0600)
		if err != nil {
			return fmt.Errorf("error writing ganesha config %s: %v", ganeshaConfig, err)
		}
	}
	err = setGracePeriod(ganeshaConfig, gracePeriod)
	if err != nil {
		return fmt.Errorf("error setting grace period to ganesha config: %v", err)
	}
	err = setFsidDevice(ganeshaConfig, true)
	if err != nil {
		return fmt.Errorf("error setting fsid device to ganesha config: %v", err)
	}

	return nil
}
40792
func Setup(c config.Config) error {
	log.Info("storage: setting up storage module")

	deviceSessionTTL = c.NetworkServer.DeviceSessionTTL
	schedulerInterval = c.NetworkServer.Scheduler.SchedulerInterval

	log.Info("storage: setting up Redis connection pool")
	redisPool = &redis.Pool{
		MaxIdle:     10,
		IdleTimeout: c.Redis.IdleTimeout,
		Dial: func() (redis.Conn, error) {
			c, err := redis.DialURL(c.Redis.URL,
				redis.DialReadTimeout(redisDialReadTimeout),
				redis.DialWriteTimeout(redisDialWriteTimeout),
			)
			if err != nil {
				return nil, fmt.Errorf("redis connection error: %s", err)
			}
			return c, err
		},
		TestOnBorrow: func(c redis.Conn, t time.Time) error {
			if time.Now().Sub(t) < onBorrowPingInterval {
				return nil
			}

			_, err := c.Do("PING")
			if err != nil {
				return fmt.Errorf("ping redis error: %s", err)
			}
			return nil
		},
	}

	log.Info("storage: connecting to PostgreSQL")
	d, err := sqlx.Open("postgres", c.PostgreSQL.DSN)
	if err != nil {
		return errors.Wrap(err, "storage: PostgreSQL connection error")
	}
	for {
		if err := d.Ping(); err != nil {
			log.WithError(err).Warning("storage: ping PostgreSQL database error, will retry in 2s")
			time.Sleep(2 * time.Second)
		} else {
			break
		}
	}

	db = &DBLogger{d}

	if c.PostgreSQL.Automigrate {
		log.Info("storage: applying PostgreSQL data migrations")
		m := &migrate.AssetMigrationSource{
			Asset:    migrations.Asset,
			AssetDir: migrations.AssetDir,
			Dir:      "",
		}
		n, err := migrate.Exec(db.DB.DB, "postgres", m, migrate.Up)
		if err != nil {
			return errors.Wrap(err, "storage: applying PostgreSQL data migrations error")
		}
		log.WithField("count", n).Info("storage: PostgreSQL data migrations applied")
	}

	return nil
}