From 5145c8f9c092d8815e516be231c20f2234764e45 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 31 Mar 2024 12:25:20 +0200 Subject: [PATCH] key list: include full key id in JSON output --- changelog/unreleased/issue-4744 | 9 +++++++++ cmd/restic/cmd_key_list.go | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 changelog/unreleased/issue-4744 diff --git a/changelog/unreleased/issue-4744 b/changelog/unreleased/issue-4744 new file mode 100644 index 000000000..b0ede1c5c --- /dev/null +++ b/changelog/unreleased/issue-4744 @@ -0,0 +1,9 @@ +Change: Include full key ID in JSON output of `key list` + +We have changed the JSON output of the `key list` command to include the full +key ID instead of just a shortened version, as the latter can be ambiguous +in some rare cases. To derive the short ID, please truncate the full ID down to +eight characters. + +https://github.com/restic/restic/issues/4744 +https://github.com/restic/restic/pull/4745 diff --git a/cmd/restic/cmd_key_list.go b/cmd/restic/cmd_key_list.go index 9bddb5ed3..fcca6055a 100644 --- a/cmd/restic/cmd_key_list.go +++ b/cmd/restic/cmd_key_list.go @@ -53,6 +53,7 @@ func listKeys(ctx context.Context, s *repository.Repository, gopts GlobalOptions type keyInfo struct { Current bool `json:"current"` ID string `json:"id"` + ShortID string `json:"-"` UserName string `json:"userName"` HostName string `json:"hostName"` Created string `json:"created"` @@ -70,7 +71,8 @@ func listKeys(ctx context.Context, s *repository.Repository, gopts GlobalOptions key := keyInfo{ Current: id == s.KeyID(), - ID: id.Str(), + ID: id.String(), + ShortID: id.Str(), UserName: k.Username, HostName: k.Hostname, Created: k.Created.Local().Format(TimeFormat), @@ -91,7 +93,7 @@ func listKeys(ctx context.Context, s *repository.Repository, gopts GlobalOptions } tab := table.New() - tab.AddColumn(" ID", "{{if .Current}}*{{else}} {{end}}{{ .ID }}") + tab.AddColumn(" ID", "{{if .Current}}*{{else}} {{end}}{{ .ShortID }}") tab.AddColumn("User", "{{ .UserName }}") tab.AddColumn("Host", "{{ .HostName }}") tab.AddColumn("Created", "{{ .Created }}")