From 1cbcc9fe73903f5abf2f22181d2ef0af88d69395 Mon Sep 17 00:00:00 2001 From: Sprait Date: Fri, 24 Nov 2023 13:49:35 +0000 Subject: [PATCH] add sort in indextxt --- backend/pki.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/backend/pki.go b/backend/pki.go index 13593a8..dd4a7d0 100644 --- a/backend/pki.go +++ b/backend/pki.go @@ -8,6 +8,7 @@ import ( "fmt" "os" "os/exec" + "sort" "time" "github.com/google/uuid" @@ -175,7 +176,6 @@ func (openVPNPKI *OpenVPNPKI) getExistCert(name string) (data ClientCert, err er func (openVPNPKI *OpenVPNPKI) BuildKeyPairClient(commonName string) (err error) { switch *StorageBackend { - case "kubernetes.secrets": // check certificate exists _, err = openVPNPKI.secretGetByLabels("name=" + commonName) @@ -215,7 +215,6 @@ func (openVPNPKI *OpenVPNPKI) BuildKeyPairClient(commonName string) (err error) if err != nil { return } - case "filesystem": if checkUserExist(commonName) { @@ -459,10 +458,17 @@ func (openVPNPKI *OpenVPNPKI) indexTxtUpdate() (err error) { } } } + var body []string - for _, line := range indexTxtFromFile{ - body = append(body, fmt.Sprintf("%s\t%s\t%s\t%s\t%s\t%s\n", line.Flag, line.ExpirationDate, line.RevocationDate, line.SerialNumber, line.Filename, line.DistinguishedName)) + keys := make([]string, 0) + for k, _ := range indexTxtFromFile { + keys = append(keys, k) } + sort.Strings(keys) + for _, k := range keys { + body = append(body, fmt.Sprintf("%s\t%s\t%s\t%s\t%s\t%s\n", indexTxtFromFile[k].Flag, indexTxtFromFile[k].ExpirationDate, indexTxtFromFile[k].RevocationDate, indexTxtFromFile[k].SerialNumber, indexTxtFromFile[k].Filename, indexTxtFromFile[k].DistinguishedName)) + } + err = fWrite(*EasyrsaDirPath+"/pki/index.txt", strings.Join(body, "")) if err != nil { return err