-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add envsubst provider * Update README.md Co-authored-by: mvkarpu1 <[email protected]> Co-authored-by: Yusuke Kuoka <[email protected]>
- Loading branch information
1 parent
b8264f6
commit d1a8606
Showing
5 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package envsubst | ||
|
||
import ( | ||
"strings" | ||
|
||
envSubst "github.com/a8m/envsubst" | ||
"github.com/variantdev/vals/pkg/api" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
type provider struct { | ||
} | ||
|
||
func New(cfg api.StaticConfig) *provider { | ||
p := &provider{} | ||
return p | ||
} | ||
|
||
func (p *provider) GetString(key string) (string, error) { | ||
key = strings.TrimSuffix(key, "/") | ||
key = strings.TrimSpace(key) | ||
|
||
str, err := envSubst.String(key) | ||
if err != nil { | ||
return "", err | ||
} | ||
return str, nil | ||
} | ||
|
||
func (p *provider) GetStringMap(key string) (map[string]interface{}, error) { | ||
key = strings.TrimSuffix(key, "/") | ||
key = strings.TrimSpace(key) | ||
|
||
bs, err := envSubst.Bytes([]byte(key)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
m := map[string]interface{}{} | ||
if err := yaml.Unmarshal(bs, &m); err != nil { | ||
return nil, err | ||
} | ||
return m, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters