create enrollementkey for existing networks

This commit is contained in:
abhishek9686 2024-10-24 13:11:53 +04:00
parent 636b2ff1a7
commit 60ea2a76a6

View file

@ -8,6 +8,7 @@ import (
"golang.org/x/exp/slog"
"github.com/google/uuid"
"github.com/gravitl/netmaker/database"
"github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/logic"
@ -122,6 +123,33 @@ func updateEnrollmentKeys() {
}
}
existingKeys, err := logic.GetAllEnrollmentKeys()
if err != nil {
return
}
// check if any tags are duplicate
existingTags := make(map[string]struct{})
for _, existingKey := range existingKeys {
for _, t := range existingKey.Tags {
existingTags[t] = struct{}{}
}
}
networks, _ := logic.GetNetworks()
for _, network := range networks {
if _, ok := existingTags[network.NetID]; ok {
continue
}
_, _ = logic.CreateEnrollmentKey(
0,
time.Time{},
[]string{network.NetID},
[]string{network.NetID},
true,
uuid.Nil,
)
}
}
func removeOldUserGrps() {