// ToQueryConfig converts InfluxQL into queryconfigs
// If influxql cannot be represented by a full query config, then, the
// query config's raw text is set to the query.
978205
func ToQueryConfig(query string) chronograf.QueryConfig {
	qc, err := influx.Convert(query)
	if err == nil {
		return qc
	}
	return chronograf.QueryConfig{
		RawText: &query,
		Fields:  []chronograf.Field{},
		GroupBy: chronograf.GroupBy{
			Tags: []string{},
		},
		Tags: make(map[string][]string),
	}
}
1011791
func (env *environ) Config() *config.Config {
	env.lock.Lock()
	defer env.lock.Unlock()

	cfg := env.ecfgUnlocked.Config
	return cfg
}
102917
func (c Config) FluentConfig() fluent.Config {
	return fluent.Config{
		FluentPort:         c.Port,
		FluentHost:         c.Host,
		FluentNetwork:      c.FluentNetwork,
		FluentSocketPath:   c.FluentSocketPath,
		Timeout:            c.Timeout,
		WriteTimeout:       c.WriteTimeout,
		BufferLimit:        c.BufferLimit,
		RetryWait:          c.RetryWait,
		MaxRetry:           c.MaxRetry,
		TagPrefix:          c.TagPrefix,
		Async:              c.AsyncConnect,
		MarshalAsJSON:      c.MarshalAsJSON,
		SubSecondPrecision: c.SubSecondPrecision,
	}
}
1244828
func Convert(influxQL string) (chronograf.QueryConfig, error) {
	itsDashboardTime := false
	intervalTime := false

	if strings.Contains(influxQL, ":interval:") {
		influxQL = strings.Replace(influxQL, ":interval:", "8675309ns", -1)
		intervalTime = true
	}

	if strings.Contains(influxQL, ":dashboardTime:") {
		influxQL = strings.Replace(influxQL, ":dashboardTime:", "now() - 15m", 1)
		itsDashboardTime = true
	}

	query, err := influxql.ParseQuery(influxQL)
	if err != nil {
		return chronograf.QueryConfig{}, err
	}

	if itsDashboardTime {
		influxQL = strings.Replace(influxQL, "now() - 15m", ":dashboardTime:", 1)
	}

	if intervalTime {
		influxQL = strings.Replace(influxQL, "8675309ns", ":interval:", -1)
	}

	raw := chronograf.QueryConfig{
		RawText: &influxQL,
		Fields:  []chronograf.Field{},
		GroupBy: chronograf.GroupBy{
			Tags: []string{},
		},
		Tags: make(map[string][]string),
	}
	qc := chronograf.QueryConfig{
		GroupBy: chronograf.GroupBy{
			Tags: []string{},
		},
		Tags: make(map[string][]string),
	}

	if len(query.Statements) != 1 {
		return raw, nil
	}

	stmt, ok := query.Statements[0].(*influxql.SelectStatement)
	if !ok {
		return raw, nil
	}

	// Query config doesn't support limits
	if stmt.Limit != 0 || stmt.Offset != 0 || stmt.SLimit != 0 || stmt.SOffset != 0 {
		return raw, nil
	}

	// Query config doesn't support sorting
	if len(stmt.SortFields) > 0 {
		return raw, nil
	}

	// Query config doesn't allow SELECT INTO
	if stmt.Target != nil {
		return raw, nil
	}

	// Query config only allows selecting from one source at a time.
	if len(stmt.Sources) != 1 {
		return raw, nil
	}

	src := stmt.Sources[0]
	measurement, ok := src.(*influxql.Measurement)
	if !ok {
		return raw, nil
	}

	if measurement.Regex != nil {
		return raw, nil
	}
	qc.Database = measurement.Database
	qc.RetentionPolicy = measurement.RetentionPolicy
	qc.Measurement = measurement.Name

	for _, dim := range stmt.Dimensions {
		switch v := dim.Expr.(type) {
		default:
			return raw, nil
		case *influxql.Call:
			if v.Name != "time" {
				return raw, nil
			}
			// Make sure there is exactly one argument.
			if len(v.Args) != 1 {
				return raw, nil
			}
			// Ensure the argument is a duration.
			lit, ok := v.Args[0].(*influxql.DurationLiteral)
			if !ok {
				return raw, nil
			}
			if intervalTime {
				qc.GroupBy.Time = "auto"
			} else {
				qc.GroupBy.Time = lit.String()
			}
			// Add fill to queryConfig only if there's a `GROUP BY time`
			switch stmt.Fill {
			case influxql.NullFill:
				qc.Fill = "null"
			case influxql.NoFill:
				qc.Fill = "none"
			case influxql.NumberFill:
				qc.Fill = fmt.Sprint(stmt.FillValue)
			case influxql.PreviousFill:
				qc.Fill = "previous"
			case influxql.LinearFill:
				qc.Fill = "linear"
			default:
				return raw, nil
			}
		case *influxql.VarRef:
			qc.GroupBy.Tags = append(qc.GroupBy.Tags, v.Val)
		}
	}

	qc.Fields = []chronograf.Field{}
	for _, fld := range stmt.Fields {
		switch f := fld.Expr.(type) {
		default:
			return raw, nil
		case *influxql.Call:
			// only support certain query config functions
			if _, ok = supportedFuncs[f.Name]; !ok {
				return raw, nil
			}

			fldArgs := []chronograf.Field{}
			for _, arg := range f.Args {
				switch ref := arg.(type) {
				case *influxql.VarRef:
					fldArgs = append(fldArgs, chronograf.Field{
						Value: ref.Val,
						Type:  "field",
					})
				case *influxql.IntegerLiteral:
					fldArgs = append(fldArgs, chronograf.Field{
						Value: strconv.FormatInt(ref.Val, 10),
						Type:  "integer",
					})
				case *influxql.NumberLiteral:
					fldArgs = append(fldArgs, chronograf.Field{
						Value: strconv.FormatFloat(ref.Val, 'f', -1, 64),
						Type:  "number",
					})
				case *influxql.RegexLiteral:
					fldArgs = append(fldArgs, chronograf.Field{
						Value: ref.Val.String(),
						Type:  "regex",
					})
				case *influxql.Wildcard:
					fldArgs = append(fldArgs, chronograf.Field{
						Value: "*",
						Type:  "wildcard",
					})
				default:
					return raw, nil
				}
			}

			qc.Fields = append(qc.Fields, chronograf.Field{
				Value: f.Name,
				Type:  "func",
				Alias: fld.Alias,
				Args:  fldArgs,
			})
		case *influxql.VarRef:
			if f.Type != influxql.Unknown {
				return raw, nil
			}
			qc.Fields = append(qc.Fields, chronograf.Field{
				Value: f.Val,
				Type:  "field",
				Alias: fld.Alias,
			})
		}
	}

	if stmt.Condition == nil {
		return qc, nil
	}

	reduced := influxql.Reduce(stmt.Condition, nil)
	logic, ok := isTagLogic(reduced)
	if !ok {
		return raw, nil
	}

	ops := map[string]bool{}
	for _, l := range logic {
		values, ok := qc.Tags[l.Tag]
		if !ok {
			values = []string{}
		}
		ops[l.Op] = true
		values = append(values, l.Value)
		qc.Tags[l.Tag] = values
	}

	if len(logic) > 0 {
		if len(ops) != 1 {
			return raw, nil
		}
		if _, ok := ops["=="]; ok {
			qc.AreTagsAccepted = true
		}
	}

	// If the condition has a time range we report back its duration
	if dur, ok := hasTimeRange(stmt.Condition); ok {
		if !itsDashboardTime {
			qc.Range = &chronograf.DurationRange{
				Lower: "now() - " + shortDur(dur),
			}
		}
	}

	return qc, nil
}
288679
func validateSQLConfig(cfg *SQLConfig) error {
	if cfg == nil {
		return fmt.Errorf("config is required")
	}

	if cfg.Execer == nil && cfg.Queryer == nil && cfg.Pinger == nil {
		return fmt.Errorf("one of Execer, Queryer, or Pinger is required in SQLConfig")
	}

	if (cfg.Execer != nil || cfg.Queryer != nil) && len(cfg.Query) == 0 {
		return fmt.Errorf("SQLConfig.Query is required")
	}

	return nil
}
355779
func (sb *SearchBuilder) ToSql() (string, []interface{}) {
	sb.params = make([]interface{}, 0)

	sb.buildSelect()

	if len(sb.tags) > 0 {
		sb.buildTagQuery()
	} else {
		sb.buildMainQuery()
	}

	sb.sql.WriteString(`
		ORDER BY dashboard.id ` + dialect.LimitOffset(sb.limit, (sb.page-1)*sb.limit) + `) as ids
		INNER JOIN dashboard on ids.id = dashboard.id
	`)

	sb.sql.WriteString(`
		LEFT OUTER JOIN dashboard folder on folder.id = dashboard.folder_id
		LEFT OUTER JOIN dashboard_tag on dashboard.id = dashboard_tag.dashboard_id`)

	sb.sql.WriteString(" ORDER BY dashboard.title ASC")
	return sb.sql.String(), sb.params
}
416811
func Convert_v1_DockerConfig_To_config_DockerConfig(in *v1.DockerConfig, out *config.DockerConfig, s conversion.Scope) error {
	return autoConvert_v1_DockerConfig_To_config_DockerConfig(in, out, s)
}
95449
func (s *configsService) Config(db *gorm.DB, app *App) (*Config, error) {
	r, err := releasesFind(db, ReleasesQuery{App: app})
	if err != nil {
		if err == gorm.RecordNotFound {
			// It's possible to have config without releases, this handles that.
			c, err := configsFind(db, ConfigsQuery{App: app})
			if err != nil {
				if err == gorm.RecordNotFound {
					// Return an empty config.
					return &Config{
						AppID: app.ID,
						App:   app,
						Vars:  make(Vars),
					}, nil
				}
				return nil, err
			}

			return c, nil
		}

		return nil, err
	}

	return r.Config, nil
}
447823
func (r *FastHttpRequest) GetQuery() url.Values {
	if !r.toQuery {
		// Attempt to convert to query
		r.query = url.Values{}
		r.Original.QueryArgs().VisitAll(func(key, value []byte) {
			r.query.Set(string(key), string(value))
		})
		r.toQuery = true
	}
	return r.query
}
701908
func Config(config amqp.Config) ClientOpt {
	return func(c *Client) {
		c.config = config
	}
}
65202
func (c *Cache) Config() Config {
	c.Lock()
	defer c.Unlock()
	return c.config
}
1290033
func config(c context.Context) *Config {
	cfg, _ := c.Value(configContextKey(0)).(*Config)
	if cfg == nil {
		panic("impossible, configContextKey is not set")
	}
	return cfg
}
598499
func DefaultConfig() Config {
	return Config{
		Status:   true,
		IP:       true,
		Method:   true,
		Path:     true,
		Query:    false,
		Columns:  false,
		LogFunc:  nil,
		Skippers: nil,
		skip:     nil,
	}
}
90688
func ToSQL(cond interface{}) (string, []interface{}, error) {
	switch cond.(type) {
	case Cond:
		return condToSQL(cond.(Cond))
	case *Builder:
		return cond.(*Builder).ToSQL()
	}
	return "", nil, ErrNotSupportType
}
1315643
func (o *Operation) Config() (*configs.Config, tfdiags.Diagnostics) {
	var diags tfdiags.Diagnostics
	config, hclDiags := o.ConfigLoader.LoadConfig(o.ConfigDir)
	diags = diags.Append(hclDiags)
	return config, diags
}
1163124
func (g *Google) Config() *oauth2.Config {
	return &oauth2.Config{
		ClientID:     g.ID(),
		ClientSecret: g.Secret(),
		Scopes:       g.Scopes(),
		Endpoint:     GoogleEndpoint,
		RedirectURL:  g.RedirectURL,
	}
}
369443
func (b *BatchBuilder) ToCql() (stmt string, names []string) {
	cql := bytes.Buffer{}

	cql.WriteString("BEGIN ")
	if b.unlogged {
		cql.WriteString("UNLOGGED ")
	}
	if b.counter {
		cql.WriteString("COUNTER ")
	}
	cql.WriteString("BATCH ")

	names = append(names, b.using.writeCql(&cql)...)

	for _, stmt := range b.stmts {
		cql.WriteString(stmt)
		cql.WriteByte(';')
		cql.WriteByte(' ')
	}
	names = append(names, b.names...)

	cql.WriteString("APPLY BATCH ")

	stmt = cql.String()
	return
}