Skip to content

[secrets] Add secrets download and upload #1720

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

Merged
merged 3 commits into from
Jan 13, 2024
Merged

Conversation

mikeland73
Copy link
Contributor

@mikeland73 mikeland73 commented Jan 11, 2024

Summary

Adds

devbox secrets download
devbox secrets upload

Also, updated envsec dependency that has a simpler API.

How was it tested?

devbox secrets download foo.json
# modified foo.json
devbox secrets upload foo.json

@mikeland73 mikeland73 requested review from loreto and savil January 11, 2024 23:01
@@ -16,6 +16,19 @@ type secretsFlags struct {
config configFlags
}

func (f *secretsFlags) genSecrets(cmd *cobra.Command) (*envsec.Envsec, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

genSecrets: are we generating them? :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thoughts on Envsec() to indicate the struct being returned?

command := &cobra.Command{
Use: "download <file1>",
Short: "Download environment variables into the specified file",
Long: "Download environment variables stored into the specified file (most commonly a .env file). The format of the file is one NAME=VALUE per line.",
Copy link
Collaborator

Choose a reason for hiding this comment

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

could we add something about unless --format is specified?

command := &cobra.Command{
Use: "upload <file1> [<fileN>]...",
Short: "Upload variables defined in a .env file",
Long: "Upload variables defined in one or more .env files. The files " +
Copy link
Collaborator

Choose a reason for hiding this comment

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

again, need to modify it to mention --format or json

WorkingDir: d.ProjectDir(),
EnvID: envsec.EnvID{
EnvName: d.environment,
Copy link
Collaborator

Choose a reason for hiding this comment

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

is it possible for d.environment to not be set? If so, could we add a validation check in this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's already validated in devbox.Open

}, nil
}
envsecInstance.EnvID.ProjectID = project.ProjectID.String()
envsecInstance.EnvID.OrgID = project.OrgID.String()
Copy link
Collaborator

Choose a reason for hiding this comment

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

its okay for now, but I feel the API could be made a bit safer by initializing EnvID as a complete struct in one place...

having it split between UninitializedSecrets and here feels like it could lead to bugs over time (once someone less experienced with this code refactors it, etc.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, this weirdness is to fix a bug that secrets init would not work because it depended on the project already existing. Agree it's a bit awkward API.

2 possible fixes:

  • We can always set the full EnvID object. Re-writing is fine.
  • The UninitializedSecrets doesn't really need EnvID set. It just felt weird not to set it.

@mikeland73 mikeland73 merged commit 933c703 into main Jan 13, 2024
@mikeland73 mikeland73 deleted the landau/download-and-upload branch January 13, 2024 00:46
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