// Configure initializes this producer with values from a plugin config.
777728
func (prod *Redis) Configure(conf core.PluginConfigReader) {
	prod.SetStopCallback(prod.close)

	prod.protocol, prod.address = tnet.ParseAddress(conf.GetString("Address", ":6379"), "tcp")

	switch strings.ToLower(conf.GetString("Storage", "hash")) {
	case "hash":
		prod.store = prod.storeHash
	case "list":
		prod.store = prod.storeList
	case "set":
		prod.store = prod.storeSet
	case "sortedset":
		prod.store = prod.storeSortedSet
	default: // string
		prod.store = prod.storeString
	}
}
447807
func (prod *S3) Configure(conf core.PluginConfigReader) {
	prod.SetStopCallback(prod.close)

	prod.streamMap = conf.GetStreamMap("StreamMapping", "default")
	prod.batch = core.NewMessageBatch(int(conf.GetInt("BatchMaxMessages", 5000)))

	prod.lastSendTime = time.Now()
	prod.closing = false
	prod.objects = make(map[string]*objectData)
	prod.objectsLock = new(sync.Mutex)

	prod.metricsRegistry = core.NewMetricsRegistry(prod.GetID())
	prod.counters = make(map[string]metrics.Counter)

	for _, s3Path := range prod.streamMap {
		counter := metrics.NewCounter()
		prod.counters[s3Path] = counter
		prod.metricsRegistry.Register(s3Path, counter)
	}

	prod.useFiles = prod.localPath != ""
	if prod.useFiles {
		if err := os.MkdirAll(prod.localPath, 0700); err != nil {
			conf.Errors.Pushf("Failed to create %s because of %s", prod.localPath, err.Error())
			return // ### return, missing directory ###
		}
		prod.stateFile = path.Join(prod.localPath, "state")
		if _, err := os.Stat(prod.stateFile); !os.IsNotExist(err) {
			data, err := ioutil.ReadFile(prod.stateFile)
			if conf.Errors.Push(err) {
				return
			}
			if err := json.Unmarshal(data, &prod.objects); conf.Errors.Push(err) {
				return
			}
			for s3Path, object := range prod.objects {
				filename := object.Filename
				basename := path.Base(filename)
				if basenum, err := strconv.ParseInt(basename, 10, 64); err == nil && basenum > prod.nextFile {
					prod.nextFile = basenum
				}
				if object.Compressed {
					filename += ".gz"
				}
				buffer, err := newS3FileBuffer(filename,
					prod.Logger.WithField("Scope", "fileBuffer"))
				if conf.Errors.Push(err) {
					return
				}
				object.buffer = buffer
				object.lock = new(sync.Mutex)
				// add missing metrics
				if _, exists := prod.counters[s3Path]; !exists {
					counter := metrics.NewCounter()
					prod.counters[s3Path] = counter
					prod.metricsRegistry.GetOrRegister(s3Path, counter)
				}
			}
		}
	}

	if conf.HasValue("PathFormatter") {
		keyFormatter := conf.GetPlugin("PathFormatter", "format.Identifier", tcontainer.MarshalMap{})
		prod.pathFormat = keyFormatter.(core.Modulator)
	} else {
		prod.pathFormat = nil
	}

	if prod.objectMaxMessages < 1 {
		prod.objectMaxMessages = 1
		prod.Logger.Warning("ObjectMaxMessages was < 1. Defaulting to 1.")
	}

	if prod.objectMaxMessages > 1 && len(prod.delimiter) == 0 {
		prod.delimiter = []byte("\n")
		prod.Logger.Warning("ObjectMessageDelimiter was empty. Defaulting to \"\\n\".")
	}

	// Config
	defaultEndpoint := "s3.amazonaws.com"
	prod.config = aws.NewConfig()
	if region := conf.GetString("Region", "eu-west-1"); region != "" {
		prod.config.WithRegion(region)
		if region != "us-east-1" {
			defaultEndpoint = "s3-" + region + ".amazonaws.com"
		}
	}

	if endpoint := conf.GetString("Endpoint", defaultEndpoint); endpoint != "" {
		prod.config.WithEndpoint(endpoint)
	}

	// Credentials
	prod.config.CredentialsChainVerboseErrors = aws.Bool(true)
	credentialType := strings.ToLower(conf.GetString("Credential/Type", s3CredentialNone))
	switch credentialType {
	case s3CredentialEnv:
		prod.config.WithCredentials(credentials.NewEnvCredentials())

	case s3CredentialStatic:
		id := conf.GetString("Credential/Id", "")
		token := conf.GetString("Credential/Token", "")
		secret := conf.GetString("Credential/Secret", "")
		prod.config.WithCredentials(credentials.NewStaticCredentials(id, secret, token))

	case s3CredentialShared:
		filename := conf.GetString("Credential/File", "")
		profile := conf.GetString("Credential/Profile", "")
		prod.config.WithCredentials(credentials.NewSharedCredentials(filename, profile))

	case s3CredentialNone:
		// Nothing

	default:
		conf.Errors.Pushf("Unknown CredentialType: %s", credentialType)
	}
}
943170
func (rotate *RotateConfig) Configure(conf core.PluginConfigReader) {
	rotateAt := conf.GetString("Rotation/At", "")
	if rotateAt != "" {
		parts := strings.Split(rotateAt, ":")
		rotateAtHour, _ := strconv.ParseInt(parts[0], 10, 8)
		rotateAtMin, _ := strconv.ParseInt(parts[1], 10, 8)

		rotate.AtHour = int(rotateAtHour)
		rotate.AtMinute = int(rotateAtMin)
	}
}
1175117
func (filter *Rate) Configure(conf core.PluginConfigReader) {
	filter.stateGuard = new(sync.RWMutex)
	filter.state = make(map[core.MessageStreamID]*rateState)
	filter.metricsRegistry = core.NewMetricsRegistry("ratelimit")

	ignore := conf.GetStreamArray("Ignore", []core.MessageStreamID{})
	for _, stream := range ignore {
		filter.state[stream] = &rateState{
			ignore: true,
		}
	}
}
286242
func (filter *SimpleFilter) Configure(conf PluginConfigReader) error {
	filter.Logger = conf.GetSubLogger("Filter")
	//filter.filteredStreamID = GetStreamID(conf.GetString("FilteredStream", InvalidStream))
	return nil
}
296636
func (p *Provider) Configure(c *terraform.ResourceConfig) error {
	// No configuration
	if p.ConfigureFunc == nil {
		return nil
	}

	sm := schemaMap(p.Schema)

	// Get a ResourceData for this configuration. To do this, we actually
	// generate an intermediary "diff" although that is never exposed.
	diff, err := sm.Diff(nil, c, nil, p.meta, true)
	if err != nil {
		return err
	}

	data, err := sm.Data(nil, diff)
	if err != nil {
		return err
	}

	meta, err := p.ConfigureFunc(data)
	if err != nil {
		return err
	}

	p.meta = meta
	return nil
}
1127596
func Configure(b *bootstrap.Bootstrapper) {
	b.Get("/", GetIndexHandler)
	b.Get("/follower/{id:long}", GetFollowerHandler)
	b.Get("/following/{id:long}", GetFollowingHandler)
	b.Get("/like/{id:long}", GetLikeHandler)
}
1362698
func Configure(apiServer, kubeconfigPath string) {
	config.APIServer = apiServer
	config.KubeconfigPath = kubeconfigPath

	if IsEnabled() &&
		config.APIServer != "" &&
		!strings.HasPrefix(apiServer, "http") {
		config.APIServer = "http://" + apiServer
	}
}
351904
func (prod *Websocket) Configure(conf core.PluginConfigReader) {
	prod.SetStopCallback(prod.close)

	prod.upgrader = websocket.Upgrader{}

	if prod.ignoreOrigin {
		prod.upgrader.CheckOrigin = func(r *http.Request) bool { return prod.ignoreOrigin }
	}
}
809557
func (cons *HTTP) Configure(conf core.PluginConfigReader) {
	if cons.htpasswd != "" {
		if _, fileErr := os.Stat(cons.htpasswd); os.IsNotExist(fileErr) {
			conf.Errors.Pushf("htpasswd file does not exist: %s", cons.htpasswd)
			cons.htpasswd = ""
		}
		cons.secrets = auth.HtpasswdFileProvider(cons.htpasswd)
	}

	certificateFile := conf.GetString("Certificate", "")
	keyFile := conf.GetString("PrivateKey", "")

	if certificateFile != "" || keyFile != "" {
		if certificateFile == "" || keyFile == "" {
			conf.Errors.Pushf("There must always be a certificate and a private key or none of both")
		} else {

			cons.certificate = new(tls.Config)
			cons.certificate.NextProtos = []string{"http/1.1"}

			keypair, err := tls.LoadX509KeyPair(certificateFile, keyFile)
			if !conf.Errors.Push(err) {
				cons.certificate.Certificates = []tls.Certificate{keypair}
			}
		}
	}
}
1057469
func (prod *AwsS3) Configure(conf core.PluginConfigReader) {
	prod.SetRollCallback(prod.rotateTargetFiles)
	prod.SetStopCallback(prod.close)

	prod.filesByStream = make(map[core.MessageStreamID]*components.BatchedWriterAssembly)
	prod.files = make(map[string]*components.BatchedWriterAssembly)

	prod.hasWildcard = strings.IndexByte(prod.fileNamePattern, '*') != -1
	prod.Rotate.Enabled = true // force rotation

	prod.batchedFileGuard = new(sync.RWMutex)
}
773018
func (prod *StatsdMetrics) Configure(conf core.PluginConfigReader) {
	prod.SetStopCallback(prod.close)

	prod.streamMap = conf.GetStreamMap("StreamMapping", "")
	prod.batch = core.NewMessageBatch(int(conf.GetInt("Batch/MaxMessages", 500)))

	server := conf.GetString("Server", "localhost:8125")
	prefix := conf.GetString("Prefix", "gollum.")
	prod.client = statsd.NewStatsdClient(server, prefix)
	conf.Errors.Push(prod.client.CreateSocket())
}
1272712
func (prod *Scribe) Configure(conf core.PluginConfigReader) {
	prod.SetStopCallback(prod.close)
	host := conf.GetString("Address", "localhost:1463")
	prod.category = conf.GetStreamMap("Categories", "")
	prod.windowSize = prod.maxWindowSize
	prod.categoryGuard = new(sync.RWMutex)
	prod.metricsRegistry = core.NewMetricsRegistryForPlugin(prod)
	prod.metricCount = make(map[core.MessageStreamID]metrics.Counter)

	// Initialize scribe connection

	var err error
	prod.socket, err = thrift.NewTSocketTimeout(host, prod.connectionTimeout)
	conf.Errors.Push(err)

	prod.transport = thrift.NewTFramedTransport(prod.socket)
	binProtocol := thrift.NewTBinaryProtocol(prod.transport, false, false)
	prod.scribe = scribe.NewScribeClientProtocol(prod.transport, binProtocol, binProtocol)

	prod.metricWindowSize = metrics.NewGauge()
	prod.metricsRegistry.Register("windowsize", prod.metricWindowSize)

	for streamID, category := range prod.category {
		counter := metrics.NewCounter()
		prod.metricCount[streamID] = counter
		prod.metricsRegistry.Register(category, counter)
	}
}
1273916
func (prod *Proxy) Configure(conf core.PluginConfigReader) {
	prod.SetStopCallback(prod.close)

	prod.protocol, prod.address = tnet.ParseAddress(conf.GetString("Address", ":5880"), "tcp")
	if prod.protocol == "udp" {
		conf.Errors.Pushf("Proxy does not support UDP")
	}

	delimiter := tstrings.Unescape(conf.GetString("Delimiter", "\n"))
	offset := int(conf.GetInt("Offset", 0))
	flags := tio.BufferedReaderFlagEverything // pass all messages as-is

	partitioner := strings.ToLower(conf.GetString("Partitioner", "delimiter"))
	switch partitioner {
	case "binary_be":
		flags |= tio.BufferedReaderFlagBigEndian
		fallthrough

	case "binary", "binary_le":
		switch conf.GetInt("Size", 4) {
		case 1:
			flags |= tio.BufferedReaderFlagMLE8
		case 2:
			flags |= tio.BufferedReaderFlagMLE16
		case 4:
			flags |= tio.BufferedReaderFlagMLE32
		case 8:
			flags |= tio.BufferedReaderFlagMLE64
		default:
			conf.Errors.Pushf("Size only supports the value 1,2,4 and 8")
		}

	case "fixed":
		flags |= tio.BufferedReaderFlagMLEFixed
		offset = int(conf.GetInt("Size", 1))

	case "ascii":
		flags |= tio.BufferedReaderFlagMLE

	case "delimiter":
		// Nothing to add

	default:
		conf.Errors.Pushf("Unknown partitioner: %s", partitioner)
	}

	prod.reader = tio.NewBufferedReader(prod.bufferSizeKB, flags, offset, delimiter)
}
446502
func (prod *AwsKinesis) Configure(conf core.PluginConfigReader) {
	prod.lastSendTime = time.Now()
	prod.counters = make(map[string]*int64)
	prod.lastMetricUpdate = time.Now()
	prod.sequence = new(int64)
	prod.metricsRegistry = core.NewMetricsRegistryForPlugin(prod)
	prod.metricCount = make(map[string]metrics.Counter)

	if prod.recordMaxMessages < 1 {
		prod.recordMaxMessages = 1
		prod.Logger.Warning("RecordMaxMessages was < 1. Defaulting to 1.")
	}

	if prod.recordMaxMessages > 1 && len(prod.delimiter) == 0 {
		prod.delimiter = []byte("\n")
		prod.Logger.Warning("RecordMessageDelimiter was empty. Defaulting to \"\\n\".")
	}

	prod.streamMap = conf.GetStreamMap("StreamMapping", "")
	for _, kinesisStreamName := range prod.streamMap {
		counter := metrics.NewCounter()
		prod.metricCount[kinesisStreamName] = counter
		prod.metricsRegistry.Register(kinesisStreamName, counter)
	}
}
668874
func (client *AwsMultiClient) Configure(conf core.PluginConfigReader) {
	client.config = aws.NewConfig()

	client.config.WithRegion(client.region)
	client.config.WithEndpoint(client.endpoint)

	credentials, err := client.Credentials.CreateAwsCredentials()
	if err != nil {
		conf.Errors.Push(err)
	}

	client.config.WithCredentials(credentials)
	client.config.CredentialsChainVerboseErrors = aws.Bool(true)
}
705265
func (db *DB) configure(prefix string) {
	// Initialize all the metrics collector at the requested prefix
	db.compTimeMeter = metrics.NewRegisteredMeter(prefix+"compact/time", nil)
	db.compReadMeter = metrics.NewRegisteredMeter(prefix+"compact/input", nil)
	db.compWriteMeter = metrics.NewRegisteredMeter(prefix+"compact/output", nil)
	db.diskReadMeter = metrics.NewRegisteredMeter(prefix+"disk/read", nil)
	db.diskWriteMeter = metrics.NewRegisteredMeter(prefix+"disk/write", nil)
	db.writeDelayMeter = metrics.NewRegisteredMeter(prefix+"compact/writedelay/duration", nil)
	db.writeDelayNMeter = metrics.NewRegisteredMeter(prefix+"compact/writedelay/counter", nil)
}