Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[envsec] Add List function to envsec library #252

Merged
merged 3 commits into from
Jan 8, 2024
Merged

Conversation

mikeland73
Copy link
Contributor

Summary

This adds a List and PrintEnvVars functions to the envsec library. It allows a 3rd party (e.g. devbox) app to use envsec functionality more easily.

I refactored stores as much as I could to make this easy to use, but it's still a bit tangled. Specifically, the envsec package uses the jetpack API internally a bunch. In theory, we could make most of these functions part of the store. That way other stores can implement their own init or whoami specifics depending on their capabilities. This is left for later.

Once this is merged, devbox will be able to:

  • Call envsec.List in order to fetch secrets (instead of the current implementation which calls the envsec CLI).
  • Implement a devbox secrets list command that fetches and prints secrets.

How was it tested?

envsec ls
envsec foo=123
envsec ls

@mikeland73 mikeland73 requested review from loreto and savil January 6, 2024 02:13
Copy link
Contributor

@savil savil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome!

}

return envsec.PrintEnvVars(
vars, cmd.OutOrStdout(), flags.ShowValues, flags.Format)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated to this PR:

I just noticed that the help message for --format isn't completely helpful. It could specify what the valid options are Display the key values in key=value format. Must be one of: table | dotenv | json".

Comment on lines 22 to 37
project, err := e.ProjectConfig()
if project == nil {
return nil, err
}

authClient, err := e.authClient()
if err != nil {
return nil, err
}

tok, err := authClient.LoginFlowIfNeededForOrg(ctx, project.OrgID.String())
if err != nil {
return nil, err
}

store.Identify(ctx, e, tok)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems repeated from the envsec.SetStore code above. Is it needed?

// A string that uniquely identifies the organization to which the environment belongs.
OrgID string
// A name that uniquely identifies the environment within the project.
// Usually one of: 'dev', 'prod'.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or preview

@@ -30,14 +32,18 @@ func newSSMStore(ctx context.Context, config *SSMConfig) (*SSMStore, error) {
return store, nil
}

func (s *SSMStore) List(ctx context.Context, envID EnvID) ([]EnvVar, error) {
func (s *SSMStore) Identify(context.Context, *envsec.Envsec, *session.Token) {
// TODO: implement
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a panic("TODO: implement SSMStore.Identify") ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really want it to panic since it does identity in a different way (via standard AWS credential chain). If we make it panic here it will break.

@mikeland73 mikeland73 merged commit 887c235 into main Jan 8, 2024
1 check passed
@mikeland73 mikeland73 deleted the landau/list-lib-call branch January 8, 2024 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants