-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from adamgoose/doppler
Adding Doppler Provider
- Loading branch information
Showing
218 changed files
with
37,122 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
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,99 @@ | ||
package providers | ||
|
||
import ( | ||
"fmt" | ||
"sort" | ||
|
||
"github.com/DopplerHQ/cli/pkg/configuration" | ||
"github.com/DopplerHQ/cli/pkg/http" | ||
"github.com/DopplerHQ/cli/pkg/models" | ||
"github.com/DopplerHQ/cli/pkg/utils" | ||
"github.com/spectralops/teller/pkg/core" | ||
) | ||
|
||
type DopplerClient interface { | ||
GetSecrets(host string, verifyTLS bool, apiKey string, project string, config string) ([]byte, http.Error) | ||
} | ||
|
||
type dopplerClient struct{} | ||
|
||
func (dopplerClient) GetSecrets(host string, verifyTLS bool, apiKey, project, config string) ([]byte, http.Error) { | ||
return http.GetSecrets(host, verifyTLS, apiKey, project, config) | ||
} | ||
|
||
type Doppler struct { | ||
client DopplerClient | ||
config models.ScopedOptions | ||
} | ||
|
||
func NewDoppler() (core.Provider, error) { | ||
configuration.Setup() | ||
configuration.LoadConfig() | ||
|
||
return &Doppler{ | ||
client: dopplerClient{}, | ||
config: configuration.Get(configuration.Scope), | ||
}, nil | ||
} | ||
|
||
func (h *Doppler) Name() string { | ||
return "doppler" | ||
} | ||
|
||
func (h *Doppler) GetMapping(p core.KeyPath) ([]core.EnvEntry, error) { | ||
s, err := h.getConfig(p.Path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
entries := []core.EnvEntry{} | ||
for k, v := range s { | ||
entries = append(entries, core.EnvEntry{ | ||
Key: k, | ||
Value: v.ComputedValue, | ||
Provider: h.Name(), | ||
ResolvedPath: p.Path, | ||
}) | ||
} | ||
sort.Sort(core.EntriesByKey(entries)) | ||
return entries, nil | ||
} | ||
|
||
func (h *Doppler) Get(p core.KeyPath) (*core.EnvEntry, error) { | ||
s, err := h.getConfig(p.Path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
key := p.Env | ||
if p.Field != "" { | ||
key = p.Field | ||
} | ||
|
||
v, ok := s[key] | ||
if !ok { | ||
return nil, fmt.Errorf("field at '%s' does not exist", p.Path) | ||
} | ||
|
||
return &core.EnvEntry{ | ||
Key: p.Env, | ||
Value: v.ComputedValue, | ||
ResolvedPath: p.Path, | ||
Provider: h.Name(), | ||
}, nil | ||
} | ||
|
||
func (h *Doppler) getConfig(config string) (map[string]models.ComputedSecret, error) { | ||
r, herr := h.client.GetSecrets( | ||
h.config.APIHost.Value, | ||
utils.GetBool(h.config.VerifyTLS.Value, true), | ||
h.config.Token.Value, | ||
h.config.EnclaveProject.Value, | ||
config, | ||
) | ||
if !herr.IsNil() { | ||
return nil, herr.Err | ||
} | ||
|
||
return models.ParseSecrets(r) | ||
} |
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,38 @@ | ||
package providers | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/DopplerHQ/cli/pkg/http" | ||
"github.com/DopplerHQ/cli/pkg/models" | ||
"github.com/golang/mock/gomock" | ||
"github.com/spectralops/teller/pkg/providers/mock_providers" | ||
) | ||
|
||
func TestDoppler(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
// Assert that Bar is invoked. | ||
defer ctrl.Finish() | ||
client := mock_providers.NewMockDopplerClient(ctrl) | ||
path := "settings/prod/billing-svc" | ||
pathmap := "settings/prod/billing-svc/all" | ||
out := []byte(`{ | ||
"secrets": { | ||
"MG_KEY": { | ||
"computed": "shazam" | ||
}, | ||
"SMTP_PASS": { | ||
"computed": "mailman" | ||
} | ||
} | ||
}`) | ||
|
||
client.EXPECT().GetSecrets(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Eq(path)).Return(out, http.Error{}).AnyTimes() | ||
client.EXPECT().GetSecrets(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Eq(pathmap)).Return(out, http.Error{}).AnyTimes() | ||
|
||
s := Doppler{ | ||
client: client, | ||
config: models.ScopedOptions{}, | ||
} | ||
AssertProvider(t, &s, true) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.