Don't include distrusted keypairs unless specifically asked to

This commit is contained in:
John Gardiner Myers 2021-07-08 23:03:03 -07:00
parent 95665f45c6
commit d865df6775
2 changed files with 13 additions and 11 deletions

View File

@ -84,7 +84,7 @@ func (c *DescribeKeypairsCommand) Run(ctx context.Context, args []string) error
return err
}
items, err := listKeypairs(keyStore, args)
items, err := listKeypairs(keyStore, args, false)
if err != nil {
return err
}

View File

@ -81,7 +81,7 @@ type keypairItem struct {
HasPrivateKey bool
}
func listKeypairs(keyStore fi.CAStore, names []string) ([]*keypairItem, error) {
func listKeypairs(keyStore fi.CAStore, names []string, includeDistrusted bool) ([]*keypairItem, error) {
var items []*keypairItem
l, err := keyStore.ListKeysets()
@ -104,14 +104,16 @@ func listKeypairs(keyStore fi.CAStore, names []string) ([]*keypairItem, error) {
}
for _, item := range keyset.Items {
items = append(items, &keypairItem{
Name: name,
Id: item.Id,
DistrustTimestamp: item.DistrustTimestamp,
IsPrimary: item.Id == keyset.Primary.Id,
Certificate: item.Certificate,
HasPrivateKey: item.PrivateKey != nil,
})
if includeDistrusted || item.DistrustTimestamp == nil {
items = append(items, &keypairItem{
Name: name,
Id: item.Id,
DistrustTimestamp: item.DistrustTimestamp,
IsPrimary: item.Id == keyset.Primary.Id,
Certificate: item.Certificate,
HasPrivateKey: item.PrivateKey != nil,
})
}
}
}
@ -134,7 +136,7 @@ func RunGetKeypairs(ctx context.Context, out io.Writer, options *GetKeypairsOpti
return err
}
items, err := listKeypairs(keyStore, args)
items, err := listKeypairs(keyStore, args, options.Distrusted)
if err != nil {
return err
}