From 4ef89d87f4d8a2db2db7ad7708edd2c5b8f2ee3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= Date: Thu, 28 Nov 2024 11:43:18 -0500 Subject: [PATCH] incusd/instance/lxc: Fix random ordering in ETag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Graber Sponsored-by: https://webdock.io --- .../server/instance/drivers/driver_lxc.go | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/internal/server/instance/drivers/driver_lxc.go b/internal/server/instance/drivers/driver_lxc.go index cac4f4f8b51..59e306b846b 100644 --- a/internal/server/instance/drivers/driver_lxc.go +++ b/internal/server/instance/drivers/driver_lxc.go @@ -3531,9 +3531,7 @@ func (d *lxc) Render(options ...func(response any) error) (any, any, error) { } if d.IsSnapshot() { - // Prepare the ETag - etag := []any{d.expiryDate} - + // Prepare the response. snapState := api.InstanceSnapshot{ CreatedAt: d.creationDate, ExpandedConfig: d.expandedConfig, @@ -3558,12 +3556,13 @@ func (d *lxc) Render(options ...func(response any) error) (any, any, error) { } } + // Prepare the ETag. + etag := []any{d.expiryDate} + return &snapState, etag, nil } - // Prepare the ETag - etag := []any{d.architecture, d.localConfig, d.localDevices, d.ephemeral, d.profiles} - + // Prepare the response. statusCode := d.statusCode() instState := api.Instance{ ExpandedConfig: d.expandedConfig, @@ -3593,6 +3592,20 @@ func (d *lxc) Render(options ...func(response any) error) (any, any, error) { } } + // Prepare the ETag + etag := []any{d.architecture, d.ephemeral, d.profiles, d.localDevices.Sorted()} + + configKeys := make([]string, 0, len(d.localConfig)) + for k := range d.localConfig { + configKeys = append(configKeys, k) + } + + sort.Strings(configKeys) + + for _, k := range configKeys { + etag = append(etag, fmt.Sprintf("%s=%s", k, d.localConfig[k])) + } + return &instState, etag, nil }