satellite/orders: ensure encryption keys handles set twice
Currently flag parsing seems to call Set twice, which causes problems with encryption keys. We can clear for every set for now. Change-Id: Id5c695b4020194ac1c50a2da9c7d2a896cb9216f
This commit is contained in:
parent
575f50df84
commit
9de1617db0
@ -152,11 +152,13 @@ func (keys *EncryptionKeys) Set(s string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
keys.Clear()
|
||||
|
||||
for _, x := range strings.Split(s, ",") {
|
||||
x = strings.TrimSpace(x)
|
||||
var ekey EncryptionKey
|
||||
if err := ekey.Set(x); err != nil {
|
||||
return ErrEncryptionKey.New("invalid keys %q: %v", s, err)
|
||||
return ErrEncryptionKey.New("invalid keys %q: %w", s, err)
|
||||
}
|
||||
if err := keys.Add(ekey); err != nil {
|
||||
return err
|
||||
@ -180,7 +182,7 @@ func (keys *EncryptionKeys) Add(ekey EncryptionKey) error {
|
||||
}
|
||||
|
||||
if _, exists := keys.KeyByID[ekey.ID]; exists {
|
||||
return ErrEncryptionKey.New("duplicate key identifier %q", ekey)
|
||||
return ErrEncryptionKey.New("duplicate key identifier %q", ekey.String())
|
||||
}
|
||||
|
||||
keys.List = append(keys.List, ekey)
|
||||
@ -188,6 +190,13 @@ func (keys *EncryptionKeys) Add(ekey EncryptionKey) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Clear removes all keys.
|
||||
func (keys *EncryptionKeys) Clear() {
|
||||
keys.Default = EncryptionKey{}
|
||||
keys.List = nil
|
||||
keys.KeyByID = map[EncryptionKeyID]storj.Key{}
|
||||
}
|
||||
|
||||
// String is required for pflag.Value.
|
||||
func (keys *EncryptionKeys) String() string {
|
||||
var s strings.Builder
|
||||
|
Loading…
Reference in New Issue
Block a user