// FindVariables retrieves all variables that match the provided filter and then filters the list down to only the resources that are authorized.
186574
func (s *VariableService) FindVariables(ctx context.Context, filter influxdb.VariableFilter, opt ...influxdb.FindOptions) ([]*influxdb.Variable, error) {
	// TODO: we'll likely want to push this operation into the database since fetching the whole list of data will likely be expensive.
	ms, err := s.s.FindVariables(ctx, filter, opt...)
	if err != nil {
		return nil, err
	}

	// This filters without allocating
	// https://github.com/golang/go/wiki/SliceTricks#filtering-without-allocating
	variables := ms[:0]
	for _, m := range ms {
		err := authorizeReadVariable(ctx, m.OrganizationID, m.ID)
		if err != nil && influxdb.ErrorCode(err) != influxdb.EUnauthorized {
			return nil, err
		}

		if influxdb.ErrorCode(err) == influxdb.EUnauthorized {
			continue
		}

		variables = append(variables, m)
	}

	return variables, nil
}
1149163
func (obj *Doc) GetVariable(ctx context.Context, name string) (*Variable, error) {
	result := &struct {
		Return *ObjectInterface	`json:"qReturn"`
	} {}
	err := obj.rpc(ctx, "GetVariable", result, name)
	if err != nil {
		return nil, err
	}
	return &Variable{obj.session.getRemoteObject(result.Return)}, err 
}
893628
func (obj *Doc) GetFavoriteVariables(ctx context.Context) ([]string, error) {
	result := &struct {
		Names []string	`json:"qNames"`
	} {}
	err := obj.rpc(ctx, "GetFavoriteVariables", result)
	return result.Names, err 
}
599687
func (l *Client) GetVariationList() ([]Variation, error) {
	res := ApiResp{}
	data := []Variation{}

	// make the request
	err := l.Get(variationListEndpoint, nil, nil, &res, &data)
	if err != nil {
		return data, err
	}

	return data, nil
}
656001
func (s *SourceService) FindSources(ctx context.Context, opts influxdb.FindOptions) ([]*influxdb.Source, int, error) {
	// TODO: we'll likely want to push this operation into the database since fetching the whole list of data will likely be expensive.
	ss, _, err := s.s.FindSources(ctx, opts)
	if err != nil {
		return nil, 0, err
	}

	// This filters without allocating
	// https://github.com/golang/go/wiki/SliceTricks#filtering-without-allocating
	sources := ss[:0]
	for _, src := range ss {
		err := authorizeReadSource(ctx, src.OrganizationID, src.ID)
		if err != nil && influxdb.ErrorCode(err) != influxdb.EUnauthorized {
			return nil, 0, err
		}

		// TODO(desa): this is a totaly hack and needs to be fixed.
		// Specifically, we need to remove the concept of a default source.
		if src.OrganizationID.String() == bolt.DefaultSourceOrganizationID {
			sources = append(sources, src)
			continue
		}

		if influxdb.ErrorCode(err) == influxdb.EUnauthorized {
			continue
		}

		sources = append(sources, src)
	}

	return sources, len(sources), nil
}
458851
func (s *VariableService) FindVariableByID(ctx context.Context, id influxdb.ID) (*influxdb.Variable, error) {
	m, err := s.s.FindVariableByID(ctx, id)
	if err != nil {
		return nil, err
	}

	if err := authorizeReadVariable(ctx, m.OrganizationID, id); err != nil {
		return nil, err
	}

	return m, nil
}
949292
func (body Body) Vars(params VarVisitorParams) VarSet {
	vis := NewVarVisitor().WithParams(params)
	Walk(vis, body)
	return vis.Vars()
}
427354
func (vf *VindexFunc) GetFields(vcursor VCursor, bindVars map[string]*querypb.BindVariable) (*sqltypes.Result, error) {
	return &sqltypes.Result{Fields: vf.Fields}, nil
}
448145
func (c *Client) FindVariables(ctx context.Context, filter platform.VariableFilter, opt ...platform.FindOptions) ([]*platform.Variable, error) {
	// todo(leodido) > handle find options
	op := getOp(platform.OpFindVariables)
	res := []*platform.Variable{}
	err := c.db.View(func(tx *bolt.Tx) error {
		variables, err := c.findVariables(ctx, tx, filter)
		if err != nil && platform.ErrorCode(err) != platform.ENotFound {
			return err
		}
		res = variables
		return nil
	})

	if err != nil {
		return nil, &platform.Error{
			Op:  op,
			Err: err,
		}
	}

	return res, nil
}
249797
func (s *CreateDeploymentInput) SetVariables(v map[string]*string) *CreateDeploymentInput {
	s.Variables = v
	return s
}
1089905
func (rule *Rule) AddVariable(variable *Variable) {
	for key, existingVariable := range rule.Variables {
		if existingVariable.Name == variable.Name {
			rule.Variables[key] = variable

			return
		}
	}

	rule.Variables = append(rule.Variables, variable)
}
301632
func (scope *EvalScope) LocalVariables(cfg LoadConfig) ([]*Variable, error) {
	vars, err := scope.Locals()
	if err != nil {
		return nil, err
	}
	vars = filterVariables(vars, func(v *Variable) bool {
		return (v.Flags & (VariableArgument | VariableReturnArgument)) == 0
	})
	cfg.MaxMapBuckets = maxMapBucketsFactor * cfg.MaxArrayValues
	loadValues(vars, cfg)
	return vars, nil
}
742558
func (s *AuthorizationService) FindAuthorizations(ctx context.Context, filter platform.AuthorizationFilter, opts ...platform.FindOptions) ([]*platform.Authorization, int, error) {
	return s.FindAuthorizationsFn(ctx, filter, opts...)
}
1234670
func (ctx *Context) GetVar(k string) (string, bool) {
	for i := len(ctx.scopes) - 1; i >= 0; i-- {
		if v, ok := ctx.scopes[i][k]; ok {
			return v, true
		}
	}

	return "", false
}
31378
func parseVariableDefinitions(parser *Parser) ([]*ast.VariableDefinition, error) {
	variableDefinitions := []*ast.VariableDefinition{}
	if !peek(parser, lexer.PAREN_L) {
		return variableDefinitions, nil
	}
	if vdefs, err := reverse(parser,
		lexer.PAREN_L, parseVariableDefinition, lexer.PAREN_R,
		true,
	); err != nil {
		return variableDefinitions, err
	} else {
		for _, vdef := range vdefs {
			variableDefinitions = append(variableDefinitions, vdef.(*ast.VariableDefinition))
		}
	}
	return variableDefinitions, nil
}
819136
func (c *Config) GetVariables() map[string]string {
	n := map[string]string{}
	for k, v := range c.variables {
		n[k] = v
	}
	return n
}
443905
func (scope *EvalScope) PackageVariables(cfg LoadConfig) ([]*Variable, error) {
	var vars []*Variable
	reader := scope.DwarfReader()

	var utypoff dwarf.Offset
	utypentry, err := reader.SeekToTypeNamed("<unspecified>")
	if err == nil {
		utypoff = utypentry.Offset
	}

	for entry, err := reader.NextPackageVariable(); entry != nil; entry, err = reader.NextPackageVariable() {
		if err != nil {
			return nil, err
		}

		if typoff, ok := entry.Val(dwarf.AttrType).(dwarf.Offset); !ok || typoff == utypoff {
			continue
		}

		// Ignore errors trying to extract values
		val, err := scope.extractVarInfoFromEntry(entry)
		if err != nil {
			continue
		}
		val.loadValue(cfg)
		vars = append(vars, val)
	}

	return vars, nil
}