From 0bb38bd778926cf2f6f95ed34cea82f36aaf57c0 Mon Sep 17 00:00:00 2001 From: Jim Date: Wed, 11 Oct 2023 20:26:43 -0400 Subject: [PATCH] refact (kms): convert to the new stdlib slices pkg (cherry picked from commit e2f98de696af6ec06b314383d9e27e82140d76e5) --- .../handlers/authmethods/authmethod_service_test.go | 12 ++++-------- internal/kms/kms.go | 6 +++--- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/internal/daemon/controller/handlers/authmethods/authmethod_service_test.go b/internal/daemon/controller/handlers/authmethods/authmethod_service_test.go index 43c566674c..1e75b98283 100644 --- a/internal/daemon/controller/handlers/authmethods/authmethod_service_test.go +++ b/internal/daemon/controller/handlers/authmethods/authmethod_service_test.go @@ -4,6 +4,7 @@ package authmethods_test import ( + stdcmp "cmp" "context" "crypto/ed25519" "crypto/rand" @@ -11,6 +12,7 @@ import ( "encoding/pem" "fmt" "regexp" + "slices" "strings" "testing" @@ -32,7 +34,6 @@ import ( "github.com/hashicorp/boundary/internal/types/scope" pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/authmethods" scopepb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/scopes" - "golang.org/x/exp/slices" "google.golang.org/grpc/codes" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/testing/protocmp" @@ -351,13 +352,8 @@ func TestList(t *testing.T) { }) } - sorterFn := func(a *pb.AuthMethod, b *pb.AuthMethod) bool { - switch { - case a.GetId() > b.GetId(): - return true - default: - return false - } + sorterFn := func(a *pb.AuthMethod, b *pb.AuthMethod) int { + return stdcmp.Compare(a.GetId(), b.GetId()) } cpSorted := func(ams []*pb.AuthMethod) []*pb.AuthMethod { cp := make([]*pb.AuthMethod, 0, len(ams)) diff --git a/internal/kms/kms.go b/internal/kms/kms.go index f08b486f7a..6d2d54cd31 100644 --- a/internal/kms/kms.go +++ b/internal/kms/kms.go @@ -9,6 +9,7 @@ import ( "fmt" "io" "reflect" + "slices" "sync" "time" @@ -18,7 +19,6 @@ import ( "github.com/hashicorp/go-dbw" wrappingKms "github.com/hashicorp/go-kms-wrapping/extras/kms/v2" wrapping "github.com/hashicorp/go-kms-wrapping/v2" - "golang.org/x/exp/slices" ) // Kms is a way to access wrappers for a given scope and purpose. Since keys can @@ -600,8 +600,8 @@ keyLoop: return false, errors.New(ctx, errors.KeyNotFound, op, "key version was not found in the scope") } // Sort versions just in case they aren't already sorted - slices.SortFunc(foundKey.Versions, func(i, j wrappingKms.KeyVersion) bool { - return i.Version < j.Version + slices.SortFunc(foundKey.Versions, func(i, j wrappingKms.KeyVersion) int { + return int(i.Version) - int(j.Version) }) if foundKey.Versions[len(foundKey.Versions)-1].Id == keyVersionId { // Attempted to destroy currently active key