github.com/chenbh/concourse/v6@v6.4.2/vars/named_vars.go (about)

     1  package vars
     2  
     3  type NamedVariables map[string]Variables
     4  
     5  // Get checks var_source if presents, then forward var to underlying secret manager.
     6  // A `varDef.Name` with a var_source looks like "myvault:foo", where "myvault" is
     7  // the var_source name, and "foo" is the real var name that should be forwarded
     8  // to the underlying secret manager.
     9  func (m NamedVariables) Get(varDef VariableDefinition) (interface{}, bool, error) {
    10  	if varDef.Ref.Source == "" {
    11  		return nil, false, nil
    12  	}
    13  
    14  	if vars, ok := m[varDef.Ref.Source]; ok {
    15  		return vars.Get(varDef)
    16  	}
    17  
    18  	return nil, false, MissingSourceError{Name: varDef.Ref.Name, Source: varDef.Ref.Source}
    19  }
    20  
    21  func (m NamedVariables) List() ([]VariableDefinition, error) {
    22  	var allDefs []VariableDefinition
    23  
    24  	for source, vars := range m {
    25  		defs, err := vars.List()
    26  		if err != nil {
    27  			return nil, err
    28  		}
    29  
    30  		for i, _ := range defs {
    31  			defs[i].Ref.Source = source
    32  		}
    33  
    34  		allDefs = append(allDefs, defs...)
    35  	}
    36  
    37  	return allDefs, nil
    38  }