Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Add secrethub import dotenv command #337

Draft
wants to merge 39 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
8fd20d5
working command, without interactive flag
hculea Aug 20, 2020
76b736d
working interactive flag
hculea Aug 20, 2020
2af5963
included error check
hculea Aug 20, 2020
d7e573f
added the secrethub.env output and the overwrite checks
hculea Aug 20, 2020
48a45d1
fix typo
hculea Aug 20, 2020
6cda093
some formatting and making the import operation transactional
hculea Aug 20, 2020
860a5c9
added the secrethub.env check and a force flag
hculea Aug 21, 2020
cccfeb3
silenced the warnings
hculea Aug 21, 2020
8d1545c
Rename import dot-env to import dotenv
SimonBarendse Nov 19, 2020
07cf5f1
Rephrase dir-path argument
SimonBarendse Nov 19, 2020
69dc065
Actually use dotenv file specified with the --env-file flag
SimonBarendse Nov 19, 2020
53eee1e
Use system default editor for import interactive mode
SimonBarendse Nov 19, 2020
571b105
Don't create a secrethub.env file on dotenv import
SimonBarendse Nov 19, 2020
d47355c
Move import helper functions to import command file
SimonBarendse Nov 19, 2020
feb2975
Extract mapping logic from openEditor function
SimonBarendse Nov 19, 2020
ba52c26
Fix missing / in openEditor function
SimonBarendse Nov 19, 2020
85fb8d7
Use TempFile function to create temporary file
SimonBarendse Nov 19, 2020
1e5d365
Defer temporary file removal in openEditor function
SimonBarendse Nov 19, 2020
1050df2
De-duplicate default envvar to path mapping
SimonBarendse Nov 19, 2020
004c21d
Use secretpath.Join to join two paths on SecretHub
SimonBarendse Nov 19, 2020
bc24a12
Separate codeblock processing interactive mode
SimonBarendse Nov 19, 2020
6206b64
Create parent directories of imported secrets if they dont exist already
SimonBarendse Nov 19, 2020
b65f008
Account for omitted envvars
SimonBarendse Nov 19, 2020
e45423e
Make storing imported secrets concurrent
SimonBarendse Nov 19, 2020
940bea8
Make checking secret existence concurrent
SimonBarendse Nov 19, 2020
d6bdb1f
Detect directory possiblities in import dotenv
SimonBarendse Nov 25, 2020
86c4ed2
Skip commented lines in dotenv import
SimonBarendse Nov 25, 2020
58d1d35
Include all after "=>" in dotenv import prompt as the secret path
SimonBarendse Nov 25, 2020
b4073f6
Handle lines not containing "=>" and lines not containing a secret path
SimonBarendse Nov 25, 2020
be48a95
Use io.Reader and io.Writer in dotenv import helper functions
SimonBarendse Nov 25, 2020
b88b4b6
Align mappings in import dotenv prompt
SimonBarendse Nov 25, 2020
f647193
Combine all secret overwrite prompts in a single prompt in dotenv import
SimonBarendse Nov 25, 2020
768c8ab
Skip empty lines in dotenv import prompt
SimonBarendse Nov 27, 2020
400e792
Add longer explanation comment to dotenv import prompt
SimonBarendse Nov 27, 2020
efe1d8b
Update dotenv import comment to indicate '=>'
SimonBarendse Nov 27, 2020
48dcfb8
Print tree at the end of dotenv import
SimonBarendse Nov 27, 2020
22c03f7
De-duplicate call to printDirContentsRecursively
SimonBarendse Nov 27, 2020
f6371fc
Make dotenv import dir-path argument required
SimonBarendse Nov 27, 2020
485780c
Change dotenv import dir-path placeholder to indicate repopath is all…
SimonBarendse Nov 27, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/aws/aws-sdk-go v1.25.49
github.com/docker/go-units v0.3.3
github.com/fatih/color v1.7.0
github.com/joho/godotenv v1.3.0
github.com/masterzen/winrm v0.0.0-20190308153735-1d17eaf15943
github.com/mattn/go-colorable v0.1.1
github.com/mattn/go-isatty v0.0.7
Expand All @@ -20,11 +21,10 @@ require (
github.com/secrethub/secrethub-go v0.30.0
github.com/zalando/go-keyring v0.0.0-20190208082241-fbe81aec3a07
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a
golang.org/x/sys v0.0.0-20200501052902-10377860bb8e
golang.org/x/text v0.3.2
google.golang.org/api v0.26.0
google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84
gopkg.in/yaml.v2 v2.2.2
gotest.tools v2.2.0+incompatible
)
17 changes: 3 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
Expand Down Expand Up @@ -162,20 +164,6 @@ github.com/secrethub/demo-app v0.1.0 h1:HwPPxuiSvx4TBE7Qppzu3A9eHqmsBrIz4Ko8u8pq
github.com/secrethub/demo-app v0.1.0/go.mod h1:ymjm8+WXTSDTFqsGVBNVmHSnwtZMYi7KptHvpo/fLH4=
github.com/secrethub/secrethub-cli v0.30.0/go.mod h1:dC0wd40v+iQdV83/0rUrOa01LYq+8Yj2AtJB1vzh2ao=
github.com/secrethub/secrethub-go v0.21.0/go.mod h1:rc2IfKKBJ4L0wGec0u4XnF5/pe0FFPE4Q1MWfrFso7s=
github.com/secrethub/secrethub-go v0.29.1-0.20200626075900-f7c68f70dc36 h1:kRVdL7PRfR80xjpOxFy1O0JROVpILWc2FZWE7Ni2Z2M=
github.com/secrethub/secrethub-go v0.29.1-0.20200626075900-f7c68f70dc36/go.mod h1:tDeBtyjfFQX3UqgaZfY+H4dYkcGfiVzrwLDf0XtfOrw=
github.com/secrethub/secrethub-go v0.29.1-0.20200630121846-9adfc0eb3add h1:+DzHsSjht15ycb7GFmyfmQ39gy8ZtA7FjWfJbWUPIYk=
github.com/secrethub/secrethub-go v0.29.1-0.20200630121846-9adfc0eb3add/go.mod h1:tDeBtyjfFQX3UqgaZfY+H4dYkcGfiVzrwLDf0XtfOrw=
github.com/secrethub/secrethub-go v0.29.1-0.20200702094400-d465926a4a6a h1:rtFQLsSWGkdqd6LQFbgHsG/be60Cpqv8tc1w4XoKgKM=
github.com/secrethub/secrethub-go v0.29.1-0.20200702094400-d465926a4a6a/go.mod h1:tDeBtyjfFQX3UqgaZfY+H4dYkcGfiVzrwLDf0XtfOrw=
github.com/secrethub/secrethub-go v0.29.1-0.20200702114848-1a3657310d91 h1:10KZJ3o7hodrTO1xAP1uNhDWSlLV9Bh9RqRFtiNCYJ4=
github.com/secrethub/secrethub-go v0.29.1-0.20200702114848-1a3657310d91/go.mod h1:tDeBtyjfFQX3UqgaZfY+H4dYkcGfiVzrwLDf0XtfOrw=
github.com/secrethub/secrethub-go v0.29.1-0.20200703092019-9f5d3de9b0e4 h1:TszZ+u/DRpPjaAGwEFSQNHkWhG4QR3KBxQJ66NfTAMk=
github.com/secrethub/secrethub-go v0.29.1-0.20200703092019-9f5d3de9b0e4/go.mod h1:tDeBtyjfFQX3UqgaZfY+H4dYkcGfiVzrwLDf0XtfOrw=
github.com/secrethub/secrethub-go v0.29.1-0.20200703150346-411544a71e9d h1:tADItWP+YXaGLD1ZMFocxDaKKVcu8wXgEulbcUmX4Ec=
github.com/secrethub/secrethub-go v0.29.1-0.20200703150346-411544a71e9d/go.mod h1:tDeBtyjfFQX3UqgaZfY+H4dYkcGfiVzrwLDf0XtfOrw=
github.com/secrethub/secrethub-go v0.29.1-0.20200707154958-5e5602145597 h1:uC9ODMKaqBo1k8fxmFSWGkLr05TgEd3t4mHqJ8Jo9Gc=
github.com/secrethub/secrethub-go v0.29.1-0.20200707154958-5e5602145597/go.mod h1:tDeBtyjfFQX3UqgaZfY+H4dYkcGfiVzrwLDf0XtfOrw=
github.com/secrethub/secrethub-go v0.30.0 h1:Nh1twPDwPbYQj/cYc1NG+j7sv76LZiXLPovyV83tZj0=
github.com/secrethub/secrethub-go v0.30.0/go.mod h1:tDeBtyjfFQX3UqgaZfY+H4dYkcGfiVzrwLDf0XtfOrw=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
Expand Down Expand Up @@ -267,6 +255,7 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a h1:WXEvlFVvvGxCJLG6REjsT03iWnKLEWinaScsxF2Vm2o=
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
Expand Down
1 change: 1 addition & 0 deletions internals/secrethub/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ func (app *App) registerCommands() {
NewAuditCommand(app.io, app.clientFactory.NewClient).Register(app.cli)
NewInjectCommand(app.io, app.clientFactory.NewClient).Register(app.cli)
NewRunCommand(app.io, app.clientFactory.NewClient).Register(app.cli)
NewImportCommand(app.io, app.clientFactory.NewClient).Register(app.cli)
NewPrintEnvCommand(app.cli, app.io).Register(app.cli)

// Hidden commands
Expand Down
26 changes: 26 additions & 0 deletions internals/secrethub/import.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package secrethub

import (
"github.com/secrethub/secrethub-cli/internals/cli/ui"
"github.com/secrethub/secrethub-cli/internals/secrethub/command"
)

// ImportCommand handles the migration of secrets from outside SecretHub to SecretHub.
type ImportCommand struct {
io ui.IO
newClient newClientFunc
}

// NewImportCommand creates a new ImportCommand.
func NewImportCommand(io ui.IO, newClient newClientFunc) *ImportCommand {
return &ImportCommand{
io: io,
newClient: newClient,
}
}

// Register registers the command and its sub-commands on the provided Registerer.
func (cmd *ImportCommand) Register(r command.Registerer) {
clause := r.Command("import", "Import secrets from outside of SecretHub.")
NewImportDotEnvCommand(cmd.io, cmd.newClient).Register(clause)
}
Loading