template/funcs.go
func secretFunc(b *Brain, used, missing *dep.Set) func(...string) (*dep.Secret, error) {
	return func(s ...string) (*dep.Secret, error) {
		var result *dep.Secret

		if len(s) == 0 {
			return result, nil
		}

		// TODO: Refactor into separate template functions
		path, rest := s[0], s[1:]
		data := make(map[string]interface{})
		for _, str := range rest {
			parts := strings.SplitN(str, "=", 2)
			if len(parts) != 2 {
				return result, fmt.Errorf("not k=v pair %q", str)
			}

			k, v := strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1])
			data[k] = v
		}

		var d dep.Dependency
		var err error

		if len(rest) == 0 {
			d, err = dep.NewVaultReadQuery(path)
		} else {
			d, err = dep.NewVaultWriteQuery(path, data)
		}

		if err != nil {
			return nil, err
		}

		used.Add(d)

		if value, ok := b.Recall(d); ok {
			result = value.(*dep.Secret)
			return result, nil
		}

		missing.Add(d)

		return result, nil
	}
}
func secretFunc(b *Brain, used, missing *dep.Set) func(...string) (*dep.Secret, error) {
	return func(s ...string) (*dep.Secret, error) {
		var result *dep.Secret

		if len(s) == 0 {
			return result, nil
		}

		// TODO: Refactor into separate template functions
		path, rest := s[0], s[1:]
		data := make(map[string]interface{})
		for _, str := range rest {
			parts := strings.SplitN(str, "=", 2)
			if len(parts) != 2 {
				return result, fmt.Errorf("not k=v pair %q", str)
			}

			k, v := strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1])
			data[k] = v
		}

		var d dep.Dependency
		var err error

		if len(rest) == 0 {
			d, err = dep.NewVaultReadQuery(path)
		} else {
			d, err = dep.NewVaultWriteQuery(path, data)
		}

		if err != nil {
			return nil, err
		}

		used.Add(d)

		if value, ok := b.Recall(d); ok {
			result = value.(*dep.Secret)
			return result, nil
		}

		missing.Add(d)

		return result, nil
	}
}
func secretFunc ( b * Brain , used , missing * dep . Set ) func ( ... string ) ( * dep . Secret , error ) { return func ( s ... string ) ( * dep . Secret , error ) { var result * dep . Secret if len ( s ) == 0 { return result , nil } // TODO: Refactor into separate template functions path , rest := s [ 0 ] , s [ 1 : ] data := make ( map [ string ] interface { } ) for _ , str := range rest { parts := strings . SplitN ( str , " " , 2 ) if len ( parts ) != 2 { return result , fmt . Errorf ( " " , str ) } k , v := strings . TrimSpace ( parts [ 0 ] ) , strings . TrimSpace ( parts [ 1 ] ) data [ k ] = v } var d dep . Dependency var err error if len ( rest ) == 0 { d , err = dep . NewVaultReadQuery ( path ) } else { d , err = dep . NewVaultWriteQuery ( path , data ) } if err != nil { return nil , err } used . Add ( d ) if value , ok := b . Recall ( d ) ; ok { result = value . ( * dep . Secret ) return result , nil } missing . Add ( d ) return result , nil } }
// secretFunc returns or accumulates secret dependencies from Vault.
secretFunc returns or accumulates secret dependencies from Vault .