From 0da9df830c5b0474450ffdc98e733eeb1c078206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= Date: Tue, 9 Jan 2024 17:08:46 -0500 Subject: [PATCH] incusd/cluster: Ensure the cluster member config is always sorted MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The database functions return maps which are inherently unsorted, this then would turn the MemberConfig slice under a similarly unsorted slice.. That's a problem because our own CLI and some 3rd party tools will ask the user to answer each of the MemberConfig questions during join. The user may assume that when joining multiple systems, the questions will be in the same order on all systems, when they're not, they may incorrectly answer some of the questions. Signed-off-by: Stéphane Graber --- cmd/incusd/api_cluster.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/cmd/incusd/api_cluster.go b/cmd/incusd/api_cluster.go index 0671ca494e8..dde606059a2 100644 --- a/cmd/incusd/api_cluster.go +++ b/cmd/incusd/api_cluster.go @@ -10,6 +10,7 @@ import ( "net/url" "os" "path/filepath" + "sort" "strconv" "strings" "sync" @@ -210,6 +211,26 @@ func clusterGet(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } + // Sort the member config. + sort.Slice(memberConfig, func(i, j int) bool { + left := memberConfig[i] + right := memberConfig[j] + + if left.Entity != right.Entity { + return left.Entity < right.Entity + } + + if left.Name != right.Name { + return left.Name < right.Name + } + + if left.Key != right.Key { + return left.Key < right.Key + } + + return left.Description < right.Description + }) + cluster := api.Cluster{ ServerName: serverName, Enabled: serverName != "",