Skip to content

Commit 2ae45c6

Browse files
committed
modify CLI output
1 parent ba14128 commit 2ae45c6

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

enterprise/cli/server_dbcrypt.go

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,18 @@ func (*RootCmd) dbcryptRotateCmd() *clibase.Cmd {
7171
return xerrors.Errorf("create ciphers: %w", err)
7272
}
7373

74-
newDigest := ciphers[0].HexDigest()
75-
oldDigests := make([]string, 0, len(ciphers)-1)
76-
for _, c := range ciphers[1:] {
77-
oldDigests = append(oldDigests, c.HexDigest())
74+
var act string
75+
switch len(flags.Old) {
76+
case 0:
77+
act = "Data will be encrypted with the new key."
78+
default:
79+
act = "Data will be decrypted with all available keys and re-encrypted with new key."
7880
}
79-
if len(oldDigests) == 0 {
80-
oldDigests = append(oldDigests, "none")
81-
}
82-
msg := fmt.Sprintf(`Rotate external token encryptions keys?\n- New key: %s\n- Old keys: %s`,
83-
newDigest,
84-
strings.Join(oldDigests, ", "),
81+
82+
msg := fmt.Sprintf("%s\n\n- New key: %s\n- Old keys: %s\n\nRotate external token encryption keys?\n",
83+
act,
84+
flags.New,
85+
strings.Join(flags.Old, ", "),
8586
)
8687
if _, err := cliui.Prompt(inv, cliui.PromptOptions{Text: msg, IsConfirm: true}); err != nil {
8788
return err
@@ -179,9 +180,13 @@ func (*RootCmd) dbcryptDeleteCmd() *clibase.Cmd {
179180
if err := flags.valid(); err != nil {
180181
return err
181182
}
183+
msg := `All encrypted data will be deleted from the database:
184+
- Encrypted user OAuth access and refresh tokens
185+
- Encrypted user Git authentication access and refresh tokens
182186
187+
Are you sure you want to continue?`
183188
if _, err := cliui.Prompt(inv, cliui.PromptOptions{
184-
Text: "This will delete all encrypted data from the database. Are you sure you want to continue?",
189+
Text: msg,
185190
IsConfirm: true,
186191
}); err != nil {
187192
return err
@@ -238,6 +243,10 @@ func (f *rotateFlags) attach(opts *clibase.OptionSet) {
238243
}
239244

240245
func (f *rotateFlags) valid() error {
246+
if f.PostgresURL == "" {
247+
return xerrors.Errorf("no database configured")
248+
}
249+
241250
if f.New == "" {
242251
return xerrors.Errorf("no new key provided")
243252
}
@@ -289,6 +298,10 @@ func (f *decryptFlags) attach(opts *clibase.OptionSet) {
289298
}
290299

291300
func (f *decryptFlags) valid() error {
301+
if f.PostgresURL == "" {
302+
return xerrors.Errorf("no database configured")
303+
}
304+
292305
if len(f.Keys) == 0 {
293306
return xerrors.Errorf("no keys provided")
294307
}

0 commit comments

Comments
 (0)