fix(kms): Update kms wrapper calls to v2

This commit is contained in:
Louis Ruch committed 2022-05-16 14:08:27 -07:00
1 parent 414cdff86e
commit b17b46d3ab
4 files changed
+19 -15

No files matched your search

+9 -5
View File
@@ -8,8 +8,11 @@ import (
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/authmethods"
kms_plugin_assets "github.com/hashicorp/boundary/plugins/kms"
"github.com/hashicorp/boundary/sdk/wrapper"
wrapping "github.com/hashicorp/go-kms-wrapping"
wrapping "github.com/hashicorp/go-kms-wrapping/v2"
"github.com/hashicorp/go-secure-stdlib/configutil/v2"
"github.com/hashicorp/go-secure-stdlib/pluginutil/v2"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
@@ -109,16 +112,17 @@ func providerAuthenticate(ctx context.Context, d *schema.ResourceData, md *metaD
if err != nil {
return fmt.Errorf(`error reading data from "recovery_kms_hcl": %v`, err)
}
wrapper, err := wrapper.GetWrapperFromHcl(recoveryHclStr, "recovery")
wrapper, _, err := wrapper.GetWrapperFromHcl(ctx, recoveryHclStr, "recovery",
configutil.WithPluginOptions(
pluginutil.WithPluginsMap(kms_plugin_assets.BuiltinKmsPlugins()),
pluginutil.WithPluginsFilesystem(kms_plugin_assets.KmsPluginPrefix, kms_plugin_assets.FileSystem()),
))
if err != nil {
return fmt.Errorf(`error reading wrappers from "recovery_kms_hcl": %v`, err)
}
if wrapper == nil {
return errors.New(`No "kms" block with purpose "recovery" found in "recovery_kms_hcl"`)
}
if err := wrapper.Init(ctx); err != nil {
return fmt.Errorf("error initializing recovery kms: %v", err)
}
md.recoveryKmsWrapper = wrapper
md.client.SetRecoveryKmsWrapper(wrapper)
+7 -8
View File
@@ -1,6 +1,7 @@
package provider
import (
"context"
"crypto/rand"
"encoding/base64"
"fmt"
@@ -8,8 +9,8 @@ import (
"testing"
"github.com/hashicorp/boundary/testing/controller"
wrapping "github.com/hashicorp/go-kms-wrapping"
"github.com/hashicorp/go-kms-wrapping/wrappers/aead"
wrapping "github.com/hashicorp/go-kms-wrapping/v2"
"github.com/hashicorp/go-kms-wrapping/v2/aead"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
@@ -36,7 +37,7 @@ func providerFactories(p **schema.Provider) map[string]func() (*schema.Provider,
}
}
func testWrapper(t *testing.T, key string) wrapping.Wrapper {
func testWrapper(ctx context.Context, t *testing.T, key string) wrapping.Wrapper {
var keyBytes []byte
switch key {
case "":
@@ -56,15 +57,13 @@ func testWrapper(t *testing.T, key string) wrapping.Wrapper {
t.Fatal(err)
}
}
wrapper := aead.NewWrapper(nil)
wrapper := aead.NewWrapper()
_, err := wrapper.SetConfig(map[string]string{
"key_id": key,
})
_, err := wrapper.SetConfig(ctx, wrapping.WithKeyId(key))
if err != nil {
t.Fatal(err)
}
if err := wrapper.SetAESGCMKeyBytes(keyBytes); err != nil {
if err := wrapper.SetAesGcmKeyBytes(keyBytes); err != nil {
t.Fatal(err)
}
return wrapper
+2 -1
View File
@@ -114,7 +114,7 @@ resource "boundary_group" "proj1" {
// NOTE: this test also tests out the recovery KMS mechanism.
func TestAccGroup(t *testing.T) {
wrapper := testWrapper(t, tcRecoveryKey)
wrapper := testWrapper(context.Background(), t, tcRecoveryKey)
tc := controller.NewTestController(t, append(tcConfig, controller.WithRecoveryKms(wrapper))...)
defer tc.Shutdown()
@@ -122,6 +122,7 @@ func TestAccGroup(t *testing.T) {
var provider *schema.Provider
resource.Test(t, resource.TestCase{
IsUnitTest: true,
ProviderFactories: providerFactories(&provider),
CheckDestroy: testAccCheckGroupResourceDestroy(t, provider),
Steps: []resource.TestStep{
@@ -41,7 +41,7 @@ resource "boundary_managed_group" "foo" {
)
func TestAccManagedGroup(t *testing.T) {
wrapper := testWrapper(t, tcRecoveryKey)
wrapper := testWrapper(context.Background(), t, tcRecoveryKey)
tp := oidc.StartTestProvider(t)
tc := controller.NewTestController(t, append(tcConfig, controller.WithRecoveryKms(wrapper))...)