Move wrapper package back to SDK (#1511)
TF uses this, so SDK is a decent place for it. It doesn't create dependencies between it and API.
This commit is contained in:
1 parent
d7a990b62b
commit
e9a8ede0d6
13 files changed
+668
-13
No files matched your search
@@ -15,7 +15,7 @@ import (
|
||||
"syscall"
|
||||
|
||||
"github.com/hashicorp/boundary/api"
|
||||
"github.com/hashicorp/boundary/internal/cmd/base/wrapper"
|
||||
"github.com/hashicorp/boundary/sdk/wrapper"
|
||||
"github.com/mitchellh/cli"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/posener/complete"
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
package wrapper
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
wrapping "github.com/hashicorp/go-kms-wrapping"
|
||||
"github.com/hashicorp/go-secure-stdlib/configutil"
|
||||
"github.com/hashicorp/go-secure-stdlib/strutil"
|
||||
)
|
||||
|
||||
func GetWrapperFromPath(path, purpose string) (wrapping.Wrapper, error) {
|
||||
kmses, err := configutil.LoadConfigKMSes(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error parsing config file: %w", err)
|
||||
}
|
||||
|
||||
return getWrapper(kmses, purpose)
|
||||
}
|
||||
|
||||
func GetWrapperFromHcl(inHcl, purpose string) (wrapping.Wrapper, error) {
|
||||
kmses, err := configutil.ParseKMSes(inHcl)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error parsing KMS HCL: %w", err)
|
||||
}
|
||||
|
||||
return getWrapper(kmses, purpose)
|
||||
}
|
||||
|
||||
func getWrapper(kmses []*configutil.KMS, purpose string) (wrapping.Wrapper, error) {
|
||||
var kms *configutil.KMS
|
||||
for _, v := range kmses {
|
||||
if strutil.StrListContains(v.Purpose, purpose) {
|
||||
if kms != nil {
|
||||
return nil, fmt.Errorf("Only one %q block marked for %q purpose is allowed", "kms", purpose)
|
||||
}
|
||||
kms = v
|
||||
}
|
||||
}
|
||||
if kms == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
wrapper, err := configutil.ConfigureWrapper(kms, nil, nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error configuring kms: %w", err)
|
||||
}
|
||||
|
||||
return wrapper, nil
|
||||
}
|
||||
Reference in new issue
Block a user