Cristian Le 5 лет назад
Родитель
Сommit
8b1ab30212
1 измененных файлов с 16 добавлено и 1 удалено
  1. 16 1
      authority/provisioner/provisioner.go

+ 16 - 1
authority/provisioner/provisioner.go

@@ -358,7 +358,7 @@ func DefaultIdentityFunc(ctx context.Context, p Interface, email string, usernam
 			}
 		}
 		usernames = append(usernames, email)
-		// Some remove duplicate function should be added
+		usernames = SanitizeStringSlices(usernames)
 		return &Identity{
 			Usernames: usernames,
 		}, nil
@@ -367,6 +367,21 @@ func DefaultIdentityFunc(ctx context.Context, p Interface, email string, usernam
 	}
 }
 
+func SanitizeStringSlices(original []string) []string {
+	output := []string{}
+	seen := make(map[string]bool)
+	for _, entry := range original {
+		if entry == "" {
+			continue
+		}
+		if _, value := seen[entry]; !value {
+			seen[entry] = true
+			output = append(output, entry)
+		}
+	}
+	return output
+}
+
 // MockProvisioner for testing
 type MockProvisioner struct {
 	Mret1, Mret2, Mret3 interface{}