@@ -17,8 +17,8 @@ import (
1717 "github.com/pluralsh/plural/pkg/utils/pathing"
1818 "github.com/pluralsh/polly/algorithms"
1919 "github.com/pluralsh/polly/containers"
20+ "github.com/samber/lo"
2021 "gopkg.in/yaml.v2"
21- "k8s.io/apimachinery/pkg/util/sets"
2222)
2323
2424const (
@@ -134,27 +134,14 @@ func SetupAge(client api.Client, emails []string) error {
134134 if err != nil {
135135 return err
136136 }
137+
137138 missingEmails := findMissingKeyForEmail (emails , keys )
138139 if len (missingEmails ) > 0 {
139140 return fmt .Errorf ("Some of the users %v have no keys setup" , missingEmails )
140141 }
141142
142- present := sets .NewString ()
143- dedupeKey := func (id * AgeIdentity ) string { return fmt .Sprintf ("%s::%s" , id .Email , id .Key ) }
144-
145- idents := ageConfig .Identities
146- for _ , id := range idents {
147- present .Insert (dedupeKey (id ))
148- }
149-
150- for _ , key := range keys {
151- id := & AgeIdentity {Key : key .Content , Email : key .User .Email }
152- if ! present .Has (dedupeKey (id )) {
153- idents = append (idents , id )
154- }
155- }
156-
157- ageConfig .Identities = idents
143+ idents := algorithms .Map (keys , func (key * api.PublicKey ) * AgeIdentity { return & AgeIdentity {Key : key .Content , Email : key .User .Email } })
144+ ageConfig .Identities = lo .UniqBy (append (idents , ageConfig .Identities ... ), func (id * AgeIdentity ) string { return fmt .Sprintf ("%s::%s" , id .Email , id .Key ) })
158145 }
159146
160147 keyPath := pathing .SanitizeFilepath (filepath .Join (cryptPath (), "key" ))
0 commit comments