-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial commit * Added nolint for strings.SplitN * Update pkg/providers/process_env.go Co-authored-by: Elad Kaplan <[email protected]> * Update pkg/providers/process_env.go Co-authored-by: Elad Kaplan <[email protected]> * Update pkg/providers/process_env.go Co-authored-by: Elad Kaplan <[email protected]> * Update pkg/providers/process_env.go Co-authored-by: Elad Kaplan <[email protected]> * Updates based on feedback * Minor tweaks for return errors * Updated template Co-authored-by: Elad Kaplan <[email protected]>
- Loading branch information
1 parent
604abec
commit 97ef49b
Showing
5 changed files
with
124 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package providers | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"sort" | ||
"strings" | ||
|
||
"github.com/spectralops/teller/pkg/core" | ||
|
||
"github.com/spectralops/teller/pkg/logging" | ||
) | ||
|
||
type ProcessEnv struct { | ||
logger logging.Logger | ||
} | ||
|
||
// NewProcessEnv creates new provider instance | ||
func NewProcessEnv(logger logging.Logger) (core.Provider, error) { | ||
return &ProcessEnv{ | ||
logger: logger, | ||
}, nil | ||
} | ||
|
||
// Name return the provider name | ||
func (a *ProcessEnv) Name() string { | ||
return "process_env" | ||
} | ||
|
||
// GetMapping returns a multiple entries | ||
func (a *ProcessEnv) GetMapping(p core.KeyPath) ([]core.EnvEntry, error) { | ||
a.logger.Debug("read secret") | ||
|
||
kvs := make(map[string]string) | ||
for _, envs := range os.Environ() { | ||
pair := strings.SplitN(envs, "=", 2) // nolint: gomnd | ||
kvs[pair[0]] = pair[1] | ||
} | ||
var entries []core.EnvEntry | ||
for k, v := range kvs { | ||
entries = append(entries, p.FoundWithKey(k, v)) | ||
} | ||
sort.Sort(core.EntriesByKey(entries)) | ||
return entries, nil | ||
} | ||
|
||
// Get returns a single entry | ||
func (a *ProcessEnv) Get(p core.KeyPath) (*core.EnvEntry, error) { | ||
a.logger.Debug("read secret") | ||
|
||
k := p.EffectiveKey() | ||
val, ok := os.LookupEnv(k) | ||
if !ok { | ||
a.logger.WithFields(map[string]interface{}{"key": k}).Debug("key not found") | ||
ent := p.Missing() | ||
return &ent, nil | ||
} | ||
|
||
ent := p.Found(val) | ||
return &ent, nil | ||
} | ||
|
||
// Delete will delete entry | ||
func (a *ProcessEnv) Delete(kp core.KeyPath) error { | ||
return fmt.Errorf("provider %s does not implement delete yet", a.Name()) | ||
} | ||
|
||
// DeleteMapping will delete the given path recessively | ||
func (a *ProcessEnv) DeleteMapping(kp core.KeyPath) error { | ||
return fmt.Errorf("provider %s does not implement deleteMapping yet", a.Name()) | ||
} | ||
|
||
// Put will create a new single entry | ||
func (a *ProcessEnv) Put(p core.KeyPath, val string) error { | ||
return fmt.Errorf("provider %s does not implement put yet", a.Name()) | ||
} | ||
|
||
// PutMapping will create a multiple entries | ||
func (a *ProcessEnv) PutMapping(p core.KeyPath, m map[string]string) error { | ||
return fmt.Errorf("provider %s does not implement putMapping yet", a.Name()) | ||
} |
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 @@ | ||
package providers |
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