Skip to content

Commit

Permalink
prepare
Browse files Browse the repository at this point in the history
  • Loading branch information
jondot committed May 7, 2021
1 parent 8f6dcc0 commit ad9b655
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ dist/
teller
.vscode/
node_modules/
todo.txt
.teller.writecase.yml
7 changes: 7 additions & 0 deletions pkg/core/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type KeyPath struct {
Optional bool `yaml:"optional,omitempty"`
Severity Severity `yaml:"severity,omitempty" default:"high"`
RedactWith string `yaml:"redact_with,omitempty" default:"**REDACTED**"`
IsSource bool `yaml:"source,omitempty"`
Handle string `yaml:"handle,omitempty"`
}
type WizardAnswers struct {
Project string
Expand All @@ -33,6 +35,8 @@ func (k *KeyPath) WithEnv(env string) KeyPath {
Field: k.Field,
Decrypt: k.Decrypt,
Optional: k.Optional,
IsSource: k.IsSource,
Handle: k.Handle,
}
}
func (k *KeyPath) SwitchPath(path string) KeyPath {
Expand All @@ -42,6 +46,8 @@ func (k *KeyPath) SwitchPath(path string) KeyPath {
Env: k.Env,
Decrypt: k.Decrypt,
Optional: k.Optional,
IsSource: k.IsSource,
Handle: k.Handle,
}
}

Expand All @@ -64,6 +70,7 @@ type EnvEntry struct {
ResolvedPath string
Severity Severity
RedactWith string
Handle string
}
type EnvEntryLookup struct {
Entries []EnvEntry
Expand Down
7 changes: 7 additions & 0 deletions pkg/providers/heroku.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func NewHeroku() (core.Provider, error) {
heroku.DefaultTransport.BearerToken = os.Getenv("HEROKU_API_KEY")

svc := heroku.NewService(heroku.DefaultClient)
//svc.ConfigVarUpdate()
return &Heroku{client: svc}, nil
}

Expand Down Expand Up @@ -77,3 +78,9 @@ func (h *Heroku) Get(p core.KeyPath) (*core.EnvEntry, error) {
func (h *Heroku) getSecret(kp core.KeyPath) (heroku.ConfigVarInfoForAppResult, error) {
return h.client.ConfigVarInfoForApp(context.TODO(), kp.Path)
}

/*
func (h *Heroku) setSecret(kp core.KeyPath) (heroku.ConfigVarInfoForAppResult, error) {
h.client.
}
*/
27 changes: 18 additions & 9 deletions pkg/teller.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,22 +311,18 @@ func updateParams(ent *core.EnvEntry, from *core.KeyPath) {
}
}

// The main "load all variables from all providers" logic. Walks over all definitions in the tellerfile
// and then: fetches, converts, creates a new EnvEntry. We're also mapping the sensitivity aspects of it.
// Note that for a similarly named entry - last one wins.
func (tl *Teller) Collect() error {
t := tl.Config
func (tl *Teller) CollectFromProviderMap(ps *ProvidersMap) ([]core.EnvEntry, error) {
entries := []core.EnvEntry{}
for pname, conf := range t.Providers {
for pname, conf := range *ps {
p, err := tl.Providers.GetProvider(pname)
if err != nil {
return err
return nil, err
}

if conf.EnvMapping != nil {
es, err := p.GetMapping(tl.Populate.KeyPath(*conf.EnvMapping))
if err != nil {
return err
return nil, err
}

// optionally remap environment variables synced from the provider
Expand All @@ -347,7 +343,7 @@ func (tl *Teller) Collect() error {
if v.Optional {
continue
} else {
return err
return nil, err
}
} else {
//nolint
Expand All @@ -359,6 +355,19 @@ func (tl *Teller) Collect() error {
}

sort.Sort(core.EntriesByKey(entries))
return entries, nil
}

// The main "load all variables from all providers" logic. Walks over all definitions in the tellerfile
// and then: fetches, converts, creates a new EnvEntry. We're also mapping the sensitivity aspects of it.
// Note that for a similarly named entry - last one wins.
func (tl *Teller) Collect() error {
t := tl.Config
entries, err := tl.CollectFromProviderMap(&t.Providers)
if err != nil {
return err
}

tl.Entries = entries
tl.Redactor = NewRedactor(entries)
return nil
Expand Down
14 changes: 8 additions & 6 deletions pkg/tellerfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import (
"gopkg.in/yaml.v2"
)

type ProvidersMap map[string]MappingConfig
type TellerFile struct {
Opts map[string]string `yaml:"opts,omitempty"`
Confirm string `yaml:"confirm,omitempty"`
Project string `yaml:"project,omitempty"`
CarryEnv bool `yaml:"carry_env,omitempty"`
Providers map[string]MappingConfig `yaml:"providers,omitempty"`
LoadedFrom string
Opts map[string]string `yaml:"opts,omitempty"`
Confirm string `yaml:"confirm,omitempty"`
Project string `yaml:"project,omitempty"`
CarryEnv bool `yaml:"carry_env,omitempty"`
Providers ProvidersMap `yaml:"providers,omitempty"`
Environments map[string]ProvidersMap `yaml:"providers,omitempty"`
LoadedFrom string
}

type MappingConfig struct {
Expand Down

0 comments on commit ad9b655

Please sign in to comment.