Skip to content

Commit

Permalink
refact (kms): convert to the new stdlib slices pkg
Browse files Browse the repository at this point in the history
(cherry picked from commit e2f98de)
  • Loading branch information
jimlambrt committed Nov 7, 2023
1 parent 6d2fb53 commit 0bb38bd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
package authmethods_test

import (
stdcmp "cmp"
"context"
"crypto/ed25519"
"crypto/rand"
"crypto/x509"
"encoding/pem"
"fmt"
"regexp"
"slices"
"strings"
"testing"

Expand All @@ -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"
Expand Down Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions internal/kms/kms.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"io"
"reflect"
"slices"
"sync"
"time"

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0bb38bd

Please sign in to comment.