Migrate some credential bits around (#3864)
This commit is contained in:
1 parent
a601316efd
commit
eb20b80c71
26 files changed
+291
-259
No files matched your search
@@ -6,9 +6,11 @@ package authmethods
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/boundary/api"
|
||||
"github.com/hashicorp/boundary/api/authtokens"
|
||||
)
|
||||
|
||||
type AuthenticateResult struct {
|
||||
@@ -51,15 +53,33 @@ func (a *AuthenticateResult) UnmarshalJSON(inBytes []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n AuthenticateResult) GetRawAttributes() json.RawMessage {
|
||||
return n.attributesRaw
|
||||
func (a AuthenticateResult) GetRawAttributes() json.RawMessage {
|
||||
return a.attributesRaw
|
||||
}
|
||||
|
||||
func (n AuthenticateResult) GetResponse() *api.Response {
|
||||
return n.response
|
||||
func (a AuthenticateResult) GetResponse() *api.Response {
|
||||
return a.response
|
||||
}
|
||||
|
||||
// Authenticate is a generic authenticate API call that returns a generic result.
|
||||
// GetAuthToken converts this AuthenticateResult into an AuthToken struct
|
||||
func (a AuthenticateResult) GetAuthToken() (*authtokens.AuthToken, error) {
|
||||
if a.attributesRaw == nil {
|
||||
return nil, errors.New("AuthenticateResult does not have a populated raw attributes field")
|
||||
}
|
||||
token := new(authtokens.AuthToken)
|
||||
if err := json.Unmarshal(a.GetRawAttributes(), token); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return token, nil
|
||||
}
|
||||
|
||||
// Authenticate is a generic authenticate API call that returns a generic
|
||||
// result. See the documentation for the attributes required for any given auth
|
||||
// method.
|
||||
//
|
||||
// Only some auth methods support multiple commands. If the documentation does
|
||||
// not specify what command to use when and with which attriubutes, use
|
||||
// "login".
|
||||
func (c *Client) Authenticate(ctx context.Context, authMethodId, command string, attributes map[string]any, opt ...Option) (*AuthenticateResult, error) {
|
||||
if c.client == nil {
|
||||
return nil, fmt.Errorf("nil client in Authenticate request")
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package consts
|
||||
|
||||
const (
|
||||
WebsocketProtocolTcpProxyV1 = "boundary-tcp-proxy-v1"
|
||||
)
|
||||
@@ -0,0 +1,16 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
|
||||
package globals
|
||||
|
||||
// CredentialType is a type of credential
|
||||
type CredentialType string
|
||||
|
||||
// Credential type values.
|
||||
const (
|
||||
UnspecifiedCredentialType CredentialType = "unspecified"
|
||||
UsernamePasswordCredentialType CredentialType = "username_password"
|
||||
SshPrivateKeyCredentialType CredentialType = "ssh_private_key"
|
||||
SshCertificateCredentialType CredentialType = "ssh_certificate"
|
||||
JsonCredentialType CredentialType = "json"
|
||||
)
|
||||
@@ -68,6 +68,8 @@ const (
|
||||
// VaultSshCertificateCredentialLibraryPrefix is the prefix for Vault SSH
|
||||
// certificate credential libraries
|
||||
VaultSshCertificateCredentialLibraryPrefix = "clvsclt"
|
||||
// DynamicCredentialPrefix is the prefix for Vault dynamic credentials
|
||||
VaultDynamicCredentialPrefix = "cdvlt"
|
||||
|
||||
// UsernamePasswordCredentialPrefix is the prefix for username/password
|
||||
// creds
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"errors"
|
||||
|
||||
"github.com/hashicorp/boundary/api/targets"
|
||||
"github.com/hashicorp/boundary/internal/credential"
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
|
||||
@@ -65,8 +65,8 @@ func parseCredentials(creds []*targets.SessionCredential) (credentials, error) {
|
||||
|
||||
var upCred usernamePassword
|
||||
var spkCred sshPrivateKey
|
||||
switch credential.Type(cred.CredentialSource.CredentialType) {
|
||||
case credential.UsernamePasswordType:
|
||||
switch globals.CredentialType(cred.CredentialSource.CredentialType) {
|
||||
case globals.UsernamePasswordCredentialType:
|
||||
// Decode attributes from credential struct
|
||||
if err := mapstructure.Decode(cred.Credential, &upCred); err != nil {
|
||||
return credentials{}, err
|
||||
@@ -78,7 +78,7 @@ func parseCredentials(creds []*targets.SessionCredential) (credentials, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
case credential.SshPrivateKeyType:
|
||||
case globals.SshPrivateKeyCredentialType:
|
||||
// Decode attributes from credential struct
|
||||
if err := mapstructure.Decode(cred.Credential, &spkCred); err != nil {
|
||||
return credentials{}, err
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/boundary/api/targets"
|
||||
"github.com/hashicorp/boundary/internal/credential"
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/hashicorp/boundary/internal/credential/static"
|
||||
"github.com/hashicorp/boundary/internal/credential/vault"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
var (
|
||||
typedUsernamePassword = &targets.SessionCredential{
|
||||
CredentialSource: &targets.CredentialSource{
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
Credential: map[string]any{
|
||||
"username": "user",
|
||||
@@ -27,7 +27,7 @@ var (
|
||||
|
||||
typedSshPrivateKey = &targets.SessionCredential{
|
||||
CredentialSource: &targets.CredentialSource{
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
Credential: map[string]any{
|
||||
"username": "user",
|
||||
|
||||
@@ -8,6 +8,7 @@ package credential
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/hashicorp/boundary/internal/boundary"
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
)
|
||||
@@ -25,24 +26,12 @@ type Store interface {
|
||||
GetProjectId() string
|
||||
}
|
||||
|
||||
// Type is the type of credential provided by a library.
|
||||
type Type string
|
||||
|
||||
// Credential type values.
|
||||
const (
|
||||
UnspecifiedType Type = "unspecified"
|
||||
UsernamePasswordType Type = "username_password"
|
||||
SshPrivateKeyType Type = "ssh_private_key"
|
||||
SshCertificateType Type = "ssh_certificate"
|
||||
JsonType Type = "json"
|
||||
)
|
||||
|
||||
// A Library is a resource that provides credentials that are of the same
|
||||
// type and access level from a single store.
|
||||
type Library interface {
|
||||
boundary.Resource
|
||||
GetStoreId() string
|
||||
CredentialType() Type
|
||||
CredentialType() globals.CredentialType
|
||||
}
|
||||
|
||||
// Purpose is the purpose of the credential.
|
||||
|
||||
@@ -6,6 +6,7 @@ package vault
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/hashicorp/boundary/internal/credential"
|
||||
"github.com/hashicorp/boundary/internal/credential/vault/store"
|
||||
"github.com/hashicorp/boundary/internal/errors"
|
||||
@@ -115,12 +116,12 @@ func (l *CredentialLibrary) oplog(op oplog.OpType) oplog.Metadata {
|
||||
}
|
||||
|
||||
// CredentialType returns the type of credential the library retrieves.
|
||||
func (l *CredentialLibrary) CredentialType() credential.Type {
|
||||
func (l *CredentialLibrary) CredentialType() globals.CredentialType {
|
||||
switch ct := l.GetCredentialType(); ct {
|
||||
case "":
|
||||
return credential.UnspecifiedType
|
||||
return globals.UnspecifiedCredentialType
|
||||
default:
|
||||
return credential.Type(ct)
|
||||
return globals.CredentialType(ct)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/credential"
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/hashicorp/boundary/internal/credential/vault/store"
|
||||
"github.com/hashicorp/boundary/internal/db"
|
||||
"github.com/hashicorp/boundary/internal/iam"
|
||||
@@ -217,7 +217,7 @@ func TestCredentialLibrary_New(t *testing.T) {
|
||||
vaultPath: "vault/path",
|
||||
opts: []Option{
|
||||
WithMethod(MethodGet),
|
||||
WithCredentialType(credential.UsernamePasswordType),
|
||||
WithCredentialType(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
want: &CredentialLibrary{
|
||||
@@ -225,7 +225,7 @@ func TestCredentialLibrary_New(t *testing.T) {
|
||||
StoreId: cs.PublicId,
|
||||
VaultPath: "vault/path",
|
||||
HttpMethod: string(MethodGet),
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -236,7 +236,7 @@ func TestCredentialLibrary_New(t *testing.T) {
|
||||
vaultPath: "vault/path",
|
||||
opts: []Option{
|
||||
WithMethod(MethodGet),
|
||||
WithCredentialType(credential.UsernamePasswordType),
|
||||
WithCredentialType(globals.UsernamePasswordCredentialType),
|
||||
WithMappingOverride(NewUsernamePasswordOverride(
|
||||
WithOverrideUsernameAttribute("test"),
|
||||
WithOverridePasswordAttribute("testpass")),
|
||||
@@ -249,7 +249,7 @@ func TestCredentialLibrary_New(t *testing.T) {
|
||||
StoreId: cs.PublicId,
|
||||
VaultPath: "vault/path",
|
||||
HttpMethod: string(MethodGet),
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -260,7 +260,7 @@ func TestCredentialLibrary_New(t *testing.T) {
|
||||
vaultPath: "vault/path",
|
||||
opts: []Option{
|
||||
WithMethod(MethodGet),
|
||||
WithCredentialType(credential.SshPrivateKeyType),
|
||||
WithCredentialType(globals.SshPrivateKeyCredentialType),
|
||||
WithMappingOverride(NewSshPrivateKeyOverride(
|
||||
WithOverrideUsernameAttribute("test"),
|
||||
WithOverridePrivateKeyAttribute("testpk")),
|
||||
@@ -273,7 +273,7 @@ func TestCredentialLibrary_New(t *testing.T) {
|
||||
StoreId: cs.PublicId,
|
||||
VaultPath: "vault/path",
|
||||
HttpMethod: string(MethodGet),
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -292,12 +292,12 @@ func TestCredentialLibrary_New(t *testing.T) {
|
||||
assert.Equal(tt.want, got)
|
||||
|
||||
switch ct := tt.want.GetCredentialType(); ct {
|
||||
case string(credential.UsernamePasswordType):
|
||||
assert.Equal(credential.UsernamePasswordType, got.CredentialType())
|
||||
case string(credential.SshPrivateKeyType):
|
||||
assert.Equal(credential.SshPrivateKeyType, got.CredentialType())
|
||||
case string(credential.UnspecifiedType), "":
|
||||
assert.Equal(credential.UnspecifiedType, got.CredentialType())
|
||||
case string(globals.UsernamePasswordCredentialType):
|
||||
assert.Equal(globals.UsernamePasswordCredentialType, got.CredentialType())
|
||||
case string(globals.SshPrivateKeyCredentialType):
|
||||
assert.Equal(globals.SshPrivateKeyCredentialType, got.CredentialType())
|
||||
case string(globals.UnspecifiedCredentialType), "":
|
||||
assert.Equal(globals.UnspecifiedCredentialType, got.CredentialType())
|
||||
default:
|
||||
assert.Failf("Unknown credential type", "%s", ct)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
package vault
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/boundary/internal/credential"
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/hashicorp/boundary/internal/credential/vault/store"
|
||||
"github.com/hashicorp/boundary/internal/db/sanitize"
|
||||
"github.com/hashicorp/boundary/internal/db/sentinel"
|
||||
@@ -13,14 +13,14 @@ import (
|
||||
|
||||
// validMappingOverride reports whether the given mapping override is valid
|
||||
// for the given credential type.
|
||||
func validMappingOverride(m MappingOverride, ct credential.Type) bool {
|
||||
func validMappingOverride(m MappingOverride, ct globals.CredentialType) bool {
|
||||
switch m.(type) {
|
||||
case nil:
|
||||
return true // it is always valid to not specify a mapping override
|
||||
case *UsernamePasswordOverride:
|
||||
return ct == credential.UsernamePasswordType
|
||||
return ct == globals.UsernamePasswordCredentialType
|
||||
case *SshPrivateKeyOverride:
|
||||
return ct == credential.SshPrivateKeyType
|
||||
return ct == globals.SshPrivateKeyCredentialType
|
||||
default:
|
||||
return false // an unknown mapping override type is never valid
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/credential"
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -22,7 +22,7 @@ var _ MappingOverride = unknownMapper(0)
|
||||
func TestValidMappingOverrides(t *testing.T) {
|
||||
tests := []struct {
|
||||
m MappingOverride
|
||||
ct credential.Type
|
||||
ct globals.CredentialType
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
@@ -32,42 +32,42 @@ func TestValidMappingOverrides(t *testing.T) {
|
||||
},
|
||||
{
|
||||
m: nil,
|
||||
ct: credential.UnspecifiedType,
|
||||
ct: globals.UnspecifiedCredentialType,
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
m: nil,
|
||||
ct: credential.UsernamePasswordType,
|
||||
ct: globals.UsernamePasswordCredentialType,
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
m: unknownMapper(1),
|
||||
ct: credential.UnspecifiedType,
|
||||
ct: globals.UnspecifiedCredentialType,
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
m: unknownMapper(1),
|
||||
ct: credential.UsernamePasswordType,
|
||||
ct: globals.UsernamePasswordCredentialType,
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
m: allocUsernamePasswordOverride(),
|
||||
ct: credential.UnspecifiedType,
|
||||
ct: globals.UnspecifiedCredentialType,
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
m: allocUsernamePasswordOverride(),
|
||||
ct: credential.UsernamePasswordType,
|
||||
ct: globals.UsernamePasswordCredentialType,
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
m: allocSshPrivateKeyOverride(),
|
||||
ct: credential.UnspecifiedType,
|
||||
ct: globals.UnspecifiedCredentialType,
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
m: allocSshPrivateKeyOverride(),
|
||||
ct: credential.SshPrivateKeyType,
|
||||
ct: globals.SshPrivateKeyCredentialType,
|
||||
want: true,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
package vault
|
||||
|
||||
import "github.com/hashicorp/boundary/internal/credential"
|
||||
import "github.com/hashicorp/boundary/globals"
|
||||
|
||||
// getOpts - iterate the inbound Options and return a struct
|
||||
func getOpts(opt ...Option) options {
|
||||
@@ -30,7 +30,7 @@ type options struct {
|
||||
withClientCert *ClientCertificate
|
||||
withMethod Method
|
||||
withRequestBody []byte
|
||||
withCredentialType credential.Type
|
||||
withCredentialType globals.CredentialType
|
||||
|
||||
withOverrideUsernameAttribute string
|
||||
withOverridePasswordAttribute string
|
||||
@@ -139,7 +139,7 @@ func WithRequestBody(b []byte) Option {
|
||||
|
||||
// WithCredentialType provides an optional credential type to associate
|
||||
// with a credential library.
|
||||
func WithCredentialType(t credential.Type) Option {
|
||||
func WithCredentialType(t globals.CredentialType) Option {
|
||||
return func(o *options) {
|
||||
o.withCredentialType = t
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/credential"
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -95,9 +95,9 @@ func Test_GetOpts(t *testing.T) {
|
||||
assert.Equal(t, opts, testOpts)
|
||||
})
|
||||
t.Run("WithCredentialType", func(t *testing.T) {
|
||||
opts := getOpts(WithCredentialType(credential.UsernamePasswordType))
|
||||
opts := getOpts(WithCredentialType(globals.UsernamePasswordCredentialType))
|
||||
testOpts := getDefaultOptions()
|
||||
testOpts.withCredentialType = credential.UsernamePasswordType
|
||||
testOpts.withCredentialType = globals.UsernamePasswordCredentialType
|
||||
assert.Equal(t, opts, testOpts)
|
||||
})
|
||||
t.Run("WithOverrideUsernameAttribute", func(t *testing.T) {
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/hashicorp/boundary/internal/credential"
|
||||
"github.com/hashicorp/boundary/internal/credential/vault/internal/sshprivatekey"
|
||||
"github.com/hashicorp/boundary/internal/credential/vault/internal/usernamepassword"
|
||||
@@ -56,9 +57,9 @@ func (bc *baseCred) isRevokable() bool { return bc.ExternalId != sen
|
||||
// UnspecifiedType.
|
||||
func convert(ctx context.Context, bc *baseCred) (dynamicCred, error) {
|
||||
switch bc.Library().CredentialType() {
|
||||
case credential.UsernamePasswordType:
|
||||
case globals.UsernamePasswordCredentialType:
|
||||
return baseToUsrPass(ctx, bc)
|
||||
case credential.SshPrivateKeyType:
|
||||
case globals.SshPrivateKeyCredentialType:
|
||||
return baseToSshPriKey(ctx, bc)
|
||||
}
|
||||
return bc, nil
|
||||
@@ -81,7 +82,7 @@ func baseToUsrPass(ctx context.Context, bc *baseCred) (*usrPassCred, error) {
|
||||
return nil, errors.E(ctx, errors.WithCode(errors.InvalidParameter), errors.WithMsg("nil baseCred"))
|
||||
case bc.lib == nil:
|
||||
return nil, errors.E(ctx, errors.WithCode(errors.InvalidParameter), errors.WithMsg("nil baseCred.lib"))
|
||||
case bc.Library().CredentialType() != credential.UsernamePasswordType:
|
||||
case bc.Library().CredentialType() != globals.UsernamePasswordCredentialType:
|
||||
return nil, errors.E(ctx, errors.WithCode(errors.InvalidParameter), errors.WithMsg("invalid credential type"))
|
||||
}
|
||||
|
||||
@@ -128,7 +129,7 @@ func baseToSshPriKey(ctx context.Context, bc *baseCred) (*sshPrivateKeyCred, err
|
||||
return nil, errors.E(ctx, errors.WithCode(errors.InvalidParameter), errors.WithMsg("nil baseCred"))
|
||||
case bc.lib == nil:
|
||||
return nil, errors.E(ctx, errors.WithCode(errors.InvalidParameter), errors.WithMsg("nil baseCred.lib"))
|
||||
case bc.Library().CredentialType() != credential.SshPrivateKeyType:
|
||||
case bc.Library().CredentialType() != globals.SshPrivateKeyCredentialType:
|
||||
return nil, errors.E(ctx, errors.WithCode(errors.InvalidParameter), errors.WithMsg("invalid credential type"))
|
||||
}
|
||||
|
||||
@@ -258,12 +259,12 @@ func (pl *genericIssuingCredentialLibrary) GetCreateTime() *timestamp.Timestamp
|
||||
func (pl *genericIssuingCredentialLibrary) GetUpdateTime() *timestamp.Timestamp { return pl.UpdateTime }
|
||||
func (pl *genericIssuingCredentialLibrary) GetPurpose() credential.Purpose { return pl.Purpose }
|
||||
|
||||
func (pl *genericIssuingCredentialLibrary) CredentialType() credential.Type {
|
||||
func (pl *genericIssuingCredentialLibrary) CredentialType() globals.CredentialType {
|
||||
switch ct := pl.CredType; ct {
|
||||
case "":
|
||||
return credential.UnspecifiedType
|
||||
return globals.UnspecifiedCredentialType
|
||||
default:
|
||||
return credential.Type(ct)
|
||||
return globals.CredentialType(ct)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -738,12 +739,12 @@ func (lib *sshCertIssuingCredentialLibrary) GetUpdateTime() *timestamp.Timestamp
|
||||
return lib.UpdateTime
|
||||
}
|
||||
|
||||
func (lib *sshCertIssuingCredentialLibrary) CredentialType() credential.Type {
|
||||
func (lib *sshCertIssuingCredentialLibrary) CredentialType() globals.CredentialType {
|
||||
switch ct := lib.CredType; ct {
|
||||
case "":
|
||||
return credential.UnspecifiedType
|
||||
return globals.UnspecifiedCredentialType
|
||||
default:
|
||||
return credential.Type(ct)
|
||||
return globals.CredentialType(ct)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/hashicorp/boundary/internal/credential"
|
||||
"github.com/hashicorp/boundary/internal/db"
|
||||
"github.com/hashicorp/boundary/internal/errors"
|
||||
@@ -122,7 +123,7 @@ func TestRepository_getPrivateLibraries(t *testing.T) {
|
||||
}
|
||||
{
|
||||
opts := []Option{
|
||||
WithCredentialType(credential.UsernamePasswordType),
|
||||
WithCredentialType(globals.UsernamePasswordCredentialType),
|
||||
}
|
||||
libIn, err := NewCredentialLibrary(origStore.GetPublicId(), "/vault/path", opts...)
|
||||
assert.NoError(err)
|
||||
@@ -136,7 +137,7 @@ func TestRepository_getPrivateLibraries(t *testing.T) {
|
||||
}
|
||||
{
|
||||
opts := []Option{
|
||||
WithCredentialType(credential.UsernamePasswordType),
|
||||
WithCredentialType(globals.UsernamePasswordCredentialType),
|
||||
WithMappingOverride(NewUsernamePasswordOverride(
|
||||
WithOverrideUsernameAttribute("test-username"),
|
||||
)),
|
||||
@@ -153,7 +154,7 @@ func TestRepository_getPrivateLibraries(t *testing.T) {
|
||||
}
|
||||
{
|
||||
opts := []Option{
|
||||
WithCredentialType(credential.UsernamePasswordType),
|
||||
WithCredentialType(globals.UsernamePasswordCredentialType),
|
||||
WithMappingOverride(NewUsernamePasswordOverride(
|
||||
WithOverridePasswordAttribute("test-password"),
|
||||
)),
|
||||
@@ -170,7 +171,7 @@ func TestRepository_getPrivateLibraries(t *testing.T) {
|
||||
}
|
||||
{
|
||||
opts := []Option{
|
||||
WithCredentialType(credential.UsernamePasswordType),
|
||||
WithCredentialType(globals.UsernamePasswordCredentialType),
|
||||
WithMappingOverride(NewUsernamePasswordOverride(
|
||||
WithOverrideUsernameAttribute("test-username"),
|
||||
WithOverridePasswordAttribute("test-password"),
|
||||
@@ -188,7 +189,7 @@ func TestRepository_getPrivateLibraries(t *testing.T) {
|
||||
}
|
||||
{
|
||||
opts := []Option{
|
||||
WithCredentialType(credential.SshPrivateKeyType),
|
||||
WithCredentialType(globals.SshPrivateKeyCredentialType),
|
||||
}
|
||||
libIn, err := NewCredentialLibrary(origStore.GetPublicId(), "/vault/path", opts...)
|
||||
assert.NoError(err)
|
||||
@@ -202,7 +203,7 @@ func TestRepository_getPrivateLibraries(t *testing.T) {
|
||||
}
|
||||
{
|
||||
opts := []Option{
|
||||
WithCredentialType(credential.SshPrivateKeyType),
|
||||
WithCredentialType(globals.SshPrivateKeyCredentialType),
|
||||
WithMappingOverride(NewSshPrivateKeyOverride(
|
||||
WithOverrideUsernameAttribute("test-username"),
|
||||
)),
|
||||
@@ -219,7 +220,7 @@ func TestRepository_getPrivateLibraries(t *testing.T) {
|
||||
}
|
||||
{
|
||||
opts := []Option{
|
||||
WithCredentialType(credential.SshPrivateKeyType),
|
||||
WithCredentialType(globals.SshPrivateKeyCredentialType),
|
||||
WithMappingOverride(NewSshPrivateKeyOverride(
|
||||
WithOverridePrivateKeyAttribute("test-private-key"),
|
||||
)),
|
||||
@@ -236,7 +237,7 @@ func TestRepository_getPrivateLibraries(t *testing.T) {
|
||||
}
|
||||
{
|
||||
opts := []Option{
|
||||
WithCredentialType(credential.SshPrivateKeyType),
|
||||
WithCredentialType(globals.SshPrivateKeyCredentialType),
|
||||
WithMappingOverride(NewSshPrivateKeyOverride(
|
||||
WithOverridePrivateKeyPassphraseAttribute("test-passphrase"),
|
||||
)),
|
||||
@@ -253,7 +254,7 @@ func TestRepository_getPrivateLibraries(t *testing.T) {
|
||||
}
|
||||
{
|
||||
opts := []Option{
|
||||
WithCredentialType(credential.SshPrivateKeyType),
|
||||
WithCredentialType(globals.SshPrivateKeyCredentialType),
|
||||
WithMappingOverride(NewSshPrivateKeyOverride(
|
||||
WithOverrideUsernameAttribute("test-username"),
|
||||
WithOverridePrivateKeyAttribute("test-private-key"),
|
||||
@@ -427,7 +428,7 @@ func TestBaseToUsrPass(t *testing.T) {
|
||||
name: "library-not-username-password-type",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.UnspecifiedType),
|
||||
CredType: string(globals.UnspecifiedCredentialType),
|
||||
},
|
||||
},
|
||||
wantErr: errors.InvalidParameter,
|
||||
@@ -436,7 +437,7 @@ func TestBaseToUsrPass(t *testing.T) {
|
||||
name: "invalid-no-username-default-password-attribute",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.UsernamePasswordType),
|
||||
CredType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
secretData: map[string]any{
|
||||
"password": "my-password",
|
||||
@@ -448,7 +449,7 @@ func TestBaseToUsrPass(t *testing.T) {
|
||||
name: "invalid-no-password-default-username-attribute",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.UsernamePasswordType),
|
||||
CredType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
secretData: map[string]any{
|
||||
"username": "my-username",
|
||||
@@ -460,7 +461,7 @@ func TestBaseToUsrPass(t *testing.T) {
|
||||
name: "valid-default-attributes",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.UsernamePasswordType),
|
||||
CredType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
secretData: map[string]any{
|
||||
"username": "my-username",
|
||||
@@ -476,7 +477,7 @@ func TestBaseToUsrPass(t *testing.T) {
|
||||
name: "valid-override-attributes",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.UsernamePasswordType),
|
||||
CredType: string(globals.UsernamePasswordCredentialType),
|
||||
UsernameAttribute: "test-username",
|
||||
PasswordAttribute: "test-password",
|
||||
},
|
||||
@@ -496,7 +497,7 @@ func TestBaseToUsrPass(t *testing.T) {
|
||||
name: "valid-default-username-override-password",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.UsernamePasswordType),
|
||||
CredType: string(globals.UsernamePasswordCredentialType),
|
||||
PasswordAttribute: "test-password",
|
||||
},
|
||||
secretData: map[string]any{
|
||||
@@ -515,7 +516,7 @@ func TestBaseToUsrPass(t *testing.T) {
|
||||
name: "valid-override-username-default-password",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.UsernamePasswordType),
|
||||
CredType: string(globals.UsernamePasswordCredentialType),
|
||||
UsernameAttribute: "test-username",
|
||||
},
|
||||
secretData: map[string]any{
|
||||
@@ -534,7 +535,7 @@ func TestBaseToUsrPass(t *testing.T) {
|
||||
name: "invalid-username-override",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.UsernamePasswordType),
|
||||
CredType: string(globals.UsernamePasswordCredentialType),
|
||||
UsernameAttribute: "missing-username",
|
||||
},
|
||||
secretData: map[string]any{
|
||||
@@ -550,7 +551,7 @@ func TestBaseToUsrPass(t *testing.T) {
|
||||
name: "invalid-password-override",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.UsernamePasswordType),
|
||||
CredType: string(globals.UsernamePasswordCredentialType),
|
||||
UsernameAttribute: "missing-password",
|
||||
},
|
||||
secretData: map[string]any{
|
||||
@@ -566,7 +567,7 @@ func TestBaseToUsrPass(t *testing.T) {
|
||||
name: "invalid-kv2-no-metadata-field",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.UsernamePasswordType),
|
||||
CredType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
secretData: map[string]any{
|
||||
"data": map[string]any{
|
||||
@@ -581,7 +582,7 @@ func TestBaseToUsrPass(t *testing.T) {
|
||||
name: "invalid-kv2-no-data-field",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.UsernamePasswordType),
|
||||
CredType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
secretData: map[string]any{
|
||||
"metadata": map[string]any{},
|
||||
@@ -593,7 +594,7 @@ func TestBaseToUsrPass(t *testing.T) {
|
||||
name: "invalid-kv2-no-username-default-password-attribute",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.UsernamePasswordType),
|
||||
CredType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
secretData: map[string]any{
|
||||
"metadata": map[string]any{},
|
||||
@@ -608,7 +609,7 @@ func TestBaseToUsrPass(t *testing.T) {
|
||||
name: "invalid-kv2-no-passsword-default-username-attribute",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.UsernamePasswordType),
|
||||
CredType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
secretData: map[string]any{
|
||||
"metadata": map[string]any{},
|
||||
@@ -623,7 +624,7 @@ func TestBaseToUsrPass(t *testing.T) {
|
||||
name: "invalid-kv2-invalid-metadata-type",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.UsernamePasswordType),
|
||||
CredType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
secretData: map[string]any{
|
||||
"metadata": "hello",
|
||||
@@ -639,7 +640,7 @@ func TestBaseToUsrPass(t *testing.T) {
|
||||
name: "invalid-kv2-invalid-metadata-type",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.UsernamePasswordType),
|
||||
CredType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
secretData: map[string]any{
|
||||
"metadata": map[string]any{},
|
||||
@@ -652,7 +653,7 @@ func TestBaseToUsrPass(t *testing.T) {
|
||||
name: "invalid-kv2-additional-field",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.UsernamePasswordType),
|
||||
CredType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
secretData: map[string]any{
|
||||
"bad-field": "hello",
|
||||
@@ -669,7 +670,7 @@ func TestBaseToUsrPass(t *testing.T) {
|
||||
name: "valid-kv2-default-attributes",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.UsernamePasswordType),
|
||||
CredType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
secretData: map[string]any{
|
||||
"metadata": map[string]any{},
|
||||
@@ -688,7 +689,7 @@ func TestBaseToUsrPass(t *testing.T) {
|
||||
name: "valid-kv2-override-attributes",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.UsernamePasswordType),
|
||||
CredType: string(globals.UsernamePasswordCredentialType),
|
||||
UsernameAttribute: "test-username",
|
||||
PasswordAttribute: "test-password",
|
||||
},
|
||||
@@ -711,7 +712,7 @@ func TestBaseToUsrPass(t *testing.T) {
|
||||
name: "valid-kv2-default-username-override-password",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.UsernamePasswordType),
|
||||
CredType: string(globals.UsernamePasswordCredentialType),
|
||||
PasswordAttribute: "test-password",
|
||||
},
|
||||
secretData: map[string]any{
|
||||
@@ -733,7 +734,7 @@ func TestBaseToUsrPass(t *testing.T) {
|
||||
name: "valid-kv2-override-username-default-password",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.UsernamePasswordType),
|
||||
CredType: string(globals.UsernamePasswordCredentialType),
|
||||
UsernameAttribute: "test-username",
|
||||
},
|
||||
secretData: map[string]any{
|
||||
@@ -792,7 +793,7 @@ func TestBaseToSshPriKey(t *testing.T) {
|
||||
name: "library-not-ssh-private-key-type",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.UnspecifiedType),
|
||||
CredType: string(globals.UnspecifiedCredentialType),
|
||||
},
|
||||
},
|
||||
wantErr: errors.InvalidParameter,
|
||||
@@ -801,7 +802,7 @@ func TestBaseToSshPriKey(t *testing.T) {
|
||||
name: "invalid-no-username-default-pk-attribute",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.SshPrivateKeyType),
|
||||
CredType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
secretData: map[string]any{
|
||||
"private_key": "my-pk",
|
||||
@@ -813,7 +814,7 @@ func TestBaseToSshPriKey(t *testing.T) {
|
||||
name: "invalid-no-pk-default-username-attribute",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.SshPrivateKeyType),
|
||||
CredType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
secretData: map[string]any{
|
||||
"username": "my-username",
|
||||
@@ -825,7 +826,7 @@ func TestBaseToSshPriKey(t *testing.T) {
|
||||
name: "valid-default-attributes",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.SshPrivateKeyType),
|
||||
CredType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
secretData: map[string]any{
|
||||
"username": "my-username",
|
||||
@@ -841,7 +842,7 @@ func TestBaseToSshPriKey(t *testing.T) {
|
||||
name: "valid-default-attributes-with-passphrase",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.SshPrivateKeyType),
|
||||
CredType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
secretData: map[string]any{
|
||||
"username": "my-username",
|
||||
@@ -859,7 +860,7 @@ func TestBaseToSshPriKey(t *testing.T) {
|
||||
name: "valid-override-attributes",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.SshPrivateKeyType),
|
||||
CredType: string(globals.SshPrivateKeyCredentialType),
|
||||
UsernameAttribute: "test-username",
|
||||
PrivateKeyAttribute: "test-pk",
|
||||
},
|
||||
@@ -879,7 +880,7 @@ func TestBaseToSshPriKey(t *testing.T) {
|
||||
name: "valid-override-attributes-with-passphrase",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.SshPrivateKeyType),
|
||||
CredType: string(globals.SshPrivateKeyCredentialType),
|
||||
UsernameAttribute: "test-username",
|
||||
PrivateKeyAttribute: "test-pk",
|
||||
PrivateKeyPassphraseAttribute: "test-pass",
|
||||
@@ -903,7 +904,7 @@ func TestBaseToSshPriKey(t *testing.T) {
|
||||
name: "valid-default-username-override-pk",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.SshPrivateKeyType),
|
||||
CredType: string(globals.SshPrivateKeyCredentialType),
|
||||
PrivateKeyAttribute: "test-pk",
|
||||
},
|
||||
secretData: map[string]any{
|
||||
@@ -922,7 +923,7 @@ func TestBaseToSshPriKey(t *testing.T) {
|
||||
name: "valid-override-username-default-pk",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.SshPrivateKeyType),
|
||||
CredType: string(globals.SshPrivateKeyCredentialType),
|
||||
UsernameAttribute: "test-username",
|
||||
},
|
||||
secretData: map[string]any{
|
||||
@@ -941,7 +942,7 @@ func TestBaseToSshPriKey(t *testing.T) {
|
||||
name: "invalid-username-override",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.SshPrivateKeyType),
|
||||
CredType: string(globals.SshPrivateKeyCredentialType),
|
||||
UsernameAttribute: "missing-username",
|
||||
},
|
||||
secretData: map[string]any{
|
||||
@@ -957,7 +958,7 @@ func TestBaseToSshPriKey(t *testing.T) {
|
||||
name: "invalid-pk-override",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.SshPrivateKeyType),
|
||||
CredType: string(globals.SshPrivateKeyCredentialType),
|
||||
UsernameAttribute: "missing-pk",
|
||||
},
|
||||
secretData: map[string]any{
|
||||
@@ -973,7 +974,7 @@ func TestBaseToSshPriKey(t *testing.T) {
|
||||
name: "invalid-kv2-no-metadata-field",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.SshPrivateKeyType),
|
||||
CredType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
secretData: map[string]any{
|
||||
"data": map[string]any{
|
||||
@@ -988,7 +989,7 @@ func TestBaseToSshPriKey(t *testing.T) {
|
||||
name: "invalid-kv2-no-data-field",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.SshPrivateKeyType),
|
||||
CredType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
secretData: map[string]any{
|
||||
"metadata": map[string]any{},
|
||||
@@ -1000,7 +1001,7 @@ func TestBaseToSshPriKey(t *testing.T) {
|
||||
name: "invalid-kv2-no-username-default-pk-attribute",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.SshPrivateKeyType),
|
||||
CredType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
secretData: map[string]any{
|
||||
"metadata": map[string]any{},
|
||||
@@ -1015,7 +1016,7 @@ func TestBaseToSshPriKey(t *testing.T) {
|
||||
name: "invalid-kv2-no-pk-default-username-attribute",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.SshPrivateKeyType),
|
||||
CredType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
secretData: map[string]any{
|
||||
"metadata": map[string]any{},
|
||||
@@ -1030,7 +1031,7 @@ func TestBaseToSshPriKey(t *testing.T) {
|
||||
name: "invalid-kv2-invalid-metadata-type",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.SshPrivateKeyType),
|
||||
CredType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
secretData: map[string]any{
|
||||
"metadata": "hello",
|
||||
@@ -1046,7 +1047,7 @@ func TestBaseToSshPriKey(t *testing.T) {
|
||||
name: "invalid-kv2-invalid-data-type",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.SshPrivateKeyType),
|
||||
CredType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
secretData: map[string]any{
|
||||
"metadata": map[string]any{},
|
||||
@@ -1059,7 +1060,7 @@ func TestBaseToSshPriKey(t *testing.T) {
|
||||
name: "invalid-kv2-additional-field",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.SshPrivateKeyType),
|
||||
CredType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
secretData: map[string]any{
|
||||
"bad-field": "hello",
|
||||
@@ -1076,7 +1077,7 @@ func TestBaseToSshPriKey(t *testing.T) {
|
||||
name: "valid-kv2-default-attributes",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.SshPrivateKeyType),
|
||||
CredType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
secretData: map[string]any{
|
||||
"metadata": map[string]any{},
|
||||
@@ -1095,7 +1096,7 @@ func TestBaseToSshPriKey(t *testing.T) {
|
||||
name: "valid-kv2-default-attributes-with-passphrase",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.SshPrivateKeyType),
|
||||
CredType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
secretData: map[string]any{
|
||||
"metadata": map[string]any{},
|
||||
@@ -1116,7 +1117,7 @@ func TestBaseToSshPriKey(t *testing.T) {
|
||||
name: "valid-kv2-override-attributes",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.SshPrivateKeyType),
|
||||
CredType: string(globals.SshPrivateKeyCredentialType),
|
||||
UsernameAttribute: "test-username",
|
||||
PrivateKeyAttribute: "test-pk",
|
||||
},
|
||||
@@ -1139,7 +1140,7 @@ func TestBaseToSshPriKey(t *testing.T) {
|
||||
name: "valid-kv2-override-attributes-with-passphrase",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.SshPrivateKeyType),
|
||||
CredType: string(globals.SshPrivateKeyCredentialType),
|
||||
UsernameAttribute: "test-username",
|
||||
PrivateKeyAttribute: "test-pk",
|
||||
PrivateKeyPassphraseAttribute: "test-pass",
|
||||
@@ -1166,7 +1167,7 @@ func TestBaseToSshPriKey(t *testing.T) {
|
||||
name: "valid-kv2-default-username-override-pk",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.SshPrivateKeyType),
|
||||
CredType: string(globals.SshPrivateKeyCredentialType),
|
||||
PrivateKeyAttribute: "test-pk",
|
||||
},
|
||||
secretData: map[string]any{
|
||||
@@ -1188,7 +1189,7 @@ func TestBaseToSshPriKey(t *testing.T) {
|
||||
name: "valid-kv2-override-username-default-pk",
|
||||
given: &baseCred{
|
||||
lib: &genericIssuingCredentialLibrary{
|
||||
CredType: string(credential.SshPrivateKeyType),
|
||||
CredType: string(globals.SshPrivateKeyCredentialType),
|
||||
UsernameAttribute: "test-username",
|
||||
},
|
||||
secretData: map[string]any{
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
if err := subtypes.Register(credential.Domain, Subtype, globals.VaultCredentialStorePrefix, DynamicCredentialPrefix); err != nil {
|
||||
if err := subtypes.Register(credential.Domain, Subtype, globals.VaultCredentialStorePrefix, globals.VaultDynamicCredentialPrefix); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := subtypes.Register(credential.Domain, GenericLibrarySubtype, globals.VaultCredentialLibraryPrefix); err != nil {
|
||||
@@ -27,9 +27,6 @@ func init() {
|
||||
|
||||
// PublicId prefixes for the resources in the vault package.
|
||||
const (
|
||||
// DynamicCredentialPrefix is the prefix for Vault dynamic credentials
|
||||
DynamicCredentialPrefix = "cdvlt"
|
||||
|
||||
Subtype = subtypes.Subtype("vault")
|
||||
GenericLibrarySubtype = subtypes.Subtype("vault-generic")
|
||||
SSHCertificateLibrarySubtype = subtypes.Subtype("vault-ssh-certificate")
|
||||
@@ -44,7 +41,7 @@ func newCredentialStoreId(ctx context.Context) (string, error) {
|
||||
}
|
||||
|
||||
func newCredentialId(ctx context.Context) (string, error) {
|
||||
id, err := db.NewPublicId(ctx, DynamicCredentialPrefix)
|
||||
id, err := db.NewPublicId(ctx, globals.VaultDynamicCredentialPrefix)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(ctx, err, "vault.newCredentialId")
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/credential"
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/hashicorp/boundary/internal/db"
|
||||
"github.com/hashicorp/boundary/internal/db/timestamp"
|
||||
"github.com/hashicorp/boundary/internal/errors"
|
||||
@@ -384,7 +384,7 @@ func (pl *listLookupLibrary) toCredentialLibrary() *CredentialLibrary {
|
||||
cl.CredentialLibrary.CredentialType = pl.CredentialType
|
||||
|
||||
switch pl.CredentialType {
|
||||
case string(credential.UsernamePasswordType):
|
||||
case string(globals.UsernamePasswordCredentialType):
|
||||
if pl.UsernameAttribute != "" || pl.PasswordAttribute != "" {
|
||||
up := allocUsernamePasswordOverride()
|
||||
up.LibraryId = pl.PublicId
|
||||
@@ -393,7 +393,7 @@ func (pl *listLookupLibrary) toCredentialLibrary() *CredentialLibrary {
|
||||
up.sanitize()
|
||||
cl.MappingOverride = up
|
||||
}
|
||||
case string(credential.SshPrivateKeyType):
|
||||
case string(globals.SshPrivateKeyCredentialType):
|
||||
if pl.UsernameAttribute != "" || pl.PrivateKeyAttribute != "" || pl.PrivateKeyPassphraseAttribute != "" {
|
||||
pk := allocSshPrivateKeyOverride()
|
||||
pk.LibraryId = pl.PublicId
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/hashicorp/boundary/internal/credential"
|
||||
"github.com/hashicorp/boundary/internal/credential/vault/store"
|
||||
"github.com/hashicorp/boundary/internal/db"
|
||||
dbassert "github.com/hashicorp/boundary/internal/db/assert"
|
||||
@@ -175,7 +174,7 @@ func TestRepository_CreateCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
want: &CredentialLibrary{
|
||||
@@ -183,7 +182,7 @@ func TestRepository_CreateCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -195,7 +194,7 @@ func TestRepository_CreateCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
wantErr: errors.VaultInvalidMappingOverride,
|
||||
@@ -222,7 +221,7 @@ func TestRepository_CreateCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
want: &CredentialLibrary{
|
||||
@@ -233,7 +232,7 @@ func TestRepository_CreateCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -247,7 +246,7 @@ func TestRepository_CreateCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
want: &CredentialLibrary{
|
||||
@@ -258,7 +257,7 @@ func TestRepository_CreateCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -273,7 +272,7 @@ func TestRepository_CreateCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
want: &CredentialLibrary{
|
||||
@@ -285,7 +284,7 @@ func TestRepository_CreateCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -296,7 +295,7 @@ func TestRepository_CreateCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
want: &CredentialLibrary{
|
||||
@@ -304,7 +303,7 @@ func TestRepository_CreateCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -316,7 +315,7 @@ func TestRepository_CreateCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
wantErr: errors.VaultInvalidMappingOverride,
|
||||
@@ -329,7 +328,7 @@ func TestRepository_CreateCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
wantErr: errors.VaultInvalidMappingOverride,
|
||||
@@ -344,7 +343,7 @@ func TestRepository_CreateCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
want: &CredentialLibrary{
|
||||
@@ -355,7 +354,7 @@ func TestRepository_CreateCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -369,7 +368,7 @@ func TestRepository_CreateCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
want: &CredentialLibrary{
|
||||
@@ -380,7 +379,7 @@ func TestRepository_CreateCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -394,7 +393,7 @@ func TestRepository_CreateCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
want: &CredentialLibrary{
|
||||
@@ -405,7 +404,7 @@ func TestRepository_CreateCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -421,7 +420,7 @@ func TestRepository_CreateCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
want: &CredentialLibrary{
|
||||
@@ -434,7 +433,7 @@ func TestRepository_CreateCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -626,7 +625,7 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
changeCredentialType := func(t credential.Type) func(*CredentialLibrary) *CredentialLibrary {
|
||||
changeCredentialType := func(t globals.CredentialType) func(*CredentialLibrary) *CredentialLibrary {
|
||||
return func(l *CredentialLibrary) *CredentialLibrary {
|
||||
l.CredentialLibrary.CredentialType = string(t)
|
||||
return l
|
||||
@@ -926,7 +925,7 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
|
||||
CredentialLibrary: &store.CredentialLibrary{
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/old/path",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
chgFn: changeVaultPath("/new/path"),
|
||||
@@ -936,7 +935,7 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
|
||||
CredentialLibrary: &store.CredentialLibrary{
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/new/path",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
wantCount: 1,
|
||||
@@ -1086,10 +1085,10 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
Name: "test-name-repo",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
chgFn: changeCredentialType(credential.UnspecifiedType),
|
||||
chgFn: changeCredentialType(globals.UnspecifiedCredentialType),
|
||||
masks: []string{"PublicId", "CreateTime", "UpdateTime", "StoreId", "CredentialType"},
|
||||
wantErr: errors.InvalidFieldMask,
|
||||
},
|
||||
@@ -1104,7 +1103,7 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
Name: "test-name-repo",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
chgFn: changeMappingOverride(
|
||||
@@ -1121,7 +1120,7 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
Name: "test-name-repo",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
wantCount: 1,
|
||||
@@ -1137,7 +1136,7 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
Name: "test-name-repo",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
chgFn: changeMappingOverride(
|
||||
@@ -1154,7 +1153,7 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
Name: "test-name-repo",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
wantCount: 1,
|
||||
@@ -1170,7 +1169,7 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
Name: "test-name-repo",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
chgFn: changeMappingOverride(
|
||||
@@ -1189,7 +1188,7 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
Name: "test-name-repo",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
wantCount: 1,
|
||||
@@ -1201,7 +1200,7 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
Name: "test-name-repo",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
chgFn: changeMappingOverride(
|
||||
@@ -1220,7 +1219,7 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
Name: "test-name-repo",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
wantCount: 1,
|
||||
@@ -1236,7 +1235,7 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
Name: "test-name-repo",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
chgFn: changeMappingOverride(nil),
|
||||
@@ -1246,7 +1245,7 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
Name: "test-name-repo",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
wantCount: 1,
|
||||
@@ -1279,7 +1278,7 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
Name: "test-ssh-private-key-repo",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
chgFn: changeMappingOverride(
|
||||
@@ -1296,7 +1295,7 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
Name: "test-ssh-private-key-repo",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
wantCount: 1,
|
||||
@@ -1311,7 +1310,7 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
Name: "test-ssh-private-key-repo",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
chgFn: changeMappingOverride(
|
||||
@@ -1328,7 +1327,7 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
Name: "test-ssh-private-key-repo",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
wantCount: 1,
|
||||
@@ -1343,7 +1342,7 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
Name: "test-ssh-private-key-repo",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
chgFn: changeMappingOverride(
|
||||
@@ -1360,7 +1359,7 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
Name: "test-ssh-private-key-repo",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
wantCount: 1,
|
||||
@@ -1377,7 +1376,7 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
Name: "test-ssh-private-key-repo",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
chgFn: changeMappingOverride(
|
||||
@@ -1398,7 +1397,7 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
Name: "test-ssh-private-key-repo",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
wantCount: 1,
|
||||
@@ -1410,7 +1409,7 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
Name: "test-ssh-private-key-repo",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
chgFn: changeMappingOverride(
|
||||
@@ -1431,7 +1430,7 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
Name: "test-ssh-private-key-repo",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
wantCount: 1,
|
||||
@@ -1448,7 +1447,7 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
Name: "test-ssh-private-key-repo",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
chgFn: changeMappingOverride(nil),
|
||||
@@ -1458,7 +1457,7 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
Name: "test-ssh-private-key-repo",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
wantCount: 1,
|
||||
@@ -1749,7 +1748,7 @@ func TestRepository_LookupCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1763,7 +1762,7 @@ func TestRepository_LookupCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1777,7 +1776,7 @@ func TestRepository_LookupCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1792,7 +1791,7 @@ func TestRepository_LookupCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1803,7 +1802,7 @@ func TestRepository_LookupCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1817,7 +1816,7 @@ func TestRepository_LookupCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1831,7 +1830,7 @@ func TestRepository_LookupCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1845,7 +1844,7 @@ func TestRepository_LookupCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1861,7 +1860,7 @@ func TestRepository_LookupCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -2027,7 +2026,7 @@ func TestRepository_DeleteCredentialLibrary(t *testing.T) {
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
Name: "test-name-repo",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -2071,7 +2070,7 @@ func TestRepository_ListCredentialLibraries(t *testing.T) {
|
||||
HttpMethod: "GET",
|
||||
VaultPath: "/some/path",
|
||||
Name: "test-name-repo",
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/hashicorp/boundary/internal/authtoken"
|
||||
"github.com/hashicorp/boundary/internal/credential"
|
||||
"github.com/hashicorp/boundary/internal/credential/vault"
|
||||
@@ -228,7 +229,7 @@ func TestRepository_IssueCredentials(t *testing.T) {
|
||||
{
|
||||
libPath := path.Join("database", "creds", "opened")
|
||||
opts := []vault.Option{
|
||||
vault.WithCredentialType(credential.UsernamePasswordType),
|
||||
vault.WithCredentialType(globals.UsernamePasswordCredentialType),
|
||||
}
|
||||
libIn, err := vault.NewCredentialLibrary(origStore.GetPublicId(), libPath, opts...)
|
||||
assert.NoError(t, err)
|
||||
@@ -241,7 +242,7 @@ func TestRepository_IssueCredentials(t *testing.T) {
|
||||
{
|
||||
libPath := path.Join("database", "creds", "opened")
|
||||
opts := []vault.Option{
|
||||
vault.WithCredentialType(credential.UsernamePasswordType),
|
||||
vault.WithCredentialType(globals.UsernamePasswordCredentialType),
|
||||
vault.WithMappingOverride(vault.NewUsernamePasswordOverride(
|
||||
vault.WithOverrideUsernameAttribute("test-username"),
|
||||
vault.WithOverridePasswordAttribute("test-password"),
|
||||
@@ -258,7 +259,7 @@ func TestRepository_IssueCredentials(t *testing.T) {
|
||||
{
|
||||
libPath := path.Join("secret", "data", "my-up-secret")
|
||||
opts := []vault.Option{
|
||||
vault.WithCredentialType(credential.UsernamePasswordType),
|
||||
vault.WithCredentialType(globals.UsernamePasswordCredentialType),
|
||||
}
|
||||
libIn, err := vault.NewCredentialLibrary(origStore.GetPublicId(), libPath, opts...)
|
||||
assert.NoError(t, err)
|
||||
@@ -271,7 +272,7 @@ func TestRepository_IssueCredentials(t *testing.T) {
|
||||
{
|
||||
libPath := path.Join("secret", "data", "my-sshpk-secret")
|
||||
opts := []vault.Option{
|
||||
vault.WithCredentialType(credential.SshPrivateKeyType),
|
||||
vault.WithCredentialType(globals.SshPrivateKeyCredentialType),
|
||||
}
|
||||
libIn, err := vault.NewCredentialLibrary(origStore.GetPublicId(), libPath, opts...)
|
||||
assert.NoError(t, err)
|
||||
@@ -284,7 +285,7 @@ func TestRepository_IssueCredentials(t *testing.T) {
|
||||
{
|
||||
libPath := path.Join("secret", "data", "my-up-secret")
|
||||
opts := []vault.Option{
|
||||
vault.WithCredentialType(credential.UsernamePasswordType),
|
||||
vault.WithCredentialType(globals.UsernamePasswordCredentialType),
|
||||
}
|
||||
libIn, err := vault.NewCredentialLibrary(expStore.GetPublicId(), libPath, opts...)
|
||||
assert.NoError(t, err)
|
||||
@@ -473,14 +474,14 @@ func TestRepository_IssueCredentials(t *testing.T) {
|
||||
assert.NotZero(len(got))
|
||||
for _, dc := range got {
|
||||
switch dc.Library().CredentialType() {
|
||||
case credential.UsernamePasswordType:
|
||||
case globals.UsernamePasswordCredentialType:
|
||||
if upc, ok := dc.(credential.UsernamePassword); ok {
|
||||
assert.NotEmpty(upc.Username())
|
||||
assert.NotEmpty(upc.Password())
|
||||
break
|
||||
}
|
||||
assert.Fail("want UsernamePassword credential from library with credential type UsernamePassword")
|
||||
case credential.UnspecifiedType:
|
||||
case globals.UnspecifiedCredentialType:
|
||||
if _, ok := dc.(credential.UsernamePassword); ok {
|
||||
assert.Fail("do not want UsernamePassword credential from library with credential type Unspecified")
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/credential"
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/hashicorp/boundary/internal/db"
|
||||
"github.com/hashicorp/boundary/internal/errors"
|
||||
"github.com/hashicorp/boundary/internal/kms"
|
||||
@@ -60,9 +60,9 @@ func (r *Repository) CreateSSHCertificateCredentialLibrary(ctx context.Context,
|
||||
}
|
||||
|
||||
if l.GetCredentialType() == "" {
|
||||
l.SSHCertificateCredentialLibrary.CredentialType = string(credential.SshCertificateType)
|
||||
l.SSHCertificateCredentialLibrary.CredentialType = string(globals.SshCertificateCredentialType)
|
||||
}
|
||||
if l.GetCredentialType() != string(credential.SshCertificateType) {
|
||||
if l.GetCredentialType() != string(globals.SshCertificateCredentialType) {
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "invalid credential type")
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/hashicorp/boundary/internal/credential"
|
||||
"github.com/hashicorp/boundary/internal/credential/vault/store"
|
||||
"github.com/hashicorp/boundary/internal/db"
|
||||
dbassert "github.com/hashicorp/boundary/internal/db/assert"
|
||||
@@ -609,7 +608,7 @@ func TestRepository_CreateSSHCertificateCredentialLibrary(t *testing.T) {
|
||||
assert.Equal(tt.want.Ttl, got.Ttl)
|
||||
assert.Equal(tt.want.CriticalOptions, got.CriticalOptions)
|
||||
assert.Equal(tt.want.Extensions, got.Extensions)
|
||||
assert.Equal(got.CredentialType(), credential.SshCertificateType)
|
||||
assert.Equal(got.CredentialType(), globals.SshCertificateCredentialType)
|
||||
assert.Equal(got.CreateTime, got.UpdateTime)
|
||||
|
||||
assert.NoError(db.TestVerifyOplog(t, rw, got.GetPublicId(), db.WithOperation(oplog.OpType_OP_TYPE_CREATE), db.WithCreateNotBefore(10*time.Second)))
|
||||
@@ -746,7 +745,7 @@ func TestRepository_LookupSSHCertificateCredentialLibrary(t *testing.T) {
|
||||
StoreId: cs.GetPublicId(),
|
||||
VaultPath: "/ssh/sign/foo",
|
||||
Username: "name",
|
||||
CredentialType: string(credential.SshCertificateType),
|
||||
CredentialType: string(globals.SshCertificateCredentialType),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package vault
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/hashicorp/boundary/internal/credential"
|
||||
"github.com/hashicorp/boundary/internal/credential/vault/store"
|
||||
"github.com/hashicorp/boundary/internal/oplog"
|
||||
@@ -55,7 +56,7 @@ func NewSSHCertificateCredentialLibrary(storeId string, vaultPath string, userna
|
||||
KeyId: opts.withKeyId,
|
||||
CriticalOptions: opts.withCriticalOptions,
|
||||
Extensions: opts.withExtensions,
|
||||
CredentialType: string(credential.SshCertificateType),
|
||||
CredentialType: string(globals.SshCertificateCredentialType),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -116,8 +117,8 @@ func (l *SSHCertificateCredentialLibrary) getDefaultKeyBits() uint32 {
|
||||
}
|
||||
|
||||
// CredentialType returns the type of credential the library retrieves.
|
||||
func (l *SSHCertificateCredentialLibrary) CredentialType() credential.Type {
|
||||
return credential.Type(l.SSHCertificateCredentialLibrary.CredentialType)
|
||||
func (l *SSHCertificateCredentialLibrary) CredentialType() globals.CredentialType {
|
||||
return globals.CredentialType(l.SSHCertificateCredentialLibrary.CredentialType)
|
||||
}
|
||||
|
||||
var _ credential.Library = (*SSHCertificateCredentialLibrary)(nil)
|
||||
+22
-22
@@ -74,10 +74,10 @@ var (
|
||||
action.List,
|
||||
}
|
||||
|
||||
validCredentialTypesVaultGeneric = []credential.Type{
|
||||
credential.UsernamePasswordType,
|
||||
credential.SshPrivateKeyType,
|
||||
credential.UnspecifiedType,
|
||||
validCredentialTypesVaultGeneric = []globals.CredentialType{
|
||||
globals.UsernamePasswordCredentialType,
|
||||
globals.SshPrivateKeyCredentialType,
|
||||
globals.UnspecifiedCredentialType,
|
||||
}
|
||||
|
||||
validKeyTypes = []string{
|
||||
@@ -275,7 +275,7 @@ func (s Service) UpdateCredentialLibrary(ctx context.Context, req *pbs.UpdateCre
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var currentCredentialType credential.Type
|
||||
var currentCredentialType globals.CredentialType
|
||||
var mo vault.MappingOverride
|
||||
switch subtypes.SubtypeFromId(domain, req.GetId()) {
|
||||
case vault.SSHCertificateLibrarySubtype:
|
||||
@@ -283,13 +283,13 @@ func (s Service) UpdateCredentialLibrary(ctx context.Context, req *pbs.UpdateCre
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
currentCredentialType = credential.Type(cur.GetCredentialType())
|
||||
currentCredentialType = globals.CredentialType(cur.GetCredentialType())
|
||||
default:
|
||||
cur, err := repo.LookupCredentialLibrary(ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
currentCredentialType = credential.Type(cur.GetCredentialType())
|
||||
currentCredentialType = globals.CredentialType(cur.GetCredentialType())
|
||||
mo = cur.MappingOverride
|
||||
}
|
||||
|
||||
@@ -444,7 +444,7 @@ func (s Service) updateInRepo(
|
||||
projId, id string,
|
||||
masks []string,
|
||||
in *pb.CredentialLibrary,
|
||||
currentCredentialType credential.Type,
|
||||
currentCredentialType globals.CredentialType,
|
||||
currentMapping vault.MappingOverride) (credential.Library, error,
|
||||
) {
|
||||
const op = "credentiallibraries.(Service).updateInRepo"
|
||||
@@ -657,7 +657,7 @@ func toProto(ctx context.Context, in credential.Library, opt ...handlers.Option)
|
||||
return nil, errors.New(ctx, errors.Internal, op, "unable to cast to vault credential library")
|
||||
}
|
||||
|
||||
if outputFields.Has(globals.CredentialTypeField) && vaultIn.GetCredentialType() != string(credential.UnspecifiedType) {
|
||||
if outputFields.Has(globals.CredentialTypeField) && vaultIn.GetCredentialType() != string(globals.UnspecifiedCredentialType) {
|
||||
out.CredentialType = vaultIn.GetCredentialType()
|
||||
if outputFields.Has(globals.CredentialMappingOverridesField) && vaultIn.MappingOverride != nil {
|
||||
m := make(map[string]any)
|
||||
@@ -771,9 +771,9 @@ func toStorageVaultLibrary(ctx context.Context, storeId string, in *pb.Credentia
|
||||
opts = append(opts, vault.WithRequestBody([]byte(attrs.GetHttpRequestBody().GetValue())))
|
||||
}
|
||||
|
||||
credentialType := credential.Type(in.GetCredentialType())
|
||||
credentialType := globals.CredentialType(in.GetCredentialType())
|
||||
switch credentialType {
|
||||
case credential.UsernamePasswordType:
|
||||
case globals.UsernamePasswordCredentialType:
|
||||
opts = append(opts, vault.WithCredentialType(credentialType))
|
||||
overrides := in.CredentialMappingOverrides.AsMap()
|
||||
var mapOpts []vault.Option
|
||||
@@ -787,7 +787,7 @@ func toStorageVaultLibrary(ctx context.Context, storeId string, in *pb.Credentia
|
||||
opts = append(opts, vault.WithMappingOverride(vault.NewUsernamePasswordOverride(mapOpts...)))
|
||||
}
|
||||
|
||||
case credential.SshPrivateKeyType:
|
||||
case globals.SshPrivateKeyCredentialType:
|
||||
opts = append(opts, vault.WithCredentialType(credentialType))
|
||||
overrides := in.CredentialMappingOverrides.AsMap()
|
||||
var mapOpts []vault.Option
|
||||
@@ -821,7 +821,7 @@ func toStorageVaultSSHCertificateLibrary(ctx context.Context, storeId string, in
|
||||
if in.GetDescription() != nil {
|
||||
opts = append(opts, vault.WithDescription(in.GetDescription().GetValue()))
|
||||
}
|
||||
opts = append(opts, vault.WithCredentialType(credential.Type(in.GetCredentialType())))
|
||||
opts = append(opts, vault.WithCredentialType(globals.CredentialType(in.GetCredentialType())))
|
||||
|
||||
attrs := in.GetVaultSshCertificateCredentialLibraryAttributes()
|
||||
if attrs.GetKeyType() != nil {
|
||||
@@ -949,7 +949,7 @@ func validateCreateRequest(req *pbs.CreateCredentialLibraryRequest) error {
|
||||
if b := attrs.GetHttpRequestBody(); b != nil && strings.ToUpper(attrs.GetHttpMethod().GetValue()) != "POST" {
|
||||
badFields[httpRequestBodyField] = fmt.Sprintf("Field can only be set if %q is set to the value 'POST'.", httpMethodField)
|
||||
}
|
||||
validateMapping(badFields, credential.Type(req.GetItem().GetCredentialType()), req.GetItem().CredentialMappingOverrides.AsMap())
|
||||
validateMapping(badFields, globals.CredentialType(req.GetItem().GetCredentialType()), req.GetItem().CredentialMappingOverrides.AsMap())
|
||||
case vault.SSHCertificateLibrarySubtype:
|
||||
if req.GetItem().GetCredentialType() != "" {
|
||||
badFields[globals.CredentialTypeField] = fmt.Sprintf("This field is read only and cannot be set.")
|
||||
@@ -985,7 +985,7 @@ func validateCreateRequest(req *pbs.CreateCredentialLibraryRequest) error {
|
||||
})
|
||||
}
|
||||
|
||||
func validateUpdateRequest(req *pbs.UpdateCredentialLibraryRequest, currentCredentialType credential.Type) error {
|
||||
func validateUpdateRequest(req *pbs.UpdateCredentialLibraryRequest, currentCredentialType globals.CredentialType) error {
|
||||
prefix := ""
|
||||
st := subtypes.SubtypeFromId(domain, req.GetId())
|
||||
switch st {
|
||||
@@ -1064,18 +1064,18 @@ func validateListRequest(ctx context.Context, req *pbs.ListCredentialLibrariesRe
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateMapping(badFields map[string]string, credentialType credential.Type, overrides map[string]any) {
|
||||
func validateMapping(badFields map[string]string, credentialType globals.CredentialType, overrides map[string]any) {
|
||||
validFields := make(map[string]bool)
|
||||
switch credentialType {
|
||||
case "", credential.UnspecifiedType:
|
||||
case "", globals.UnspecifiedCredentialType:
|
||||
if len(overrides) > 0 {
|
||||
badFields[globals.CredentialMappingOverridesField] = fmt.Sprintf("This field can only be set if %q is set", globals.CredentialTypeField)
|
||||
}
|
||||
return
|
||||
case credential.UsernamePasswordType:
|
||||
case globals.UsernamePasswordCredentialType:
|
||||
validFields[usernameAttribute] = true
|
||||
validFields[passwordAttribute] = true
|
||||
case credential.SshPrivateKeyType:
|
||||
case globals.SshPrivateKeyCredentialType:
|
||||
validFields[usernameAttribute] = true
|
||||
validFields[privateKeyAttribute] = true
|
||||
validFields[pkPassphraseAttribute] = true
|
||||
@@ -1127,7 +1127,7 @@ func getMapUpdate(field string, apiMasks []string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func getMappingUpdates(credentialType credential.Type, current vault.MappingOverride, new map[string]any, apiMasks []string) (map[string]any, bool) {
|
||||
func getMappingUpdates(credentialType globals.CredentialType, current vault.MappingOverride, new map[string]any, apiMasks []string) (map[string]any, bool) {
|
||||
ret := make(map[string]any)
|
||||
masks := make(map[string]bool)
|
||||
for _, m := range apiMasks {
|
||||
@@ -1148,7 +1148,7 @@ func getMappingUpdates(credentialType credential.Type, current vault.MappingOver
|
||||
}
|
||||
|
||||
switch credentialType {
|
||||
case credential.UsernamePasswordType:
|
||||
case globals.UsernamePasswordCredentialType:
|
||||
var currentUser, currentPass any
|
||||
if overrides, ok := current.(*vault.UsernamePasswordOverride); ok {
|
||||
currentUser = overrides.UsernameAttribute
|
||||
@@ -1169,7 +1169,7 @@ func getMappingUpdates(credentialType credential.Type, current vault.MappingOver
|
||||
ret[passwordAttribute] = currentPass
|
||||
}
|
||||
|
||||
case credential.SshPrivateKeyType:
|
||||
case globals.SshPrivateKeyCredentialType:
|
||||
var currentUser, currentpPass, currentPk any
|
||||
if overrides, ok := current.(*vault.SshPrivateKeyOverride); ok {
|
||||
currentUser = overrides.UsernameAttribute
|
||||
|
||||
+15
-16
@@ -13,7 +13,6 @@ import (
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/hashicorp/boundary/internal/credential"
|
||||
"github.com/hashicorp/boundary/internal/credential/vault"
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller/auth"
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller/handlers"
|
||||
@@ -468,7 +467,7 @@ func TestCreate(t *testing.T) {
|
||||
Path: wrapperspb.String("something"),
|
||||
},
|
||||
},
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
CredentialMappingOverrides: func() *structpb.Struct {
|
||||
v := map[string]any{
|
||||
usernameAttribute: "user-test",
|
||||
@@ -563,7 +562,7 @@ func TestCreate(t *testing.T) {
|
||||
Path: wrapperspb.String("something"),
|
||||
},
|
||||
},
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
}},
|
||||
idPrefix: globals.VaultCredentialLibraryPrefix + "_",
|
||||
res: &pbs.CreateCredentialLibraryResponse{
|
||||
@@ -582,7 +581,7 @@ func TestCreate(t *testing.T) {
|
||||
HttpMethod: wrapperspb.String("GET"),
|
||||
},
|
||||
},
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
AuthorizedActions: testAuthorizedActions,
|
||||
},
|
||||
},
|
||||
@@ -605,7 +604,7 @@ func TestCreate(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
return ret
|
||||
}(),
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
}},
|
||||
idPrefix: globals.VaultCredentialLibraryPrefix + "_",
|
||||
res: &pbs.CreateCredentialLibraryResponse{
|
||||
@@ -624,7 +623,7 @@ func TestCreate(t *testing.T) {
|
||||
HttpMethod: wrapperspb.String("GET"),
|
||||
},
|
||||
},
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
CredentialMappingOverrides: func() *structpb.Struct {
|
||||
v := map[string]any{
|
||||
usernameAttribute: "user-test",
|
||||
@@ -656,7 +655,7 @@ func TestCreate(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
return ret
|
||||
}(),
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
}},
|
||||
idPrefix: globals.VaultCredentialLibraryPrefix + "_",
|
||||
res: &pbs.CreateCredentialLibraryResponse{
|
||||
@@ -675,7 +674,7 @@ func TestCreate(t *testing.T) {
|
||||
HttpMethod: wrapperspb.String("GET"),
|
||||
},
|
||||
},
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
CredentialMappingOverrides: func() *structpb.Struct {
|
||||
v := map[string]any{
|
||||
usernameAttribute: "user-test",
|
||||
@@ -699,7 +698,7 @@ func TestCreate(t *testing.T) {
|
||||
Path: wrapperspb.String("something"),
|
||||
},
|
||||
},
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
}},
|
||||
idPrefix: globals.VaultCredentialLibraryPrefix + "_",
|
||||
res: &pbs.CreateCredentialLibraryResponse{
|
||||
@@ -718,7 +717,7 @@ func TestCreate(t *testing.T) {
|
||||
HttpMethod: wrapperspb.String("GET"),
|
||||
},
|
||||
},
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
AuthorizedActions: testAuthorizedActions,
|
||||
},
|
||||
},
|
||||
@@ -743,7 +742,7 @@ func TestCreate(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
return ret
|
||||
}(),
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
}},
|
||||
idPrefix: globals.VaultCredentialLibraryPrefix + "_",
|
||||
res: &pbs.CreateCredentialLibraryResponse{
|
||||
@@ -762,7 +761,7 @@ func TestCreate(t *testing.T) {
|
||||
HttpMethod: wrapperspb.String("GET"),
|
||||
},
|
||||
},
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
CredentialMappingOverrides: func() *structpb.Struct {
|
||||
v := map[string]any{
|
||||
usernameAttribute: "user-test",
|
||||
@@ -1791,7 +1790,7 @@ func TestUpdate(t *testing.T) {
|
||||
{
|
||||
name: "read only credential type",
|
||||
path: "credential_type",
|
||||
item: &pb.CredentialLibrary{CredentialType: string(credential.UsernamePasswordType)},
|
||||
item: &pb.CredentialLibrary{CredentialType: string(globals.UsernamePasswordCredentialType)},
|
||||
},
|
||||
}
|
||||
for _, tc := range errCases {
|
||||
@@ -2093,7 +2092,7 @@ func TestCreate_SSHCertificateCredentialLibrary(t *testing.T) {
|
||||
},
|
||||
},
|
||||
AuthorizedActions: testAuthorizedActions,
|
||||
CredentialType: string(credential.SshCertificateType),
|
||||
CredentialType: string(globals.SshCertificateCredentialType),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -2131,7 +2130,7 @@ func TestCreate_SSHCertificateCredentialLibrary(t *testing.T) {
|
||||
},
|
||||
},
|
||||
AuthorizedActions: testAuthorizedActions,
|
||||
CredentialType: string(credential.SshCertificateType),
|
||||
CredentialType: string(globals.SshCertificateCredentialType),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -2468,7 +2467,7 @@ func TestUpdate_SSHCertificateCredentialLibrary(t *testing.T) {
|
||||
{
|
||||
name: "read only credential type",
|
||||
path: "credential_type",
|
||||
item: &pb.CredentialLibrary{CredentialType: string(credential.UsernamePasswordType)},
|
||||
item: &pb.CredentialLibrary{CredentialType: string(globals.UsernamePasswordCredentialType)},
|
||||
},
|
||||
}
|
||||
for _, tc := range errCases {
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/hashicorp/boundary/internal/credential"
|
||||
credstatic "github.com/hashicorp/boundary/internal/credential/static"
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller/handlers"
|
||||
@@ -98,7 +99,7 @@ func dynamicToSessionCredential(ctx context.Context, cred credential.Dynamic) (*
|
||||
|
||||
var credType string
|
||||
var credData *structpb.Struct
|
||||
if l.CredentialType() != credential.UnspecifiedType {
|
||||
if l.CredentialType() != globals.UnspecifiedCredentialType {
|
||||
credType = string(l.CredentialType())
|
||||
|
||||
switch c := cred.(type) {
|
||||
@@ -194,7 +195,7 @@ func staticToSessionCredential(ctx context.Context, cred credential.Static) (*pb
|
||||
switch c := cred.(type) {
|
||||
case *credstatic.UsernamePasswordCredential:
|
||||
var err error
|
||||
credType = string(credential.UsernamePasswordType)
|
||||
credType = string(globals.UsernamePasswordCredentialType)
|
||||
credData, err = handlers.ProtoToStruct(
|
||||
&pb.UsernamePasswordCredential{
|
||||
Username: c.GetUsername(),
|
||||
@@ -211,7 +212,7 @@ func staticToSessionCredential(ctx context.Context, cred credential.Static) (*pb
|
||||
|
||||
case *credstatic.SshPrivateKeyCredential:
|
||||
var err error
|
||||
credType = string(credential.SshPrivateKeyType)
|
||||
credType = string(globals.SshPrivateKeyCredentialType)
|
||||
credData, err = handlers.ProtoToStruct(
|
||||
&pb.SshPrivateKeyCredential{
|
||||
Username: c.GetUsername(),
|
||||
@@ -232,7 +233,7 @@ func staticToSessionCredential(ctx context.Context, cred credential.Static) (*pb
|
||||
|
||||
case *credstatic.JsonCredential:
|
||||
var err error
|
||||
credType = string(credential.JsonType)
|
||||
credType = string(globals.JsonCredentialType)
|
||||
object := map[string]any{}
|
||||
err = json.Unmarshal(c.GetObject(), &object)
|
||||
if err != nil {
|
||||
|
||||
@@ -3009,7 +3009,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
|
||||
Description: clsRespUsernamePassword.GetItem().GetDescription().GetValue(),
|
||||
CredentialStoreId: vaultStore.GetPublicId(),
|
||||
Type: vault.GenericLibrarySubtype.String(),
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
Credential: func() *structpb.Struct {
|
||||
data := map[string]any{
|
||||
@@ -3035,7 +3035,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
|
||||
Description: clsRespUsernamePasswordWithMapping.GetItem().GetDescription().GetValue(),
|
||||
CredentialStoreId: vaultStore.GetPublicId(),
|
||||
Type: vault.GenericLibrarySubtype.String(),
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
Credential: func() *structpb.Struct {
|
||||
data := map[string]any{
|
||||
@@ -3061,7 +3061,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
|
||||
Description: upCredResp.GetItem().GetDescription().GetValue(),
|
||||
CredentialStoreId: staticStore.GetPublicId(),
|
||||
Type: credstatic.Subtype.String(),
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
CredentialType: string(globals.UsernamePasswordCredentialType),
|
||||
},
|
||||
Credential: func() *structpb.Struct {
|
||||
data := map[string]any{
|
||||
@@ -3087,7 +3087,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
|
||||
Description: sshPkCredResp.GetItem().GetDescription().GetValue(),
|
||||
CredentialStoreId: staticStore.GetPublicId(),
|
||||
Type: credstatic.Subtype.String(),
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
Credential: func() *structpb.Struct {
|
||||
data := map[string]any{
|
||||
@@ -3113,7 +3113,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
|
||||
Description: clsRespSshPrivateKey.GetItem().GetDescription().GetValue(),
|
||||
CredentialStoreId: vaultStore.GetPublicId(),
|
||||
Type: vault.GenericLibrarySubtype.String(),
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
Credential: func() *structpb.Struct {
|
||||
data := map[string]any{
|
||||
@@ -3139,7 +3139,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
|
||||
Description: clsRespSshPrivateKeyWithMapping.GetItem().GetDescription().GetValue(),
|
||||
CredentialStoreId: vaultStore.GetPublicId(),
|
||||
Type: vault.GenericLibrarySubtype.String(),
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
Credential: func() *structpb.Struct {
|
||||
data := map[string]any{
|
||||
@@ -3165,7 +3165,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
|
||||
Description: sshPkWithPassCredResp.GetItem().GetDescription().GetValue(),
|
||||
CredentialStoreId: staticStore.GetPublicId(),
|
||||
Type: credstatic.Subtype.String(),
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
Credential: func() *structpb.Struct {
|
||||
data := map[string]any{
|
||||
@@ -3192,7 +3192,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
|
||||
Description: clsRespSshPrivateKeyWithPass.GetItem().GetDescription().GetValue(),
|
||||
CredentialStoreId: vaultStore.GetPublicId(),
|
||||
Type: vault.GenericLibrarySubtype.String(),
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
Credential: func() *structpb.Struct {
|
||||
data := map[string]any{
|
||||
@@ -3219,7 +3219,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
|
||||
Description: clsRespSshPrivateKeyWithPassWithMapping.GetItem().GetDescription().GetValue(),
|
||||
CredentialStoreId: vaultStore.GetPublicId(),
|
||||
Type: vault.GenericLibrarySubtype.String(),
|
||||
CredentialType: string(credential.SshPrivateKeyType),
|
||||
CredentialType: string(globals.SshPrivateKeyCredentialType),
|
||||
},
|
||||
Credential: func() *structpb.Struct {
|
||||
data := map[string]any{
|
||||
|
||||
Reference in new issue
Block a user