Add generic read/update/delete commands (#3967)

* Add generic read/update/delete commands

This adds three generic commands that use the resource prefix to
determine the subcommand to run and pass through args over to that
subcommand. Since this occurs very early on and to avoid loading
essentially every internal resource package, I moved subtype definitions
to globals.

* Update main.go

Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>

* Update changelog and remove another deprecated command

---------

Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
This commit is contained in:
Jeff MitchellandJohan Brandhorst-Satzkorn authored and GitHub committed 2023-11-01 16:24:16 -04:00
1 parent de4ce93931
commit 0bf60996c5
82 files changed
+1563 -1895

No files matched your search

+29 -6
View File
@@ -4,10 +4,37 @@ Canonical reference for changes, improvements, and bugfixes for Boundary.
## Next
### Deprecations/Changes
* Per the note in Boundary 0.12.0, the `vault` credential library subtype has
now been removed in favor of `vault-generic`. For example, instead of
`boundary credential-libraries create vault`, you must use `boundary
credential-libraries create vault-generic`.
### New and Improved
* cli: New generic commands `read`, `update`, and `delete` have been added.
These allow operating on resources by directly specifying the ID of the
resource as the next parameter (e.g. `boundary update ttcp_1234567890`).
Subtypes do not need to be specified (e.g. that command is equivalent to
`boundary targets update tcp -id ttcp_1234567890`), and any flags given after
the ID are passed through to the type-specific subcommand. Once the ID has
been entered, autocomplete is also supported.
## 0.14.2 (Not Yet Released)
### Bug Fixes
* High CPU consumption: A background GRPC connection state check caused high CPU utilization. This was caused by a long running loop that was checking for GRPC connection state changes between a worker and an upstream connection address. The loop was not correctly waiting for GRPC connection state changes before running. The issue was fixed by correctly updating the state that determines when the loop in GRPC connection state check should run. ([PR](https://github.com/hashicorp/boundary/pull/3884))
* High CPU consumption: A background GRPC connection state check caused high CPU
utilization. This was caused by a long running loop that was checking for GRPC
connection state changes between a worker and an upstream connection address.
The loop was not correctly waiting for GRPC connection state changes before
running. The issue was fixed by correctly updating the state that determines
when the loop in GRPC connection state check should run.
([PR](https://github.com/hashicorp/boundary/pull/3884))
* LDAP auth methods: Fix encoding of mTLS client key which prevented Boundary
from making mTLS connections to an LDAP server ([Issue](https://github.com/hashicorp/boundary/issues/3927),
from making mTLS connections to an LDAP server
([Issue](https://github.com/hashicorp/boundary/issues/3927),
[PR](https://github.com/hashicorp/boundary/pull/3929)).
## 0.14.1 (2023/10/17)
@@ -23,10 +50,6 @@ Canonical reference for changes, improvements, and bugfixes for Boundary.
### Deprecations/Changes
* Per the note in Boundary 0.12.0, the `vault` credential library subtype has
now been removed in favor of `vault-generic`. For example, instead of
`boundary credential-libraries create vault`, you must use `boundary
credential-libraries create vault-generic`.
* Per the note in Boundary 0.12.0, errors returned from the cli when using the
`-format=json` option will now only use the `status_code` field. The `status`
field has been removed.
-3
View File
@@ -4,14 +4,11 @@
package main
import (
"math/rand"
"os"
"time"
"github.com/hashicorp/boundary/internal/cmd"
)
func main() {
rand.Seed(time.Now().UnixNano())
os.Exit(cmd.Run(os.Args[1:]))
}
+175 -42
View File
@@ -125,57 +125,190 @@ const (
ChannelRecordingPrefix = "chr"
)
var prefixToResourceType = map[string]resource.Type{
AuthTokenPrefix: resource.AuthToken,
PasswordAuthMethodPrefix: resource.AuthMethod,
PasswordAccountPrefix: resource.Account,
PasswordAccountPreviousPrefix: resource.Account,
OidcAuthMethodPrefix: resource.AuthMethod,
OidcAccountPrefix: resource.Account,
OidcManagedGroupPrefix: resource.ManagedGroup,
GlobalPrefix: resource.Scope,
ProjectPrefix: resource.Scope,
OrgPrefix: resource.Scope,
UserPrefix: resource.User,
GroupPrefix: resource.Group,
RolePrefix: resource.Role,
StaticCredentialStorePrefix: resource.CredentialStore,
StaticCredentialStorePreviousPrefix: resource.CredentialStore,
VaultCredentialStorePrefix: resource.CredentialStore,
VaultCredentialLibraryPrefix: resource.CredentialLibrary,
VaultSshCertificateCredentialLibraryPrefix: resource.CredentialLibrary,
UsernamePasswordCredentialPrefix: resource.Credential,
UsernamePasswordCredentialPreviousPrefix: resource.Credential,
SshPrivateKeyCredentialPrefix: resource.Credential,
JsonCredentialPrefix: resource.Credential,
StaticHostCatalogPrefix: resource.HostCatalog,
StaticHostSetPrefix: resource.HostSet,
StaticHostPrefix: resource.Host,
PluginHostCatalogPrefix: resource.HostCatalog,
PluginHostCatalogPreviousPrefix: resource.HostCatalog,
PluginHostSetPrefix: resource.HostSet,
PluginHostSetPreviousPrefix: resource.HostSet,
PluginHostPrefix: resource.Host,
PluginHostPreviousPrefix: resource.Host,
SessionPrefix: resource.Session,
TcpTargetPrefix: resource.Target,
SshTargetPrefix: resource.Target,
WorkerPrefix: resource.Worker,
PluginStorageBucketPrefix: resource.StorageBucket,
SessionRecordingPrefix: resource.SessionRecording,
type ResourceInfo struct {
Type resource.Type
Subtype Subtype
}
var prefixToResourceType = map[string]ResourceInfo{
AuthTokenPrefix: {
Type: resource.AuthToken,
},
PasswordAuthMethodPrefix: {
Type: resource.AuthMethod,
Subtype: PasswordSubtype,
},
PasswordAccountPrefix: {
Type: resource.Account,
Subtype: PasswordSubtype,
},
PasswordAccountPreviousPrefix: {
Type: resource.Account,
Subtype: PasswordSubtype,
},
OidcAuthMethodPrefix: {
Type: resource.AuthMethod,
Subtype: OidcSubtype,
},
OidcAccountPrefix: {
Type: resource.Account,
Subtype: OidcSubtype,
},
OidcManagedGroupPrefix: {
Type: resource.ManagedGroup,
Subtype: OidcSubtype,
},
LdapManagedGroupPrefix: {
Type: resource.ManagedGroup,
},
LdapAuthMethodPrefix: {
Type: resource.AuthMethod,
},
LdapAccountPrefix: {
Type: resource.Account,
},
ProjectPrefix: {
Type: resource.Scope,
},
OrgPrefix: {
Type: resource.Scope,
},
GlobalPrefix: {
Type: resource.Scope,
},
UserPrefix: {
Type: resource.User,
},
GroupPrefix: {
Type: resource.Group,
},
RolePrefix: {
Type: resource.Role,
},
StaticCredentialStorePrefix: {
Type: resource.CredentialStore,
Subtype: StaticSubtype,
},
StaticCredentialStorePreviousPrefix: {
Type: resource.CredentialStore,
Subtype: StaticSubtype,
},
VaultCredentialStorePrefix: {
Type: resource.CredentialStore,
Subtype: VaultSubtype,
},
VaultCredentialLibraryPrefix: {
Type: resource.CredentialLibrary,
Subtype: VaultGenericLibrarySubtype,
},
VaultSshCertificateCredentialLibraryPrefix: {
Type: resource.CredentialLibrary,
Subtype: VaultSshCertificateLibrarySubtype,
},
VaultDynamicCredentialPrefix: {
Type: resource.Credential,
Subtype: VaultSubtype,
},
UsernamePasswordCredentialPrefix: {
Type: resource.Credential,
Subtype: UsernamePasswordSubtype,
},
UsernamePasswordCredentialPreviousPrefix: {
Type: resource.Credential,
Subtype: UsernamePasswordSubtype,
},
SshPrivateKeyCredentialPrefix: {
Type: resource.Credential,
Subtype: SshPrivateKeySubtype,
},
JsonCredentialPrefix: {
Type: resource.Credential,
Subtype: JsonSubtype,
},
StaticHostCatalogPrefix: {
Type: resource.HostCatalog,
Subtype: StaticSubtype,
},
StaticHostSetPrefix: {
Type: resource.HostSet,
Subtype: StaticSubtype,
},
StaticHostPrefix: {
Type: resource.Host,
Subtype: StaticSubtype,
},
PluginHostCatalogPrefix: {
Type: resource.HostCatalog,
Subtype: PluginSubtype,
},
PluginHostCatalogPreviousPrefix: {
Type: resource.HostCatalog,
Subtype: PluginSubtype,
},
PluginHostSetPrefix: {
Type: resource.HostSet,
Subtype: PluginSubtype,
},
PluginHostSetPreviousPrefix: {
Type: resource.HostSet,
Subtype: PluginSubtype,
},
PluginHostPrefix: {
Type: resource.Host,
Subtype: PluginSubtype,
},
PluginHostPreviousPrefix: {
Type: resource.Host,
Subtype: PluginSubtype,
},
SessionPrefix: {
Type: resource.Session,
},
TcpTargetPrefix: {
Type: resource.Target,
Subtype: TcpSubtype,
},
SshTargetPrefix: {
Type: resource.Target,
Subtype: SshSubtype,
},
WorkerPrefix: {
Type: resource.Worker,
},
PluginStorageBucketPrefix: {
Type: resource.StorageBucket,
},
SessionRecordingPrefix: {
Type: resource.SessionRecording,
},
}
var resourceTypeToPrefixes map[resource.Type][]string = func() map[resource.Type][]string {
ret := make(map[resource.Type][]string)
for k, v := range prefixToResourceType {
ret[v] = append(ret[v], k)
ret[v.Type] = append(ret[v.Type], k)
}
return ret
}()
// ResourceTypeFromPrefix takes in a resource ID (or a prefix) and returns the
// corresponding resource typ
func ResourceTypeFromPrefix(in string) resource.Type {
// ResourceInfoFromPrefix takes in a resource ID (or a prefix) and returns the
// corresponding resource info
func ResourceInfoFromPrefix(in string) ResourceInfo {
// If full ID, trim to just prefix
in, _, _ = strings.Cut(in, "_")
return prefixToResourceType[in]
+4 -4
View File
@@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/assert"
)
func TestResourceTypeFromPrefix(t *testing.T) {
func TestResourceInfoFromPrefix(t *testing.T) {
// Test a random sampling
vals := map[string]resource.Type{
VaultCredentialLibraryPrefix: resource.CredentialLibrary,
@@ -21,8 +21,8 @@ func TestResourceTypeFromPrefix(t *testing.T) {
}
for prefix, typ := range vals {
assert.Equal(t, typ, ResourceTypeFromPrefix(prefix))
assert.Equal(t, typ, ResourceTypeFromPrefix(fmt.Sprintf("%s_foobar", prefix)))
assert.Equal(t, resource.Unknown, ResourceTypeFromPrefix(fmt.Sprintf("%sfoobar", prefix)))
assert.Equal(t, typ, ResourceInfoFromPrefix(prefix).Type)
assert.Equal(t, typ, ResourceInfoFromPrefix(fmt.Sprintf("%s_foobar", prefix)).Type)
assert.Equal(t, resource.Unknown, ResourceInfoFromPrefix(fmt.Sprintf("%sfoobar", prefix)))
}
}
+29
View File
@@ -0,0 +1,29 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package globals
// Subtype variables identify a boundary resource subtype.
type Subtype string
const (
UnknownSubtype Subtype = ""
PasswordSubtype Subtype = "password"
OidcSubtype Subtype = "oidc"
LdapSubtype Subtype = "ldap"
StaticSubtype Subtype = "static"
PluginSubtype Subtype = "plugin"
VaultSubtype Subtype = "vault"
VaultGenericLibrarySubtype Subtype = "vault-generic"
VaultSshCertificateLibrarySubtype Subtype = "vault-ssh-certificate"
UsernamePasswordSubtype Subtype = "username_password"
SshPrivateKeySubtype Subtype = "ssh_private_key"
JsonSubtype Subtype = "json"
TcpSubtype Subtype = "tcp"
SshSubtype Subtype = "ssh"
)
// String returns the string representation of a Subtype
func (t Subtype) String() string {
return string(t)
}
+1 -5
View File
@@ -14,15 +14,11 @@ import (
)
func init() {
if err := subtypes.Register(auth.Domain, Subtype, globals.LdapAuthMethodPrefix, globals.LdapAccountPrefix, globals.LdapManagedGroupPrefix); err != nil {
if err := subtypes.Register(auth.Domain, globals.LdapSubtype, globals.LdapAuthMethodPrefix, globals.LdapAccountPrefix, globals.LdapManagedGroupPrefix); err != nil {
panic(err)
}
}
const (
Subtype = subtypes.Subtype("ldap")
)
func newAuthMethodId(ctx context.Context) (string, error) {
const op = "ldap.newAuthMethodId"
id, err := db.NewPublicId(ctx, globals.LdapAuthMethodPrefix)
+1 -5
View File
@@ -14,15 +14,11 @@ import (
)
func init() {
if err := subtypes.Register(auth.Domain, Subtype, globals.OidcAuthMethodPrefix, globals.OidcAccountPrefix, globals.OidcManagedGroupPrefix); err != nil {
if err := subtypes.Register(auth.Domain, globals.OidcSubtype, globals.OidcAuthMethodPrefix, globals.OidcAccountPrefix, globals.OidcManagedGroupPrefix); err != nil {
panic(err)
}
}
const (
Subtype = subtypes.Subtype("oidc")
)
func newAuthMethodId(ctx context.Context) (string, error) {
const op = "oidc.newAuthMethodId"
id, err := db.NewPublicId(ctx, globals.OidcAuthMethodPrefix)
+1 -6
View File
@@ -14,16 +14,11 @@ import (
)
func init() {
if err := subtypes.Register(auth.Domain, Subtype, globals.PasswordAuthMethodPrefix, globals.PasswordAccountPreviousPrefix, globals.PasswordAccountPrefix); err != nil {
if err := subtypes.Register(auth.Domain, globals.PasswordSubtype, globals.PasswordAuthMethodPrefix, globals.PasswordAccountPreviousPrefix, globals.PasswordAccountPrefix); err != nil {
panic(err)
}
}
// PublicId prefixes for the resources in the password package.
const (
Subtype = subtypes.Subtype("password")
)
func newAuthMethodId(ctx context.Context) (string, error) {
const op = "password.newAuthMethodId"
id, err := db.NewPublicId(ctx, globals.PasswordAuthMethodPrefix)
+3 -1
View File
@@ -142,12 +142,14 @@ type Command struct {
}
// New returns a new instance of a base.Command type
func NewCommand(ui cli.Ui) *Command {
func NewCommand(ui cli.Ui, opt ...Option) *Command {
opts := getOpts(opt...)
ctx, cancel := context.WithCancel(context.Background())
ret := &Command{
UI: ui,
ShutdownCh: MakeShutdownCh(),
Context: ctx,
FlagId: opts.withImplicitId,
}
go func() {
<-ret.ShutdownCh
+2 -3
View File
@@ -17,7 +17,6 @@ import (
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/plugin"
"github.com/hashicorp/boundary/internal/target"
"github.com/hashicorp/boundary/internal/target/tcp"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/hashicorp/boundary/internal/util"
plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin"
@@ -461,7 +460,7 @@ func (b *Server) CreateInitialTargetWithAddress(ctx context.Context) (target.Tar
target.WithPublicId(b.DevTargetId),
target.WithAddress(b.DevTargetAddress),
}
t, err := target.New(ctx, tcp.Subtype, b.DevProjectId, opts...)
t, err := target.New(ctx, globals.TcpSubtype, b.DevProjectId, opts...)
if err != nil {
return nil, fmt.Errorf("failed to create target object: %w", err)
}
@@ -525,7 +524,7 @@ func (b *Server) CreateInitialTargetWithHostSources(ctx context.Context) (target
target.WithSessionConnectionLimit(int32(b.DevTargetSessionConnectionLimit)),
target.WithPublicId(b.DevSecondaryTargetId),
}
t, err := target.New(ctx, tcp.Subtype, b.DevProjectId, opts...)
t, err := target.New(ctx, globals.TcpSubtype, b.DevProjectId, opts...)
if err != nil {
return nil, fmt.Errorf("failed to create target object: %w", err)
}
+9
View File
@@ -44,6 +44,7 @@ type Options struct {
withStatusCode int
withHostPlugin func() (string, plugin.HostPluginServiceClient)
withEventGating bool
withImplicitId string
}
func getDefaultOptions() Options {
@@ -200,3 +201,11 @@ func WithEventGating(with bool) Option {
o.withEventGating = with
}
}
// WithImplicitId is used when creating the command if we are implicitly
// overriding the ID via a top-level read/update/delete command
func WithImplicitId(with string) Option {
return func(o *Options) {
o.withImplicitId = with
}
}
+237 -223
View File
File diff suppressed because it is too large. Load diff
@@ -24,7 +24,7 @@ type Command struct {
}
func (c *Command) Synopsis() string {
return wordwrap.WrapString("Authenticate the Boundary command-line client", base.TermWidth)
return wordwrap.WrapString("Authenticate the local client", base.TermWidth)
}
func (c *Command) Help() string {
+1 -1
View File
@@ -15,7 +15,7 @@ type Command struct {
}
func (c *Command) Synopsis() string {
return "Manage resources related to Boundary's local configuration"
return "Manage the local client's configuration"
}
func (c *Command) Help() string {
@@ -0,0 +1,44 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package genericcmd
import (
"fmt"
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/mitchellh/cli"
)
var _ cli.Command = (*Command)(nil)
type Command struct {
*base.Command
Func string
}
func (c *Command) Synopsis() string {
return fmt.Sprintf("Run a generic %s command against a resource", c.Func)
}
func (c *Command) Help() string {
aAn := "a"
if c.Func == "update" {
aAn = "an"
}
return base.WrapForHelpText([]string{
fmt.Sprintf("Usage: boundary %s [resource ID] [args]", c.Func),
"",
fmt.Sprintf(" This command runs %s %s command against the given resource ID. Arguments are the same as the type-specific command.", aAn, c.Func),
"",
fmt.Sprintf(" Note: this command forwards to a type-specific command; help/error/cURL output from that command may show the full command syntax."),
})
}
func (c *Command) Run(args []string) int {
if len(args) > 0 {
return cli.RunResultHelp
}
return base.CommandSuccess
}
+1 -3
View File
@@ -17,8 +17,6 @@ import (
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/hashicorp/boundary/internal/credential"
"github.com/hashicorp/boundary/internal/credential/static"
"github.com/hashicorp/boundary/internal/credential/vault"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/hashicorp/go-secure-stdlib/strutil"
"github.com/mitchellh/go-wordwrap"
@@ -727,7 +725,7 @@ func printCustomActionOutputImpl(c *Command) (bool, error) {
var secretStr []string
switch cred.CredentialSource.Type {
case vault.Subtype.String(), vault.GenericLibrarySubtype.String(), static.Subtype.String():
case globals.VaultSubtype.String(), globals.VaultGenericLibrarySubtype.String(), globals.StaticSubtype.String():
switch {
case cred.Credential != nil:
maxLength := 0
+4 -3
View File
@@ -54,9 +54,10 @@ func PopulateCommonFlags(c *base.Command, f *base.FlagSet, resourceType string,
})
case "id":
f.StringVar(&base.StringVar{
Name: "id",
Target: &c.FlagId,
Usage: fmt.Sprintf("ID of the %s on which to operate.", resourceType),
Name: "id",
Target: &c.FlagId,
Default: c.FlagId,
Usage: fmt.Sprintf("ID of the %s on which to operate.", resourceType),
})
case "name":
f.StringVar(&base.StringVar{
+103 -10
View File
@@ -8,15 +8,17 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"sort"
"strconv"
"strings"
"text/tabwriter"
"github.com/fatih/color"
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/hashicorp/boundary/internal/types/resource"
colorable "github.com/mattn/go-colorable"
"github.com/mitchellh/cli"
)
@@ -85,10 +87,55 @@ func setupEnv(args []string) (retArgs []string, format string, outputCurlString
return args, format, outputCurlString
}
func handleHighLevelShortcuts(args []string, runOpts *RunOptions) []string {
switch len(args) {
case 0, 1:
return args
}
switch strings.ToLower(args[0]) {
case "read", "update", "delete":
default:
return args
}
// At this point we know it's something we want to handle in this function
info := globals.ResourceInfoFromPrefix(args[1])
if info.Type == resource.Unknown {
return args
}
newArgs := make([]string, 0, len(args)+5)
newArgs = append(newArgs,
// Start with the plural of the resource type ("credential-libraries")
info.Type.PluralString(),
// Add the action to take ("update")
args[0],
)
// If it's update, add the subtype
if info.Subtype != globals.UnknownSubtype &&
strings.ToLower(args[0]) == "update" {
newArgs = append(newArgs,
strings.ReplaceAll(info.Subtype.String(), "_", "-"),
)
}
// Make sure we override the ID in commands
runOpts.ImplicitId = args[1]
// Now add the rest of the args
newArgs = append(newArgs,
args[2:]...,
)
return newArgs
}
type RunOptions struct {
Stdout io.Writer
Stderr io.Writer
Address string
Stdout io.Writer
Stderr io.Writer
Address string
ImplicitId string
}
func Run(args []string) int {
@@ -134,7 +181,7 @@ func RunCustom(args []string, runOpts *RunOptions) int {
uiErrWriter := runOpts.Stderr
if outputCurlString {
uiErrWriter = ioutil.Discard
uiErrWriter = io.Discard
}
ui := &base.BoundaryUI{
@@ -169,6 +216,29 @@ func RunCustom(args []string, runOpts *RunOptions) int {
return 1
}
// For autocompletion we need to manage the COMP_LINE var. That means
// reading args out of it now and then setting updated args back.
compLine := os.Getenv("COMP_LINE")
if compLine != "" {
point, err := strconv.Atoi(os.Getenv("COMP_POINT"))
if err != nil {
point = len(compLine)
}
if point != 0 && point < len(compLine) {
compLine = compLine[:point]
}
args = strings.Split(compLine, " ")
args = args[1:] // elide "boundary" since the function below expects it to not be there
}
args = handleHighLevelShortcuts(args, runOpts)
// Set args back
if compLine != "" {
// We need to add back "boundary" as well
os.Setenv("COMP_LINE", strings.Join(append([]string{"boundary"}, args...), " "))
}
initCommands(ui, serverCmdUi, runOpts)
hiddenCommands := []string{"version"}
@@ -222,15 +292,38 @@ func groupedHelpFunc(f cli.HelpFunc) cli.HelpFunc {
fmt.Fprintf(tw, "Usage: boundary <command> [args]\n")
otherCommands := make([]string, 0, len(commands))
genericCommands := make([]string, 0, 3)
clientCommands := make([]string, 0, 6)
typeSpecificCommands := make([]string, 0, len(commands)-cap(genericCommands)-cap(clientCommands))
for k := range commands {
otherCommands = append(otherCommands, k)
switch k {
case "authenticate", "config", "connect", "dev", "logout", "server":
clientCommands = append(clientCommands, k)
case "read", "update", "delete":
genericCommands = append(genericCommands, k)
default:
typeSpecificCommands = append(typeSpecificCommands, k)
}
}
sort.Strings(otherCommands)
sort.Strings(clientCommands)
fmt.Fprintf(tw, "\n")
fmt.Fprintf(tw, "Commands:\n")
for _, v := range otherCommands {
fmt.Fprintf(tw, "Local/Client Commands:\n")
for _, v := range clientCommands {
printCommand(tw, v, commands[v])
}
sort.Strings(genericCommands)
fmt.Fprintf(tw, "\n")
fmt.Fprintf(tw, "Generic Commands:\n")
for _, v := range genericCommands {
printCommand(tw, v, commands[v])
}
sort.Strings(typeSpecificCommands)
fmt.Fprintf(tw, "\n")
fmt.Fprintf(tw, "Type-Specific Commands:\n")
for _, v := range typeSpecificCommands {
printCommand(tw, v, commands[v])
}
+73
View File
@@ -0,0 +1,73 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package cmd
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestHandleHighLevelShortcuts(t *testing.T) {
t.Parallel()
tests := []struct {
name string
in []string
out []string
expRunOpts bool
}{
{
name: "zero length",
},
{
name: "one length",
in: []string{"foo"},
out: []string{"foo"},
},
{
name: "not a match",
in: []string{"foo", "bar"},
out: []string{"foo", "bar"},
},
{
name: "unhandled prefix",
in: []string{"read", "bar"},
out: []string{"read", "bar"},
},
{
name: "handled read",
in: []string{"read", "hst_1234567890"},
out: []string{"hosts", "read"},
expRunOpts: true,
},
{
name: "handled delete",
in: []string{"delete", "clvlt_1234567890"},
out: []string{"credential-libraries", "delete"},
expRunOpts: true,
},
{
name: "handled update",
in: []string{"update", "g_1234567890"},
out: []string{"groups", "update"},
expRunOpts: true,
},
{
name: "handled subtype update",
in: []string{"update", "credspk_1234567890"},
out: []string{"credentials", "update", "ssh-private-key"},
expRunOpts: true,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
var runOpts RunOptions
out := handleHighLevelShortcuts(tc.in, &runOpts)
assert.EqualValues(t, tc.out, out)
if tc.expRunOpts {
assert.Equal(t, tc.in[1], runOpts.ImplicitId)
}
})
}
}
+3 -11
View File
@@ -13,25 +13,17 @@ import (
)
func init() {
if err := subtypes.Register(Domain, UsernamePasswordSubtype, globals.UsernamePasswordCredentialPrefix, globals.UsernamePasswordCredentialPreviousPrefix); err != nil {
if err := subtypes.Register(Domain, globals.UsernamePasswordSubtype, globals.UsernamePasswordCredentialPrefix, globals.UsernamePasswordCredentialPreviousPrefix); err != nil {
panic(err)
}
if err := subtypes.Register(Domain, SshPrivateKeySubtype, globals.SshPrivateKeyCredentialPrefix); err != nil {
if err := subtypes.Register(Domain, globals.SshPrivateKeySubtype, globals.SshPrivateKeyCredentialPrefix); err != nil {
panic(err)
}
if err := subtypes.Register(Domain, JsonSubtype, globals.JsonCredentialPrefix); err != nil {
if err := subtypes.Register(Domain, globals.JsonSubtype, globals.JsonCredentialPrefix); err != nil {
panic(err)
}
}
const (
UsernamePasswordSubtype = subtypes.Subtype("username_password")
SshPrivateKeySubtype = subtypes.Subtype("ssh_private_key")
JsonSubtype = subtypes.Subtype("json")
)
func NewUsernamePasswordCredentialId(ctx context.Context) (string, error) {
id, err := db.NewPublicId(ctx, globals.UsernamePasswordCredentialPrefix)
if err != nil {
+1 -6
View File
@@ -14,16 +14,11 @@ import (
)
func init() {
if err := subtypes.Register(credential.Domain, Subtype, globals.StaticCredentialStorePrefix, globals.StaticCredentialStorePreviousPrefix); err != nil {
if err := subtypes.Register(credential.Domain, globals.StaticSubtype, globals.StaticCredentialStorePrefix, globals.StaticCredentialStorePreviousPrefix); err != nil {
panic(err)
}
}
// PublicId prefixes for the resources in the static package.
const (
Subtype = subtypes.Subtype("static")
)
func newCredentialStoreId(ctx context.Context) (string, error) {
id, err := db.NewPublicId(ctx, globals.StaticCredentialStorePrefix)
if err != nil {
@@ -8,6 +8,7 @@ import (
"fmt"
"strings"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/credential"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
@@ -290,7 +291,7 @@ func (r *Repository) LookupCredential(ctx context.Context, publicId string, _ ..
var cred credential.Static
switch subtypes.SubtypeFromId(credential.Domain, publicId) {
case credential.UsernamePasswordSubtype:
case globals.UsernamePasswordSubtype:
upCred := allocUsernamePasswordCredential()
upCred.PublicId = publicId
if err := r.reader.LookupByPublicId(ctx, upCred); err != nil {
@@ -304,7 +305,7 @@ func (r *Repository) LookupCredential(ctx context.Context, publicId string, _ ..
upCred.Password = nil
cred = upCred
case credential.SshPrivateKeySubtype:
case globals.SshPrivateKeySubtype:
spkCred := allocSshPrivateKeyCredential()
spkCred.PublicId = publicId
if err := r.reader.LookupByPublicId(ctx, spkCred); err != nil {
@@ -321,7 +322,7 @@ func (r *Repository) LookupCredential(ctx context.Context, publicId string, _ ..
spkCred.PrivateKeyPassphrase = nil
cred = spkCred
case credential.JsonSubtype:
case globals.JsonSubtype:
jsonCred := allocJsonCredential()
jsonCred.PublicId = publicId
if err := r.reader.LookupByPublicId(ctx, jsonCred); err != nil {
@@ -793,17 +794,17 @@ func (r *Repository) DeleteCredential(ctx context.Context, projectId, id string,
var input any
var md oplog.Metadata
switch subtypes.SubtypeFromId(credential.Domain, id) {
case credential.UsernamePasswordSubtype:
case globals.UsernamePasswordSubtype:
c := allocUsernamePasswordCredential()
c.PublicId = id
input = c
md = c.oplog(oplog.OpType_OP_TYPE_DELETE)
case credential.SshPrivateKeySubtype:
case globals.SshPrivateKeySubtype:
c := allocSshPrivateKeyCredential()
c.PublicId = id
input = c
md = c.oplog(oplog.OpType_OP_TYPE_DELETE)
case credential.JsonSubtype:
case globals.JsonSubtype:
c := allocJsonCredential()
c.PublicId = id
input = c
+3 -10
View File
@@ -14,24 +14,17 @@ import (
)
func init() {
if err := subtypes.Register(credential.Domain, Subtype, globals.VaultCredentialStorePrefix, globals.VaultDynamicCredentialPrefix); err != nil {
if err := subtypes.Register(credential.Domain, globals.VaultSubtype, globals.VaultCredentialStorePrefix, globals.VaultDynamicCredentialPrefix); err != nil {
panic(err)
}
if err := subtypes.Register(credential.Domain, GenericLibrarySubtype, globals.VaultCredentialLibraryPrefix); err != nil {
if err := subtypes.Register(credential.Domain, globals.VaultGenericLibrarySubtype, globals.VaultCredentialLibraryPrefix); err != nil {
panic(err)
}
if err := subtypes.Register(credential.Domain, SSHCertificateLibrarySubtype, globals.VaultSshCertificateCredentialLibraryPrefix); err != nil {
if err := subtypes.Register(credential.Domain, globals.VaultSshCertificateLibrarySubtype, globals.VaultSshCertificateCredentialLibraryPrefix); err != nil {
panic(err)
}
}
// PublicId prefixes for the resources in the vault package.
const (
Subtype = subtypes.Subtype("vault")
GenericLibrarySubtype = subtypes.Subtype("vault-generic")
SSHCertificateLibrarySubtype = subtypes.Subtype("vault-ssh-certificate")
)
func newCredentialStoreId(ctx context.Context) (string, error) {
id, err := db.NewPublicId(ctx, globals.VaultCredentialStorePrefix)
if err != nil {
+3 -6
View File
@@ -14,9 +14,6 @@ import (
"github.com/hashicorp/boundary/api/recovery"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/auth/ldap"
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/auth/password"
"github.com/hashicorp/boundary/internal/daemon/controller/common"
"github.com/hashicorp/boundary/internal/daemon/controller/handlers"
"github.com/hashicorp/boundary/internal/errors"
@@ -556,21 +553,21 @@ func (v verifier) performAuthCheck(ctx context.Context) (
var acct auth.Account
var err error
switch subtypes.SubtypeFromId(domain, *userData.Account.Id) {
case password.Subtype:
case globals.PasswordSubtype:
repo, repoErr := v.passwordAuthRepoFn()
if repoErr != nil {
retErr = errors.Wrap(ctx, repoErr, op, errors.WithMsg("failed to get password auth repo"))
return
}
acct, err = repo.LookupAccount(ctx, *userData.Account.Id)
case oidc.Subtype:
case globals.OidcSubtype:
repo, repoErr := v.oidcAuthRepoFn()
if repoErr != nil {
retErr = errors.Wrap(ctx, repoErr, op, errors.WithMsg("failed to get oidc auth repo"))
return
}
acct, err = repo.LookupAccount(ctx, *userData.Account.Id)
case ldap.Subtype:
case globals.LdapSubtype:
repo, repoErr := v.ldapAuthRepoFn()
if repoErr != nil {
retErr = errors.Wrap(ctx, repoErr, op, errors.WithMsg("failed to get ldap auth repo"))
@@ -69,8 +69,8 @@ var (
// IdActions contains the set of actions that can be performed on
// individual resources
IdActions = map[subtypes.Subtype]action.ActionSet{
password.Subtype: {
IdActions = map[globals.Subtype]action.ActionSet{
globals.PasswordSubtype: {
action.NoOp,
action.Read,
action.Update,
@@ -78,13 +78,13 @@ var (
action.SetPassword,
action.ChangePassword,
},
oidc.Subtype: {
globals.OidcSubtype: {
action.NoOp,
action.Read,
action.Update,
action.Delete,
},
ldap.Subtype: {
globals.LdapSubtype: {
action.NoOp,
action.Read,
action.Update,
@@ -418,7 +418,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (auth.Account, []st
var acct auth.Account
var mgIds []string
switch subtypes.SubtypeFromId(domain, id) {
case password.Subtype:
case globals.PasswordSubtype:
repo, err := s.pwRepoFn()
if err != nil {
return nil, nil, err
@@ -431,7 +431,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (auth.Account, []st
return nil, nil, err
}
acct = a
case oidc.Subtype:
case globals.OidcSubtype:
repo, err := s.oidcRepoFn()
if err != nil {
return nil, nil, err
@@ -451,7 +451,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (auth.Account, []st
mgIds = append(mgIds, mg.GetManagedGroupId())
}
acct = a
case ldap.Subtype:
case globals.LdapSubtype:
repo, err := s.ldapRepoFn()
if err != nil {
return nil, nil, err
@@ -593,7 +593,7 @@ func (s Service) createInRepo(ctx context.Context, am auth.AuthMethod, item *pb.
}
var out auth.Account
switch subtypes.SubtypeFromId(domain, am.GetPublicId()) {
case password.Subtype:
case globals.PasswordSubtype:
am, err := s.createPwInRepo(ctx, am, item)
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -602,7 +602,7 @@ func (s Service) createInRepo(ctx context.Context, am auth.AuthMethod, item *pb.
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create account but no error returned from repository.")
}
out = am
case oidc.Subtype:
case globals.OidcSubtype:
am, err := s.createOidcInRepo(ctx, am, item)
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -611,7 +611,7 @@ func (s Service) createInRepo(ctx context.Context, am auth.AuthMethod, item *pb.
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create account but no error returned from repository.")
}
out = am
case ldap.Subtype:
case globals.LdapSubtype:
am, err := s.createLdapInRepo(ctx, am, item)
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -753,7 +753,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId, authMethodId string,
const op = "accounts.(Service).updateInRepo"
var out auth.Account
switch subtypes.SubtypeFromId(domain, req.GetId()) {
case password.Subtype:
case globals.PasswordSubtype:
a, err := s.updatePwInRepo(ctx, scopeId, authMethodId, req.GetId(), req.GetUpdateMask().GetPaths(), req.GetItem())
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -762,7 +762,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId, authMethodId string,
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to update account but no error returned from repository.")
}
out = a
case oidc.Subtype:
case globals.OidcSubtype:
a, err := s.updateOidcInRepo(ctx, scopeId, authMethodId, req.GetId(), req.GetUpdateMask().GetPaths(), req.GetItem())
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -771,7 +771,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId, authMethodId string,
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to update account but no error returned from repository.")
}
out = a
case ldap.Subtype:
case globals.LdapSubtype:
a, err := s.updateLdapInRepo(ctx, scopeId, authMethodId, req.GetId(), req.GetUpdateMask().GetPaths(), req.GetItem())
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -789,19 +789,19 @@ func (s Service) deleteFromRepo(ctx context.Context, scopeId, id string) (bool,
var rows int
var err error
switch subtypes.SubtypeFromId(domain, id) {
case password.Subtype:
case globals.PasswordSubtype:
repo, iErr := s.pwRepoFn()
if iErr != nil {
return false, iErr
}
rows, err = repo.DeleteAccount(ctx, scopeId, id)
case oidc.Subtype:
case globals.OidcSubtype:
repo, iErr := s.oidcRepoFn()
if iErr != nil {
return false, iErr
}
rows, err = repo.DeleteAccount(ctx, scopeId, id)
case ldap.Subtype:
case globals.LdapSubtype:
repo, iErr := s.ldapRepoFn()
if iErr != nil {
return false, iErr
@@ -822,7 +822,7 @@ func (s Service) listFromRepo(ctx context.Context, authMethodId string) ([]auth.
var outUl []auth.Account
switch subtypes.SubtypeFromId(domain, authMethodId) {
case password.Subtype:
case globals.PasswordSubtype:
pwRepo, err := s.pwRepoFn()
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -834,7 +834,7 @@ func (s Service) listFromRepo(ctx context.Context, authMethodId string) ([]auth.
for _, a := range pwl {
outUl = append(outUl, a)
}
case oidc.Subtype:
case globals.OidcSubtype:
oidcRepo, err := s.oidcRepoFn()
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -846,7 +846,7 @@ func (s Service) listFromRepo(ctx context.Context, authMethodId string) ([]auth.
for _, a := range oidcl {
outUl = append(outUl, a)
}
case ldap.Subtype:
case globals.LdapSubtype:
ldapRepo, err := s.ldapRepoFn()
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -934,7 +934,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
parentId = id
default:
switch subtypes.SubtypeFromId(domain, id) {
case password.Subtype:
case globals.PasswordSubtype:
acct, err := pwRepo.LookupAccount(ctx, id)
if err != nil {
res.Error = err
@@ -945,7 +945,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
return nil, res
}
parentId = acct.GetAuthMethodId()
case oidc.Subtype:
case globals.OidcSubtype:
acct, err := oidcRepo.LookupAccount(ctx, id)
if err != nil {
res.Error = err
@@ -956,7 +956,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
return nil, res
}
parentId = acct.GetAuthMethodId()
case ldap.Subtype:
case globals.LdapSubtype:
acct, err := ldapRepo.LookupAccount(ctx, id)
if err != nil {
res.Error = err
@@ -973,7 +973,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
var authMeth auth.AuthMethod
switch subtypes.SubtypeFromId(domain, parentId) {
case password.Subtype:
case globals.PasswordSubtype:
am, err := pwRepo.LookupAuthMethod(ctx, parentId)
if err != nil {
res.Error = err
@@ -984,7 +984,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
return nil, res
}
authMeth = am
case oidc.Subtype:
case globals.OidcSubtype:
am, err := oidcRepo.LookupAuthMethod(ctx, parentId)
if err != nil {
res.Error = err
@@ -995,7 +995,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
return nil, res
}
authMeth = am
case ldap.Subtype:
case globals.LdapSubtype:
am, err := ldapRepo.LookupAuthMethod(ctx, parentId)
if err != nil {
res.Error = err
@@ -1054,7 +1054,7 @@ func toProto(ctx context.Context, in auth.Account, opt ...handlers.Option) (*pb.
switch i := in.(type) {
case *password.Account:
if outputFields.Has(globals.TypeField) {
out.Type = password.Subtype.String()
out.Type = globals.PasswordSubtype.String()
}
if !outputFields.Has(globals.AttributesField) {
break
@@ -1066,7 +1066,7 @@ func toProto(ctx context.Context, in auth.Account, opt ...handlers.Option) (*pb.
}
case *oidc.Account:
if outputFields.Has(globals.TypeField) {
out.Type = oidc.Subtype.String()
out.Type = globals.OidcSubtype.String()
}
if !outputFields.Has(globals.AttributesField) {
break
@@ -1102,7 +1102,7 @@ func toProto(ctx context.Context, in auth.Account, opt ...handlers.Option) (*pb.
out.Attrs = attrs
case *ldap.Account:
if outputFields.Has(globals.TypeField) {
out.Type = ldap.Subtype.String()
out.Type = globals.LdapSubtype.String()
}
if !outputFields.Has(globals.AttributesField) {
break
@@ -1175,8 +1175,8 @@ func validateCreateRequest(ctx context.Context, req *pbs.CreateAccountRequest) e
badFields[authMethodIdField] = "This field is required."
}
switch subtypes.SubtypeFromId(domain, req.GetItem().GetAuthMethodId()) {
case password.Subtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != password.Subtype.String() {
case globals.PasswordSubtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != globals.PasswordSubtype.String() {
badFields[typeField] = "Doesn't match the parent resource's type."
}
attrs := req.GetItem().GetPasswordAccountAttributes()
@@ -1188,8 +1188,8 @@ func validateCreateRequest(ctx context.Context, req *pbs.CreateAccountRequest) e
badFields[loginNameKey] = "This is a required field for this type."
}
}
case oidc.Subtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != oidc.Subtype.String() {
case globals.OidcSubtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != globals.OidcSubtype.String() {
badFields[typeField] = "Doesn't match the parent resource's type."
}
attrs := req.GetItem().GetOidcAccountAttributes()
@@ -1216,8 +1216,8 @@ func validateCreateRequest(ctx context.Context, req *pbs.CreateAccountRequest) e
badFields[emailClaimField] = "This is a read only field."
}
}
case ldap.Subtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != ldap.Subtype.String() {
case globals.LdapSubtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != globals.LdapSubtype.String() {
badFields[typeField] = "Doesn't match the parent resource's type."
}
attrs := req.GetItem().GetLdapAccountAttributes()
@@ -1256,12 +1256,12 @@ func validateUpdateRequest(ctx context.Context, req *pbs.UpdateAccountRequest) e
return handlers.ValidateUpdateRequest(req, req.GetItem(), func() map[string]string {
badFields := map[string]string{}
switch subtypes.SubtypeFromId(domain, req.GetId()) {
case password.Subtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != password.Subtype.String() {
case globals.PasswordSubtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != globals.PasswordSubtype.String() {
badFields[typeField] = "Cannot modify the resource type."
}
case oidc.Subtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != oidc.Subtype.String() {
case globals.OidcSubtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != globals.OidcSubtype.String() {
badFields[typeField] = "Cannot modify the resource type."
}
if handlers.MaskContains(req.GetUpdateMask().GetPaths(), subjectField) {
@@ -1276,8 +1276,8 @@ func validateUpdateRequest(ctx context.Context, req *pbs.UpdateAccountRequest) e
if handlers.MaskContains(req.GetUpdateMask().GetPaths(), nameClaimField) {
badFields[nameClaimField] = "Field is read only."
}
case ldap.Subtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != ldap.Subtype.String() {
case globals.LdapSubtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != globals.LdapSubtype.String() {
badFields[typeField] = "Cannot modify the resource type."
}
if handlers.MaskContains(req.GetUpdateMask().GetPaths(), loginAttrField) {
@@ -151,7 +151,7 @@ func TestGet(t *testing.T) {
UpdatedTime: pwA.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: org.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: password.Subtype.String(),
Type: globals.PasswordSubtype.String(),
Attrs: &pb.Account_PasswordAccountAttributes{
&pb.PasswordAccountAttributes{LoginName: pwA.GetLoginName()},
},
@@ -178,7 +178,7 @@ func TestGet(t *testing.T) {
UpdatedTime: oidcA.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: org.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.Account_OidcAccountAttributes{
&pb.OidcAccountAttributes{
Issuer: oidcAm.GetIssuer(),
@@ -213,7 +213,7 @@ func TestGet(t *testing.T) {
MemberOfGroups: []string{"admin"},
},
},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
AuthorizedActions: ldapAuthorizedActions,
ManagedGroupIds: []string{ldapMg.GetPublicId()},
}
@@ -280,7 +280,7 @@ func TestGet(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
if subtypes.SubtypeFromId(domain, tc.req.Id) == oidc.Subtype {
if subtypes.SubtypeFromId(domain, tc.req.Id) == globals.OidcSubtype {
// Set up managed groups before getting. First get the current
// managed group to make sure we have the right version.
oidcRepo, err := oidcRepoFn()
@@ -484,7 +484,7 @@ func TestListOidc(t *testing.T) {
UpdatedTime: aa.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.Account_OidcAccountAttributes{
&pb.OidcAccountAttributes{
Issuer: amSomeAccounts.GetIssuer(),
@@ -506,7 +506,7 @@ func TestListOidc(t *testing.T) {
UpdatedTime: aa.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.Account_OidcAccountAttributes{
&pb.OidcAccountAttributes{
Issuer: amOtherAccounts.GetIssuer(),
@@ -641,7 +641,7 @@ func TestListLdap(t *testing.T) {
UpdatedTime: aa.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.Account_LdapAccountAttributes{
LdapAccountAttributes: &pb.LdapAccountAttributes{
LoginName: loginName,
@@ -662,7 +662,7 @@ func TestListLdap(t *testing.T) {
UpdatedTime: aa.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.Account_LdapAccountAttributes{
LdapAccountAttributes: &pb.LdapAccountAttributes{
LoginName: loginName,
@@ -1210,7 +1210,7 @@ func TestCreateOidc(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "name"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.Account_OidcAccountAttributes{
&pb.OidcAccountAttributes{
Subject: "valid-account",
@@ -1226,7 +1226,7 @@ func TestCreateOidc(t *testing.T) {
Description: &wrapperspb.StringValue{Value: "desc"},
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.Account_OidcAccountAttributes{
&pb.OidcAccountAttributes{
Subject: "valid-account",
@@ -1255,7 +1255,7 @@ func TestCreateOidc(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.Account_OidcAccountAttributes{
&pb.OidcAccountAttributes{
Subject: "no type defined",
@@ -1272,7 +1272,7 @@ func TestCreateOidc(t *testing.T) {
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "overwritten issuer"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.Account_OidcAccountAttributes{
&pb.OidcAccountAttributes{
Subject: "overwritten-issuer",
@@ -1288,7 +1288,7 @@ func TestCreateOidc(t *testing.T) {
Name: &wrapperspb.StringValue{Value: "overwritten issuer"},
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.Account_OidcAccountAttributes{
&pb.OidcAccountAttributes{
Subject: "overwritten-issuer",
@@ -1304,7 +1304,7 @@ func TestCreateOidc(t *testing.T) {
req: &pbs.CreateAccountRequest{
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
Type: password.Subtype.String(),
Type: globals.PasswordSubtype.String(),
Attrs: &pb.Account_OidcAccountAttributes{
&pb.OidcAccountAttributes{
Subject: "cant-specify-mismatching-type",
@@ -1321,7 +1321,7 @@ func TestCreateOidc(t *testing.T) {
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
Id: globals.OidcAccountPrefix + "_notallowed",
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.Account_OidcAccountAttributes{
&pb.OidcAccountAttributes{
Subject: "cant-specify-id",
@@ -1338,7 +1338,7 @@ func TestCreateOidc(t *testing.T) {
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
CreatedTime: timestamppb.Now(),
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.Account_OidcAccountAttributes{
&pb.OidcAccountAttributes{
Subject: "cant-specify-created-time",
@@ -1355,7 +1355,7 @@ func TestCreateOidc(t *testing.T) {
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
UpdatedTime: timestamppb.Now(),
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.Account_OidcAccountAttributes{
&pb.OidcAccountAttributes{
Subject: "cant-specify-update-time",
@@ -1371,7 +1371,7 @@ func TestCreateOidc(t *testing.T) {
req: &pbs.CreateAccountRequest{
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
},
},
res: nil,
@@ -1442,7 +1442,7 @@ func TestCreateLdap(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "name"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.Account_LdapAccountAttributes{
LdapAccountAttributes: &pb.LdapAccountAttributes{
LoginName: "valid-account",
@@ -1458,7 +1458,7 @@ func TestCreateLdap(t *testing.T) {
Description: &wrapperspb.StringValue{Value: "desc"},
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.Account_LdapAccountAttributes{
LdapAccountAttributes: &pb.LdapAccountAttributes{
LoginName: "valid-account",
@@ -1486,7 +1486,7 @@ func TestCreateLdap(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.Account_LdapAccountAttributes{
LdapAccountAttributes: &pb.LdapAccountAttributes{
LoginName: "no type defined",
@@ -1501,7 +1501,7 @@ func TestCreateLdap(t *testing.T) {
req: &pbs.CreateAccountRequest{
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
Type: password.Subtype.String(),
Type: globals.PasswordSubtype.String(),
Attrs: &pb.Account_LdapAccountAttributes{
LdapAccountAttributes: &pb.LdapAccountAttributes{
LoginName: "cant-specify-mismatching-type",
@@ -1519,7 +1519,7 @@ func TestCreateLdap(t *testing.T) {
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
Id: globals.LdapAccountPrefix + "_notallowed",
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.Account_LdapAccountAttributes{
LdapAccountAttributes: &pb.LdapAccountAttributes{
LoginName: "cant-specify-mismatching-type",
@@ -1537,7 +1537,7 @@ func TestCreateLdap(t *testing.T) {
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
CreatedTime: timestamppb.Now(),
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.Account_LdapAccountAttributes{
LdapAccountAttributes: &pb.LdapAccountAttributes{
LoginName: "cant-specify-mismatching-type",
@@ -1555,7 +1555,7 @@ func TestCreateLdap(t *testing.T) {
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
UpdatedTime: timestamppb.Now(),
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.Account_LdapAccountAttributes{
LdapAccountAttributes: &pb.LdapAccountAttributes{
LoginName: "cant-specify-mismatching-type",
@@ -1572,7 +1572,7 @@ func TestCreateLdap(t *testing.T) {
req: &pbs.CreateAccountRequest{
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.Account_LdapAccountAttributes{
LdapAccountAttributes: &pb.LdapAccountAttributes{},
},
@@ -1587,7 +1587,7 @@ func TestCreateLdap(t *testing.T) {
req: &pbs.CreateAccountRequest{
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.Account_LdapAccountAttributes{
LdapAccountAttributes: &pb.LdapAccountAttributes{
LoginName: "cant-specify-full-name",
@@ -1605,7 +1605,7 @@ func TestCreateLdap(t *testing.T) {
req: &pbs.CreateAccountRequest{
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.Account_LdapAccountAttributes{
LdapAccountAttributes: &pb.LdapAccountAttributes{
LoginName: "cant-specify-email",
@@ -1623,7 +1623,7 @@ func TestCreateLdap(t *testing.T) {
req: &pbs.CreateAccountRequest{
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.Account_LdapAccountAttributes{
LdapAccountAttributes: &pb.LdapAccountAttributes{
LoginName: "cant-specify-dn",
@@ -1641,7 +1641,7 @@ func TestCreateLdap(t *testing.T) {
req: &pbs.CreateAccountRequest{
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.Account_LdapAccountAttributes{
LdapAccountAttributes: &pb.LdapAccountAttributes{
LoginName: "cant-specify-member-of",
@@ -2145,7 +2145,7 @@ func TestUpdateOidc(t *testing.T) {
Item: &pb.Account{
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
},
},
res: &pbs.UpdateAccountResponse{
@@ -2153,7 +2153,7 @@ func TestUpdateOidc(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -2169,7 +2169,7 @@ func TestUpdateOidc(t *testing.T) {
Item: &pb.Account{
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
},
},
res: &pbs.UpdateAccountResponse{
@@ -2177,7 +2177,7 @@ func TestUpdateOidc(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -2247,7 +2247,7 @@ func TestUpdateOidc(t *testing.T) {
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
Description: &wrapperspb.StringValue{Value: "default"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -2271,7 +2271,7 @@ func TestUpdateOidc(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "updated"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -2295,7 +2295,7 @@ func TestUpdateOidc(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "notignored"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -2524,7 +2524,7 @@ func TestUpdateLdap(t *testing.T) {
Item: &pb.Account{
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
},
},
res: &pbs.UpdateAccountResponse{
@@ -2532,7 +2532,7 @@ func TestUpdateLdap(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: ldapAuthorizedActions,
@@ -2548,7 +2548,7 @@ func TestUpdateLdap(t *testing.T) {
Item: &pb.Account{
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
},
},
res: &pbs.UpdateAccountResponse{
@@ -2556,7 +2556,7 @@ func TestUpdateLdap(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: ldapAuthorizedActions,
@@ -2626,7 +2626,7 @@ func TestUpdateLdap(t *testing.T) {
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
Description: &wrapperspb.StringValue{Value: "default"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: ldapAuthorizedActions,
@@ -2649,7 +2649,7 @@ func TestUpdateLdap(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "updated"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: ldapAuthorizedActions,
@@ -2672,7 +2672,7 @@ func TestUpdateLdap(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "notignored"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: ldapAuthorizedActions,
@@ -10,9 +10,6 @@ import (
"testing"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth/ldap"
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/auth/password"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/accounts"
"github.com/stretchr/testify/assert"
@@ -41,7 +38,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "mismatched pw authmethod oidc type",
item: &pb.Account{
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
AuthMethodId: globals.PasswordAuthMethodPrefix + "_1234567890",
},
errContains: fieldError(typeField, "Doesn't match the parent resource's type."),
@@ -49,7 +46,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "mismatched oidc authmethod pw type",
item: &pb.Account{
Type: password.Subtype.String(),
Type: globals.PasswordSubtype.String(),
AuthMethodId: globals.OidcAuthMethodPrefix + "_1234567890",
},
errContains: fieldError(typeField, "Doesn't match the parent resource's type."),
@@ -57,7 +54,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "mismatched pw authmethod ldap type",
item: &pb.Account{
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
AuthMethodId: globals.PasswordAuthMethodPrefix + "_1234567890",
},
errContains: fieldError(typeField, "Doesn't match the parent resource's type."),
@@ -65,7 +62,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "missing oidc attributes",
item: &pb.Account{
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
AuthMethodId: globals.OidcAuthMethodPrefix + "_1234567890",
},
errContains: fieldError(attributesField, "This is a required field."),
@@ -73,7 +70,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "missing oidc subject",
item: &pb.Account{
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
AuthMethodId: globals.OidcAuthMethodPrefix + "_1234567890",
Attrs: &pb.Account_OidcAccountAttributes{
OidcAccountAttributes: &pb.OidcAccountAttributes{},
@@ -84,7 +81,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "read only name claim field",
item: &pb.Account{
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
AuthMethodId: globals.OidcAuthMethodPrefix + "_1234567890",
Attrs: &pb.Account_OidcAccountAttributes{
OidcAccountAttributes: &pb.OidcAccountAttributes{FullName: "something"},
@@ -95,7 +92,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "read only email claim field",
item: &pb.Account{
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
AuthMethodId: globals.OidcAuthMethodPrefix + "_1234567890",
Attrs: &pb.Account_OidcAccountAttributes{
OidcAccountAttributes: &pb.OidcAccountAttributes{Email: "something"},
@@ -106,7 +103,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "missing ldap attributes",
item: &pb.Account{
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
AuthMethodId: globals.LdapAuthMethodPrefix + "_1234567890",
},
errContains: fieldError(attributesField, "This is a required field."),
@@ -114,7 +111,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "missing login name for ldap type",
item: &pb.Account{
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
AuthMethodId: globals.LdapAuthMethodPrefix + "_1234567890",
Attrs: &pb.Account_LdapAccountAttributes{
LdapAccountAttributes: &pb.LdapAccountAttributes{},
@@ -125,7 +122,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "read only full name attr field",
item: &pb.Account{
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
AuthMethodId: globals.LdapAuthMethodPrefix + "_1234567890",
Attrs: &pb.Account_LdapAccountAttributes{
LdapAccountAttributes: &pb.LdapAccountAttributes{FullName: "something"},
@@ -136,7 +133,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "read only email attr field",
item: &pb.Account{
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
AuthMethodId: globals.LdapAuthMethodPrefix + "_1234567890",
Attrs: &pb.Account_LdapAccountAttributes{
LdapAccountAttributes: &pb.LdapAccountAttributes{Email: "something"},
@@ -147,7 +144,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "read only dn attr field",
item: &pb.Account{
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
AuthMethodId: globals.LdapAuthMethodPrefix + "_1234567890",
Attrs: &pb.Account_LdapAccountAttributes{
LdapAccountAttributes: &pb.LdapAccountAttributes{Dn: "something"},
@@ -158,7 +155,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "read only member of attr field",
item: &pb.Account{
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
AuthMethodId: globals.LdapAuthMethodPrefix + "_1234567890",
Attrs: &pb.Account_LdapAccountAttributes{
LdapAccountAttributes: &pb.LdapAccountAttributes{MemberOfGroups: []string{"something"}},
@@ -169,7 +166,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "missing password attributes",
item: &pb.Account{
Type: password.Subtype.String(),
Type: globals.PasswordSubtype.String(),
AuthMethodId: globals.PasswordAuthMethodPrefix + "_1234567890",
},
errContains: fieldError(attributesField, "This is a required field."),
@@ -177,7 +174,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "missing login name for password type",
item: &pb.Account{
Type: password.Subtype.String(),
Type: globals.PasswordSubtype.String(),
AuthMethodId: globals.PasswordAuthMethodPrefix + "_1234567890",
Attrs: &pb.Account_PasswordAccountAttributes{
PasswordAccountAttributes: &pb.PasswordAccountAttributes{},
@@ -188,7 +185,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "no error",
item: &pb.Account{
Type: password.Subtype.String(),
Type: globals.PasswordSubtype.String(),
AuthMethodId: globals.PasswordAuthMethodPrefix + "_1234567890",
Attrs: &pb.Account_PasswordAccountAttributes{
PasswordAccountAttributes: &pb.PasswordAccountAttributes{
@@ -200,7 +197,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "no oidc errors",
item: &pb.Account{
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
AuthMethodId: globals.OidcAuthMethodPrefix + "_1234567890",
Attrs: &pb.Account_OidcAccountAttributes{
OidcAccountAttributes: &pb.OidcAccountAttributes{Subject: "no oidc errors"},
@@ -210,7 +207,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "no ldap errors",
item: &pb.Account{
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
AuthMethodId: globals.LdapAuthMethodPrefix + "_1234567890",
Attrs: &pb.Account_LdapAccountAttributes{
LdapAccountAttributes: &pb.LdapAccountAttributes{LoginName: "no oidc errors"},
@@ -246,7 +243,7 @@ func TestValidateUpdateRequest(t *testing.T) {
req: &pbs.UpdateAccountRequest{
Id: globals.PasswordAccountPreviousPrefix + "_1234567890",
Item: &pb.Account{
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
},
},
errContains: fieldError(typeField, "Cannot modify the resource type."),
@@ -256,7 +253,7 @@ func TestValidateUpdateRequest(t *testing.T) {
req: &pbs.UpdateAccountRequest{
Id: globals.PasswordAccountPrefix + "_1234567890",
Item: &pb.Account{
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
},
},
errContains: fieldError(typeField, "Cannot modify the resource type."),
@@ -266,7 +263,7 @@ func TestValidateUpdateRequest(t *testing.T) {
req: &pbs.UpdateAccountRequest{
Id: globals.OidcAccountPrefix + "_1234567890",
Item: &pb.Account{
Type: password.Subtype.String(),
Type: globals.PasswordSubtype.String(),
},
},
errContains: fieldError(typeField, "Cannot modify the resource type."),
@@ -64,7 +64,7 @@ const (
var (
// IdActions contains the set of actions that can be performed on
// individual resources
IdActions = make(map[subtypes.Subtype]action.ActionSet)
IdActions = make(map[globals.Subtype]action.ActionSet)
// CollectionActions contains the set of actions that can be performed on
// this collection
@@ -425,15 +425,15 @@ func (s Service) Authenticate(ctx context.Context, req *pbs.AuthenticateRequest)
}
switch subtypes.SubtypeFromId(domain, req.GetAuthMethodId()) {
case password.Subtype:
case globals.PasswordSubtype:
if err := validateAuthenticatePasswordRequest(req); err != nil {
return nil, err
}
case oidc.Subtype:
case globals.OidcSubtype:
if err := validateAuthenticateOidcRequest(req); err != nil {
return nil, err
}
case ldap.Subtype:
case globals.LdapSubtype:
if err := validateAuthenticateLdapRequest(req); err != nil {
return nil, err
}
@@ -445,12 +445,12 @@ func (s Service) Authenticate(ctx context.Context, req *pbs.AuthenticateRequest)
}
switch subtypes.SubtypeFromId(domain, req.GetAuthMethodId()) {
case password.Subtype:
case globals.PasswordSubtype:
return s.authenticatePassword(ctx, req, &authResults)
case oidc.Subtype:
case globals.OidcSubtype:
return s.authenticateOidc(ctx, req, &authResults)
case ldap.Subtype:
case globals.LdapSubtype:
return s.authenticateLdap(ctx, req, &authResults)
}
return nil, errors.New(ctx, errors.Internal, op, "Invalid auth method subtype not caught in validation function.")
@@ -460,21 +460,21 @@ func (s Service) getFromRepo(ctx context.Context, id string) (auth.AuthMethod, e
var lookupErr error
var am auth.AuthMethod
switch subtypes.SubtypeFromId(domain, id) {
case password.Subtype:
case globals.PasswordSubtype:
repo, err := s.pwRepoFn()
if err != nil {
return nil, err
}
am, lookupErr = repo.LookupAuthMethod(ctx, id)
case oidc.Subtype:
case globals.OidcSubtype:
repo, err := s.oidcRepoFn()
if err != nil {
return nil, err
}
am, lookupErr = repo.LookupAuthMethod(ctx, id)
case ldap.Subtype:
case globals.LdapSubtype:
repo, err := s.ldapRepoFn()
if err != nil {
return nil, err
@@ -550,7 +550,7 @@ func (s Service) createInRepo(ctx context.Context, scopeId string, item *pb.Auth
const op = "authmethods.(Service).createInRepo"
var out auth.AuthMethod
switch subtypes.SubtypeFromType(domain, item.GetType()) {
case password.Subtype:
case globals.PasswordSubtype:
am, err := s.createPwInRepo(ctx, scopeId, item)
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -559,7 +559,7 @@ func (s Service) createInRepo(ctx context.Context, scopeId string, item *pb.Auth
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create auth method but no error returned from repository.")
}
out = am
case oidc.Subtype:
case globals.OidcSubtype:
am, err := s.createOidcInRepo(ctx, scopeId, item)
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -568,7 +568,7 @@ func (s Service) createInRepo(ctx context.Context, scopeId string, item *pb.Auth
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create auth method but no error returned from repository.")
}
out = am
case ldap.Subtype:
case globals.LdapSubtype:
am, err := s.createLdapInRepo(ctx, scopeId, item)
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -588,7 +588,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId string, req *pbs.Upda
var dryRun bool
switch subtypes.SubtypeFromId(domain, req.GetId()) {
case password.Subtype:
case globals.PasswordSubtype:
pam, err := s.updatePwInRepo(ctx, scopeId, req.GetId(), req.GetUpdateMask().GetPaths(), req.GetItem())
if err != nil {
return nil, false, errors.Wrap(ctx, err, op)
@@ -598,7 +598,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId string, req *pbs.Upda
}
am = pam
case oidc.Subtype:
case globals.OidcSubtype:
oam, dr, err := s.updateOidcInRepo(ctx, scopeId, req)
if err != nil {
return nil, false, errors.Wrap(ctx, err, op)
@@ -609,7 +609,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId string, req *pbs.Upda
am = oam
dryRun = dr
case ldap.Subtype:
case globals.LdapSubtype:
lam, err := s.updateLdapInRepo(ctx, scopeId, req.GetId(), req.GetUpdateMask().GetPaths(), req.GetItem())
if err != nil {
_, apiErr := err.(*handlers.ApiError)
@@ -636,20 +636,20 @@ func (s Service) deleteFromRepo(ctx context.Context, scopeId, id string) (bool,
var rows int
var dErr error
switch subtypes.SubtypeFromId(domain, id) {
case password.Subtype:
case globals.PasswordSubtype:
repo, err := s.pwRepoFn()
if err != nil {
return false, errors.Wrap(ctx, err, op)
}
rows, dErr = repo.DeleteAuthMethod(ctx, scopeId, id)
case oidc.Subtype:
case globals.OidcSubtype:
repo, err := s.oidcRepoFn()
if err != nil {
return false, errors.Wrap(ctx, err, op)
}
rows, dErr = repo.DeleteAuthMethod(ctx, id)
case ldap.Subtype:
case globals.LdapSubtype:
repo, err := s.ldapRepoFn()
if err != nil {
return false, errors.Wrap(ctx, err, op)
@@ -673,7 +673,7 @@ func (s Service) changeStateInRepo(ctx context.Context, req *pbs.ChangeStateRequ
const op = "authmethod_service.(Service).changeStateInRepo"
switch subtypes.SubtypeFromId(domain, req.GetId()) {
case oidc.Subtype:
case globals.OidcSubtype:
repo, err := s.oidcRepoFn()
if err != nil {
return nil, err
@@ -732,7 +732,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) reque
default:
var authMeth auth.AuthMethod
switch subtypes.SubtypeFromId(domain, id) {
case password.Subtype:
case globals.PasswordSubtype:
repo, err := s.pwRepoFn()
if err != nil {
res.Error = err
@@ -748,7 +748,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) reque
return res
}
authMeth = am
case oidc.Subtype:
case globals.OidcSubtype:
repo, err := s.oidcRepoFn()
if err != nil {
res.Error = err
@@ -764,7 +764,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) reque
return res
}
authMeth = am
case ldap.Subtype:
case globals.LdapSubtype:
repo, err := s.ldapRepoFn()
if err != nil {
res.Error = err
@@ -835,7 +835,7 @@ func toAuthMethodProto(ctx context.Context, in auth.AuthMethod, opt ...handlers.
switch i := in.(type) {
case *password.AuthMethod:
if outputFields.Has(globals.TypeField) {
out.Type = password.Subtype.String()
out.Type = globals.PasswordSubtype.String()
}
if !outputFields.Has(globals.AttributesField) {
break
@@ -848,7 +848,7 @@ func toAuthMethodProto(ctx context.Context, in auth.AuthMethod, opt ...handlers.
}
case *oidc.AuthMethod:
if outputFields.Has(globals.TypeField) {
out.Type = oidc.Subtype.String()
out.Type = globals.OidcSubtype.String()
}
if !outputFields.Has(globals.AttributesField) {
break
@@ -886,7 +886,7 @@ func toAuthMethodProto(ctx context.Context, in auth.AuthMethod, opt ...handlers.
}
case *ldap.AuthMethod:
if outputFields.Has(globals.TypeField) {
out.Type = ldap.Subtype.String()
out.Type = globals.LdapSubtype.String()
}
if !outputFields.Has(globals.AttributesField) {
break
@@ -988,9 +988,9 @@ func validateCreateRequest(ctx context.Context, req *pbs.CreateAuthMethodRequest
badFields[isPrimaryField] = "This field is read only."
}
switch subtypes.SubtypeFromType(domain, req.GetItem().GetType()) {
case password.Subtype:
case globals.PasswordSubtype:
// Password attributes are not required when creating a password auth method.
case oidc.Subtype:
case globals.OidcSubtype:
attrs := req.GetItem().GetOidcAuthMethodsAttributes()
if attrs == nil {
// OIDC attributes are required when creating an OIDC auth method.
@@ -1066,13 +1066,13 @@ func validateCreateRequest(ctx context.Context, req *pbs.CreateAuthMethodRequest
}
}
}
case ldap.Subtype:
case globals.LdapSubtype:
if len(req.GetItem().GetLdapAuthMethodsAttributes().GetUrls()) == 0 {
badFields[urlsField] = "At least one URL is required"
}
validateLdapAttributes(ctx, req.GetItem().GetLdapAuthMethodsAttributes(), badFields)
default:
badFields[typeField] = fmt.Sprintf("This is a required field and must be %q.", password.Subtype.String())
badFields[typeField] = fmt.Sprintf("This is a required field and must be %q.", globals.PasswordSubtype.String())
}
return badFields
})
@@ -1089,12 +1089,12 @@ func validateUpdateRequest(ctx context.Context, req *pbs.UpdateAuthMethodRequest
badFields[isPrimaryField] = "This field is read only."
}
switch subtypes.SubtypeFromId(domain, req.GetId()) {
case password.Subtype:
if req.GetItem().GetType() != "" && subtypes.SubtypeFromType(domain, req.GetItem().GetType()) != password.Subtype {
case globals.PasswordSubtype:
if req.GetItem().GetType() != "" && subtypes.SubtypeFromType(domain, req.GetItem().GetType()) != globals.PasswordSubtype {
badFields[typeField] = "Cannot modify the resource type."
}
case oidc.Subtype:
if req.GetItem().GetType() != "" && subtypes.SubtypeFromType(domain, req.GetItem().GetType()) != oidc.Subtype {
case globals.OidcSubtype:
if req.GetItem().GetType() != "" && subtypes.SubtypeFromType(domain, req.GetItem().GetType()) != globals.OidcSubtype {
badFields[typeField] = "Cannot modify the resource type."
}
attrs := req.GetItem().GetOidcAuthMethodsAttributes()
@@ -1197,8 +1197,8 @@ func validateUpdateRequest(ctx context.Context, req *pbs.UpdateAuthMethodRequest
}
}
}
case ldap.Subtype:
if req.GetItem().GetType() != "" && subtypes.SubtypeFromType(domain, req.GetItem().GetType()) != ldap.Subtype {
case globals.LdapSubtype:
if req.GetItem().GetType() != "" && subtypes.SubtypeFromType(domain, req.GetItem().GetType()) != globals.LdapSubtype {
badFields[typeField] = "Cannot modify the resource type."
}
validateLdapAttributes(ctx, req.GetItem().GetLdapAuthMethodsAttributes(), badFields)
@@ -1241,8 +1241,8 @@ func validateChangeStateRequest(ctx context.Context, req *pbs.ChangeStateRequest
if req == nil {
return errors.New(ctx, errors.InvalidParameter, op, "Missing request")
}
if st := subtypes.SubtypeFromId(domain, req.GetId()); st != oidc.Subtype {
return handlers.NotFoundErrorf("This endpoint is only available for the %q Auth Method type.", oidc.Subtype.String())
if st := subtypes.SubtypeFromId(domain, req.GetId()); st != globals.OidcSubtype {
return handlers.NotFoundErrorf("This endpoint is only available for the %q Auth Method type.", globals.OidcSubtype.String())
}
badFields := make(map[string]string)
if req.GetVersion() == 0 {
@@ -1278,7 +1278,7 @@ func validateAuthenticateRequest(ctx context.Context, req *pbs.AuthenticateReque
} else {
st := subtypes.SubtypeFromId(domain, req.GetAuthMethodId())
switch st {
case password.Subtype, oidc.Subtype, ldap.Subtype:
case globals.PasswordSubtype, globals.OidcSubtype, globals.LdapSubtype:
default:
badFields[authMethodIdField] = "Unknown auth method type."
}
@@ -1381,7 +1381,7 @@ func transformAuthenticateRequestAttributes(msg proto.Message) error {
return nil
}
switch subtypes.SubtypeFromId(domain, authRequest.GetAuthMethodId()) {
case password.Subtype:
case globals.PasswordSubtype:
newAttrs := &pbs.PasswordLoginAttributes{}
if err := handlers.StructToProto(attrs, newAttrs); err != nil {
return err
@@ -1389,7 +1389,7 @@ func transformAuthenticateRequestAttributes(msg proto.Message) error {
authRequest.Attrs = &pbs.AuthenticateRequest_PasswordLoginAttributes{
PasswordLoginAttributes: newAttrs,
}
case oidc.Subtype:
case globals.OidcSubtype:
switch authRequest.GetCommand() {
case startCommand:
newAttrs := &pbs.OidcStartAttributes{}
@@ -1418,7 +1418,7 @@ func transformAuthenticateRequestAttributes(msg proto.Message) error {
default:
return fmt.Errorf("%s: unknown command %q", op, authRequest.GetCommand())
}
case ldap.Subtype:
case globals.LdapSubtype:
newAttrs := &pbs.LdapLoginAttributes{}
if err := handlers.StructToProto(attrs, newAttrs); err != nil {
return err
@@ -150,7 +150,7 @@ func TestGet(t *testing.T) {
ScopeId: oidcam.GetScopeId(),
CreatedTime: oidcam.CreateTime.GetTimestamp(),
UpdatedTime: oidcam.UpdateTime.GetTimestamp(),
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.AuthMethod_OidcAuthMethodsAttributes{
OidcAuthMethodsAttributes: &pb.OidcAuthMethodAttributes{
Issuer: wrapperspb.String("https://alice.com"),
@@ -183,7 +183,7 @@ func TestGet(t *testing.T) {
ScopeId: ldapAm.GetScopeId(),
CreatedTime: ldapAm.CreateTime.GetTimestamp(),
UpdatedTime: ldapAm.UpdateTime.GetTimestamp(),
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.AuthMethod_LdapAuthMethodsAttributes{
LdapAuthMethodsAttributes: &pb.LdapAuthMethodAttributes{
State: string(ldap.InactiveState),
@@ -313,7 +313,7 @@ func TestList(t *testing.T) {
UpdatedTime: oidcam.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: oWithAuthMethods.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 2,
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.AuthMethod_OidcAuthMethodsAttributes{
OidcAuthMethodsAttributes: &pb.OidcAuthMethodAttributes{
Issuer: wrapperspb.String("https://alice.com"),
@@ -376,7 +376,7 @@ func TestList(t *testing.T) {
UpdatedTime: ldapAm.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: oWithAuthMethods.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.AuthMethod_LdapAuthMethodsAttributes{
LdapAuthMethodsAttributes: &pb.LdapAuthMethodAttributes{
State: string(ldap.ActivePublicState),
@@ -713,7 +713,7 @@ func TestCreate(t *testing.T) {
name: "Create a valid OIDC AuthMethod",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.AuthMethod_OidcAuthMethodsAttributes{
OidcAuthMethodsAttributes: &pb.OidcAuthMethodAttributes{
Issuer: wrapperspb.String("https://example.discovery.url:4821/.well-known/openid-configuration/"),
@@ -736,7 +736,7 @@ func TestCreate(t *testing.T) {
UpdatedTime: defaultAm.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: o.GetType(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.AuthMethod_OidcAuthMethodsAttributes{
OidcAuthMethodsAttributes: &pb.OidcAuthMethodAttributes{
Issuer: wrapperspb.String("https://example.discovery.url:4821/"),
@@ -759,7 +759,7 @@ func TestCreate(t *testing.T) {
name: "create-a-valid-ldap-auth-method",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.AuthMethod_LdapAuthMethodsAttributes{
LdapAuthMethodsAttributes: &pb.LdapAuthMethodAttributes{
StartTls: true,
@@ -796,7 +796,7 @@ func TestCreate(t *testing.T) {
UpdatedTime: defaultAm.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: o.GetType(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.AuthMethod_LdapAuthMethodsAttributes{
LdapAuthMethodsAttributes: &pb.LdapAuthMethodAttributes{
State: string(ldap.InactiveState),
@@ -863,7 +863,7 @@ func TestCreate(t *testing.T) {
name: "Create a global OIDC AuthMethod",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: scope.Global.String(),
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.AuthMethod_OidcAuthMethodsAttributes{
OidcAuthMethodsAttributes: &pb.OidcAuthMethodAttributes{
Issuer: wrapperspb.String("https://example.discovery.url"),
@@ -883,7 +883,7 @@ func TestCreate(t *testing.T) {
UpdatedTime: defaultAm.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: scope.Global.String(), Type: scope.Global.String(), Name: scope.Global.String(), Description: "Global Scope"},
Version: 1,
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.AuthMethod_OidcAuthMethodsAttributes{
OidcAuthMethodsAttributes: &pb.OidcAuthMethodAttributes{
ApiUrlPrefix: wrapperspb.String("https://api.com"),
@@ -902,7 +902,7 @@ func TestCreate(t *testing.T) {
name: "create-a-global-ldap-auth-method",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: scope.Global.String(),
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.AuthMethod_LdapAuthMethodsAttributes{
LdapAuthMethodsAttributes: &pb.LdapAuthMethodAttributes{
Urls: []string{"ldap://ldap1", "ldaps://ldap1"},
@@ -920,7 +920,7 @@ func TestCreate(t *testing.T) {
UpdatedTime: defaultAm.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: scope.Global.String(), Type: scope.Global.String(), Name: scope.Global.String(), Description: "Global Scope"},
Version: 1,
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.AuthMethod_LdapAuthMethodsAttributes{
LdapAuthMethodsAttributes: &pb.LdapAuthMethodAttributes{
State: string(ldap.InactiveState),
@@ -949,7 +949,7 @@ func TestCreate(t *testing.T) {
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
CreatedTime: timestamppb.Now(),
Type: password.Subtype.String(),
Type: globals.PasswordSubtype.String(),
}},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
@@ -959,7 +959,7 @@ func TestCreate(t *testing.T) {
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
UpdatedTime: timestamppb.Now(),
Type: password.Subtype.String(),
Type: globals.PasswordSubtype.String(),
}},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
@@ -968,7 +968,7 @@ func TestCreate(t *testing.T) {
name: "Can't specify IsPrimary",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: password.Subtype.String(),
Type: globals.PasswordSubtype.String(),
IsPrimary: true,
}},
res: nil,
@@ -979,7 +979,7 @@ func TestCreate(t *testing.T) {
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
UpdatedTime: timestamppb.Now(),
Type: password.Subtype.String(),
Type: globals.PasswordSubtype.String(),
}},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
@@ -998,7 +998,7 @@ func TestCreate(t *testing.T) {
name: "OIDC AuthMethod Doesn't Require Issuer",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.AuthMethod_OidcAuthMethodsAttributes{
OidcAuthMethodsAttributes: &pb.OidcAuthMethodAttributes{
ApiUrlPrefix: wrapperspb.String("https://api.com"),
@@ -1016,7 +1016,7 @@ func TestCreate(t *testing.T) {
UpdatedTime: defaultAm.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: o.GetType(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.AuthMethod_OidcAuthMethodsAttributes{
OidcAuthMethodsAttributes: &pb.OidcAuthMethodAttributes{
ApiUrlPrefix: wrapperspb.String("https://api.com"),
@@ -1034,7 +1034,7 @@ func TestCreate(t *testing.T) {
name: "OIDC AuthMethod Requires ApiUrl",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.AuthMethod_OidcAuthMethodsAttributes{
OidcAuthMethodsAttributes: &pb.OidcAuthMethodAttributes{
ClientId: wrapperspb.String("someclientid"),
@@ -1048,7 +1048,7 @@ func TestCreate(t *testing.T) {
name: "OIDC AuthMethod Requires Client Id",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.AuthMethod_OidcAuthMethodsAttributes{
OidcAuthMethodsAttributes: &pb.OidcAuthMethodAttributes{
ApiUrlPrefix: wrapperspb.String("https://api.com"),
@@ -1063,7 +1063,7 @@ func TestCreate(t *testing.T) {
name: "OIDC AuthMethod Requires Client Secret",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.AuthMethod_OidcAuthMethodsAttributes{
OidcAuthMethodsAttributes: &pb.OidcAuthMethodAttributes{
ApiUrlPrefix: wrapperspb.String("https://api.com"),
@@ -1078,7 +1078,7 @@ func TestCreate(t *testing.T) {
name: "OIDC AuthMethod cant specify client secret hmac",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.AuthMethod_OidcAuthMethodsAttributes{
OidcAuthMethodsAttributes: &pb.OidcAuthMethodAttributes{
ApiUrlPrefix: wrapperspb.String("https://api.com"),
@@ -1095,7 +1095,7 @@ func TestCreate(t *testing.T) {
name: "OIDC AuthMethod cant specify state",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.AuthMethod_OidcAuthMethodsAttributes{
OidcAuthMethodsAttributes: &pb.OidcAuthMethodAttributes{
ApiUrlPrefix: wrapperspb.String("https://api.com"),
@@ -1112,7 +1112,7 @@ func TestCreate(t *testing.T) {
name: "OIDC AuthMethod Must Match Standard Alg Names",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.AuthMethod_OidcAuthMethodsAttributes{
OidcAuthMethodsAttributes: &pb.OidcAuthMethodAttributes{
ApiUrlPrefix: wrapperspb.String("https://api.com"),
@@ -1129,7 +1129,7 @@ func TestCreate(t *testing.T) {
name: "OIDC AuthMethod API Urls Prefix Format",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.AuthMethod_OidcAuthMethodsAttributes{
OidcAuthMethodsAttributes: &pb.OidcAuthMethodAttributes{
Issuer: wrapperspb.String("https://example2.discovery.url:4821"),
@@ -1145,7 +1145,7 @@ func TestCreate(t *testing.T) {
name: "OIDC AuthMethod Callback Url Read Only",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.AuthMethod_OidcAuthMethodsAttributes{
OidcAuthMethodsAttributes: &pb.OidcAuthMethodAttributes{
Issuer: wrapperspb.String("https://example2.discovery.url:4821"),
@@ -1161,7 +1161,7 @@ func TestCreate(t *testing.T) {
name: "OIDC AuthMethod unparseable certificates",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.AuthMethod_OidcAuthMethodsAttributes{
OidcAuthMethodsAttributes: &pb.OidcAuthMethodAttributes{
ApiUrlPrefix: wrapperspb.String("https://api.com"),
@@ -1178,7 +1178,7 @@ func TestCreate(t *testing.T) {
name: "OIDC AuthMethod cant specify default claims scopes of openid",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.AuthMethod_OidcAuthMethodsAttributes{
OidcAuthMethodsAttributes: &pb.OidcAuthMethodAttributes{
ApiUrlPrefix: wrapperspb.String("https://api.com"),
@@ -1195,7 +1195,7 @@ func TestCreate(t *testing.T) {
name: "ldap-auth-method-requires-urls",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.AuthMethod_LdapAuthMethodsAttributes{
LdapAuthMethodsAttributes: &pb.LdapAuthMethodAttributes{},
},
@@ -1207,7 +1207,7 @@ func TestCreate(t *testing.T) {
name: "ldap-auth-method-invalid-urls",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.AuthMethod_LdapAuthMethodsAttributes{
LdapAuthMethodsAttributes: &pb.LdapAuthMethodAttributes{
Urls: []string{"ldap://ldap1", "not-ldap-scheme://ldap2"},
@@ -1221,7 +1221,7 @@ func TestCreate(t *testing.T) {
name: "ldap-auth-method-invalid-deref-aliases",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.AuthMethod_LdapAuthMethodsAttributes{
LdapAuthMethodsAttributes: &pb.LdapAuthMethodAttributes{
Urls: []string{"ldap://ldap1"},
@@ -1236,7 +1236,7 @@ func TestCreate(t *testing.T) {
name: "ldap-auth-method-invalid-cert",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.AuthMethod_LdapAuthMethodsAttributes{
LdapAuthMethodsAttributes: &pb.LdapAuthMethodAttributes{
Urls: []string{"ldap://ldap1"},
@@ -1251,7 +1251,7 @@ func TestCreate(t *testing.T) {
name: "ldap-auth-method-missing-bind-dn",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.AuthMethod_LdapAuthMethodsAttributes{
LdapAuthMethodsAttributes: &pb.LdapAuthMethodAttributes{
Urls: []string{"ldap://ldap1"},
@@ -1265,7 +1265,7 @@ func TestCreate(t *testing.T) {
name: "ldap-auth-method-missing-bind-password",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.AuthMethod_LdapAuthMethodsAttributes{
LdapAuthMethodsAttributes: &pb.LdapAuthMethodAttributes{
Urls: []string{"ldap://ldap1"},
@@ -1279,7 +1279,7 @@ func TestCreate(t *testing.T) {
name: "ldap-auth-method-invalid-client-cert",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.AuthMethod_LdapAuthMethodsAttributes{
LdapAuthMethodsAttributes: &pb.LdapAuthMethodAttributes{
Urls: []string{"ldap://ldap1"},
@@ -1295,7 +1295,7 @@ func TestCreate(t *testing.T) {
name: "ldap-auth-method-invalid-client-cert-key",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.AuthMethod_LdapAuthMethodsAttributes{
LdapAuthMethodsAttributes: &pb.LdapAuthMethodAttributes{
Urls: []string{"ldap://ldap1"},
@@ -1311,7 +1311,7 @@ func TestCreate(t *testing.T) {
name: "ldap-auth-method-client-cert-key-not-a-key",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.AuthMethod_LdapAuthMethodsAttributes{
LdapAuthMethodsAttributes: &pb.LdapAuthMethodAttributes{
Urls: []string{"ldap://ldap1"},
@@ -1327,7 +1327,7 @@ func TestCreate(t *testing.T) {
name: "ldap-auth-method-missing-client-cert-key",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.AuthMethod_LdapAuthMethodsAttributes{
LdapAuthMethodsAttributes: &pb.LdapAuthMethodAttributes{
Urls: []string{"ldap://ldap1"},
@@ -1342,7 +1342,7 @@ func TestCreate(t *testing.T) {
name: "ldap-auth-method-missing-client-cert",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.AuthMethod_LdapAuthMethodsAttributes{
LdapAuthMethodsAttributes: &pb.LdapAuthMethodAttributes{
Urls: []string{"ldap://ldap1"},
@@ -1357,7 +1357,7 @@ func TestCreate(t *testing.T) {
name: "ldap-auth-method-invalid-attribute-map",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.AuthMethod_LdapAuthMethodsAttributes{
LdapAuthMethodsAttributes: &pb.LdapAuthMethodAttributes{
Urls: []string{"ldap://ldap1"},
@@ -11,6 +11,7 @@ import (
"net/url"
"strings"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth/ldap"
ldapstore "github.com/hashicorp/boundary/internal/auth/ldap/store"
"github.com/hashicorp/boundary/internal/daemon/controller/auth"
@@ -36,7 +37,7 @@ func init() {
panic(err)
}
IdActions[ldap.Subtype] = action.ActionSet{
IdActions[globals.LdapSubtype] = action.ActionSet{
action.NoOp,
action.Read,
action.Update,
@@ -96,7 +96,7 @@ func Test_UpdateLdap(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: wrapperspb.String("default"),
Description: wrapperspb.String("default"),
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: attrs,
}})
require.NoError(t, err)
@@ -129,7 +129,7 @@ func Test_UpdateLdap(t *testing.T) {
Item: &pb.AuthMethod{
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
},
},
res: &pbs.UpdateAuthMethodResponse{
@@ -138,7 +138,7 @@ func Test_UpdateLdap(t *testing.T) {
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Version: 2,
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: defaultReadAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: ldapAuthorizedActions,
@@ -155,7 +155,7 @@ func Test_UpdateLdap(t *testing.T) {
Item: &pb.AuthMethod{
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
},
},
res: &pbs.UpdateAuthMethodResponse{
@@ -164,7 +164,7 @@ func Test_UpdateLdap(t *testing.T) {
Version: 2,
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: defaultReadAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: ldapAuthorizedActions,
@@ -213,7 +213,7 @@ func Test_UpdateLdap(t *testing.T) {
UpdateMask: &field_mask.FieldMask{Paths: []string{"name", "type"}},
Item: &pb.AuthMethod{
Name: &wrapperspb.StringValue{Value: "updated name"},
Type: password.Subtype.String(),
Type: globals.PasswordSubtype.String(),
},
},
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
@@ -245,7 +245,7 @@ func Test_UpdateLdap(t *testing.T) {
ScopeId: o.GetPublicId(),
Version: 2,
Description: &wrapperspb.StringValue{Value: "default"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: defaultReadAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: ldapAuthorizedActions,
@@ -268,7 +268,7 @@ func Test_UpdateLdap(t *testing.T) {
ScopeId: o.GetPublicId(),
Version: 2,
Name: &wrapperspb.StringValue{Value: "default"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: defaultReadAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: ldapAuthorizedActions,
@@ -296,7 +296,7 @@ func Test_UpdateLdap(t *testing.T) {
Version: 2,
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.AuthMethod_LdapAuthMethodsAttributes{
LdapAuthMethodsAttributes: &pb.LdapAuthMethodAttributes{
Urls: []string{"ldaps://ldap1"},
@@ -326,7 +326,7 @@ func Test_UpdateLdap(t *testing.T) {
Version: 2,
Name: &wrapperspb.StringValue{Value: "updated"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: defaultReadAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: ldapAuthorizedActions,
@@ -351,7 +351,7 @@ func Test_UpdateLdap(t *testing.T) {
Version: 2,
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "notignored"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: defaultReadAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: ldapAuthorizedActions,
@@ -387,7 +387,7 @@ func Test_UpdateLdap(t *testing.T) {
Version: 2,
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.AuthMethod_LdapAuthMethodsAttributes{
LdapAuthMethodsAttributes: &pb.LdapAuthMethodAttributes{
Urls: []string{"ldaps://ldap1"},
@@ -448,7 +448,7 @@ func Test_UpdateLdap(t *testing.T) {
Version: 2,
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.AuthMethod_LdapAuthMethodsAttributes{
LdapAuthMethodsAttributes: &pb.LdapAuthMethodAttributes{
Urls: []string{"ldaps://ldap1"},
@@ -547,7 +547,7 @@ func Test_UpdateLdap(t *testing.T) {
Paths: []string{"type"},
},
Item: &pb.AuthMethod{
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
},
},
res: nil,
@@ -609,7 +609,7 @@ func Test_UpdateLdap(t *testing.T) {
Version: 2,
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.AuthMethod_LdapAuthMethodsAttributes{
LdapAuthMethodsAttributes: &pb.LdapAuthMethodAttributes{
Urls: []string{"ldaps://ldap1"},
@@ -643,7 +643,7 @@ func Test_UpdateLdap(t *testing.T) {
Version: 2,
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.AuthMethod_LdapAuthMethodsAttributes{
LdapAuthMethodsAttributes: &pb.LdapAuthMethodAttributes{
Urls: []string{"ldaps://ldap2", "ldaps://ldap3"},
@@ -696,7 +696,7 @@ func Test_UpdateLdap(t *testing.T) {
Version: 2,
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.AuthMethod_LdapAuthMethodsAttributes{
LdapAuthMethodsAttributes: &pb.LdapAuthMethodAttributes{
Urls: []string{"ldaps://ldap1"},
@@ -733,7 +733,7 @@ func Test_UpdateLdap(t *testing.T) {
Version: 2,
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.AuthMethod_LdapAuthMethodsAttributes{
LdapAuthMethodsAttributes: &pb.LdapAuthMethodAttributes{
Urls: []string{"ldaps://ldap1"},
@@ -788,7 +788,7 @@ func Test_UpdateLdap(t *testing.T) {
Version: 2,
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.AuthMethod_LdapAuthMethodsAttributes{
LdapAuthMethodsAttributes: &pb.LdapAuthMethodAttributes{
Urls: []string{"ldaps://ldap1"},
@@ -10,6 +10,7 @@ import (
"net/url"
"strings"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth/oidc"
oidcstore "github.com/hashicorp/boundary/internal/auth/oidc/store"
"github.com/hashicorp/boundary/internal/daemon/controller/auth"
@@ -56,7 +57,7 @@ func init() {
panic(err)
}
IdActions[oidc.Subtype] = action.ActionSet{
IdActions[globals.OidcSubtype] = action.ActionSet{
action.NoOp,
action.Read,
action.Update,
@@ -311,7 +311,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: wrapperspb.String("default"),
Description: wrapperspb.String("default"),
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: defaultAttributes,
}})
require.NoError(t, err)
@@ -351,7 +351,7 @@ func TestUpdate_OIDC(t *testing.T) {
Item: &pb.AuthMethod{
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
},
},
res: &pbs.UpdateAuthMethodResponse{
@@ -359,7 +359,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: defaultReadAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -376,7 +376,7 @@ func TestUpdate_OIDC(t *testing.T) {
Item: &pb.AuthMethod{
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
},
},
res: &pbs.UpdateAuthMethodResponse{
@@ -384,7 +384,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: defaultReadAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -412,7 +412,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: func() *pb.AuthMethod_OidcAuthMethodsAttributes {
f := proto.Clone(defaultReadAttributes.OidcAuthMethodsAttributes).(*pb.OidcAuthMethodAttributes)
f.Issuer = wrapperspb.String("http://localhost:72759/somepath/")
@@ -481,7 +481,7 @@ func TestUpdate_OIDC(t *testing.T) {
UpdateMask: &field_mask.FieldMask{Paths: []string{"name", "type"}},
Item: &pb.AuthMethod{
Name: &wrapperspb.StringValue{Value: "updated name"},
Type: password.Subtype.String(),
Type: globals.PasswordSubtype.String(),
},
},
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
@@ -510,7 +510,7 @@ func TestUpdate_OIDC(t *testing.T) {
Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Description: &wrapperspb.StringValue{Value: "default"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: defaultReadAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -532,7 +532,7 @@ func TestUpdate_OIDC(t *testing.T) {
Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: defaultReadAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -556,7 +556,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "updated"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: defaultReadAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -580,7 +580,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "notignored"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: defaultReadAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -650,7 +650,7 @@ func TestUpdate_OIDC(t *testing.T) {
Paths: []string{"type"},
},
Item: &pb.AuthMethod{
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
},
},
res: nil,
@@ -705,7 +705,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: func() *pb.AuthMethod_OidcAuthMethodsAttributes {
f := proto.Clone(defaultReadAttributes.OidcAuthMethodsAttributes).(*pb.OidcAuthMethodAttributes)
f.MaxAge = wrapperspb.UInt32(0)
@@ -736,7 +736,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: func() *pb.AuthMethod_OidcAuthMethodsAttributes {
f := proto.Clone(defaultReadAttributes.OidcAuthMethodsAttributes).(*pb.OidcAuthMethodAttributes)
f.MaxAge = wrapperspb.UInt32(4)
@@ -767,7 +767,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: func() *pb.AuthMethod_OidcAuthMethodsAttributes {
f := proto.Clone(defaultReadAttributes.OidcAuthMethodsAttributes).(*pb.OidcAuthMethodAttributes)
f.ClientId = wrapperspb.String("new id")
@@ -814,7 +814,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: func() *pb.AuthMethod_OidcAuthMethodsAttributes {
f := proto.Clone(defaultReadAttributes.OidcAuthMethodsAttributes).(*pb.OidcAuthMethodAttributes)
f.ApiUrlPrefix = wrapperspb.String("https://callback.prefix:9281/path")
@@ -846,7 +846,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: func() *pb.AuthMethod_OidcAuthMethodsAttributes {
f := proto.Clone(defaultReadAttributes.OidcAuthMethodsAttributes).(*pb.OidcAuthMethodAttributes)
f.AllowedAudiences = []string{"bar", "foo"}
@@ -877,7 +877,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: func() *pb.AuthMethod_OidcAuthMethodsAttributes {
f := proto.Clone(defaultReadAttributes.OidcAuthMethodsAttributes).(*pb.OidcAuthMethodAttributes)
f.ClaimsScopes = []string{"email", "profile"}
@@ -908,7 +908,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: func() *pb.AuthMethod_OidcAuthMethodsAttributes {
f := proto.Clone(defaultReadAttributes.OidcAuthMethodsAttributes).(*pb.OidcAuthMethodAttributes)
f.AccountClaimMaps = []string{"display_name=name"}
@@ -982,7 +982,7 @@ func TestUpdate_OIDC(t *testing.T) {
ScopeId: o.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: func() *pb.AuthMethod_OidcAuthMethodsAttributes {
f := proto.Clone(defaultReadAttributes.OidcAuthMethodsAttributes).(*pb.OidcAuthMethodAttributes)
f.SigningAlgorithms = []string{string(oidc.EdDSA)}
@@ -1115,7 +1115,7 @@ func TestUpdate_OIDCDryRun(t *testing.T) {
CreatedTime: am.GetCreateTime().GetTimestamp(),
UpdatedTime: am.GetUpdateTime().GetTimestamp(),
Version: am.GetVersion(),
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
AuthorizedActions: oidcAuthorizedActions,
AuthorizedCollectionActions: authorizedCollectionActions,
Attrs: &pb.AuthMethod_OidcAuthMethodsAttributes{
@@ -1289,7 +1289,7 @@ func TestChangeState_OIDC(t *testing.T) {
ScopeId: oidcam.GetScopeId(),
CreatedTime: oidcam.CreateTime.GetTimestamp(),
UpdatedTime: oidcam.UpdateTime.GetTimestamp(),
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.AuthMethod_OidcAuthMethodsAttributes{
OidcAuthMethodsAttributes: &pb.OidcAuthMethodAttributes{
Issuer: wrapperspb.String(oidcam.GetIssuer()),
@@ -8,6 +8,7 @@ import (
"fmt"
"strings"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth/password"
pwstore "github.com/hashicorp/boundary/internal/auth/password/store"
"github.com/hashicorp/boundary/internal/daemon/controller/auth"
@@ -36,7 +37,7 @@ func init() {
panic(err)
}
IdActions[password.Subtype] = action.ActionSet{
IdActions[globals.PasswordSubtype] = action.ActionSet{
action.NoOp,
action.Read,
action.Update,
@@ -278,7 +278,7 @@ func (s Service) UpdateCredentialLibrary(ctx context.Context, req *pbs.UpdateCre
var currentCredentialType globals.CredentialType
var mo vault.MappingOverride
switch subtypes.SubtypeFromId(domain, req.GetId()) {
case vault.SSHCertificateLibrarySubtype:
case globals.VaultSshCertificateLibrarySubtype:
cur, err := repo.LookupSSHCertificateCredentialLibrary(ctx, req.Id)
if err != nil {
return nil, err
@@ -375,7 +375,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (credential.Library
return nil, errors.Wrap(ctx, err, op)
}
switch subtypes.SubtypeFromId(domain, id) {
case vault.GenericLibrarySubtype:
case globals.VaultGenericLibrarySubtype:
cs, err := repo.LookupCredentialLibrary(ctx, id)
if err != nil && !errors.IsNotFoundError(err) {
return nil, errors.Wrap(ctx, err, op)
@@ -384,7 +384,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (credential.Library
return nil, errors.New(ctx, errors.InvalidParameter, op, fmt.Sprintf("credential library %q not found", id))
}
return cs, err
case vault.SSHCertificateLibrarySubtype:
case globals.VaultSshCertificateLibrarySubtype:
cs, err := repo.LookupSSHCertificateCredentialLibrary(ctx, id)
if err != nil && !errors.IsNotFoundError(err) {
return nil, errors.Wrap(ctx, err, op)
@@ -401,7 +401,7 @@ func (s Service) createInRepo(ctx context.Context, scopeId string, item *pb.Cred
const op = "credentiallibraries.(Service).createInRepo"
var out credential.Library
switch subtypes.SubtypeFromType(domain, item.GetType()) {
case vault.SSHCertificateLibrarySubtype:
case globals.VaultSshCertificateLibrarySubtype:
cl, err := toStorageVaultSSHCertificateLibrary(ctx, item.GetCredentialStoreId(), item)
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -471,7 +471,7 @@ func (s Service) updateInRepo(
return nil, errors.Wrap(ctx, err, op)
}
switch subtypes.SubtypeFromId(domain, id) {
case vault.SSHCertificateLibrarySubtype:
case globals.VaultSshCertificateLibrarySubtype:
dbMasks = append(dbMasks, sshCertMaskManager.Translate(masks)...)
if getMapUpdate(criticalOptionsField, masks) {
dbMasks = append(dbMasks, vault.CriticalOptionsField)
@@ -523,7 +523,7 @@ func (s Service) deleteFromRepo(ctx context.Context, scopeId, id string) (bool,
}
rows := 0
switch subtypes.SubtypeFromId(domain, id) {
case vault.SSHCertificateLibrarySubtype:
case globals.VaultSshCertificateLibrarySubtype:
rows, err = repo.DeleteSSHCertificateCredentialLibrary(ctx, scopeId, id)
default:
rows, err = repo.DeleteCredentialLibrary(ctx, scopeId, id)
@@ -555,7 +555,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth.
opts = append(opts, auth.WithId(id))
parentId = id
switch subtypes.SubtypeFromId(domain, id) {
case vault.GenericLibrarySubtype:
case globals.VaultGenericLibrarySubtype:
cl, err := repo.LookupCredentialLibrary(ctx, id)
if err != nil {
res.Error = err
@@ -566,7 +566,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth.
return res
}
parentId = cl.GetStoreId()
case vault.SSHCertificateLibrarySubtype:
case globals.VaultSshCertificateLibrarySubtype:
cl, err := repo.LookupSSHCertificateCredentialLibrary(ctx, id)
if err != nil {
res.Error = err
@@ -591,7 +591,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth.
opts = append(opts, auth.WithPin(parentId))
switch subtypes.SubtypeFromId(domain, parentId) {
case vault.Subtype:
case globals.VaultSubtype:
cs, err := repo.LookupCredentialStore(ctx, parentId)
if err != nil {
res.Error = err
@@ -651,7 +651,7 @@ func toProto(ctx context.Context, in credential.Library, opt ...handlers.Option)
out.AuthorizedActions = opts.WithAuthorizedActions
}
switch subtypes.SubtypeFromId(domain, in.GetPublicId()) {
case vault.GenericLibrarySubtype:
case globals.VaultGenericLibrarySubtype:
vaultIn, ok := in.(*vault.CredentialLibrary)
if !ok {
return nil, errors.New(ctx, errors.Internal, op, "unable to cast to vault credential library")
@@ -704,7 +704,7 @@ func toProto(ctx context.Context, in credential.Library, opt ...handlers.Option)
VaultGenericCredentialLibraryAttributes: attrs,
}
}
case vault.SSHCertificateLibrarySubtype:
case globals.VaultSshCertificateLibrarySubtype:
vaultIn, ok := in.(*vault.SSHCertificateCredentialLibrary)
if !ok {
return nil, errors.New(ctx, errors.Internal, op, "unable to cast to vault ssh certificate credential library")
@@ -880,7 +880,7 @@ func toStorageVaultSSHCertificateLibrary(ctx context.Context, storeId string, in
func validateGetRequest(req *pbs.GetCredentialLibraryRequest) error {
prefix := ""
switch subtypes.SubtypeFromId(domain, req.GetId()) {
case vault.SSHCertificateLibrarySubtype:
case globals.VaultSshCertificateLibrarySubtype:
prefix = globals.VaultSshCertificateCredentialLibraryPrefix
default:
prefix = globals.VaultCredentialLibraryPrefix
@@ -892,18 +892,18 @@ func validateCreateRequest(req *pbs.CreateCredentialLibraryRequest) error {
return handlers.ValidateCreateRequest(req.GetItem(), func() map[string]string {
badFields := map[string]string{}
switch subtypes.SubtypeFromId(domain, req.GetItem().GetCredentialStoreId()) {
case vault.Subtype:
case globals.VaultSubtype:
var t string
if version.SupportsFeature(version.Binary, version.CredentialLibraryVaultSubtype) {
t = req.GetItem().GetType()
// To support older cli's that do not send a `type`, assume
// subtype of vault-generic based on the credential store's subtype.
// To support the deprecated subtype 'vault.Subtype', convert it
// To support the deprecated subtype 'globals.VaultSubtype', convert it
// to vault-generic.
if t == "" || subtypes.SubtypeFromType(domain, t) == vault.Subtype {
if t == "" || subtypes.SubtypeFromType(domain, t) == globals.VaultSubtype {
// fallback to assuming subtype from credential store.
t = vault.GenericLibrarySubtype.String()
t = globals.VaultGenericLibrarySubtype.String()
req.GetItem().Type = t
switch req.GetItem().Attrs.(type) {
@@ -927,13 +927,13 @@ func validateCreateRequest(req *pbs.CreateCredentialLibraryRequest) error {
}
}
if subtypes.SubtypeFromType(domain, t) != vault.GenericLibrarySubtype &&
subtypes.SubtypeFromType(domain, t) != vault.SSHCertificateLibrarySubtype {
badFields[globals.CredentialStoreIdField] = fmt.Sprintf("Type must be a vault subtype %q or %q", vault.GenericLibrarySubtype.String(), vault.SSHCertificateLibrarySubtype.String())
if subtypes.SubtypeFromType(domain, t) != globals.VaultGenericLibrarySubtype &&
subtypes.SubtypeFromType(domain, t) != globals.VaultSshCertificateLibrarySubtype {
badFields[globals.CredentialStoreIdField] = fmt.Sprintf("Type must be a vault subtype %q or %q", globals.VaultGenericLibrarySubtype.String(), globals.VaultSshCertificateLibrarySubtype.String())
}
switch subtypes.SubtypeFromType(domain, req.GetItem().GetType()) {
case vault.GenericLibrarySubtype:
case globals.VaultGenericLibrarySubtype:
isValidCred := false
ct := req.GetItem().GetCredentialType()
for _, t := range validCredentialTypesVaultGeneric {
@@ -964,7 +964,7 @@ func validateCreateRequest(req *pbs.CreateCredentialLibraryRequest) error {
badFields[httpRequestBodyField] = fmt.Sprintf("Field can only be set if %q is set to the value 'POST'.", httpMethodField)
}
validateMapping(badFields, globals.CredentialType(req.GetItem().GetCredentialType()), req.GetItem().CredentialMappingOverrides.AsMap())
case vault.SSHCertificateLibrarySubtype:
case globals.VaultSshCertificateLibrarySubtype:
if req.GetItem().GetCredentialType() != "" {
badFields[globals.CredentialTypeField] = fmt.Sprintf("This field is read only and cannot be set.")
}
@@ -1003,16 +1003,16 @@ func validateUpdateRequest(req *pbs.UpdateCredentialLibraryRequest, currentCrede
prefix := ""
st := subtypes.SubtypeFromId(domain, req.GetId())
switch st {
case vault.GenericLibrarySubtype:
case globals.VaultGenericLibrarySubtype:
prefix = globals.VaultCredentialLibraryPrefix
case vault.SSHCertificateLibrarySubtype:
case globals.VaultSshCertificateLibrarySubtype:
prefix = globals.VaultSshCertificateCredentialLibraryPrefix
}
return handlers.ValidateUpdateRequest(req, req.GetItem(), func() map[string]string {
badFields := map[string]string{}
switch st {
case vault.GenericLibrarySubtype:
if req.GetItem().GetType() != "" && subtypes.SubtypeFromType(domain, req.GetItem().GetType()) != vault.GenericLibrarySubtype {
case globals.VaultGenericLibrarySubtype:
if req.GetItem().GetType() != "" && subtypes.SubtypeFromType(domain, req.GetItem().GetType()) != globals.VaultGenericLibrarySubtype {
badFields[globals.TypeField] = "Cannot modify resource type."
}
if req.GetItem().GetCredentialType() != "" && req.GetItem().GetCredentialType() != string(currentCredentialType) {
@@ -1035,8 +1035,8 @@ func validateUpdateRequest(req *pbs.UpdateCredentialLibraryRequest, currentCrede
}
validateMapping(badFields, currentCredentialType, req.GetItem().CredentialMappingOverrides.AsMap())
}
case vault.SSHCertificateLibrarySubtype:
if req.GetItem().GetType() != "" && subtypes.SubtypeFromType(domain, req.GetItem().GetType()) != vault.SSHCertificateLibrarySubtype {
case globals.VaultSshCertificateLibrarySubtype:
if req.GetItem().GetType() != "" && subtypes.SubtypeFromType(domain, req.GetItem().GetType()) != globals.VaultSshCertificateLibrarySubtype {
badFields[globals.TypeField] = "Cannot modify resource type."
}
if req.GetItem().GetCredentialType() != "" && req.GetItem().GetCredentialType() != string(currentCredentialType) {
@@ -68,7 +68,7 @@ func TestList(t *testing.T) {
CreatedTime: l.GetCreateTime().GetTimestamp(),
UpdatedTime: l.GetUpdateTime().GetTimestamp(),
Version: l.GetVersion(),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
AuthorizedActions: testAuthorizedActions,
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{
@@ -87,7 +87,7 @@ func TestList(t *testing.T) {
CreatedTime: l.GetCreateTime().GetTimestamp(),
UpdatedTime: l.GetUpdateTime().GetTimestamp(),
Version: l.GetVersion(),
Type: vault.SSHCertificateLibrarySubtype.String(),
Type: globals.VaultSshCertificateLibrarySubtype.String(),
AuthorizedActions: testAuthorizedActions,
Attrs: &pb.CredentialLibrary_VaultSshCertificateCredentialLibraryAttributes{
VaultSshCertificateCredentialLibraryAttributes: &pb.VaultSSHCertificateCredentialLibraryAttributes{
@@ -199,7 +199,7 @@ func TestList_Attributes(t *testing.T) {
CreatedTime: l.GetCreateTime().GetTimestamp(),
UpdatedTime: l.GetUpdateTime().GetTimestamp(),
Version: l.GetVersion(),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
AuthorizedActions: testAuthorizedActions,
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{
@@ -218,7 +218,7 @@ func TestList_Attributes(t *testing.T) {
CreatedTime: l.GetCreateTime().GetTimestamp(),
UpdatedTime: l.GetUpdateTime().GetTimestamp(),
Version: l.GetVersion(),
Type: vault.SSHCertificateLibrarySubtype.String(),
Type: globals.VaultSshCertificateLibrarySubtype.String(),
AuthorizedActions: testAuthorizedActions,
Attrs: &pb.CredentialLibrary_VaultSshCertificateCredentialLibraryAttributes{
VaultSshCertificateCredentialLibraryAttributes: &pb.VaultSSHCertificateCredentialLibraryAttributes{
@@ -317,7 +317,7 @@ func TestCreate(t *testing.T) {
name: "missing vault path",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{},
},
@@ -329,7 +329,7 @@ func TestCreate(t *testing.T) {
name: "Can't specify Id",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Id: globals.VaultCredentialLibraryPrefix + "_notallowed",
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{
@@ -344,7 +344,7 @@ func TestCreate(t *testing.T) {
name: "Can't specify Created Time",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
CreatedTime: timestamppb.Now(),
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{
@@ -359,7 +359,7 @@ func TestCreate(t *testing.T) {
name: "Can't specify Update Time",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
UpdatedTime: timestamppb.Now(),
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{
@@ -387,7 +387,7 @@ func TestCreate(t *testing.T) {
{
name: "parent id must be included",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -401,7 +401,7 @@ func TestCreate(t *testing.T) {
name: "Cannot specify a http request body when http method is get",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -416,7 +416,7 @@ func TestCreate(t *testing.T) {
name: "Invalid Method",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -431,7 +431,7 @@ func TestCreate(t *testing.T) {
name: "Request Body With GET Method",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -446,7 +446,7 @@ func TestCreate(t *testing.T) {
name: "Invalid credential type",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -461,7 +461,7 @@ func TestCreate(t *testing.T) {
name: "Invalid username_password mapping",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -485,7 +485,7 @@ func TestCreate(t *testing.T) {
name: "Using POST method",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -504,7 +504,7 @@ func TestCreate(t *testing.T) {
UpdatedTime: store.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: prj.GetType(), ParentScopeId: prj.GetParentId()},
Version: 1,
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -520,7 +520,7 @@ func TestCreate(t *testing.T) {
name: "Create a valid vault CredentialLibrary",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Name: &wrapperspb.StringValue{Value: "name"},
Description: &wrapperspb.StringValue{Value: "desc"},
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
@@ -541,7 +541,7 @@ func TestCreate(t *testing.T) {
Description: &wrapperspb.StringValue{Value: "desc"},
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: prj.GetType(), ParentScopeId: prj.GetParentId()},
Version: 1,
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -556,7 +556,7 @@ func TestCreate(t *testing.T) {
name: "Create a valid vault CredentialLibrary username_password type",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -574,7 +574,7 @@ func TestCreate(t *testing.T) {
UpdatedTime: store.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: prj.GetType(), ParentScopeId: prj.GetParentId()},
Version: 1,
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -590,7 +590,7 @@ func TestCreate(t *testing.T) {
name: "Create a valid vault CredentialLibrary username_password type with username mapping",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -616,7 +616,7 @@ func TestCreate(t *testing.T) {
UpdatedTime: store.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: prj.GetType(), ParentScopeId: prj.GetParentId()},
Version: 1,
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -640,7 +640,7 @@ func TestCreate(t *testing.T) {
name: "Create a valid vault CredentialLibrary username_password type with username/password mapping",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -667,7 +667,7 @@ func TestCreate(t *testing.T) {
UpdatedTime: store.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: prj.GetType(), ParentScopeId: prj.GetParentId()},
Version: 1,
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -692,7 +692,7 @@ func TestCreate(t *testing.T) {
name: "Create a valid vault CredentialLibrary ssh_private_key type",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -710,7 +710,7 @@ func TestCreate(t *testing.T) {
UpdatedTime: store.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: prj.GetType(), ParentScopeId: prj.GetParentId()},
Version: 1,
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -726,7 +726,7 @@ func TestCreate(t *testing.T) {
name: "Create a valid vault CredentialLibrary ssh_private_key type with mapping",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -754,7 +754,7 @@ func TestCreate(t *testing.T) {
UpdatedTime: store.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: prj.GetType(), ParentScopeId: prj.GetParentId()},
Version: 1,
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -780,7 +780,7 @@ func TestCreate(t *testing.T) {
name: "Create a valid vault CredentialLibrary with the 'vault' subtype",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultCredentialLibraryAttributes{
VaultCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -797,7 +797,7 @@ func TestCreate(t *testing.T) {
UpdatedTime: store.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: prj.GetType(), ParentScopeId: prj.GetParentId()},
Version: 1,
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -916,7 +916,7 @@ func TestGet(t *testing.T) {
Id: unspecifiedLib.GetPublicId(),
CredentialStoreId: unspecifiedLib.GetStoreId(),
Scope: &scopepb.ScopeInfo{Id: store.GetProjectId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
AuthorizedActions: testAuthorizedActions,
CreatedTime: unspecifiedLib.CreateTime.GetTimestamp(),
UpdatedTime: unspecifiedLib.UpdateTime.GetTimestamp(),
@@ -938,7 +938,7 @@ func TestGet(t *testing.T) {
Id: userPassLib.GetPublicId(),
CredentialStoreId: userPassLib.GetStoreId(),
Scope: &scopepb.ScopeInfo{Id: store.GetProjectId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
AuthorizedActions: testAuthorizedActions,
CreatedTime: userPassLib.CreateTime.GetTimestamp(),
UpdatedTime: userPassLib.UpdateTime.GetTimestamp(),
@@ -970,7 +970,7 @@ func TestGet(t *testing.T) {
Id: sshPkLib.GetPublicId(),
CredentialStoreId: sshPkLib.GetStoreId(),
Scope: &scopepb.ScopeInfo{Id: store.GetProjectId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
AuthorizedActions: testAuthorizedActions,
CreatedTime: sshPkLib.CreateTime.GetTimestamp(),
UpdatedTime: sshPkLib.UpdateTime.GetTimestamp(),
@@ -1004,7 +1004,7 @@ func TestGet(t *testing.T) {
CredentialStoreId: sshCertLib.GetStoreId(),
CredentialType: sshCertLib.GetCredentialType(),
Scope: &scopepb.ScopeInfo{Id: store.GetProjectId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
Type: vault.SSHCertificateLibrarySubtype.String(),
Type: globals.VaultSshCertificateLibrarySubtype.String(),
AuthorizedActions: testAuthorizedActions,
CreatedTime: sshCertLib.CreateTime.GetTimestamp(),
UpdatedTime: sshCertLib.UpdateTime.GetTimestamp(),
@@ -1923,7 +1923,7 @@ func TestCreate_SSHCertificateCredentialLibrary(t *testing.T) {
name: "missing vault path",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.SSHCertificateLibrarySubtype.String(),
Type: globals.VaultSshCertificateLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultSshCertificateCredentialLibraryAttributes{
VaultSshCertificateCredentialLibraryAttributes: &pb.VaultSSHCertificateCredentialLibraryAttributes{
Username: wrapperspb.String("username"),
@@ -1937,7 +1937,7 @@ func TestCreate_SSHCertificateCredentialLibrary(t *testing.T) {
name: "missing username",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.SSHCertificateLibrarySubtype.String(),
Type: globals.VaultSshCertificateLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultSshCertificateCredentialLibraryAttributes{
VaultSshCertificateCredentialLibraryAttributes: &pb.VaultSSHCertificateCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -1951,7 +1951,7 @@ func TestCreate_SSHCertificateCredentialLibrary(t *testing.T) {
name: "Can't specify Id",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.SSHCertificateLibrarySubtype.String(),
Type: globals.VaultSshCertificateLibrarySubtype.String(),
Id: globals.VaultSshCertificateCredentialLibraryPrefix + "_notallowed",
Attrs: &pb.CredentialLibrary_VaultSshCertificateCredentialLibraryAttributes{
VaultSshCertificateCredentialLibraryAttributes: &pb.VaultSSHCertificateCredentialLibraryAttributes{
@@ -1967,7 +1967,7 @@ func TestCreate_SSHCertificateCredentialLibrary(t *testing.T) {
name: "Can't specify Created Time",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.SSHCertificateLibrarySubtype.String(),
Type: globals.VaultSshCertificateLibrarySubtype.String(),
CreatedTime: timestamppb.Now(),
Attrs: &pb.CredentialLibrary_VaultSshCertificateCredentialLibraryAttributes{
VaultSshCertificateCredentialLibraryAttributes: &pb.VaultSSHCertificateCredentialLibraryAttributes{
@@ -1983,7 +1983,7 @@ func TestCreate_SSHCertificateCredentialLibrary(t *testing.T) {
name: "Can't specify Update Time",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.SSHCertificateLibrarySubtype.String(),
Type: globals.VaultSshCertificateLibrarySubtype.String(),
UpdatedTime: timestamppb.Now(),
Attrs: &pb.CredentialLibrary_VaultSshCertificateCredentialLibraryAttributes{
VaultSshCertificateCredentialLibraryAttributes: &pb.VaultSSHCertificateCredentialLibraryAttributes{
@@ -2013,7 +2013,7 @@ func TestCreate_SSHCertificateCredentialLibrary(t *testing.T) {
{
name: "parent id must be included",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
Type: vault.SSHCertificateLibrarySubtype.String(),
Type: globals.VaultSshCertificateLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultSshCertificateCredentialLibraryAttributes{
VaultSshCertificateCredentialLibraryAttributes: &pb.VaultSSHCertificateCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -2028,7 +2028,7 @@ func TestCreate_SSHCertificateCredentialLibrary(t *testing.T) {
name: "Invalid credential type",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.SSHCertificateLibrarySubtype.String(),
Type: globals.VaultSshCertificateLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultSshCertificateCredentialLibraryAttributes{
VaultSshCertificateCredentialLibraryAttributes: &pb.VaultSSHCertificateCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -2044,7 +2044,7 @@ func TestCreate_SSHCertificateCredentialLibrary(t *testing.T) {
name: "Invalid key type key bits combination",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.SSHCertificateLibrarySubtype.String(),
Type: globals.VaultSshCertificateLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultSshCertificateCredentialLibraryAttributes{
VaultSshCertificateCredentialLibraryAttributes: &pb.VaultSSHCertificateCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -2061,7 +2061,7 @@ func TestCreate_SSHCertificateCredentialLibrary(t *testing.T) {
name: "Create a valid vault SSHCertificateCredentialLibrary",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.SSHCertificateLibrarySubtype.String(),
Type: globals.VaultSshCertificateLibrarySubtype.String(),
Name: &wrapperspb.StringValue{Value: "name1"},
Description: &wrapperspb.StringValue{Value: "desc"},
Attrs: &pb.CredentialLibrary_VaultSshCertificateCredentialLibraryAttributes{
@@ -2083,7 +2083,7 @@ func TestCreate_SSHCertificateCredentialLibrary(t *testing.T) {
Description: &wrapperspb.StringValue{Value: "desc"},
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: prj.GetType(), ParentScopeId: prj.GetParentId()},
Version: 1,
Type: vault.SSHCertificateLibrarySubtype.String(),
Type: globals.VaultSshCertificateLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultSshCertificateCredentialLibraryAttributes{
VaultSshCertificateCredentialLibraryAttributes: &pb.VaultSSHCertificateCredentialLibraryAttributes{
Path: wrapperspb.String("/ssh/sign/foo"),
@@ -2100,7 +2100,7 @@ func TestCreate_SSHCertificateCredentialLibrary(t *testing.T) {
name: "Seting key type ed25119 with key bits nil",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.SSHCertificateLibrarySubtype.String(),
Type: globals.VaultSshCertificateLibrarySubtype.String(),
Name: &wrapperspb.StringValue{Value: "name2"},
Attrs: &pb.CredentialLibrary_VaultSshCertificateCredentialLibraryAttributes{
VaultSshCertificateCredentialLibraryAttributes: &pb.VaultSSHCertificateCredentialLibraryAttributes{
@@ -2121,7 +2121,7 @@ func TestCreate_SSHCertificateCredentialLibrary(t *testing.T) {
Name: &wrapperspb.StringValue{Value: "name2"},
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: prj.GetType(), ParentScopeId: prj.GetParentId()},
Version: 1,
Type: vault.SSHCertificateLibrarySubtype.String(),
Type: globals.VaultSshCertificateLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultSshCertificateCredentialLibraryAttributes{
VaultSshCertificateCredentialLibraryAttributes: &pb.VaultSSHCertificateCredentialLibraryAttributes{
Path: wrapperspb.String("/ssh/sign/foo"),
@@ -2138,7 +2138,7 @@ func TestCreate_SSHCertificateCredentialLibrary(t *testing.T) {
name: "valid vault SSHCertificateCredentialLibrary with AdditionalValidPrincipals",
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.SSHCertificateLibrarySubtype.String(),
Type: globals.VaultSshCertificateLibrarySubtype.String(),
Name: &wrapperspb.StringValue{Value: "name"},
Description: &wrapperspb.StringValue{Value: "desc"},
Attrs: &pb.CredentialLibrary_VaultSshCertificateCredentialLibraryAttributes{
@@ -2161,7 +2161,7 @@ func TestCreate_SSHCertificateCredentialLibrary(t *testing.T) {
Description: &wrapperspb.StringValue{Value: "desc"},
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: prj.GetType(), ParentScopeId: prj.GetParentId()},
Version: 1,
Type: vault.SSHCertificateLibrarySubtype.String(),
Type: globals.VaultSshCertificateLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultSshCertificateCredentialLibraryAttributes{
VaultSshCertificateCredentialLibraryAttributes: &pb.VaultSSHCertificateCredentialLibraryAttributes{
Path: wrapperspb.String("/ssh/sign/foo"),
@@ -2292,7 +2292,7 @@ func TestUpdate_SSHCertificateCredentialLibrary(t *testing.T) {
req: &pbs.UpdateCredentialLibraryRequest{
UpdateMask: fieldmask(sshCertUsernameField),
Item: &pb.CredentialLibrary{
Type: vault.SSHCertificateLibrarySubtype.String(),
Type: globals.VaultSshCertificateLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultSshCertificateCredentialLibraryAttributes{
VaultSshCertificateCredentialLibraryAttributes: &pb.VaultSSHCertificateCredentialLibraryAttributes{
Username: wrapperspb.String("changed-username"),
@@ -2311,7 +2311,7 @@ func TestUpdate_SSHCertificateCredentialLibrary(t *testing.T) {
req: &pbs.UpdateCredentialLibraryRequest{
UpdateMask: fieldmask("attributes.key_type", "attributes.key_bits"),
Item: &pb.CredentialLibrary{
Type: vault.SSHCertificateLibrarySubtype.String(),
Type: globals.VaultSshCertificateLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultSshCertificateCredentialLibraryAttributes{
VaultSshCertificateCredentialLibraryAttributes: &pb.VaultSSHCertificateCredentialLibraryAttributes{
KeyType: wrapperspb.String(vault.KeyTypeRsa),
@@ -2332,7 +2332,7 @@ func TestUpdate_SSHCertificateCredentialLibrary(t *testing.T) {
req: &pbs.UpdateCredentialLibraryRequest{
UpdateMask: fieldmask(vaultPathField),
Item: &pb.CredentialLibrary{
Type: vault.SSHCertificateLibrarySubtype.String(),
Type: globals.VaultSshCertificateLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultSshCertificateCredentialLibraryAttributes{
VaultSshCertificateCredentialLibraryAttributes: &pb.VaultSSHCertificateCredentialLibraryAttributes{
Path: wrapperspb.String("/ssh/issue/foo"),
@@ -2351,7 +2351,7 @@ func TestUpdate_SSHCertificateCredentialLibrary(t *testing.T) {
req: &pbs.UpdateCredentialLibraryRequest{
UpdateMask: fieldmask("attributes.ttl", "attributes.key_id", "attributes.critical_options.some", "attributes.extensions.permity-pty"),
Item: &pb.CredentialLibrary{
Type: vault.SSHCertificateLibrarySubtype.String(),
Type: globals.VaultSshCertificateLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultSshCertificateCredentialLibraryAttributes{
VaultSshCertificateCredentialLibraryAttributes: &pb.VaultSSHCertificateCredentialLibraryAttributes{
KeyId: wrapperspb.String("id"),
@@ -2377,7 +2377,7 @@ func TestUpdate_SSHCertificateCredentialLibrary(t *testing.T) {
req: &pbs.UpdateCredentialLibraryRequest{
UpdateMask: fieldmask("attributes.critical_options", "attributes.extensions.permit-pty"),
Item: &pb.CredentialLibrary{
Type: vault.SSHCertificateLibrarySubtype.String(),
Type: globals.VaultSshCertificateLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultSshCertificateCredentialLibraryAttributes{
VaultSshCertificateCredentialLibraryAttributes: &pb.VaultSSHCertificateCredentialLibraryAttributes{
CriticalOptions: nil,
@@ -2399,7 +2399,7 @@ func TestUpdate_SSHCertificateCredentialLibrary(t *testing.T) {
req: &pbs.UpdateCredentialLibraryRequest{
UpdateMask: fieldmask("attributes.critical_options.option-b", "attributes.extensions"),
Item: &pb.CredentialLibrary{
Type: vault.SSHCertificateLibrarySubtype.String(),
Type: globals.VaultSshCertificateLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultSshCertificateCredentialLibraryAttributes{
VaultSshCertificateCredentialLibraryAttributes: &pb.VaultSSHCertificateCredentialLibraryAttributes{
CriticalOptions: map[string]string{"option-b": "set-b"},
@@ -2421,7 +2421,7 @@ func TestUpdate_SSHCertificateCredentialLibrary(t *testing.T) {
UpdateMask: fieldmask("attributes.critical_options.option-a", "attributes.critical_options.option-b", "attributes.critical_options.option-c",
"attributes.extensions.permit-pty", "attributes.extensions.permit-port-forwarding", "attributes.extensions.permit-X11-forwarding"),
Item: &pb.CredentialLibrary{
Type: vault.SSHCertificateLibrarySubtype.String(),
Type: globals.VaultSshCertificateLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultSshCertificateCredentialLibraryAttributes{
VaultSshCertificateCredentialLibraryAttributes: &pb.VaultSSHCertificateCredentialLibraryAttributes{
CriticalOptions: map[string]string{"option-a": "set-a", "option-b": "set-b", "option-c": "set-c"},
@@ -2536,7 +2536,7 @@ func TestUpdate_SSHCertificateCredentialLibrary(t *testing.T) {
req: &pbs.UpdateCredentialLibraryRequest{
UpdateMask: fieldmask(keyBitsField, keyTypeField),
Item: &pb.CredentialLibrary{
Type: vault.SSHCertificateLibrarySubtype.String(),
Type: globals.VaultSshCertificateLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultSshCertificateCredentialLibraryAttributes{
VaultSshCertificateCredentialLibraryAttributes: &pb.VaultSSHCertificateCredentialLibraryAttributes{
KeyType: wrapperspb.String(vault.KeyTypeEcdsa),
@@ -2552,7 +2552,7 @@ func TestUpdate_SSHCertificateCredentialLibrary(t *testing.T) {
req: &pbs.UpdateCredentialLibraryRequest{
UpdateMask: fieldmask(keyTypeField),
Item: &pb.CredentialLibrary{
Type: vault.SSHCertificateLibrarySubtype.String(),
Type: globals.VaultSshCertificateLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultSshCertificateCredentialLibraryAttributes{
VaultSshCertificateCredentialLibraryAttributes: &pb.VaultSSHCertificateCredentialLibraryAttributes{
KeyType: wrapperspb.String("unknown-type"),
@@ -2567,7 +2567,7 @@ func TestUpdate_SSHCertificateCredentialLibrary(t *testing.T) {
req: &pbs.UpdateCredentialLibraryRequest{
UpdateMask: fieldmask(keyBitsField),
Item: &pb.CredentialLibrary{
Type: vault.SSHCertificateLibrarySubtype.String(),
Type: globals.VaultSshCertificateLibrarySubtype.String(),
Attrs: &pb.CredentialLibrary_VaultSshCertificateCredentialLibraryAttributes{
VaultSshCertificateCredentialLibraryAttributes: &pb.VaultSSHCertificateCredentialLibraryAttributes{
KeyBits: wrapperspb.UInt32(1234),
@@ -346,7 +346,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (credential.Static,
func (s Service) createInRepo(ctx context.Context, scopeId string, item *pb.Credential) (credential.Static, error) {
const op = "credentials.(Service).createInRepo"
switch item.GetType() {
case credential.UsernamePasswordSubtype.String():
case globals.UsernamePasswordSubtype.String():
cred, err := toUsernamePasswordStorageCredential(ctx, item.GetCredentialStoreId(), item)
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -363,7 +363,7 @@ func (s Service) createInRepo(ctx context.Context, scopeId string, item *pb.Cred
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create credential but no error returned from repository.")
}
return out, nil
case credential.SshPrivateKeySubtype.String():
case globals.SshPrivateKeySubtype.String():
cred, err := toSshPrivateKeyStorageCredential(ctx, item.GetCredentialStoreId(), item)
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -380,7 +380,7 @@ func (s Service) createInRepo(ctx context.Context, scopeId string, item *pb.Cred
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create credential but no error returned from repository.")
}
return out, nil
case credential.JsonSubtype.String():
case globals.JsonSubtype.String():
cred, err := toJsonStorageCredential(ctx, item.GetCredentialStoreId(), item)
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -414,7 +414,7 @@ func (s Service) updateInRepo(
item := proto.Clone(in).(*pb.Credential)
switch subtypes.SubtypeFromId(domain, id) {
case credential.UsernamePasswordSubtype:
case globals.UsernamePasswordSubtype:
dbMasks = append(dbMasks, upMaskManager.Translate(masks)...)
if len(dbMasks) == 0 {
return nil, handlers.InvalidArgumentErrorf("No valid fields included in the update mask.", map[string]string{"update_mask": "No valid fields provided in the update mask."})
@@ -438,7 +438,7 @@ func (s Service) updateInRepo(
}
return out, nil
case credential.SshPrivateKeySubtype:
case globals.SshPrivateKeySubtype:
dbMasks = append(dbMasks, spkMaskManager.Translate(masks)...)
if len(dbMasks) == 0 {
return nil, handlers.InvalidArgumentErrorf("No valid fields included in the update mask.", map[string]string{"update_mask": "No valid fields provided in the update mask."})
@@ -472,7 +472,7 @@ func (s Service) updateInRepo(
}
return out, nil
case credential.JsonSubtype:
case globals.JsonSubtype:
dbMasks = append(dbMasks, jsonMaskManager.Translate(masks, "attributes", "object")...)
if len(dbMasks) == 0 {
return nil, handlers.InvalidArgumentErrorf("No valid fields included in the update mask.", map[string]string{"update_mask": "No valid fields provided in the update mask."})
@@ -585,11 +585,11 @@ func toProto(in credential.Static, opt ...handlers.Option) (*pb.Credential, erro
if outputFields.Has(globals.TypeField) {
switch in.(type) {
case *static.UsernamePasswordCredential:
out.Type = credential.UsernamePasswordSubtype.String()
out.Type = globals.UsernamePasswordSubtype.String()
case *static.SshPrivateKeyCredential:
out.Type = credential.SshPrivateKeySubtype.String()
out.Type = globals.SshPrivateKeySubtype.String()
case *static.JsonCredential:
out.Type = credential.JsonSubtype.String()
out.Type = globals.JsonSubtype.String()
}
}
if outputFields.Has(globals.DescriptionField) && in.GetDescription() != "" {
@@ -752,7 +752,7 @@ func validateCreateRequest(req *pbs.CreateCredentialRequest) error {
}
switch req.Item.GetType() {
case credential.UsernamePasswordSubtype.String():
case globals.UsernamePasswordSubtype.String():
if req.Item.GetUsernamePasswordAttributes().GetUsername().GetValue() == "" {
badFields[usernameField] = "Field required for creating a username-password credential."
}
@@ -760,7 +760,7 @@ func validateCreateRequest(req *pbs.CreateCredentialRequest) error {
badFields[passwordField] = "Field required for creating a username-password credential."
}
case credential.SshPrivateKeySubtype.String():
case globals.SshPrivateKeySubtype.String():
if req.Item.GetSshPrivateKeyAttributes().GetUsername().GetValue() == "" {
badFields[usernameField] = "Field required for creating an SSH private key credential."
}
@@ -789,7 +789,7 @@ func validateCreateRequest(req *pbs.CreateCredentialRequest) error {
}
}
case credential.JsonSubtype.String():
case globals.JsonSubtype.String():
object := req.GetItem().GetJsonAttributes().GetObject()
if object == nil || len(object.AsMap()) <= 0 {
badFields[objectField] = "This is a required field and cannot be set to empty."
@@ -809,7 +809,7 @@ func validateUpdateRequest(req *pbs.UpdateCredentialRequest) error {
return handlers.ValidateUpdateRequest(req, req.GetItem(), func() map[string]string {
badFields := map[string]string{}
switch subtypes.SubtypeFromId(domain, req.GetId()) {
case credential.UsernamePasswordSubtype:
case globals.UsernamePasswordSubtype:
attrs := req.GetItem().GetUsernamePasswordAttributes()
if handlers.MaskContains(req.GetUpdateMask().GetPaths(), usernameField) && attrs.GetUsername().GetValue() == "" {
badFields[usernameField] = "This is a required field and cannot be set to empty."
@@ -818,7 +818,7 @@ func validateUpdateRequest(req *pbs.UpdateCredentialRequest) error {
badFields[passwordField] = "This is a required field and cannot be set to empty."
}
case credential.SshPrivateKeySubtype:
case globals.SshPrivateKeySubtype:
attrs := req.GetItem().GetSshPrivateKeyAttributes()
if handlers.MaskContains(req.GetUpdateMask().GetPaths(), usernameField) && attrs.GetUsername().GetValue() == "" {
badFields[usernameField] = "This is a required field and cannot be set to empty."
@@ -850,7 +850,7 @@ func validateUpdateRequest(req *pbs.UpdateCredentialRequest) error {
}
}
case credential.JsonSubtype:
case globals.JsonSubtype:
if handlers.MaskContainsPrefix(req.GetUpdateMask().GetPaths(), objectField) {
object := req.GetItem().GetJsonAttributes().GetObject()
if object == nil || len(object.AsMap()) <= 0 {
@@ -78,7 +78,7 @@ func TestList(t *testing.T) {
CreatedTime: c.GetCreateTime().GetTimestamp(),
UpdatedTime: c.GetUpdateTime().GetTimestamp(),
Version: c.GetVersion(),
Type: credential.UsernamePasswordSubtype.String(),
Type: globals.UsernamePasswordSubtype.String(),
AuthorizedActions: testAuthorizedActions,
Attrs: &pb.Credential_UsernamePasswordAttributes{
UsernamePasswordAttributes: &pb.UsernamePasswordAttributes{
@@ -98,7 +98,7 @@ func TestList(t *testing.T) {
CreatedTime: spk.GetCreateTime().GetTimestamp(),
UpdatedTime: spk.GetUpdateTime().GetTimestamp(),
Version: spk.GetVersion(),
Type: credential.SshPrivateKeySubtype.String(),
Type: globals.SshPrivateKeySubtype.String(),
AuthorizedActions: testAuthorizedActions,
Attrs: &pb.Credential_SshPrivateKeyAttributes{
SshPrivateKeyAttributes: &pb.SshPrivateKeyAttributes{
@@ -120,7 +120,7 @@ func TestList(t *testing.T) {
CreatedTime: credJson.GetCreateTime().GetTimestamp(),
UpdatedTime: credJson.GetUpdateTime().GetTimestamp(),
Version: credJson.GetVersion(),
Type: credential.JsonSubtype.String(),
Type: globals.JsonSubtype.String(),
AuthorizedActions: testAuthorizedActions,
Attrs: &pb.Credential_JsonAttributes{
JsonAttributes: &pb.JsonAttributes{
@@ -264,7 +264,7 @@ func TestGet(t *testing.T) {
Id: upCred.GetPublicId(),
CredentialStoreId: upCred.GetStoreId(),
Scope: &scopepb.ScopeInfo{Id: store.GetProjectId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
Type: credential.UsernamePasswordSubtype.String(),
Type: globals.UsernamePasswordSubtype.String(),
AuthorizedActions: testAuthorizedActions,
CreatedTime: upCred.CreateTime.GetTimestamp(),
UpdatedTime: upCred.UpdateTime.GetTimestamp(),
@@ -286,7 +286,7 @@ func TestGet(t *testing.T) {
Id: upCredPrev.GetPublicId(),
CredentialStoreId: upCred.GetStoreId(),
Scope: &scopepb.ScopeInfo{Id: store.GetProjectId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
Type: credential.UsernamePasswordSubtype.String(),
Type: globals.UsernamePasswordSubtype.String(),
AuthorizedActions: testAuthorizedActions,
CreatedTime: upCredPrev.CreateTime.GetTimestamp(),
UpdatedTime: upCredPrev.UpdateTime.GetTimestamp(),
@@ -308,7 +308,7 @@ func TestGet(t *testing.T) {
Id: spkCred.GetPublicId(),
CredentialStoreId: spkCred.GetStoreId(),
Scope: &scopepb.ScopeInfo{Id: store.GetProjectId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
Type: credential.SshPrivateKeySubtype.String(),
Type: globals.SshPrivateKeySubtype.String(),
AuthorizedActions: testAuthorizedActions,
CreatedTime: spkCred.CreateTime.GetTimestamp(),
UpdatedTime: spkCred.UpdateTime.GetTimestamp(),
@@ -330,7 +330,7 @@ func TestGet(t *testing.T) {
Id: spkCredWithPass.GetPublicId(),
CredentialStoreId: spkCredWithPass.GetStoreId(),
Scope: &scopepb.ScopeInfo{Id: store.GetProjectId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
Type: credential.SshPrivateKeySubtype.String(),
Type: globals.SshPrivateKeySubtype.String(),
AuthorizedActions: testAuthorizedActions,
CreatedTime: spkCredWithPass.CreateTime.GetTimestamp(),
UpdatedTime: spkCredWithPass.UpdateTime.GetTimestamp(),
@@ -353,7 +353,7 @@ func TestGet(t *testing.T) {
Id: jsonCred.GetPublicId(),
CredentialStoreId: jsonCred.GetStoreId(),
Scope: &scopepb.ScopeInfo{Id: store.GetProjectId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
Type: credential.JsonSubtype.String(),
Type: globals.JsonSubtype.String(),
AuthorizedActions: testAuthorizedActions,
CreatedTime: jsonCred.CreateTime.GetTimestamp(),
UpdatedTime: jsonCred.UpdateTime.GetTimestamp(),
@@ -511,7 +511,7 @@ func TestCreate(t *testing.T) {
req: &pbs.CreateCredentialRequest{Item: &pb.Credential{
CredentialStoreId: store.GetPublicId(),
Id: globals.UsernamePasswordCredentialPrefix + "_notallowed",
Type: credential.UsernamePasswordSubtype.String(),
Type: globals.UsernamePasswordSubtype.String(),
Attrs: &pb.Credential_UsernamePasswordAttributes{
UsernamePasswordAttributes: &pb.UsernamePasswordAttributes{
Username: wrapperspb.String("username"),
@@ -526,7 +526,7 @@ func TestCreate(t *testing.T) {
name: "Invalid Credential Store Id",
req: &pbs.CreateCredentialRequest{Item: &pb.Credential{
CredentialStoreId: "p_invalidid",
Type: credential.UsernamePasswordSubtype.String(),
Type: globals.UsernamePasswordSubtype.String(),
Attrs: &pb.Credential_UsernamePasswordAttributes{
UsernamePasswordAttributes: &pb.UsernamePasswordAttributes{
Username: wrapperspb.String("username"),
@@ -542,7 +542,7 @@ func TestCreate(t *testing.T) {
req: &pbs.CreateCredentialRequest{Item: &pb.Credential{
CredentialStoreId: store.GetPublicId(),
CreatedTime: timestamppb.Now(),
Type: credential.UsernamePasswordSubtype.String(),
Type: globals.UsernamePasswordSubtype.String(),
Attrs: &pb.Credential_UsernamePasswordAttributes{
UsernamePasswordAttributes: &pb.UsernamePasswordAttributes{
Username: wrapperspb.String("username"),
@@ -557,7 +557,7 @@ func TestCreate(t *testing.T) {
req: &pbs.CreateCredentialRequest{Item: &pb.Credential{
CredentialStoreId: store.GetPublicId(),
UpdatedTime: timestamppb.Now(),
Type: credential.UsernamePasswordSubtype.String(),
Type: globals.UsernamePasswordSubtype.String(),
Attrs: &pb.Credential_UsernamePasswordAttributes{
UsernamePasswordAttributes: &pb.UsernamePasswordAttributes{
Username: wrapperspb.String("username"),
@@ -586,7 +586,7 @@ func TestCreate(t *testing.T) {
name: "Must provide username",
req: &pbs.CreateCredentialRequest{Item: &pb.Credential{
CredentialStoreId: store.GetPublicId(),
Type: credential.UsernamePasswordSubtype.String(),
Type: globals.UsernamePasswordSubtype.String(),
Attrs: &pb.Credential_UsernamePasswordAttributes{
UsernamePasswordAttributes: &pb.UsernamePasswordAttributes{
Password: wrapperspb.String("password"),
@@ -600,7 +600,7 @@ func TestCreate(t *testing.T) {
name: "Must provide password",
req: &pbs.CreateCredentialRequest{Item: &pb.Credential{
CredentialStoreId: store.GetPublicId(),
Type: credential.UsernamePasswordSubtype.String(),
Type: globals.UsernamePasswordSubtype.String(),
Attrs: &pb.Credential_UsernamePasswordAttributes{
UsernamePasswordAttributes: &pb.UsernamePasswordAttributes{
Username: wrapperspb.String("username"),
@@ -614,7 +614,7 @@ func TestCreate(t *testing.T) {
name: "Must provide private key",
req: &pbs.CreateCredentialRequest{Item: &pb.Credential{
CredentialStoreId: store.GetPublicId(),
Type: credential.SshPrivateKeySubtype.String(),
Type: globals.SshPrivateKeySubtype.String(),
Attrs: &pb.Credential_SshPrivateKeyAttributes{
SshPrivateKeyAttributes: &pb.SshPrivateKeyAttributes{
Username: wrapperspb.String("username"),
@@ -628,7 +628,7 @@ func TestCreate(t *testing.T) {
name: "Must provide json secret",
req: &pbs.CreateCredentialRequest{Item: &pb.Credential{
CredentialStoreId: store.GetPublicId(),
Type: credential.JsonSubtype.String(),
Type: globals.JsonSubtype.String(),
Attrs: &pb.Credential_JsonAttributes{
JsonAttributes: &pb.JsonAttributes{},
},
@@ -640,7 +640,7 @@ func TestCreate(t *testing.T) {
name: "valid-up",
req: &pbs.CreateCredentialRequest{Item: &pb.Credential{
CredentialStoreId: store.GetPublicId(),
Type: credential.UsernamePasswordSubtype.String(),
Type: globals.UsernamePasswordSubtype.String(),
Attrs: &pb.Credential_UsernamePasswordAttributes{
UsernamePasswordAttributes: &pb.UsernamePasswordAttributes{
Username: wrapperspb.String("username"),
@@ -658,7 +658,7 @@ func TestCreate(t *testing.T) {
UpdatedTime: store.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: prj.GetType(), ParentScopeId: prj.GetParentId()},
Version: 1,
Type: credential.UsernamePasswordSubtype.String(),
Type: globals.UsernamePasswordSubtype.String(),
AuthorizedActions: testAuthorizedActions,
},
},
@@ -667,7 +667,7 @@ func TestCreate(t *testing.T) {
name: "valid-spk",
req: &pbs.CreateCredentialRequest{Item: &pb.Credential{
CredentialStoreId: store.GetPublicId(),
Type: credential.SshPrivateKeySubtype.String(),
Type: globals.SshPrivateKeySubtype.String(),
Attrs: &pb.Credential_SshPrivateKeyAttributes{
SshPrivateKeyAttributes: &pb.SshPrivateKeyAttributes{
Username: wrapperspb.String("username"),
@@ -685,7 +685,7 @@ func TestCreate(t *testing.T) {
UpdatedTime: store.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: prj.GetType(), ParentScopeId: prj.GetParentId()},
Version: 1,
Type: credential.SshPrivateKeySubtype.String(),
Type: globals.SshPrivateKeySubtype.String(),
AuthorizedActions: testAuthorizedActions,
},
},
@@ -694,7 +694,7 @@ func TestCreate(t *testing.T) {
name: "valid-spk-with-passphrase",
req: &pbs.CreateCredentialRequest{Item: &pb.Credential{
CredentialStoreId: store.GetPublicId(),
Type: credential.SshPrivateKeySubtype.String(),
Type: globals.SshPrivateKeySubtype.String(),
Attrs: &pb.Credential_SshPrivateKeyAttributes{
SshPrivateKeyAttributes: &pb.SshPrivateKeyAttributes{
Username: wrapperspb.String("username"),
@@ -713,7 +713,7 @@ func TestCreate(t *testing.T) {
UpdatedTime: store.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: prj.GetType(), ParentScopeId: prj.GetParentId()},
Version: 1,
Type: credential.SshPrivateKeySubtype.String(),
Type: globals.SshPrivateKeySubtype.String(),
AuthorizedActions: testAuthorizedActions,
},
},
@@ -722,7 +722,7 @@ func TestCreate(t *testing.T) {
name: "valid-json",
req: &pbs.CreateCredentialRequest{Item: &pb.Credential{
CredentialStoreId: store.GetPublicId(),
Type: credential.JsonSubtype.String(),
Type: globals.JsonSubtype.String(),
Attrs: &pb.Credential_JsonAttributes{
JsonAttributes: &pb.JsonAttributes{
Object: obj.Struct,
@@ -739,7 +739,7 @@ func TestCreate(t *testing.T) {
UpdatedTime: store.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: prj.GetType(), ParentScopeId: prj.GetParentId()},
Version: 1,
Type: credential.JsonSubtype.String(),
Type: globals.JsonSubtype.String(),
AuthorizedActions: testAuthorizedActions,
},
},
@@ -779,7 +779,7 @@ func TestCreate(t *testing.T) {
require.NoError(err)
switch tc.req.Item.Type {
case credential.UsernamePasswordSubtype.String():
case globals.UsernamePasswordSubtype.String():
password := tc.req.GetItem().GetUsernamePasswordAttributes().GetPassword().GetValue()
hm, err := crypto.HmacSha256(ctx, []byte(password), databaseWrapper, []byte(store.GetPublicId()), nil, crypto.WithEd25519())
require.NoError(err)
@@ -790,7 +790,7 @@ func TestCreate(t *testing.T) {
assert.Equal(base64.RawURLEncoding.EncodeToString([]byte(hm)), got.GetItem().GetUsernamePasswordAttributes().GetPasswordHmac())
assert.Empty(got.GetItem().GetUsernamePasswordAttributes().GetPassword())
case credential.SshPrivateKeySubtype.String():
case globals.SshPrivateKeySubtype.String():
pk := tc.req.GetItem().GetSshPrivateKeyAttributes().GetPrivateKey().GetValue()
hm, err := crypto.HmacSha256(ctx, []byte(pk), databaseWrapper, []byte(store.GetPublicId()), nil)
require.NoError(err)
@@ -809,7 +809,7 @@ func TestCreate(t *testing.T) {
assert.Empty(got.GetItem().GetSshPrivateKeyAttributes().GetPrivateKeyPassphrase())
}
case credential.JsonSubtype.String():
case globals.JsonSubtype.String():
hm, err := crypto.HmacSha256(ctx, objBytes, databaseWrapper, []byte(store.GetPublicId()), nil)
require.NoError(err)
@@ -395,7 +395,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (credential.Store,
const op = "credentialstores.(Service).getFromRepo"
switch subtypes.SubtypeFromId(domain, id) {
case vault.Subtype:
case globals.VaultSubtype:
repo, err := s.vaultRepoFn()
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -408,7 +408,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (credential.Store,
return cs, nil
}
case static.Subtype:
case globals.StaticSubtype:
repo, err := s.staticRepoFn()
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -429,7 +429,7 @@ func (s Service) createInRepo(ctx context.Context, projId string, item *pb.Crede
const op = "credentialstores.(Service).createInRepo"
switch item.Type {
case vault.Subtype.String():
case globals.VaultSubtype.String():
cs, err := toStorageVaultStore(ctx, projId, item)
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -444,7 +444,7 @@ func (s Service) createInRepo(ctx context.Context, projId string, item *pb.Crede
}
return out, nil
case static.Subtype.String():
case globals.StaticSubtype.String():
cs, err := toStorageStaticStore(ctx, projId, item)
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -476,7 +476,7 @@ func (s Service) updateInRepo(ctx context.Context, projId, id string, mask []str
}
switch subtypes.SubtypeFromId(domain, id) {
case vault.Subtype:
case globals.VaultSubtype:
cs, err := toStorageVaultStore(ctx, projId, item)
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -492,7 +492,7 @@ func (s Service) updateInRepo(ctx context.Context, projId, id string, mask []str
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to update credential store"))
}
case static.Subtype:
case globals.StaticSubtype:
cs, err := toStorageStaticStore(ctx, projId, item)
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -519,7 +519,7 @@ func (s Service) deleteFromRepo(ctx context.Context, id string) (bool, error) {
var rows int
switch subtypes.SubtypeFromId(domain, id) {
case vault.Subtype:
case globals.VaultSubtype:
repo, err := s.vaultRepoFn()
if err != nil {
return false, err
@@ -532,7 +532,7 @@ func (s Service) deleteFromRepo(ctx context.Context, id string) (bool, error) {
return false, errors.Wrap(ctx, err, op, errors.WithMsg("unable to delete credential store"))
}
case static.Subtype:
case globals.StaticSubtype:
repo, err := s.staticRepoFn()
if err != nil {
return false, err
@@ -582,7 +582,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth.
}
default:
switch subtypes.SubtypeFromId(domain, id) {
case vault.Subtype:
case globals.VaultSubtype:
cs, err := vaultRepo.LookupCredentialStore(ctx, id)
if err != nil {
res.Error = err
@@ -594,7 +594,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth.
}
parentId = cs.GetProjectId()
case static.Subtype:
case globals.StaticSubtype:
var err error
cs, err := staticRepo.LookupCredentialStore(ctx, id)
if err != nil {
@@ -658,7 +658,7 @@ func toProto(ctx context.Context, in credential.Store, opt ...handlers.Option) (
}
if outputFields.Has(globals.AttributesField) {
switch subtypes.SubtypeFromId(domain, in.GetPublicId()) {
case vault.Subtype:
case globals.VaultSubtype:
vaultIn, ok := in.(*vault.CredentialStore)
if !ok {
return nil, errors.New(ctx, errors.Internal, op, "unable to cast to vault credential store")
@@ -791,7 +791,7 @@ func validateCreateRequest(ctx context.Context, req *pbs.CreateCredentialStoreRe
badFields["scope_id"] = "This field must be a valid project scope id."
}
switch subtypes.SubtypeFromType(domain, req.GetItem().GetType()) {
case vault.Subtype:
case globals.VaultSubtype:
attrs := req.GetItem().GetVaultCredentialStoreAttributes()
if attrs == nil {
badFields[globals.AttributesField] = "Attributes are required for creating a vault credential store"
@@ -828,7 +828,7 @@ func validateCreateRequest(ctx context.Context, req *pbs.CreateCredentialStoreRe
if len(cs) > 0 && pk == nil {
badFields[clientCertField] = "Cannot set a client certificate without a private key."
}
case static.Subtype:
case globals.StaticSubtype:
// No additional validation required for static credential store
default:
badFields[globals.TypeField] = "This is a required field and must be a known credential store type."
@@ -841,8 +841,8 @@ func validateUpdateRequest(ctx context.Context, req *pbs.UpdateCredentialStoreRe
return handlers.ValidateUpdateRequest(req, req.GetItem(), func() map[string]string {
badFields := map[string]string{}
switch subtypes.SubtypeFromId(domain, req.GetId()) {
case vault.Subtype:
if req.GetItem().GetType() != "" && subtypes.SubtypeFromType(domain, req.GetItem().GetType()) != vault.Subtype {
case globals.VaultSubtype:
if req.GetItem().GetType() != "" && subtypes.SubtypeFromType(domain, req.GetItem().GetType()) != globals.VaultSubtype {
badFields["type"] = "Cannot modify resource type."
}
attrs := req.GetItem().GetVaultCredentialStoreAttributes()
@@ -904,10 +904,10 @@ func calculateAuthorizedCollectionActions(ctx context.Context, authResults auth.
var collectionActions map[string]*structpb.ListValue
var err error
switch subtypes.SubtypeFromId(domain, id) {
case vault.Subtype:
case globals.VaultSubtype:
collectionActions, err = auth.CalculateAuthorizedCollectionActions(ctx, authResults, vaultCollectionTypeMap, authResults.Scope.Id, id)
case static.Subtype:
case globals.StaticSubtype:
collectionActions, err = auth.CalculateAuthorizedCollectionActions(ctx, authResults, staticCollectionTypeMap, authResults.Scope.Id, id)
}
if err != nil {
@@ -92,7 +92,7 @@ func TestList(t *testing.T) {
CreatedTime: s.GetCreateTime().GetTimestamp(),
UpdatedTime: s.GetUpdateTime().GetTimestamp(),
Version: s.GetVersion(),
Type: vault.Subtype.String(),
Type: globals.VaultSubtype.String(),
AuthorizedActions: testAuthorizedActions,
AuthorizedCollectionActions: testAuthorizedVaultCollectionActions,
Attrs: &pb.CredentialStore_VaultCredentialStoreAttributes{
@@ -116,7 +116,7 @@ func TestList(t *testing.T) {
CreatedTime: s.GetCreateTime().GetTimestamp(),
UpdatedTime: s.GetUpdateTime().GetTimestamp(),
Version: s.GetVersion(),
Type: credstatic.Subtype.String(),
Type: globals.StaticSubtype.String(),
AuthorizedActions: testAuthorizedActions,
AuthorizedCollectionActions: testAuthorizedStaticCollectionActions,
})
@@ -257,7 +257,7 @@ func TestCreateVault(t *testing.T) {
name: "missing ca certificate",
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Type: vault.Subtype.String(),
Type: globals.VaultSubtype.String(),
Attrs: &pb.CredentialStore_VaultCredentialStoreAttributes{
VaultCredentialStoreAttributes: &pb.VaultCredentialStoreAttributes{
Address: wrapperspb.String(v.Addr),
@@ -274,7 +274,7 @@ func TestCreateVault(t *testing.T) {
name: "Bad token",
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Type: vault.Subtype.String(),
Type: globals.VaultSubtype.String(),
Attrs: &pb.CredentialStore_VaultCredentialStoreAttributes{
VaultCredentialStoreAttributes: &pb.VaultCredentialStoreAttributes{
Address: wrapperspb.String(v.Addr),
@@ -292,7 +292,7 @@ func TestCreateVault(t *testing.T) {
name: "Define only client cert",
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Type: vault.Subtype.String(),
Type: globals.VaultSubtype.String(),
Attrs: &pb.CredentialStore_VaultCredentialStoreAttributes{
VaultCredentialStoreAttributes: &pb.VaultCredentialStoreAttributes{
Address: wrapperspb.String(v.Addr),
@@ -309,7 +309,7 @@ func TestCreateVault(t *testing.T) {
name: "Define only client cert key",
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Type: vault.Subtype.String(),
Type: globals.VaultSubtype.String(),
Attrs: &pb.CredentialStore_VaultCredentialStoreAttributes{
VaultCredentialStoreAttributes: &pb.VaultCredentialStoreAttributes{
Address: wrapperspb.String(v.Addr),
@@ -326,7 +326,7 @@ func TestCreateVault(t *testing.T) {
name: "Define key in both client cert payload and key field",
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Type: vault.Subtype.String(),
Type: globals.VaultSubtype.String(),
Attrs: &pb.CredentialStore_VaultCredentialStoreAttributes{
VaultCredentialStoreAttributes: &pb.VaultCredentialStoreAttributes{
Address: wrapperspb.String(v.Addr),
@@ -345,7 +345,7 @@ func TestCreateVault(t *testing.T) {
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Id: globals.VaultCredentialStorePrefix + "_notallowed",
Type: vault.Subtype.String(),
Type: globals.VaultSubtype.String(),
Attrs: &pb.CredentialStore_VaultCredentialStoreAttributes{
VaultCredentialStoreAttributes: &pb.VaultCredentialStoreAttributes{
Address: wrapperspb.String(v.Addr),
@@ -361,7 +361,7 @@ func TestCreateVault(t *testing.T) {
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
CreatedTime: timestamppb.Now(),
Type: vault.Subtype.String(),
Type: globals.VaultSubtype.String(),
Attrs: &pb.CredentialStore_VaultCredentialStoreAttributes{
VaultCredentialStoreAttributes: &pb.VaultCredentialStoreAttributes{
Address: wrapperspb.String(v.Addr),
@@ -377,7 +377,7 @@ func TestCreateVault(t *testing.T) {
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
UpdatedTime: timestamppb.Now(),
Type: vault.Subtype.String(),
Type: globals.VaultSubtype.String(),
Attrs: &pb.CredentialStore_VaultCredentialStoreAttributes{
VaultCredentialStoreAttributes: &pb.VaultCredentialStoreAttributes{
Address: wrapperspb.String(v.Addr),
@@ -392,7 +392,7 @@ func TestCreateVault(t *testing.T) {
name: "Can't specify worker filter",
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Type: vault.Subtype.String(),
Type: globals.VaultSubtype.String(),
Attrs: &pb.CredentialStore_VaultCredentialStoreAttributes{
VaultCredentialStoreAttributes: &pb.VaultCredentialStoreAttributes{
Address: wrapperspb.String(v.Addr),
@@ -424,7 +424,7 @@ func TestCreateVault(t *testing.T) {
name: "Must specify vault VaultAddress",
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Type: vault.Subtype.String(),
Type: globals.VaultSubtype.String(),
Attrs: &pb.CredentialStore_VaultCredentialStoreAttributes{
VaultCredentialStoreAttributes: &pb.VaultCredentialStoreAttributes{
Token: wrapperspb.String(newToken()),
@@ -438,7 +438,7 @@ func TestCreateVault(t *testing.T) {
name: "Must specify vault token",
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Type: vault.Subtype.String(),
Type: globals.VaultSubtype.String(),
Attrs: &pb.CredentialStore_VaultCredentialStoreAttributes{
VaultCredentialStoreAttributes: &pb.VaultCredentialStoreAttributes{
Address: wrapperspb.String(v.Addr),
@@ -452,7 +452,7 @@ func TestCreateVault(t *testing.T) {
name: "Create a valid vault CredentialStore with client cert and key in same field",
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Type: vault.Subtype.String(),
Type: globals.VaultSubtype.String(),
Attrs: &pb.CredentialStore_VaultCredentialStoreAttributes{
VaultCredentialStoreAttributes: &pb.VaultCredentialStoreAttributes{
Address: wrapperspb.String(v.Addr),
@@ -469,7 +469,7 @@ func TestCreateVault(t *testing.T) {
ScopeId: prj.GetPublicId(),
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: prj.GetType(), ParentScopeId: prj.GetParentId()},
Version: 1,
Type: vault.Subtype.String(),
Type: globals.VaultSubtype.String(),
Attrs: &pb.CredentialStore_VaultCredentialStoreAttributes{
VaultCredentialStoreAttributes: &pb.VaultCredentialStoreAttributes{
CaCert: wrapperspb.String(string(v.CaCert)),
@@ -491,7 +491,7 @@ func TestCreateVault(t *testing.T) {
ScopeId: prj.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "name"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: vault.Subtype.String(),
Type: globals.VaultSubtype.String(),
Attrs: &pb.CredentialStore_VaultCredentialStoreAttributes{
VaultCredentialStoreAttributes: &pb.VaultCredentialStoreAttributes{
Address: wrapperspb.String(v.Addr),
@@ -511,7 +511,7 @@ func TestCreateVault(t *testing.T) {
Description: &wrapperspb.StringValue{Value: "desc"},
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: prj.GetType(), ParentScopeId: prj.GetParentId()},
Version: 1,
Type: vault.Subtype.String(),
Type: globals.VaultSubtype.String(),
Attrs: &pb.CredentialStore_VaultCredentialStoreAttributes{
VaultCredentialStoreAttributes: &pb.VaultCredentialStoreAttributes{
CaCert: wrapperspb.String(string(v.CaCert)),
@@ -629,7 +629,7 @@ func TestCreateStatic(t *testing.T) {
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Id: globals.StaticCredentialStorePrefix + "_notallowed",
Type: credstatic.Subtype.String(),
Type: globals.StaticSubtype.String(),
}},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
@@ -639,7 +639,7 @@ func TestCreateStatic(t *testing.T) {
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
CreatedTime: timestamppb.Now(),
Type: credstatic.Subtype.String(),
Type: globals.StaticSubtype.String(),
}},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
@@ -649,7 +649,7 @@ func TestCreateStatic(t *testing.T) {
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
UpdatedTime: timestamppb.Now(),
Type: credstatic.Subtype.String(),
Type: globals.StaticSubtype.String(),
}},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
@@ -666,7 +666,7 @@ func TestCreateStatic(t *testing.T) {
name: "Create a valid static CredentialStore",
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Type: credstatic.Subtype.String(),
Type: globals.StaticSubtype.String(),
}},
idPrefix: globals.StaticCredentialStorePrefix + "_",
res: &pbs.CreateCredentialStoreResponse{
@@ -675,7 +675,7 @@ func TestCreateStatic(t *testing.T) {
ScopeId: prj.GetPublicId(),
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: prj.GetType(), ParentScopeId: prj.GetParentId()},
Version: 1,
Type: credstatic.Subtype.String(),
Type: globals.StaticSubtype.String(),
AuthorizedActions: testAuthorizedActions,
AuthorizedCollectionActions: testAuthorizedStaticCollectionActions,
},
@@ -687,7 +687,7 @@ func TestCreateStatic(t *testing.T) {
ScopeId: prj.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "name"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: credstatic.Subtype.String(),
Type: globals.StaticSubtype.String(),
}},
idPrefix: globals.StaticCredentialStorePrefix + "_",
res: &pbs.CreateCredentialStoreResponse{
@@ -696,7 +696,7 @@ func TestCreateStatic(t *testing.T) {
ScopeId: prj.GetPublicId(),
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: prj.GetType(), ParentScopeId: prj.GetParentId()},
Version: 1,
Type: credstatic.Subtype.String(),
Type: globals.StaticSubtype.String(),
AuthorizedActions: testAuthorizedActions,
Name: &wrapperspb.StringValue{Value: "name"},
Description: &wrapperspb.StringValue{Value: "desc"},
@@ -791,7 +791,7 @@ func TestGet(t *testing.T) {
Id: vaultStore.GetPublicId(),
ScopeId: vaultStore.GetProjectId(),
Scope: &scopepb.ScopeInfo{Id: vaultStore.GetProjectId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
Type: vault.Subtype.String(),
Type: globals.VaultSubtype.String(),
AuthorizedActions: testAuthorizedActions,
AuthorizedCollectionActions: testAuthorizedVaultCollectionActions,
CreatedTime: vaultStore.CreateTime.GetTimestamp(),
@@ -817,7 +817,7 @@ func TestGet(t *testing.T) {
Id: staticStore.GetPublicId(),
ScopeId: staticStore.GetProjectId(),
Scope: &scopepb.ScopeInfo{Id: staticStore.GetProjectId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
Type: credstatic.Subtype.String(),
Type: globals.StaticSubtype.String(),
AuthorizedActions: testAuthorizedActions,
AuthorizedCollectionActions: testAuthorizedStaticCollectionActions,
CreatedTime: staticStore.CreateTime.GetTimestamp(),
@@ -834,7 +834,7 @@ func TestGet(t *testing.T) {
Id: staticStorePrev.GetPublicId(),
ScopeId: staticStorePrev.GetProjectId(),
Scope: &scopepb.ScopeInfo{Id: staticStorePrev.GetProjectId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
Type: credstatic.Subtype.String(),
Type: globals.StaticSubtype.String(),
AuthorizedActions: testAuthorizedActions,
AuthorizedCollectionActions: testAuthorizedStaticCollectionActions,
CreatedTime: staticStorePrev.CreateTime.GetTimestamp(),
@@ -57,12 +57,12 @@ var (
action.List,
}
collectionTypeMap = map[subtypes.Subtype]map[resource.Type]action.ActionSet{
static.Subtype: {
collectionTypeMap = map[globals.Subtype]map[resource.Type]action.ActionSet{
globals.StaticSubtype: {
resource.HostSet: host_sets.CollectionActions,
resource.Host: hosts.CollectionActions,
},
hostplugin.Subtype: {
globals.PluginSubtype: {
resource.HostSet: host_sets.CollectionActions,
resource.Host: action.ActionSet{
action.List,
@@ -183,12 +183,12 @@ func (s Service) ListHostCatalogs(ctx context.Context, req *pbs.ListHostCatalogs
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authorizedActions))
}
if outputFields.Has(globals.AuthorizedCollectionActionsField) {
var subtype subtypes.Subtype
var subtype globals.Subtype
switch item.(type) {
case *static.HostCatalog:
subtype = static.Subtype
subtype = globals.StaticSubtype
case *hostplugin.HostCatalog:
subtype = hostplugin.Subtype
subtype = globals.PluginSubtype
}
if subtype != "" {
collectionActions, err := auth.CalculateAuthorizedCollectionActions(ctx, authResults, collectionTypeMap[subtype], authResults.Scope.Id, item.GetPublicId())
@@ -253,12 +253,12 @@ func (s Service) GetHostCatalog(ctx context.Context, req *pbs.GetHostCatalogRequ
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, hc.GetPublicId(), IdActions).Strings()))
}
if outputFields.Has(globals.AuthorizedCollectionActionsField) {
var subtype subtypes.Subtype
var subtype globals.Subtype
switch hc.(type) {
case *static.HostCatalog:
subtype = static.Subtype
subtype = globals.StaticSubtype
case *hostplugin.HostCatalog:
subtype = hostplugin.Subtype
subtype = globals.PluginSubtype
}
if subtype != "" {
collectionActions, err := auth.CalculateAuthorizedCollectionActions(ctx, authResults, collectionTypeMap[subtype], authResults.Scope.Id, hc.GetPublicId())
@@ -310,12 +310,12 @@ func (s Service) CreateHostCatalog(ctx context.Context, req *pbs.CreateHostCatal
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, hc.GetPublicId(), IdActions).Strings()))
}
if outputFields.Has(globals.AuthorizedCollectionActionsField) {
var subtype subtypes.Subtype
var subtype globals.Subtype
switch hc.(type) {
case *static.HostCatalog:
subtype = static.Subtype
subtype = globals.StaticSubtype
case *hostplugin.HostCatalog:
subtype = hostplugin.Subtype
subtype = globals.PluginSubtype
}
if subtype != "" {
collectionActions, err := auth.CalculateAuthorizedCollectionActions(ctx, authResults, collectionTypeMap[subtype], authResults.Scope.Id, hc.GetPublicId())
@@ -373,12 +373,12 @@ func (s Service) UpdateHostCatalog(ctx context.Context, req *pbs.UpdateHostCatal
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, hc.GetPublicId(), IdActions).Strings()))
}
if outputFields.Has(globals.AuthorizedCollectionActionsField) {
var subtype subtypes.Subtype
var subtype globals.Subtype
switch hc.(type) {
case *static.HostCatalog:
subtype = static.Subtype
subtype = globals.StaticSubtype
case *hostplugin.HostCatalog:
subtype = hostplugin.Subtype
subtype = globals.PluginSubtype
}
if subtype != "" {
collectionActions, err := auth.CalculateAuthorizedCollectionActions(ctx, authResults, collectionTypeMap[subtype], authResults.Scope.Id, hc.GetPublicId())
@@ -416,7 +416,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (host.Catalog, *plu
var plg *plugins.PluginInfo
var cat host.Catalog
switch subtypes.SubtypeFromId(domain, id) {
case static.Subtype:
case globals.StaticSubtype:
repo, err := s.staticRepoFn()
if err != nil {
return nil, nil, err
@@ -429,7 +429,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (host.Catalog, *plu
return nil, nil, handlers.NotFoundErrorf("Host Catalog %q doesn't exist.", id)
}
cat = hc
case hostplugin.Subtype:
case globals.PluginSubtype:
repo, err := s.pluginHostRepoFn()
if err != nil {
return nil, nil, err
@@ -538,7 +538,7 @@ func (s Service) createPluginInRepo(ctx context.Context, projId string, req *pbs
func (s Service) createInRepo(ctx context.Context, projId string, req *pbs.CreateHostCatalogRequest) (hc host.Catalog, info *plugins.PluginInfo, err error) {
var plg *plugins.PluginInfo
switch subtypes.SubtypeFromType(domain, req.GetItem().GetType()) {
case static.Subtype:
case globals.StaticSubtype:
hc, err = s.createStaticInRepo(ctx, projId, req.GetItem())
default:
hc, plg, err = s.createPluginInRepo(ctx, projId, req)
@@ -602,9 +602,9 @@ func (s Service) updatePluginInRepo(ctx context.Context, projId, id string, mask
func (s Service) updateInRepo(ctx context.Context, projId string, req *pbs.UpdateHostCatalogRequest) (hc host.Catalog, plg *plugins.PluginInfo, err error) {
const op = "host_catalogs.(Service).updateInRepo"
switch subtypes.SubtypeFromId(domain, req.GetId()) {
case static.Subtype:
case globals.StaticSubtype:
hc, err = s.updateStaticInRepo(ctx, projId, req.GetId(), req.GetUpdateMask().GetPaths(), req.GetItem())
case hostplugin.Subtype:
case globals.PluginSubtype:
hc, plg, err = s.updatePluginInRepo(ctx, projId, req.GetId(), req.GetUpdateMask().GetPaths(), req.GetItem())
}
return
@@ -614,7 +614,7 @@ func (s Service) deleteFromRepo(ctx context.Context, id string) (bool, error) {
const op = "host_catalogs.(Service).deleteFromRepo"
rows := 0
switch subtypes.SubtypeFromId(domain, id) {
case static.Subtype:
case globals.StaticSubtype:
repo, err := s.staticRepoFn()
if err != nil {
return false, errors.Wrap(ctx, err, op)
@@ -623,7 +623,7 @@ func (s Service) deleteFromRepo(ctx context.Context, id string) (bool, error) {
if err != nil {
return false, errors.Wrap(ctx, err, op, errors.WithMsg("unable to delete host"))
}
case hostplugin.Subtype:
case globals.PluginSubtype:
repo, err := s.pluginHostRepoFn()
if err != nil {
return false, errors.Wrap(ctx, err, op)
@@ -660,7 +660,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth.
}
default:
switch subtypes.SubtypeFromId(domain, id) {
case static.Subtype:
case globals.StaticSubtype:
repo, err := s.staticRepoFn()
if err != nil {
res.Error = err
@@ -677,7 +677,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth.
}
parentId = cat.GetProjectId()
opts = append(opts, auth.WithId(id))
case hostplugin.Subtype:
case globals.PluginSubtype:
repo, err := s.pluginHostRepoFn()
if err != nil {
res.Error = err
@@ -729,9 +729,9 @@ func toProto(ctx context.Context, in host.Catalog, opt ...handlers.Option) (*pb.
if outputFields.Has(globals.TypeField) {
switch in.(type) {
case *static.HostCatalog:
out.Type = static.Subtype.String()
out.Type = globals.StaticSubtype.String()
case *hostplugin.HostCatalog:
out.Type = hostplugin.Subtype.String()
out.Type = globals.PluginSubtype.String()
}
}
if outputFields.Has(globals.DescriptionField) && in.GetDescription() != "" {
@@ -844,8 +844,8 @@ func validateCreateRequest(req *pbs.CreateHostCatalogRequest) error {
badFields[globals.SecretsHmacField] = "This is a read only field."
}
switch subtypes.SubtypeFromType(domain, req.GetItem().GetType()) {
case static.Subtype:
case hostplugin.Subtype:
case globals.StaticSubtype:
case globals.PluginSubtype:
if req.GetItem().GetPlugin() != nil {
badFields[globals.PluginField] = "This is a read only field."
}
@@ -858,7 +858,7 @@ func validateCreateRequest(req *pbs.CreateHostCatalogRequest) error {
badFields[globals.PluginNameField] = "Can't set the plugin id field along with this field."
}
default:
badFields[globals.TypeField] = fmt.Sprintf("This is a required field and must be either %q or %q.", static.Subtype.String(), hostplugin.Subtype.String())
badFields[globals.TypeField] = fmt.Sprintf("This is a required field and must be either %q or %q.", globals.StaticSubtype.String(), globals.PluginSubtype.String())
}
return badFields
})
@@ -871,15 +871,15 @@ func validateUpdateRequest(req *pbs.UpdateHostCatalogRequest) error {
badFields[globals.SecretsHmacField] = "This is a read only field."
}
switch subtypes.SubtypeFromId(domain, req.GetId()) {
case static.Subtype:
if req.GetItem().GetType() != "" && subtypes.SubtypeFromType(domain, req.GetItem().GetType()) != static.Subtype {
case globals.StaticSubtype:
if req.GetItem().GetType() != "" && subtypes.SubtypeFromType(domain, req.GetItem().GetType()) != globals.StaticSubtype {
badFields[globals.TypeField] = "Cannot modify resource type."
}
if req.GetItem().GetPlugin() != nil {
badFields[globals.PluginField] = "This field is unused for this type of host catalog."
}
case hostplugin.Subtype:
if req.GetItem().GetType() != "" && subtypes.SubtypeFromType(domain, req.GetItem().GetType()) != hostplugin.Subtype {
case globals.PluginSubtype:
if req.GetItem().GetType() != "" && subtypes.SubtypeFromType(domain, req.GetItem().GetType()) != globals.PluginSubtype {
badFields[globals.TypeField] = "Cannot modify resource type."
}
if req.GetItem().GetPlugin() != nil {
@@ -28,7 +28,6 @@ import (
"github.com/hashicorp/boundary/internal/plugin/loopback"
"github.com/hashicorp/boundary/internal/scheduler"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/hashicorp/boundary/internal/types/subtypes"
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/hostcatalogs"
"github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/plugins"
scopepb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/scopes"
@@ -46,8 +45,8 @@ import (
"github.com/stretchr/testify/require"
)
var authorizedCollectionActions = map[subtypes.Subtype]map[string]*structpb.ListValue{
static.Subtype: {
var authorizedCollectionActions = map[globals.Subtype]map[string]*structpb.ListValue{
globals.StaticSubtype: {
"host-sets": {
Values: []*structpb.Value{
structpb.NewStringValue("create"),
@@ -61,7 +60,7 @@ var authorizedCollectionActions = map[subtypes.Subtype]map[string]*structpb.List
},
},
},
hostplugin.Subtype: {
globals.PluginSubtype: {
"host-sets": {
Values: []*structpb.Value{
structpb.NewStringValue("create"),
@@ -113,7 +112,7 @@ func TestGet_Static(t *testing.T) {
UpdatedTime: hc.UpdateTime.GetTimestamp(),
Type: "static",
AuthorizedActions: testAuthorizedActions,
AuthorizedCollectionActions: authorizedCollectionActions[static.Subtype],
AuthorizedCollectionActions: authorizedCollectionActions[globals.StaticSubtype],
}
cases := []struct {
@@ -215,9 +214,9 @@ func TestGet_Plugin(t *testing.T) {
},
CreatedTime: hc.CreateTime.GetTimestamp(),
UpdatedTime: hc.UpdateTime.GetTimestamp(),
Type: hostplugin.Subtype.String(),
Type: globals.PluginSubtype.String(),
AuthorizedActions: testAuthorizedActions,
AuthorizedCollectionActions: authorizedCollectionActions[hostplugin.Subtype],
AuthorizedCollectionActions: authorizedCollectionActions[globals.PluginSubtype],
SecretsHmac: base58.Encode([]byte("foobar")),
}
@@ -321,7 +320,7 @@ func TestList(t *testing.T) {
Version: 1,
Type: "static",
AuthorizedActions: testAuthorizedActions,
AuthorizedCollectionActions: authorizedCollectionActions[static.Subtype],
AuthorizedCollectionActions: authorizedCollectionActions[globals.StaticSubtype],
})
}
@@ -343,9 +342,9 @@ func TestList(t *testing.T) {
Description: plg.GetDescription(),
},
Version: 1,
Type: hostplugin.Subtype.String(),
Type: globals.PluginSubtype.String(),
AuthorizedActions: testAuthorizedActions,
AuthorizedCollectionActions: authorizedCollectionActions[hostplugin.Subtype],
AuthorizedCollectionActions: authorizedCollectionActions[globals.PluginSubtype],
}
wantSomeCatalogs = append(wantSomeCatalogs, cat)
testPluginCatalogs = append(testPluginCatalogs, cat)
@@ -362,7 +361,7 @@ func TestList(t *testing.T) {
Version: 1,
Type: "static",
AuthorizedActions: testAuthorizedActions,
AuthorizedCollectionActions: authorizedCollectionActions[static.Subtype],
AuthorizedCollectionActions: authorizedCollectionActions[globals.StaticSubtype],
})
}
@@ -383,9 +382,9 @@ func TestList(t *testing.T) {
Description: diffPlg.GetDescription(),
},
Version: 1,
Type: hostplugin.Subtype.String(),
Type: globals.PluginSubtype.String(),
AuthorizedActions: testAuthorizedActions,
AuthorizedCollectionActions: authorizedCollectionActions[hostplugin.Subtype],
AuthorizedCollectionActions: authorizedCollectionActions[globals.PluginSubtype],
})
}
@@ -719,7 +718,7 @@ func TestCreate_Static(t *testing.T) {
Description: &wrappers.StringValue{Value: "desc"},
Type: "static",
AuthorizedActions: testAuthorizedActions,
AuthorizedCollectionActions: authorizedCollectionActions[static.Subtype],
AuthorizedCollectionActions: authorizedCollectionActions[globals.StaticSubtype],
},
},
},
@@ -870,7 +869,7 @@ func TestCreate_Plugin(t *testing.T) {
ScopeId: proj.GetPublicId(),
Name: &wrappers.StringValue{Value: "name"},
Description: &wrappers.StringValue{Value: "desc"},
Type: hostplugin.Subtype.String(),
Type: globals.PluginSubtype.String(),
PluginId: plg.GetPublicId(),
}},
res: &pbs.CreateHostCatalogResponse{
@@ -886,9 +885,9 @@ func TestCreate_Plugin(t *testing.T) {
},
Name: &wrappers.StringValue{Value: "name"},
Description: &wrappers.StringValue{Value: "desc"},
Type: hostplugin.Subtype.String(),
Type: globals.PluginSubtype.String(),
AuthorizedActions: testAuthorizedActions,
AuthorizedCollectionActions: authorizedCollectionActions[hostplugin.Subtype],
AuthorizedCollectionActions: authorizedCollectionActions[globals.PluginSubtype],
},
},
},
@@ -896,7 +895,7 @@ func TestCreate_Plugin(t *testing.T) {
name: "Cant create in org",
req: &pbs.CreateHostCatalogRequest{Item: &pb.HostCatalog{
ScopeId: org.GetParentId(),
Type: hostplugin.Subtype.String(),
Type: globals.PluginSubtype.String(),
PluginId: plg.GetPublicId(),
}},
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
@@ -905,7 +904,7 @@ func TestCreate_Plugin(t *testing.T) {
name: "Cant create in global",
req: &pbs.CreateHostCatalogRequest{Item: &pb.HostCatalog{
ScopeId: scope.Global.String(),
Type: hostplugin.Subtype.String(),
Type: globals.PluginSubtype.String(),
PluginId: plg.GetPublicId(),
}},
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
@@ -932,7 +931,7 @@ func TestCreate_Plugin(t *testing.T) {
req: &pbs.CreateHostCatalogRequest{Item: &pb.HostCatalog{
Id: "not allowed to be set",
ScopeId: proj.GetPublicId(),
Type: hostplugin.Subtype.String(),
Type: globals.PluginSubtype.String(),
PluginId: plg.GetPublicId(),
}},
res: nil,
@@ -943,7 +942,7 @@ func TestCreate_Plugin(t *testing.T) {
req: &pbs.CreateHostCatalogRequest{Item: &pb.HostCatalog{
CreatedTime: timestamppb.Now(),
ScopeId: proj.GetPublicId(),
Type: hostplugin.Subtype.String(),
Type: globals.PluginSubtype.String(),
PluginId: plg.GetPublicId(),
}},
res: nil,
@@ -954,7 +953,7 @@ func TestCreate_Plugin(t *testing.T) {
req: &pbs.CreateHostCatalogRequest{Item: &pb.HostCatalog{
UpdatedTime: timestamppb.Now(),
ScopeId: proj.GetPublicId(),
Type: hostplugin.Subtype.String(),
Type: globals.PluginSubtype.String(),
PluginId: plg.GetPublicId(),
}},
res: nil,
@@ -1077,7 +1076,7 @@ func TestUpdate_Static(t *testing.T) {
CreatedTime: hc.GetCreateTime().GetTimestamp(),
Type: "static",
AuthorizedActions: testAuthorizedActions,
AuthorizedCollectionActions: authorizedCollectionActions[static.Subtype],
AuthorizedCollectionActions: authorizedCollectionActions[globals.StaticSubtype],
},
},
},
@@ -1103,7 +1102,7 @@ func TestUpdate_Static(t *testing.T) {
CreatedTime: hc.GetCreateTime().GetTimestamp(),
Type: "static",
AuthorizedActions: testAuthorizedActions,
AuthorizedCollectionActions: authorizedCollectionActions[static.Subtype],
AuthorizedCollectionActions: authorizedCollectionActions[globals.StaticSubtype],
},
},
},
@@ -1158,7 +1157,7 @@ func TestUpdate_Static(t *testing.T) {
CreatedTime: hc.GetCreateTime().GetTimestamp(),
Type: "static",
AuthorizedActions: testAuthorizedActions,
AuthorizedCollectionActions: authorizedCollectionActions[static.Subtype],
AuthorizedCollectionActions: authorizedCollectionActions[globals.StaticSubtype],
},
},
},
@@ -1181,7 +1180,7 @@ func TestUpdate_Static(t *testing.T) {
CreatedTime: hc.GetCreateTime().GetTimestamp(),
Type: "static",
AuthorizedActions: testAuthorizedActions,
AuthorizedCollectionActions: authorizedCollectionActions[static.Subtype],
AuthorizedCollectionActions: authorizedCollectionActions[globals.StaticSubtype],
},
},
},
@@ -1206,7 +1205,7 @@ func TestUpdate_Static(t *testing.T) {
CreatedTime: hc.GetCreateTime().GetTimestamp(),
Type: "static",
AuthorizedActions: testAuthorizedActions,
AuthorizedCollectionActions: authorizedCollectionActions[static.Subtype],
AuthorizedCollectionActions: authorizedCollectionActions[globals.StaticSubtype],
},
},
},
@@ -1231,7 +1230,7 @@ func TestUpdate_Static(t *testing.T) {
CreatedTime: hc.GetCreateTime().GetTimestamp(),
Type: "static",
AuthorizedActions: testAuthorizedActions,
AuthorizedCollectionActions: authorizedCollectionActions[static.Subtype],
AuthorizedCollectionActions: authorizedCollectionActions[globals.StaticSubtype],
},
},
},
@@ -1482,7 +1481,7 @@ func TestUpdate_Plugin(t *testing.T) {
check: func(t *testing.T, in *pb.HostCatalog) {
assert.Equal(t, "new", in.Name.GetValue())
assert.Equal(t, "desc", in.Description.GetValue())
assert.Empty(t, cmp.Diff(authorizedCollectionActions[hostplugin.Subtype], in.GetAuthorizedCollectionActions(), cmpopts.IgnoreUnexported(structpb.ListValue{}, structpb.Value{})))
assert.Empty(t, cmp.Diff(authorizedCollectionActions[globals.PluginSubtype], in.GetAuthorizedCollectionActions(), cmpopts.IgnoreUnexported(structpb.ListValue{}, structpb.Value{})))
},
},
{
@@ -35,12 +35,12 @@ import (
)
var (
maskManager = map[subtypes.Subtype]handlers.MaskManager{}
maskManager = map[globals.Subtype]handlers.MaskManager{}
// IdActions contains the set of actions that can be performed on
// individual resources
idActionsTypeMap = map[subtypes.Subtype]action.ActionSet{
static.Subtype: {
idActionsTypeMap = map[globals.Subtype]action.ActionSet{
globals.StaticSubtype: {
action.NoOp,
action.Read,
action.Update,
@@ -49,7 +49,7 @@ var (
action.SetHosts,
action.RemoveHosts,
},
hostplugin.Subtype: {
globals.PluginSubtype: {
action.NoOp,
action.Read,
action.Update,
@@ -69,14 +69,14 @@ const domain = "host"
func init() {
var err error
if maskManager[static.Subtype], err = handlers.NewMaskManager(
if maskManager[globals.StaticSubtype], err = handlers.NewMaskManager(
context.Background(),
handlers.MaskDestination{&staticstore.HostSet{}, &staticstore.UnimplementedSetFields{}},
handlers.MaskSource{&pb.HostSet{}},
); err != nil {
panic(err)
}
if maskManager[hostplugin.Subtype], err = handlers.NewMaskManager(
if maskManager[globals.PluginSubtype], err = handlers.NewMaskManager(
context.Background(),
handlers.MaskDestination{&plugstore.HostSet{}},
handlers.MaskSource{&pb.HostSet{}},
@@ -443,7 +443,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (host.Set, []host.H
var hl []host.Host
var plg *plugins.PluginInfo
switch subtypes.SubtypeFromId(domain, id) {
case static.Subtype:
case globals.StaticSubtype:
repo, err := s.staticRepoFn()
if err != nil {
return nil, nil, nil, err
@@ -459,7 +459,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (host.Set, []host.H
hl = append(hl, h)
}
hs = hset
case hostplugin.Subtype:
case globals.PluginSubtype:
repo, err := s.pluginRepoFn()
if err != nil {
return nil, nil, nil, err
@@ -493,7 +493,7 @@ func (s Service) createInRepo(ctx context.Context, projectId, catalogId string,
var hSet host.Set
var plg *plugins.PluginInfo
switch subtypes.SubtypeFromId(domain, catalogId) {
case static.Subtype:
case globals.StaticSubtype:
h, err := toStorageStaticSet(ctx, catalogId, item)
if err != nil {
return nil, nil, err
@@ -510,7 +510,7 @@ func (s Service) createInRepo(ctx context.Context, projectId, catalogId string,
return nil, nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create host set but no error returned from repository.")
}
hSet = out
case hostplugin.Subtype:
case globals.PluginSubtype:
h, err := toStoragePluginSet(ctx, catalogId, item)
if err != nil {
return nil, nil, err
@@ -542,7 +542,7 @@ func (s Service) updateStaticInRepo(ctx context.Context, projectId, catalogId st
return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("Unable to build host set for update"))
}
h.PublicId = req.GetId()
dbMask := maskManager[static.Subtype].Translate(req.GetUpdateMask().GetPaths())
dbMask := maskManager[globals.StaticSubtype].Translate(req.GetUpdateMask().GetPaths())
if len(dbMask) == 0 {
return nil, nil, handlers.InvalidArgumentErrorf("No valid fields included in the update mask.", map[string]string{"update_mask": "No valid fields provided in the update mask."})
}
@@ -572,7 +572,7 @@ func (s Service) updatePluginInRepo(ctx context.Context, projectId string, req *
return nil, nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("Unable to build host set for update"))
}
h.PublicId = req.GetId()
dbMask := maskManager[hostplugin.Subtype].Translate(req.GetUpdateMask().GetPaths(), "attributes")
dbMask := maskManager[globals.PluginSubtype].Translate(req.GetUpdateMask().GetPaths(), "attributes")
if len(dbMask) == 0 {
return nil, nil, nil, handlers.InvalidArgumentErrorf("No valid fields included in the update mask.", map[string]string{"update_mask": "No valid fields provided in the update mask."})
}
@@ -597,9 +597,9 @@ func (s Service) updatePluginInRepo(ctx context.Context, projectId string, req *
func (s Service) updateInRepo(ctx context.Context, projectId, catalogId string, req *pbs.UpdateHostSetRequest) (hs host.Set, hosts []host.Host, plg *plugins.PluginInfo, err error) {
const op = "host_sets.(Service).updateInRepo"
switch subtypes.SubtypeFromId(domain, req.GetId()) {
case static.Subtype:
case globals.StaticSubtype:
hs, hosts, err = s.updateStaticInRepo(ctx, projectId, catalogId, req)
case hostplugin.Subtype:
case globals.PluginSubtype:
hs, hosts, plg, err = s.updatePluginInRepo(ctx, projectId, req)
}
return
@@ -609,7 +609,7 @@ func (s Service) deleteFromRepo(ctx context.Context, projectId, id string) (bool
const op = "host_sets.(Service).deleteFromRepo"
rows := 0
switch subtypes.SubtypeFromId(domain, id) {
case static.Subtype:
case globals.StaticSubtype:
repo, err := s.staticRepoFn()
if err != nil {
return false, err
@@ -618,7 +618,7 @@ func (s Service) deleteFromRepo(ctx context.Context, projectId, id string) (bool
if err != nil {
return false, errors.Wrap(ctx, err, op, errors.WithMsg("unable to delete host"))
}
case hostplugin.Subtype:
case globals.PluginSubtype:
repo, err := s.pluginRepoFn()
if err != nil {
return false, err
@@ -636,7 +636,7 @@ func (s Service) listFromRepo(ctx context.Context, catalogId string, opt ...host
var plg *plugins.PluginInfo
var sets []host.Set
switch subtypes.SubtypeFromId(domain, catalogId) {
case static.Subtype:
case globals.StaticSubtype:
repo, err := s.staticRepoFn()
if err != nil {
return nil, nil, err
@@ -648,7 +648,7 @@ func (s Service) listFromRepo(ctx context.Context, catalogId string, opt ...host
for _, a := range sl {
sets = append(sets, a)
}
case hostplugin.Subtype:
case globals.PluginSubtype:
repo, err := s.pluginRepoFn()
if err != nil {
return nil, nil, err
@@ -761,7 +761,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
default:
var set host.Set
switch subtypes.SubtypeFromId(domain, id) {
case static.Subtype:
case globals.StaticSubtype:
ss, _, err := staticRepo.LookupSet(ctx, id)
if err != nil {
res.Error = err
@@ -772,7 +772,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
return nil, res
}
set = ss
case hostplugin.Subtype:
case globals.PluginSubtype:
ps, _, err := pluginRepo.LookupSet(ctx, id)
if err != nil {
res.Error = err
@@ -790,7 +790,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
var cat host.Catalog
switch subtypes.SubtypeFromId(domain, id) {
case static.Subtype:
case globals.StaticSubtype:
cs, err := staticRepo.LookupCatalog(ctx, parentId)
if err != nil {
res.Error = err
@@ -801,7 +801,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
return nil, res
}
cat = cs
case hostplugin.Subtype:
case globals.PluginSubtype:
pc, _, err := pluginRepo.LookupCatalog(ctx, parentId)
if err != nil {
res.Error = err
@@ -846,9 +846,9 @@ func toProto(ctx context.Context, in host.Set, hosts []host.Host, opt ...handler
if outputFields.Has(globals.TypeField) {
switch in.(type) {
case *static.HostSet:
out.Type = static.Subtype.String()
out.Type = globals.StaticSubtype.String()
case *hostplugin.HostSet:
out.Type = hostplugin.Subtype.String()
out.Type = globals.PluginSubtype.String()
}
}
if outputFields.Has(globals.DescriptionField) && in.GetDescription() != "" {
@@ -971,15 +971,15 @@ func validateCreateRequest(ctx context.Context, req *pbs.CreateHostSetRequest) e
}
}
switch subtypes.SubtypeFromId(domain, req.GetItem().GetHostCatalogId()) {
case static.Subtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != static.Subtype.String() {
case globals.StaticSubtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != globals.StaticSubtype.String() {
badFields[globals.TypeField] = "Doesn't match the parent resource's type."
}
if len(req.GetItem().PreferredEndpoints) > 0 {
badFields[globals.PreferredEndpointsField] = "This field is not yet supported for static host sets."
}
case hostplugin.Subtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != hostplugin.Subtype.String() {
case globals.PluginSubtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != globals.PluginSubtype.String() {
badFields[globals.TypeField] = "Doesn't match the parent resource's type."
}
if val := req.GetItem().GetSyncIntervalSeconds(); val != nil {
@@ -1002,11 +1002,11 @@ func validateUpdateRequest(ctx context.Context, req *pbs.UpdateHostSetRequest) e
}
}
switch subtypes.SubtypeFromId(domain, req.GetId()) {
case static.Subtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != static.Subtype.String() {
case globals.StaticSubtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != globals.StaticSubtype.String() {
badFields[globals.TypeField] = "Cannot modify the resource type."
}
case hostplugin.Subtype:
case globals.PluginSubtype:
if val := req.GetItem().GetSyncIntervalSeconds(); val != nil {
if val.GetValue() == 0 || val.GetValue() < -1 {
badFields[globals.SyncIntervalSecondsField] = "Must be -1 or a positive integer."
@@ -28,7 +28,6 @@ import (
"github.com/hashicorp/boundary/internal/plugin/loopback"
"github.com/hashicorp/boundary/internal/scheduler"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/hashicorp/boundary/internal/types/subtypes"
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/hostsets"
"github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/plugins"
"github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/scopes"
@@ -45,9 +44,9 @@ import (
"google.golang.org/protobuf/types/known/wrapperspb"
)
var testAuthorizedActions = map[subtypes.Subtype][]string{
static.Subtype: {"no-op", "read", "update", "delete", "add-hosts", "set-hosts", "remove-hosts"},
hostplugin.Subtype: {"no-op", "read", "update", "delete"},
var testAuthorizedActions = map[globals.Subtype][]string{
globals.StaticSubtype: {"no-op", "read", "update", "delete", "add-hosts", "set-hosts", "remove-hosts"},
globals.PluginSubtype: {"no-op", "read", "update", "delete"},
}
func TestGet_Static(t *testing.T) {
@@ -89,7 +88,7 @@ func TestGet_Static(t *testing.T) {
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
Type: "static",
HostIds: hIds,
AuthorizedActions: testAuthorizedActions[static.Subtype],
AuthorizedActions: testAuthorizedActions[globals.StaticSubtype],
}
cases := []struct {
@@ -186,7 +185,7 @@ func TestGet_Plugin(t *testing.T) {
Id: hs.GetPublicId(),
CreatedTime: hs.CreateTime.GetTimestamp(),
UpdatedTime: hs.UpdateTime.GetTimestamp(),
Type: hostplugin.Subtype.String(),
Type: globals.PluginSubtype.String(),
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
Plugin: &plugins.PluginInfo{
Id: plg.GetPublicId(),
@@ -195,7 +194,7 @@ func TestGet_Plugin(t *testing.T) {
},
PreferredEndpoints: prefEndpoints,
SyncIntervalSeconds: &wrappers.Int32Value{Value: -1},
AuthorizedActions: testAuthorizedActions[hostplugin.Subtype],
AuthorizedActions: testAuthorizedActions[globals.PluginSubtype],
}
cases := []struct {
@@ -297,8 +296,8 @@ func TestList_Static(t *testing.T) {
CreatedTime: h.GetCreateTime().GetTimestamp(),
UpdatedTime: h.GetUpdateTime().GetTimestamp(),
Version: h.GetVersion(),
Type: static.Subtype.String(),
AuthorizedActions: testAuthorizedActions[static.Subtype],
Type: globals.StaticSubtype.String(),
AuthorizedActions: testAuthorizedActions[globals.StaticSubtype],
})
}
@@ -409,8 +408,8 @@ func TestList_Plugin(t *testing.T) {
CreatedTime: h.GetCreateTime().GetTimestamp(),
UpdatedTime: h.GetUpdateTime().GetTimestamp(),
Version: h.GetVersion(),
Type: hostplugin.Subtype.String(),
AuthorizedActions: testAuthorizedActions[hostplugin.Subtype],
Type: globals.PluginSubtype.String(),
AuthorizedActions: testAuthorizedActions[globals.PluginSubtype],
PreferredEndpoints: preferredEndpoints,
SyncIntervalSeconds: &wrappers.Int32Value{Value: 5},
})
@@ -716,7 +715,7 @@ func TestCreate_Static(t *testing.T) {
Name: &wrappers.StringValue{Value: "name"},
Description: &wrappers.StringValue{Value: "desc"},
Type: "static",
AuthorizedActions: testAuthorizedActions[static.Subtype],
AuthorizedActions: testAuthorizedActions[globals.StaticSubtype],
},
},
},
@@ -726,7 +725,7 @@ func TestCreate_Static(t *testing.T) {
HostCatalogId: hc.GetPublicId(),
Name: &wrappers.StringValue{Value: "name"},
Description: &wrappers.StringValue{Value: "desc"},
Type: static.Subtype.String(),
Type: globals.StaticSubtype.String(),
PreferredEndpoints: prefEndpoints,
}},
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
@@ -756,7 +755,7 @@ func TestCreate_Static(t *testing.T) {
Name: &wrappers.StringValue{Value: "no type name"},
Description: &wrappers.StringValue{Value: "no type desc"},
Type: "static",
AuthorizedActions: testAuthorizedActions[static.Subtype],
AuthorizedActions: testAuthorizedActions[globals.StaticSubtype],
},
},
},
@@ -900,7 +899,7 @@ func TestCreate_Plugin(t *testing.T) {
HostCatalogId: hc.GetPublicId(),
Name: &wrappers.StringValue{Value: "No Attributes"},
Description: &wrappers.StringValue{Value: "desc"},
Type: hostplugin.Subtype.String(),
Type: globals.PluginSubtype.String(),
SyncIntervalSeconds: &wrapperspb.Int32Value{Value: -1},
}},
res: &pbs.CreateHostSetResponse{
@@ -915,8 +914,8 @@ func TestCreate_Plugin(t *testing.T) {
},
Name: &wrappers.StringValue{Value: "No Attributes"},
Description: &wrappers.StringValue{Value: "desc"},
Type: hostplugin.Subtype.String(),
AuthorizedActions: testAuthorizedActions[hostplugin.Subtype],
Type: globals.PluginSubtype.String(),
AuthorizedActions: testAuthorizedActions[globals.PluginSubtype],
SyncIntervalSeconds: &wrapperspb.Int32Value{Value: -1},
},
},
@@ -927,7 +926,7 @@ func TestCreate_Plugin(t *testing.T) {
HostCatalogId: hc.GetPublicId(),
Name: &wrappers.StringValue{Value: "With Attributes"},
Description: &wrappers.StringValue{Value: "desc"},
Type: hostplugin.Subtype.String(),
Type: globals.PluginSubtype.String(),
SyncIntervalSeconds: &wrapperspb.Int32Value{Value: 90},
Attrs: &pb.HostSet_Attributes{
Attributes: testInputAttrs,
@@ -945,9 +944,9 @@ func TestCreate_Plugin(t *testing.T) {
},
Name: &wrappers.StringValue{Value: "With Attributes"},
Description: &wrappers.StringValue{Value: "desc"},
Type: hostplugin.Subtype.String(),
Type: globals.PluginSubtype.String(),
SyncIntervalSeconds: &wrapperspb.Int32Value{Value: 90},
AuthorizedActions: testAuthorizedActions[hostplugin.Subtype],
AuthorizedActions: testAuthorizedActions[globals.PluginSubtype],
Attrs: &pb.HostSet_Attributes{
Attributes: testOutputAttrs,
},
@@ -960,7 +959,7 @@ func TestCreate_Plugin(t *testing.T) {
HostCatalogId: hc.GetPublicId(),
Name: &wrappers.StringValue{Value: "name"},
Description: &wrappers.StringValue{Value: "desc"},
Type: hostplugin.Subtype.String(),
Type: globals.PluginSubtype.String(),
PreferredEndpoints: prefEndpoints,
}},
res: &pbs.CreateHostSetResponse{
@@ -975,9 +974,9 @@ func TestCreate_Plugin(t *testing.T) {
},
Name: &wrappers.StringValue{Value: "name"},
Description: &wrappers.StringValue{Value: "desc"},
Type: hostplugin.Subtype.String(),
Type: globals.PluginSubtype.String(),
PreferredEndpoints: prefEndpoints,
AuthorizedActions: testAuthorizedActions[hostplugin.Subtype],
AuthorizedActions: testAuthorizedActions[globals.PluginSubtype],
},
},
},
@@ -987,7 +986,7 @@ func TestCreate_Plugin(t *testing.T) {
HostCatalogId: hc.GetPublicId(),
Name: &wrappers.StringValue{Value: "name"},
Description: &wrappers.StringValue{Value: "desc"},
Type: hostplugin.Subtype.String(),
Type: globals.PluginSubtype.String(),
PreferredEndpoints: append(prefEndpoints, "foobar:1.2.3.4"),
}},
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
@@ -1021,8 +1020,8 @@ func TestCreate_Plugin(t *testing.T) {
},
Name: &wrappers.StringValue{Value: "no type name"},
Description: &wrappers.StringValue{Value: "no type desc"},
Type: hostplugin.Subtype.String(),
AuthorizedActions: testAuthorizedActions[hostplugin.Subtype],
Type: globals.PluginSubtype.String(),
AuthorizedActions: testAuthorizedActions[globals.PluginSubtype],
},
},
},
@@ -1174,7 +1173,7 @@ func TestUpdate_Static(t *testing.T) {
CreatedTime: hs.GetCreateTime().GetTimestamp(),
Type: "static",
HostIds: hIds,
AuthorizedActions: testAuthorizedActions[static.Subtype],
AuthorizedActions: testAuthorizedActions[globals.StaticSubtype],
},
},
},
@@ -1200,7 +1199,7 @@ func TestUpdate_Static(t *testing.T) {
CreatedTime: hs.GetCreateTime().GetTimestamp(),
Type: "static",
HostIds: hIds,
AuthorizedActions: testAuthorizedActions[static.Subtype],
AuthorizedActions: testAuthorizedActions[globals.StaticSubtype],
},
},
},
@@ -1269,7 +1268,7 @@ func TestUpdate_Static(t *testing.T) {
CreatedTime: hs.GetCreateTime().GetTimestamp(),
Type: "static",
HostIds: hIds,
AuthorizedActions: testAuthorizedActions[static.Subtype],
AuthorizedActions: testAuthorizedActions[globals.StaticSubtype],
},
},
},
@@ -1292,7 +1291,7 @@ func TestUpdate_Static(t *testing.T) {
CreatedTime: hs.GetCreateTime().GetTimestamp(),
Type: "static",
HostIds: hIds,
AuthorizedActions: testAuthorizedActions[static.Subtype],
AuthorizedActions: testAuthorizedActions[globals.StaticSubtype],
},
},
},
@@ -1317,7 +1316,7 @@ func TestUpdate_Static(t *testing.T) {
CreatedTime: hs.GetCreateTime().GetTimestamp(),
Type: "static",
HostIds: hIds,
AuthorizedActions: testAuthorizedActions[static.Subtype],
AuthorizedActions: testAuthorizedActions[globals.StaticSubtype],
},
},
},
@@ -1342,7 +1341,7 @@ func TestUpdate_Static(t *testing.T) {
CreatedTime: hs.GetCreateTime().GetTimestamp(),
Type: "static",
HostIds: hIds,
AuthorizedActions: testAuthorizedActions[static.Subtype],
AuthorizedActions: testAuthorizedActions[globals.StaticSubtype],
},
},
},
@@ -1515,7 +1514,7 @@ func TestUpdate_Plugin(t *testing.T) {
HostCatalogId: hc.GetPublicId(),
Name: wrapperspb.String("default"),
Description: wrapperspb.String("default"),
Type: hostplugin.Subtype.String(),
Type: globals.PluginSubtype.String(),
Attrs: &pb.HostSet_Attributes{
Attributes: attr,
},
@@ -36,14 +36,14 @@ var (
// IdActions contains the set of actions that can be performed on
// individual resources
idActionsTypeMap = map[subtypes.Subtype]action.ActionSet{
static.Subtype: {
idActionsTypeMap = map[globals.Subtype]action.ActionSet{
globals.StaticSubtype: {
action.NoOp,
action.Read,
action.Update,
action.Delete,
},
hostplugin.Subtype: {
globals.PluginSubtype: {
action.NoOp,
action.Read,
},
@@ -302,7 +302,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (host.Host, *plugin
var h host.Host
var plg *plugins.PluginInfo
switch subtypes.SubtypeFromId(domain, id) {
case static.Subtype:
case globals.StaticSubtype:
repo, err := s.staticRepoFn()
if err != nil {
return nil, nil, err
@@ -314,7 +314,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (host.Host, *plugin
if h == nil {
return nil, nil, handlers.NotFoundErrorf("Host %q doesn't exist.", id)
}
case hostplugin.Subtype:
case globals.PluginSubtype:
repo, err := s.pluginRepoFn()
if err != nil {
return nil, nil, err
@@ -417,7 +417,7 @@ func (s Service) listFromRepo(ctx context.Context, catalogId string) ([]host.Hos
var hosts []host.Host
var plg *plugins.PluginInfo
switch subtypes.SubtypeFromId(domain, catalogId) {
case static.Subtype:
case globals.StaticSubtype:
repo, err := s.staticRepoFn()
if err != nil {
return nil, nil, err
@@ -429,7 +429,7 @@ func (s Service) listFromRepo(ctx context.Context, catalogId string) ([]host.Hos
for _, h := range hl {
hosts = append(hosts, h)
}
case hostplugin.Subtype:
case globals.PluginSubtype:
repo, err := s.pluginRepoFn()
if err != nil {
return nil, nil, err
@@ -466,7 +466,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
parentId = id
default:
switch subtypes.SubtypeFromId(domain, id) {
case static.Subtype:
case globals.StaticSubtype:
h, err := staticRepo.LookupHost(ctx, id)
if err != nil {
res.Error = err
@@ -477,7 +477,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
return nil, res
}
parentId = h.GetCatalogId()
case hostplugin.Subtype:
case globals.PluginSubtype:
h, _, err := pluginRepo.LookupHost(ctx, id)
if err != nil {
res.Error = err
@@ -494,7 +494,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
var cat host.Catalog
switch subtypes.SubtypeFromId(domain, id) {
case static.Subtype:
case globals.StaticSubtype:
stcat, err := staticRepo.LookupCatalog(ctx, parentId)
if err != nil {
res.Error = err
@@ -505,7 +505,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
return nil, res
}
cat = stcat
case hostplugin.Subtype:
case globals.PluginSubtype:
plcat, _, err := pluginRepo.LookupCatalog(ctx, parentId)
if err != nil {
res.Error = err
@@ -549,9 +549,9 @@ func toProto(ctx context.Context, in host.Host, opt ...handlers.Option) (*pb.Hos
if outputFields.Has(globals.TypeField) {
switch in.(type) {
case *static.Host:
out.Type = static.Subtype.String()
out.Type = globals.StaticSubtype.String()
case *hostplugin.Host:
out.Type = hostplugin.Subtype.String()
out.Type = globals.PluginSubtype.String()
}
}
if outputFields.Has(globals.DescriptionField) && in.GetDescription() != "" {
@@ -620,7 +620,7 @@ func validateGetRequest(req *pbs.GetHostRequest) error {
return handlers.ValidateGetRequest(func() map[string]string {
badFields := map[string]string{}
ct := subtypes.SubtypeFromId(domain, req.GetId())
if ct == subtypes.UnknownSubtype {
if ct == globals.UnknownSubtype {
badFields["id"] = "Improperly formatted identifier used."
}
return badFields
@@ -634,8 +634,8 @@ func validateCreateRequest(req *pbs.CreateHostRequest) error {
badFields["host_catalog_id"] = "The field is incorrectly formatted."
}
switch subtypes.SubtypeFromId(domain, req.GetItem().GetHostCatalogId()) {
case static.Subtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != static.Subtype.String() {
case globals.StaticSubtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != globals.StaticSubtype.String() {
badFields[globals.TypeField] = "Doesn't match the parent resource's type."
}
if len(req.GetItem().GetIpAddresses()) > 0 {
@@ -665,7 +665,7 @@ func validateCreateRequest(req *pbs.CreateHostRequest) error {
}
}
}
case hostplugin.Subtype:
case globals.PluginSubtype:
badFields[globals.HostCatalogIdField] = "Cannot manually create hosts for this type of catalog."
}
return badFields
@@ -676,8 +676,8 @@ func validateUpdateRequest(req *pbs.UpdateHostRequest) error {
return handlers.ValidateUpdateRequest(req, req.GetItem(), func() map[string]string {
badFields := map[string]string{}
switch subtypes.SubtypeFromId(domain, req.GetId()) {
case static.Subtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != static.Subtype.String() {
case globals.StaticSubtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != globals.StaticSubtype.String() {
badFields[globals.TypeField] = "Cannot modify the resource type."
}
if handlers.MaskContains(req.GetUpdateMask().GetPaths(), globals.AttributesAddressField) {
@@ -703,7 +703,7 @@ func validateUpdateRequest(req *pbs.UpdateHostRequest) error {
}
}
}
case hostplugin.Subtype:
case globals.PluginSubtype:
badFields[globals.IdField] = "Cannot modify this type of host."
default:
badFields["id"] = "Improperly formatted identifier used."
@@ -716,7 +716,7 @@ func validateDeleteRequest(req *pbs.DeleteHostRequest) error {
return handlers.ValidateDeleteRequest(func() map[string]string {
badFields := map[string]string{}
switch subtypes.SubtypeFromId(domain, req.GetId()) {
case hostplugin.Subtype:
case globals.PluginSubtype:
badFields[globals.IdField] = "Cannot manually delete this type of host."
}
return badFields
@@ -27,7 +27,6 @@ import (
"github.com/hashicorp/boundary/internal/plugin/loopback"
"github.com/hashicorp/boundary/internal/scheduler"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/hashicorp/boundary/internal/types/subtypes"
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/hosts"
"github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/plugins"
"github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/scopes"
@@ -42,9 +41,9 @@ import (
"google.golang.org/protobuf/types/known/wrapperspb"
)
var testAuthorizedActions = map[subtypes.Subtype][]string{
static.Subtype: {"no-op", "read", "update", "delete"},
hostplugin.Subtype: {"no-op", "read"},
var testAuthorizedActions = map[globals.Subtype][]string{
globals.StaticSubtype: {"no-op", "read", "update", "delete"},
globals.PluginSubtype: {"no-op", "read"},
}
func TestGet_Static(t *testing.T) {
@@ -86,7 +85,7 @@ func TestGet_Static(t *testing.T) {
Address: wrapperspb.String(h.GetAddress()),
},
},
AuthorizedActions: testAuthorizedActions[static.Subtype],
AuthorizedActions: testAuthorizedActions[globals.StaticSubtype],
HostSetIds: []string{s.GetPublicId()},
}
@@ -182,7 +181,7 @@ func TestGet_Plugin(t *testing.T) {
CreatedTime: h.CreateTime.GetTimestamp(),
UpdatedTime: h.UpdateTime.GetTimestamp(),
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
Type: hostplugin.Subtype.String(),
Type: globals.PluginSubtype.String(),
Plugin: &plugins.PluginInfo{
Id: plg.GetPublicId(),
Name: plg.GetName(),
@@ -191,7 +190,7 @@ func TestGet_Plugin(t *testing.T) {
HostSetIds: []string{hs.GetPublicId()},
ExternalId: "test",
ExternalName: "test-ext-name",
AuthorizedActions: testAuthorizedActions[hostplugin.Subtype],
AuthorizedActions: testAuthorizedActions[globals.PluginSubtype],
}
cases := []struct {
@@ -295,13 +294,13 @@ func TestList_Static(t *testing.T) {
CreatedTime: h.GetCreateTime().GetTimestamp(),
UpdatedTime: h.GetUpdateTime().GetTimestamp(),
Version: h.GetVersion(),
Type: static.Subtype.String(),
Type: globals.StaticSubtype.String(),
Attrs: &pb.Host_StaticHostAttributes{
StaticHostAttributes: &pb.StaticHostAttributes{
Address: wrapperspb.String(h.GetAddress()),
},
},
AuthorizedActions: testAuthorizedActions[static.Subtype],
AuthorizedActions: testAuthorizedActions[globals.StaticSubtype],
HostSetIds: []string{hset.GetPublicId()},
})
}
@@ -424,8 +423,8 @@ func TestList_Plugin(t *testing.T) {
Version: 1,
ExternalId: extId,
ExternalName: fmt.Sprintf("ext-name-%d", i),
Type: hostplugin.Subtype.String(),
AuthorizedActions: testAuthorizedActions[hostplugin.Subtype],
Type: globals.PluginSubtype.String(),
AuthorizedActions: testAuthorizedActions[globals.PluginSubtype],
})
}
sort.Slice(wantHs, func(i, j int) bool {
@@ -687,7 +686,7 @@ func TestCreate(t *testing.T) {
Address: wrapperspb.String("123.456.789"),
},
},
AuthorizedActions: testAuthorizedActions[static.Subtype],
AuthorizedActions: testAuthorizedActions[globals.StaticSubtype],
},
},
},
@@ -775,7 +774,7 @@ func TestCreate(t *testing.T) {
Address: wrapperspb.String("123.456.789"),
},
},
AuthorizedActions: testAuthorizedActions[static.Subtype],
AuthorizedActions: testAuthorizedActions[globals.StaticSubtype],
},
},
},
@@ -944,7 +943,7 @@ func TestUpdate_Static(t *testing.T) {
Address: wrapperspb.String("defaultaddress"),
},
},
AuthorizedActions: testAuthorizedActions[static.Subtype],
AuthorizedActions: testAuthorizedActions[globals.StaticSubtype],
HostSetIds: []string{s.GetPublicId()},
},
},
@@ -976,7 +975,7 @@ func TestUpdate_Static(t *testing.T) {
Address: wrapperspb.String("defaultaddress"),
},
},
AuthorizedActions: testAuthorizedActions[static.Subtype],
AuthorizedActions: testAuthorizedActions[globals.StaticSubtype],
HostSetIds: []string{s.GetPublicId()},
},
},
@@ -1058,7 +1057,7 @@ func TestUpdate_Static(t *testing.T) {
Address: wrapperspb.String("defaultaddress"),
},
},
AuthorizedActions: testAuthorizedActions[static.Subtype],
AuthorizedActions: testAuthorizedActions[globals.StaticSubtype],
HostSetIds: []string{s.GetPublicId()},
},
},
@@ -1087,7 +1086,7 @@ func TestUpdate_Static(t *testing.T) {
Address: wrapperspb.String("defaultaddress"),
},
},
AuthorizedActions: testAuthorizedActions[static.Subtype],
AuthorizedActions: testAuthorizedActions[globals.StaticSubtype],
HostSetIds: []string{s.GetPublicId()},
},
},
@@ -1118,7 +1117,7 @@ func TestUpdate_Static(t *testing.T) {
Address: wrapperspb.String("defaultaddress"),
},
},
AuthorizedActions: testAuthorizedActions[static.Subtype],
AuthorizedActions: testAuthorizedActions[globals.StaticSubtype],
HostSetIds: []string{s.GetPublicId()},
},
},
@@ -1149,7 +1148,7 @@ func TestUpdate_Static(t *testing.T) {
Address: wrapperspb.String("defaultaddress"),
},
},
AuthorizedActions: testAuthorizedActions[static.Subtype],
AuthorizedActions: testAuthorizedActions[globals.StaticSubtype],
HostSetIds: []string{s.GetPublicId()},
},
},
@@ -44,14 +44,14 @@ var (
// IdActions contains the set of actions that can be performed on
// individual resources
IdActions = map[subtypes.Subtype]action.ActionSet{
oidc.Subtype: {
IdActions = map[globals.Subtype]action.ActionSet{
globals.OidcSubtype: {
action.NoOp,
action.Read,
action.Update,
action.Delete,
},
ldap.Subtype: {
globals.LdapSubtype: {
action.NoOp,
action.Read,
action.Update,
@@ -310,7 +310,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (auth.ManagedGroup,
var out auth.ManagedGroup
var memberIds []string
switch subtypes.SubtypeFromId(domain, id) {
case oidc.Subtype:
case globals.OidcSubtype:
repo, err := s.oidcRepoFn()
if err != nil {
return nil, nil, err
@@ -333,7 +333,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (auth.ManagedGroup,
}
}
out = mg
case ldap.Subtype:
case globals.LdapSubtype:
repo, err := s.ldapRepoFn()
if err != nil {
return nil, nil, err
@@ -433,7 +433,7 @@ func (s Service) createInRepo(ctx context.Context, am auth.AuthMethod, item *pb.
}
var out auth.ManagedGroup
switch subtypes.SubtypeFromId(domain, am.GetPublicId()) {
case oidc.Subtype:
case globals.OidcSubtype:
am, err := s.createOidcInRepo(ctx, am, item)
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -442,7 +442,7 @@ func (s Service) createInRepo(ctx context.Context, am auth.AuthMethod, item *pb.
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create managed group but no error returned from repository.")
}
out = am
case ldap.Subtype:
case globals.LdapSubtype:
am, err := s.createLdapInRepo(ctx, am, item)
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -535,7 +535,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId, authMethodId string,
const op = "managed_groups.(Service).updateInRepo"
var out auth.ManagedGroup
switch subtypes.SubtypeFromId(domain, req.GetId()) {
case oidc.Subtype:
case globals.OidcSubtype:
mg, err := s.updateOidcInRepo(ctx, scopeId, authMethodId, req.GetId(), req.GetUpdateMask().GetPaths(), req.GetItem())
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -544,7 +544,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId, authMethodId string,
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to update managed group but no error returned from repository.")
}
out = mg
case ldap.Subtype:
case globals.LdapSubtype:
mg, err := s.updateLdapInRepo(ctx, scopeId, authMethodId, req.GetId(), req.GetUpdateMask().GetPaths(), req.GetItem())
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -562,13 +562,13 @@ func (s Service) deleteFromRepo(ctx context.Context, scopeId, id string) (bool,
var rows int
var err error
switch subtypes.SubtypeFromId(domain, id) {
case oidc.Subtype:
case globals.OidcSubtype:
repo, iErr := s.oidcRepoFn()
if iErr != nil {
return false, iErr
}
rows, err = repo.DeleteManagedGroup(ctx, scopeId, id)
case ldap.Subtype:
case globals.LdapSubtype:
repo, iErr := s.ldapRepoFn()
if iErr != nil {
return false, iErr
@@ -589,7 +589,7 @@ func (s Service) listFromRepo(ctx context.Context, authMethodId string) ([]auth.
var outUl []auth.ManagedGroup
switch subtypes.SubtypeFromId(domain, authMethodId) {
case oidc.Subtype:
case globals.OidcSubtype:
oidcRepo, err := s.oidcRepoFn()
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -601,7 +601,7 @@ func (s Service) listFromRepo(ctx context.Context, authMethodId string) ([]auth.
for _, a := range oidcl {
outUl = append(outUl, a)
}
case ldap.Subtype:
case globals.LdapSubtype:
ldapRepo, err := s.ldapRepoFn()
if err != nil {
return nil, errors.Wrap(ctx, err, op)
@@ -638,7 +638,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
parentId = id
default:
switch subtypes.SubtypeFromId(domain, id) {
case oidc.Subtype:
case globals.OidcSubtype:
grp, err := oidcRepo.LookupManagedGroup(ctx, id)
if err != nil {
res.Error = err
@@ -649,7 +649,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
return nil, res
}
parentId = grp.GetAuthMethodId()
case ldap.Subtype:
case globals.LdapSubtype:
grp, err := ldapRepo.LookupManagedGroup(ctx, id)
if err != nil {
res.Error = err
@@ -669,7 +669,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
var authMeth auth.AuthMethod
switch subtypes.SubtypeFromId(domain, parentId) {
case oidc.Subtype:
case globals.OidcSubtype:
am, err := oidcRepo.LookupAuthMethod(ctx, parentId)
if err != nil {
res.Error = err
@@ -681,7 +681,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
}
authMeth = am
opts = append(opts, requestauth.WithScopeId(am.GetScopeId()))
case ldap.Subtype:
case globals.LdapSubtype:
am, err := ldapRepo.LookupAuthMethod(ctx, parentId)
if err != nil {
res.Error = err
@@ -742,7 +742,7 @@ func toProto(ctx context.Context, in auth.ManagedGroup, opt ...handlers.Option)
switch i := in.(type) {
case *oidc.ManagedGroup:
if outputFields.Has(globals.TypeField) {
out.Type = oidc.Subtype.String()
out.Type = globals.OidcSubtype.String()
}
if !outputFields.Has(globals.AttributesField) {
break
@@ -755,7 +755,7 @@ func toProto(ctx context.Context, in auth.ManagedGroup, opt ...handlers.Option)
}
case *ldap.ManagedGroup:
if outputFields.Has(globals.TypeField) {
out.Type = ldap.Subtype.String()
out.Type = globals.LdapSubtype.String()
}
if !outputFields.Has(globals.AttributesField) {
break
@@ -800,8 +800,8 @@ func validateCreateRequest(ctx context.Context, req *pbs.CreateManagedGroupReque
badFields[globals.AuthMethodIdField] = "This field is required."
}
switch subtypes.SubtypeFromId(domain, req.GetItem().GetAuthMethodId()) {
case oidc.Subtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != oidc.Subtype.String() {
case globals.OidcSubtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != globals.OidcSubtype.String() {
badFields[globals.TypeField] = "Doesn't match the parent resource's type."
}
attrs := req.GetItem().GetOidcManagedGroupAttributes()
@@ -816,8 +816,8 @@ func validateCreateRequest(ctx context.Context, req *pbs.CreateManagedGroupReque
}
}
}
case ldap.Subtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != ldap.Subtype.String() {
case globals.LdapSubtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != globals.LdapSubtype.String() {
badFields[globals.TypeField] = "Doesn't match the parent resource's type."
}
attrs := req.GetItem().GetLdapManagedGroupAttributes()
@@ -843,8 +843,8 @@ func validateUpdateRequest(ctx context.Context, req *pbs.UpdateManagedGroupReque
return handlers.ValidateUpdateRequest(req, req.GetItem(), func() map[string]string {
badFields := map[string]string{}
switch subtypes.SubtypeFromId(domain, req.GetId()) {
case oidc.Subtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != oidc.Subtype.String() {
case globals.OidcSubtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != globals.OidcSubtype.String() {
badFields[globals.TypeField] = "Cannot modify the resource type."
}
attrs := req.GetItem().GetOidcManagedGroupAttributes()
@@ -862,8 +862,8 @@ func validateUpdateRequest(ctx context.Context, req *pbs.UpdateManagedGroupReque
}
}
}
case ldap.Subtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != ldap.Subtype.String() {
case globals.LdapSubtype:
if req.GetItem().GetType() != "" && req.GetItem().GetType() != globals.LdapSubtype.String() {
badFields[globals.TypeField] = "Cannot modify the resource type."
}
attrs := req.GetItem().GetLdapManagedGroupAttributes()
@@ -16,7 +16,6 @@ import (
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth/ldap"
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/auth/password"
"github.com/hashicorp/boundary/internal/daemon/controller/auth"
"github.com/hashicorp/boundary/internal/daemon/controller/common"
"github.com/hashicorp/boundary/internal/daemon/controller/handlers"
@@ -294,7 +293,7 @@ func TestListOidc(t *testing.T) {
UpdatedTime: mg.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.ManagedGroup_OidcManagedGroupAttributes{
OidcManagedGroupAttributes: &pb.OidcManagedGroupAttributes{
Filter: oidc.TestFakeManagedGroupFilter,
@@ -315,7 +314,7 @@ func TestListOidc(t *testing.T) {
UpdatedTime: mg.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.ManagedGroup_OidcManagedGroupAttributes{
OidcManagedGroupAttributes: &pb.OidcManagedGroupAttributes{
Filter: oidc.TestFakeManagedGroupFilter,
@@ -447,7 +446,7 @@ func TestListLdap(t *testing.T) {
UpdatedTime: mg.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.ManagedGroup_LdapManagedGroupAttributes{
LdapManagedGroupAttributes: &pb.LdapManagedGroupAttributes{
GroupNames: testGroups,
@@ -468,7 +467,7 @@ func TestListLdap(t *testing.T) {
UpdatedTime: mg.GetUpdateTime().GetTimestamp(),
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.ManagedGroup_LdapManagedGroupAttributes{
LdapManagedGroupAttributes: &pb.LdapManagedGroupAttributes{
GroupNames: testGroups,
@@ -752,7 +751,7 @@ func TestCreateOidc(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "name"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.ManagedGroup_OidcManagedGroupAttributes{
OidcManagedGroupAttributes: &pb.OidcManagedGroupAttributes{
Filter: oidc.TestFakeManagedGroupFilter,
@@ -768,7 +767,7 @@ func TestCreateOidc(t *testing.T) {
Description: &wrapperspb.StringValue{Value: "desc"},
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.ManagedGroup_OidcManagedGroupAttributes{
OidcManagedGroupAttributes: &pb.OidcManagedGroupAttributes{
Filter: oidc.TestFakeManagedGroupFilter,
@@ -796,7 +795,7 @@ func TestCreateOidc(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.ManagedGroup_OidcManagedGroupAttributes{
OidcManagedGroupAttributes: &pb.OidcManagedGroupAttributes{
Filter: oidc.TestFakeManagedGroupFilter,
@@ -811,7 +810,7 @@ func TestCreateOidc(t *testing.T) {
req: &pbs.CreateManagedGroupRequest{
Item: &pb.ManagedGroup{
AuthMethodId: am.GetPublicId(),
Type: password.Subtype.String(),
Type: globals.PasswordSubtype.String(),
Attrs: &pb.ManagedGroup_OidcManagedGroupAttributes{
OidcManagedGroupAttributes: &pb.OidcManagedGroupAttributes{
Filter: oidc.TestFakeManagedGroupFilter,
@@ -828,7 +827,7 @@ func TestCreateOidc(t *testing.T) {
Item: &pb.ManagedGroup{
AuthMethodId: am.GetPublicId(),
Id: globals.OidcManagedGroupPrefix + "_notallowed",
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.ManagedGroup_OidcManagedGroupAttributes{
OidcManagedGroupAttributes: &pb.OidcManagedGroupAttributes{
Filter: oidc.TestFakeManagedGroupFilter,
@@ -845,7 +844,7 @@ func TestCreateOidc(t *testing.T) {
Item: &pb.ManagedGroup{
AuthMethodId: am.GetPublicId(),
CreatedTime: timestamppb.Now(),
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.ManagedGroup_OidcManagedGroupAttributes{
OidcManagedGroupAttributes: &pb.OidcManagedGroupAttributes{
Filter: oidc.TestFakeManagedGroupFilter,
@@ -862,7 +861,7 @@ func TestCreateOidc(t *testing.T) {
Item: &pb.ManagedGroup{
AuthMethodId: am.GetPublicId(),
UpdatedTime: timestamppb.Now(),
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.ManagedGroup_OidcManagedGroupAttributes{
OidcManagedGroupAttributes: &pb.OidcManagedGroupAttributes{
Filter: oidc.TestFakeManagedGroupFilter,
@@ -879,7 +878,7 @@ func TestCreateOidc(t *testing.T) {
Item: &pb.ManagedGroup{
AuthMethodId: am.GetPublicId(),
UpdatedTime: timestamppb.Now(),
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.ManagedGroup_OidcManagedGroupAttributes{
OidcManagedGroupAttributes: &pb.OidcManagedGroupAttributes{
Filter: "foobar",
@@ -952,7 +951,7 @@ func TestCreateLdap(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "name"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.ManagedGroup_LdapManagedGroupAttributes{
LdapManagedGroupAttributes: &pb.LdapManagedGroupAttributes{
GroupNames: []string{"admin", "users"},
@@ -968,7 +967,7 @@ func TestCreateLdap(t *testing.T) {
Description: &wrapperspb.StringValue{Value: "desc"},
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.ManagedGroup_LdapManagedGroupAttributes{
LdapManagedGroupAttributes: &pb.LdapManagedGroupAttributes{
GroupNames: []string{"admin", "users"},
@@ -996,7 +995,7 @@ func TestCreateLdap(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
Version: 1,
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.ManagedGroup_LdapManagedGroupAttributes{
LdapManagedGroupAttributes: &pb.LdapManagedGroupAttributes{
GroupNames: []string{"admin", "users"},
@@ -1011,7 +1010,7 @@ func TestCreateLdap(t *testing.T) {
req: &pbs.CreateManagedGroupRequest{
Item: &pb.ManagedGroup{
AuthMethodId: am.GetPublicId(),
Type: password.Subtype.String(),
Type: globals.PasswordSubtype.String(),
Attrs: &pb.ManagedGroup_LdapManagedGroupAttributes{
LdapManagedGroupAttributes: &pb.LdapManagedGroupAttributes{
GroupNames: []string{"admin", "users"},
@@ -1029,7 +1028,7 @@ func TestCreateLdap(t *testing.T) {
Item: &pb.ManagedGroup{
AuthMethodId: am.GetPublicId(),
Id: globals.LdapManagedGroupPrefix + "_notallowed",
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.ManagedGroup_LdapManagedGroupAttributes{
LdapManagedGroupAttributes: &pb.LdapManagedGroupAttributes{
GroupNames: []string{"admin", "users"},
@@ -1047,7 +1046,7 @@ func TestCreateLdap(t *testing.T) {
Item: &pb.ManagedGroup{
AuthMethodId: am.GetPublicId(),
CreatedTime: timestamppb.Now(),
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.ManagedGroup_LdapManagedGroupAttributes{
LdapManagedGroupAttributes: &pb.LdapManagedGroupAttributes{
GroupNames: []string{"admin", "users"},
@@ -1065,7 +1064,7 @@ func TestCreateLdap(t *testing.T) {
Item: &pb.ManagedGroup{
AuthMethodId: am.GetPublicId(),
UpdatedTime: timestamppb.Now(),
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: &pb.ManagedGroup_LdapManagedGroupAttributes{
LdapManagedGroupAttributes: &pb.LdapManagedGroupAttributes{
GroupNames: []string{"admin", "users"},
@@ -1082,7 +1081,7 @@ func TestCreateLdap(t *testing.T) {
req: &pbs.CreateManagedGroupRequest{
Item: &pb.ManagedGroup{
AuthMethodId: am.GetPublicId(),
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: &pb.ManagedGroup_LdapManagedGroupAttributes{
LdapManagedGroupAttributes: &pb.LdapManagedGroupAttributes{
GroupNames: []string{},
@@ -1197,7 +1196,7 @@ func TestUpdateOidc(t *testing.T) {
Item: &pb.ManagedGroup{
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
},
},
res: &pbs.UpdateManagedGroupResponse{
@@ -1205,7 +1204,7 @@ func TestUpdateOidc(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -1221,7 +1220,7 @@ func TestUpdateOidc(t *testing.T) {
Item: &pb.ManagedGroup{
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
},
},
res: &pbs.UpdateManagedGroupResponse{
@@ -1229,7 +1228,7 @@ func TestUpdateOidc(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -1299,7 +1298,7 @@ func TestUpdateOidc(t *testing.T) {
Item: &pb.ManagedGroup{
AuthMethodId: am.GetPublicId(),
Description: &wrapperspb.StringValue{Value: "default"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -1323,7 +1322,7 @@ func TestUpdateOidc(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "updated"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -1347,7 +1346,7 @@ func TestUpdateOidc(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "notignored"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -1449,7 +1448,7 @@ func TestUpdateOidc(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
Attrs: modifiedAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: oidcAuthorizedActions,
@@ -1582,7 +1581,7 @@ func TestUpdateLdap(t *testing.T) {
Item: &pb.ManagedGroup{
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
},
},
res: &pbs.UpdateManagedGroupResponse{
@@ -1590,7 +1589,7 @@ func TestUpdateLdap(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: ldapAuthorizedActions,
@@ -1606,7 +1605,7 @@ func TestUpdateLdap(t *testing.T) {
Item: &pb.ManagedGroup{
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
},
},
res: &pbs.UpdateManagedGroupResponse{
@@ -1614,7 +1613,7 @@ func TestUpdateLdap(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "desc"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: ldapAuthorizedActions,
@@ -1685,7 +1684,7 @@ func TestUpdateLdap(t *testing.T) {
Item: &pb.ManagedGroup{
AuthMethodId: am.GetPublicId(),
Description: &wrapperspb.StringValue{Value: "default"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: ldapAuthorizedActions,
@@ -1709,7 +1708,7 @@ func TestUpdateLdap(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "updated"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: ldapAuthorizedActions,
@@ -1733,7 +1732,7 @@ func TestUpdateLdap(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "notignored"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: defaultAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: ldapAuthorizedActions,
@@ -1841,7 +1840,7 @@ func TestUpdateLdap(t *testing.T) {
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "default"},
Description: &wrapperspb.StringValue{Value: "default"},
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
Attrs: modifiedAttributes,
Scope: defaultScopeInfo,
AuthorizedActions: ldapAuthorizedActions,
@@ -10,9 +10,6 @@ import (
"testing"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth/ldap"
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/auth/password"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/managedgroups"
"github.com/stretchr/testify/assert"
@@ -49,7 +46,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "missing oidc attributes",
item: &pb.ManagedGroup{
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
AuthMethodId: globals.OidcAuthMethodPrefix + "_1234567890",
Attrs: nil,
},
@@ -58,7 +55,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "bad oidc attributes",
item: &pb.ManagedGroup{
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
AuthMethodId: globals.OidcAuthMethodPrefix + "_1234567890",
Attrs: &pb.ManagedGroup_OidcManagedGroupAttributes{
OidcManagedGroupAttributes: &pb.OidcManagedGroupAttributes{
@@ -71,7 +68,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "no oidc errors",
item: &pb.ManagedGroup{
Type: oidc.Subtype.String(),
Type: globals.OidcSubtype.String(),
AuthMethodId: globals.OidcAuthMethodPrefix + "_1234567890",
Attrs: &pb.ManagedGroup_OidcManagedGroupAttributes{
OidcManagedGroupAttributes: &pb.OidcManagedGroupAttributes{
@@ -91,7 +88,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "missing ldap attributes",
item: &pb.ManagedGroup{
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
AuthMethodId: globals.LdapAuthMethodPrefix + "_1234567890",
Attrs: nil,
},
@@ -100,7 +97,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "bad ldap attributes",
item: &pb.ManagedGroup{
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
AuthMethodId: globals.LdapAuthMethodPrefix + "_1234567890",
Attrs: &pb.ManagedGroup_LdapManagedGroupAttributes{
LdapManagedGroupAttributes: &pb.LdapManagedGroupAttributes{
@@ -113,7 +110,7 @@ func TestValidateCreateRequest(t *testing.T) {
{
name: "no ldap errors",
item: &pb.ManagedGroup{
Type: ldap.Subtype.String(),
Type: globals.LdapSubtype.String(),
AuthMethodId: globals.LdapAuthMethodPrefix + "_1234567890",
Attrs: &pb.ManagedGroup_LdapManagedGroupAttributes{
LdapManagedGroupAttributes: &pb.LdapManagedGroupAttributes{
@@ -151,7 +148,7 @@ func TestValidateUpdateRequest(t *testing.T) {
req: &pbs.UpdateManagedGroupRequest{
Id: globals.OidcManagedGroupPrefix + "_1234567890",
Item: &pb.ManagedGroup{
Type: password.Subtype.String(),
Type: globals.PasswordSubtype.String(),
},
},
errContains: fieldError(globals.TypeField, "Cannot modify the resource type."),
@@ -176,7 +173,7 @@ func TestValidateUpdateRequest(t *testing.T) {
req: &pbs.UpdateManagedGroupRequest{
Id: globals.LdapManagedGroupPrefix + "_1234567890",
Item: &pb.ManagedGroup{
Type: password.Subtype.String(),
Type: globals.PasswordSubtype.String(),
},
},
errContains: fieldError(globals.TypeField, "Cannot modify the resource type."),
@@ -98,7 +98,7 @@ func TestGetSession(t *testing.T) {
Scope: &scopes.ScopeInfo{Id: p.GetPublicId(), Type: scope.Project.String(), ParentScopeId: o.GetPublicId()},
States: []*pb.SessionState{{Status: session.StatusPending.String(), StartTime: sess.CreateTime.GetTimestamp()}},
Certificate: sess.Certificate,
Type: tcp.Subtype.String(),
Type: globals.TcpSubtype.String(),
AuthorizedActions: testAuthorizedActions,
}
@@ -352,7 +352,7 @@ func TestList(t *testing.T) {
Status: status,
States: states,
Certificate: sess.Certificate,
Type: tcp.Subtype.String(),
Type: globals.TcpSubtype.String(),
AuthorizedActions: testAuthorizedActions,
Connections: []*pb.Connection{}, // connections should not be returned for list
}
@@ -392,7 +392,7 @@ func TestList(t *testing.T) {
Status: status,
States: states,
Certificate: sess.Certificate,
Type: tcp.Subtype.String(),
Type: globals.TcpSubtype.String(),
AuthorizedActions: testAuthorizedActions,
Connections: []*pb.Connection{}, // connections should not be returned for list
}
@@ -440,7 +440,7 @@ func TestList(t *testing.T) {
States: states,
Certificate: sess.Certificate,
TerminationReason: sess.TerminationReason,
Type: tcp.Subtype.String(),
Type: globals.TcpSubtype.String(),
AuthorizedActions: testAuthorizedActions,
Connections: []*pb.Connection{}, // connections should not be returned for list
}
@@ -664,7 +664,7 @@ func TestCancel(t *testing.T) {
Scope: &scopes.ScopeInfo{Id: p.GetPublicId(), Type: scope.Project.String(), ParentScopeId: o.GetPublicId()},
Status: session.StatusCanceling.String(),
Certificate: sess.Certificate,
Type: tcp.Subtype.String(),
Type: globals.TcpSubtype.String(),
AuthorizedActions: testAuthorizedActions,
}
@@ -265,7 +265,7 @@ func staticToSessionCredential(ctx context.Context, cred credential.Static) (*pb
Name: cred.GetName(),
Description: cred.GetDescription(),
CredentialStoreId: cred.GetStoreId(),
Type: credstatic.Subtype.String(),
Type: globals.StaticSubtype.String(),
CredentialType: credType,
},
Secret: &pb.SessionSecret{
@@ -8,10 +8,10 @@ import (
"fmt"
"sync"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/daemon/controller/handlers"
"github.com/hashicorp/boundary/internal/session"
"github.com/hashicorp/boundary/internal/target"
"github.com/hashicorp/boundary/internal/types/subtypes"
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/targets"
"google.golang.org/protobuf/proto"
)
@@ -52,7 +52,7 @@ type registry struct {
*sync.Map
}
func (r registry) get(s subtypes.Subtype) (*registryEntry, error) {
func (r registry) get(s globals.Subtype) (*registryEntry, error) {
v, ok := r.Load(s)
if !ok {
return nil, fmt.Errorf("subtype %q not registered", s)
@@ -65,7 +65,7 @@ func (r registry) get(s subtypes.Subtype) (*registryEntry, error) {
return re, nil
}
func (r registry) maskManager(s subtypes.Subtype) (handlers.MaskManager, error) {
func (r registry) maskManager(s globals.Subtype) (handlers.MaskManager, error) {
re, err := r.get(s)
if err != nil {
return nil, err
@@ -77,7 +77,7 @@ func (r registry) maskManager(s subtypes.Subtype) (handlers.MaskManager, error)
// newAttribute creates an Attribute for the given subtype. It delegates the
// allocation of the Attribute to the registered attrFunc for the given
// subtype. An error is returned if the provided subtype is not registered
func (r registry) newAttribute(s subtypes.Subtype, m any) (Attributes, error) {
func (r registry) newAttribute(s globals.Subtype, m any) (Attributes, error) {
re, err := r.get(s)
if err != nil {
return nil, err
@@ -92,7 +92,7 @@ func (r registry) newAttribute(s subtypes.Subtype, m any) (Attributes, error) {
// setting of the specific attribute type to the registered setAttributeFunc for
// the given subtype. An error is returned if the provided subtype is not
// registered.
func (r registry) setAttributes(s subtypes.Subtype, in target.Target, out *pb.Target) error {
func (r registry) setAttributes(s globals.Subtype, in target.Target, out *pb.Target) error {
re, err := r.get(s)
if err != nil {
return err
@@ -106,7 +106,7 @@ var subtypeRegistry = registry{
}
// Register registers a subtype for used by the service handler.
func Register(s subtypes.Subtype, maskManager handlers.MaskManager, af attributeFunc, sf setAttributeFunc, vsf validateSessionStateFunc) {
func Register(s globals.Subtype, maskManager handlers.MaskManager, af attributeFunc, sf setAttributeFunc, vsf validateSessionStateFunc) {
if _, existed := subtypeRegistry.LoadOrStore(s, &registryEntry{
maskManager: maskManager,
attrFunc: af,
@@ -26,7 +26,6 @@ import (
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
intglobals "github.com/hashicorp/boundary/internal/globals"
"github.com/hashicorp/boundary/internal/host"
"github.com/hashicorp/boundary/internal/host/plugin"
"github.com/hashicorp/boundary/internal/host/static"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/perms"
@@ -95,7 +94,7 @@ var (
action.List,
}
validateCredentialSourcesFn = func(context.Context, subtypes.Subtype, []target.CredentialSource) error { return nil }
validateCredentialSourcesFn = func(context.Context, globals.Subtype, []target.CredentialSource) error { return nil }
ValidateIngressWorkerFilterFn = IngressWorkerFilterUnsupported
AuthorizeSessionWorkerFilterFn = AuthorizeSessionWithWorkerFilter
PostSessionAuthorizationCallback = DefaultPostSessionAuthorizationCallback
@@ -800,7 +799,7 @@ func (s Service) AuthorizeSession(ctx context.Context, req *pbs.AuthorizeSession
for _, hSource := range hostSources {
hsId := hSource.Id()
switch subtypes.SubtypeFromId(hostDomain, hsId) {
case static.Subtype:
case globals.StaticSubtype:
eps, err := staticHostRepo.Endpoints(ctx, hsId)
if err != nil {
return nil, err
@@ -2039,7 +2038,7 @@ func validateAuthorizeSessionRequest(req *pbs.AuthorizeSessionRequest) error {
}
if req.GetHostId() != "" {
switch subtypes.SubtypeFromId(hostDomain, req.GetHostId()) {
case static.Subtype, plugin.Subtype:
case globals.StaticSubtype, globals.PluginSubtype:
default:
badFields[globals.HostIdField] = "Incorrectly formatted identifier."
}
@@ -156,7 +156,7 @@ func TestGet(t *testing.T) {
CreatedTime: tar.GetCreateTime().GetTimestamp(),
UpdatedTime: tar.GetUpdateTime().GetTimestamp(),
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: o.GetPublicId()},
Type: tcp.Subtype.String(),
Type: globals.TcpSubtype.String(),
HostSourceIds: []string{hs[0].GetPublicId(), hs[1].GetPublicId()},
Attrs: &pb.Target_TcpTargetAttributes{},
SessionMaxSeconds: wrapperspb.UInt32(28800),
@@ -175,7 +175,7 @@ func TestGet(t *testing.T) {
CreatedTime: tarAddr.GetCreateTime().GetTimestamp(),
UpdatedTime: tarAddr.GetUpdateTime().GetTimestamp(),
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: o.GetPublicId()},
Type: tcp.Subtype.String(),
Type: globals.TcpSubtype.String(),
Attrs: &pb.Target_TcpTargetAttributes{},
SessionMaxSeconds: wrapperspb.UInt32(28800),
SessionConnectionLimit: wrapperspb.Int32(-1),
@@ -299,7 +299,7 @@ func TestList(t *testing.T) {
CreatedTime: tar.GetCreateTime().GetTimestamp(),
UpdatedTime: tar.GetUpdateTime().GetTimestamp(),
Version: tar.GetVersion(),
Type: tcp.Subtype.String(),
Type: globals.TcpSubtype.String(),
Attrs: &pb.Target_TcpTargetAttributes{},
SessionMaxSeconds: wrapperspb.UInt32(28800),
SessionConnectionLimit: wrapperspb.Int32(-1),
@@ -316,7 +316,7 @@ func TestList(t *testing.T) {
CreatedTime: tar.GetCreateTime().GetTimestamp(),
UpdatedTime: tar.GetUpdateTime().GetTimestamp(),
Version: tar.GetVersion(),
Type: tcp.Subtype.String(),
Type: globals.TcpSubtype.String(),
Attrs: &pb.Target_TcpTargetAttributes{},
SessionMaxSeconds: wrapperspb.UInt32(28800),
SessionConnectionLimit: wrapperspb.Int32(-1),
@@ -586,7 +586,7 @@ func TestCreate(t *testing.T) {
ScopeId: proj.GetPublicId(),
Name: wrapperspb.String("name"),
Description: wrapperspb.String("desc"),
Type: tcp.Subtype.String(),
Type: globals.TcpSubtype.String(),
Attrs: &pb.Target_TcpTargetAttributes{
TcpTargetAttributes: &pb.TcpTargetAttributes{
DefaultPort: wrapperspb.UInt32(2),
@@ -602,7 +602,7 @@ func TestCreate(t *testing.T) {
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
Name: wrapperspb.String("name"),
Description: wrapperspb.String("desc"),
Type: tcp.Subtype.String(),
Type: globals.TcpSubtype.String(),
Attrs: &pb.Target_TcpTargetAttributes{
TcpTargetAttributes: &pb.TcpTargetAttributes{
DefaultPort: wrapperspb.UInt32(2),
@@ -623,7 +623,7 @@ func TestCreate(t *testing.T) {
ScopeId: proj.GetPublicId(),
Name: wrapperspb.String("name"),
Description: wrapperspb.String("desc"),
Type: tcp.Subtype.String(),
Type: globals.TcpSubtype.String(),
EgressWorkerFilter: wrapperspb.String(`type == "bar"`),
}},
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
@@ -633,7 +633,7 @@ func TestCreate(t *testing.T) {
req: &pbs.CreateTargetRequest{Item: &pb.Target{
Name: wrapperspb.String("name"),
Description: wrapperspb.String("desc"),
Type: tcp.Subtype.String(),
Type: globals.TcpSubtype.String(),
Attrs: &pb.Target_TcpTargetAttributes{
TcpTargetAttributes: &pb.TcpTargetAttributes{
DefaultPort: wrapperspb.UInt32(2),
@@ -818,7 +818,7 @@ func TestUpdate(t *testing.T) {
{Id: hs[1].GetPublicId(), HostCatalogId: hs[1].GetCatalogId()},
}
ttar, err := target.New(ctx, tcp.Subtype, proj.GetPublicId(),
ttar, err := target.New(ctx, globals.TcpSubtype, proj.GetPublicId(),
target.WithName("default"),
target.WithDescription("default"),
target.WithSessionMaxSeconds(1),
@@ -871,7 +871,7 @@ func TestUpdate(t *testing.T) {
Description: wrapperspb.String("desc"),
SessionMaxSeconds: wrapperspb.UInt32(3600),
SessionConnectionLimit: wrapperspb.Int32(5),
Type: tcp.Subtype.String(),
Type: globals.TcpSubtype.String(),
},
},
res: &pbs.UpdateTargetResponse{
@@ -881,7 +881,7 @@ func TestUpdate(t *testing.T) {
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
Name: wrapperspb.String("name"),
Description: wrapperspb.String("desc"),
Type: tcp.Subtype.String(),
Type: globals.TcpSubtype.String(),
Attrs: &pb.Target_TcpTargetAttributes{
TcpTargetAttributes: &pb.TcpTargetAttributes{
DefaultPort: wrapperspb.UInt32(2),
@@ -907,7 +907,7 @@ func TestUpdate(t *testing.T) {
Item: &pb.Target{
Name: wrapperspb.String("name"),
Description: wrapperspb.String("desc"),
Type: tcp.Subtype.String(),
Type: globals.TcpSubtype.String(),
},
},
res: &pbs.UpdateTargetResponse{
@@ -918,7 +918,7 @@ func TestUpdate(t *testing.T) {
Name: wrapperspb.String("name"),
Description: wrapperspb.String("desc"),
CreatedTime: tar.GetCreateTime().GetTimestamp(),
Type: tcp.Subtype.String(),
Type: globals.TcpSubtype.String(),
Attrs: &pb.Target_TcpTargetAttributes{
TcpTargetAttributes: &pb.TcpTargetAttributes{
DefaultPort: wrapperspb.UInt32(2),
@@ -1018,7 +1018,7 @@ func TestUpdate(t *testing.T) {
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
Name: wrapperspb.String("default"),
CreatedTime: tar.GetCreateTime().GetTimestamp(),
Type: tcp.Subtype.String(),
Type: globals.TcpSubtype.String(),
Attrs: &pb.Target_TcpTargetAttributes{
TcpTargetAttributes: &pb.TcpTargetAttributes{
DefaultPort: wrapperspb.UInt32(2),
@@ -1053,7 +1053,7 @@ func TestUpdate(t *testing.T) {
Name: wrapperspb.String("updated"),
Description: wrapperspb.String("default"),
CreatedTime: tar.GetCreateTime().GetTimestamp(),
Type: tcp.Subtype.String(),
Type: globals.TcpSubtype.String(),
Attrs: &pb.Target_TcpTargetAttributes{
TcpTargetAttributes: &pb.TcpTargetAttributes{
DefaultPort: wrapperspb.UInt32(2),
@@ -1094,7 +1094,7 @@ func TestUpdate(t *testing.T) {
DefaultClientPort: wrapperspb.UInt32(3),
},
},
Type: tcp.Subtype.String(),
Type: globals.TcpSubtype.String(),
HostSourceIds: hostSourceIds,
HostSources: hostSources,
SessionMaxSeconds: wrapperspb.UInt32(tar.GetSessionMaxSeconds()),
@@ -1306,7 +1306,7 @@ func TestUpdate_BadVersion(t *testing.T) {
repo, err := repoFn()
require.NoError(t, err, "Couldn't create new target repo.")
ttar, err := target.New(ctx, tcp.Subtype, proj.GetPublicId(), target.WithName("default"), target.WithDescription("default"))
ttar, err := target.New(ctx, globals.TcpSubtype, proj.GetPublicId(), target.WithName("default"), target.WithDescription("default"))
tar := ttar.(*tcp.Target)
tar.DefaultPort = 2
tar.DefaultClientPort = 3
@@ -2544,7 +2544,7 @@ func TestAuthorizeSession(t *testing.T) {
CredentialStoreId: vaultStore.GetPublicId(),
Name: wrapperspb.String("Library Name"),
Description: wrapperspb.String("Library Description"),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &credlibpb.CredentialLibrary_VaultCredentialLibraryAttributes{
VaultCredentialLibraryAttributes: &credlibpb.VaultCredentialLibraryAttributes{
Path: &wrapperspb.StringValue{
@@ -2659,7 +2659,7 @@ func TestAuthorizeSession(t *testing.T) {
Name: clsResp.GetItem().GetName().GetValue(),
Description: clsResp.GetItem().GetDescription().GetValue(),
CredentialStoreId: vaultStore.GetPublicId(),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
},
},
},
@@ -2791,7 +2791,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
CredentialStoreId: vaultStore.GetPublicId(),
Name: wrapperspb.String("Usernamepassword Library"),
Description: wrapperspb.String("Usernamepassword Library Description"),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &credlibpb.CredentialLibrary_VaultCredentialLibraryAttributes{
VaultCredentialLibraryAttributes: &credlibpb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String(path.Join("secret", "data", "default-userpass")),
@@ -2806,7 +2806,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
CredentialStoreId: vaultStore.GetPublicId(),
Name: wrapperspb.String("Unspecified Library"),
Description: wrapperspb.String("Unspecified Library Description"),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &credlibpb.CredentialLibrary_VaultCredentialLibraryAttributes{
VaultCredentialLibraryAttributes: &credlibpb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String(path.Join("secret", "data", "default-userpass")),
@@ -2824,7 +2824,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
CredentialStoreId: vaultStore.GetPublicId(),
Name: wrapperspb.String("Usernamepassword Mapping Library"),
Description: wrapperspb.String("Usernamepassword Mapping Library Description"),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &credlibpb.CredentialLibrary_VaultCredentialLibraryAttributes{
VaultCredentialLibraryAttributes: &credlibpb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String(path.Join("secret", "data", "non-default-userpass")),
@@ -2844,7 +2844,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
require.NoError(t, err)
upCredResp, err := credService.CreateCredential(ctx, &pbs.CreateCredentialRequest{Item: &credpb.Credential{
CredentialStoreId: staticStore.GetPublicId(),
Type: credential.UsernamePasswordSubtype.String(),
Type: globals.UsernamePasswordSubtype.String(),
Name: wrapperspb.String("Cred Name"),
Description: wrapperspb.String("Cred Description"),
Attrs: &credpb.Credential_UsernamePasswordAttributes{
@@ -2859,7 +2859,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
sshPkCredResp, err := credService.CreateCredential(ctx, &pbs.CreateCredentialRequest{Item: &credpb.Credential{
CredentialStoreId: staticStore.GetPublicId(),
Type: credential.SshPrivateKeySubtype.String(),
Type: globals.SshPrivateKeySubtype.String(),
Name: wrapperspb.String("Cred SSH Name"),
Description: wrapperspb.String("Cred SSH Description"),
Attrs: &credpb.Credential_SshPrivateKeyAttributes{
@@ -2874,7 +2874,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
sshPkWithPassCredResp, err := credService.CreateCredential(ctx, &pbs.CreateCredentialRequest{Item: &credpb.Credential{
CredentialStoreId: staticStore.GetPublicId(),
Type: credential.SshPrivateKeySubtype.String(),
Type: globals.SshPrivateKeySubtype.String(),
Name: wrapperspb.String("Cred SSH With Pass Name"),
Description: wrapperspb.String("Cred SSH Description"),
Attrs: &credpb.Credential_SshPrivateKeyAttributes{
@@ -2896,7 +2896,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
CredentialStoreId: vaultStore.GetPublicId(),
Name: wrapperspb.String("SSH Private Key Library"),
Description: wrapperspb.String("SSH Private Key Library Description"),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &credlibpb.CredentialLibrary_VaultCredentialLibraryAttributes{
VaultCredentialLibraryAttributes: &credlibpb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String(path.Join("secret", "data", "default-sshpk")),
@@ -2915,7 +2915,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
CredentialStoreId: vaultStore.GetPublicId(),
Name: wrapperspb.String("SSH Private Key Mapping Library"),
Description: wrapperspb.String("SSH Private Key Mapping Library Description"),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &credlibpb.CredentialLibrary_VaultCredentialLibraryAttributes{
VaultCredentialLibraryAttributes: &credlibpb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String(path.Join("secret", "data", "non-default-sshpk")),
@@ -2938,7 +2938,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
CredentialStoreId: vaultStore.GetPublicId(),
Name: wrapperspb.String("SSH Private Key With Passphrase Library"),
Description: wrapperspb.String("SSH Private Key Library Description"),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &credlibpb.CredentialLibrary_VaultCredentialLibraryAttributes{
VaultCredentialLibraryAttributes: &credlibpb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String(path.Join("secret", "data", "default-sshpk-with-pass")),
@@ -2958,7 +2958,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
CredentialStoreId: vaultStore.GetPublicId(),
Name: wrapperspb.String("SSH Private Key With Passphrase Mapping Library"),
Description: wrapperspb.String("SSH Private Key Mapping Library Description"),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &credlibpb.CredentialLibrary_VaultCredentialLibraryAttributes{
VaultCredentialLibraryAttributes: &credlibpb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String(path.Join("secret", "data", "non-default-sshpk-with-pass")),
@@ -2995,7 +2995,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
Name: clsRespUnspecified.GetItem().GetName().GetValue(),
Description: clsRespUnspecified.GetItem().GetDescription().GetValue(),
CredentialStoreId: vaultStore.GetPublicId(),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
},
},
},
@@ -3011,7 +3011,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
Name: clsRespUsernamePassword.GetItem().GetName().GetValue(),
Description: clsRespUsernamePassword.GetItem().GetDescription().GetValue(),
CredentialStoreId: vaultStore.GetPublicId(),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
CredentialType: string(globals.UsernamePasswordCredentialType),
},
Credential: func() *structpb.Struct {
@@ -3037,7 +3037,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
Name: clsRespUsernamePasswordWithMapping.GetItem().GetName().GetValue(),
Description: clsRespUsernamePasswordWithMapping.GetItem().GetDescription().GetValue(),
CredentialStoreId: vaultStore.GetPublicId(),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
CredentialType: string(globals.UsernamePasswordCredentialType),
},
Credential: func() *structpb.Struct {
@@ -3063,7 +3063,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
Name: upCredResp.GetItem().GetName().GetValue(),
Description: upCredResp.GetItem().GetDescription().GetValue(),
CredentialStoreId: staticStore.GetPublicId(),
Type: credstatic.Subtype.String(),
Type: globals.StaticSubtype.String(),
CredentialType: string(globals.UsernamePasswordCredentialType),
},
Credential: func() *structpb.Struct {
@@ -3089,7 +3089,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
Name: sshPkCredResp.GetItem().GetName().GetValue(),
Description: sshPkCredResp.GetItem().GetDescription().GetValue(),
CredentialStoreId: staticStore.GetPublicId(),
Type: credstatic.Subtype.String(),
Type: globals.StaticSubtype.String(),
CredentialType: string(globals.SshPrivateKeyCredentialType),
},
Credential: func() *structpb.Struct {
@@ -3115,7 +3115,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
Name: clsRespSshPrivateKey.GetItem().GetName().GetValue(),
Description: clsRespSshPrivateKey.GetItem().GetDescription().GetValue(),
CredentialStoreId: vaultStore.GetPublicId(),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
CredentialType: string(globals.SshPrivateKeyCredentialType),
},
Credential: func() *structpb.Struct {
@@ -3141,7 +3141,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
Name: clsRespSshPrivateKeyWithMapping.GetItem().GetName().GetValue(),
Description: clsRespSshPrivateKeyWithMapping.GetItem().GetDescription().GetValue(),
CredentialStoreId: vaultStore.GetPublicId(),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
CredentialType: string(globals.SshPrivateKeyCredentialType),
},
Credential: func() *structpb.Struct {
@@ -3167,7 +3167,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
Name: sshPkWithPassCredResp.GetItem().GetName().GetValue(),
Description: sshPkWithPassCredResp.GetItem().GetDescription().GetValue(),
CredentialStoreId: staticStore.GetPublicId(),
Type: credstatic.Subtype.String(),
Type: globals.StaticSubtype.String(),
CredentialType: string(globals.SshPrivateKeyCredentialType),
},
Credential: func() *structpb.Struct {
@@ -3194,7 +3194,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
Name: clsRespSshPrivateKeyWithPass.GetItem().GetName().GetValue(),
Description: clsRespSshPrivateKeyWithPass.GetItem().GetDescription().GetValue(),
CredentialStoreId: vaultStore.GetPublicId(),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
CredentialType: string(globals.SshPrivateKeyCredentialType),
},
Credential: func() *structpb.Struct {
@@ -3221,7 +3221,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
Name: clsRespSshPrivateKeyWithPassWithMapping.GetItem().GetName().GetValue(),
Description: clsRespSshPrivateKeyWithPassWithMapping.GetItem().GetDescription().GetValue(),
CredentialStoreId: vaultStore.GetPublicId(),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
CredentialType: string(globals.SshPrivateKeyCredentialType),
},
Credential: func() *structpb.Struct {
@@ -3435,7 +3435,7 @@ func TestAuthorizeSession_Errors(t *testing.T) {
clsResp, err := credService.CreateCredentialLibrary(ctx, &pbs.CreateCredentialLibraryRequest{Item: &credlibpb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Description: wrapperspb.String(fmt.Sprintf("Library Description for target %q", tar.GetName())),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &credlibpb.CredentialLibrary_VaultCredentialLibraryAttributes{
VaultCredentialLibraryAttributes: &credlibpb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String(path.Join("database", "creds", "opened")),
@@ -3460,7 +3460,7 @@ func TestAuthorizeSession_Errors(t *testing.T) {
clsResp, err := credService.CreateCredentialLibrary(ctx, &pbs.CreateCredentialLibraryRequest{Item: &credlibpb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Description: wrapperspb.String(fmt.Sprintf("Library Description for target %q", tar.GetName())),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &credlibpb.CredentialLibrary_VaultCredentialLibraryAttributes{
VaultCredentialLibraryAttributes: &credlibpb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String("bad path"),
@@ -3485,7 +3485,7 @@ func TestAuthorizeSession_Errors(t *testing.T) {
clsResp, err := credService.CreateCredentialLibrary(ctx, &pbs.CreateCredentialLibraryRequest{Item: &credlibpb.CredentialLibrary{
CredentialStoreId: expiredStore.GetPublicId(),
Description: wrapperspb.String(fmt.Sprintf("Library Description for target %q", tar.GetName())),
Type: vault.GenericLibrarySubtype.String(),
Type: globals.VaultGenericLibrarySubtype.String(),
Attrs: &credlibpb.CredentialLibrary_VaultCredentialLibraryAttributes{
VaultCredentialLibraryAttributes: &credlibpb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String(path.Join("database", "creds", "opened")),
@@ -8,12 +8,12 @@ import (
"math"
"github.com/golang/protobuf/ptypes/wrappers"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/daemon/controller/handlers"
"github.com/hashicorp/boundary/internal/daemon/controller/handlers/targets"
"github.com/hashicorp/boundary/internal/session"
"github.com/hashicorp/boundary/internal/target"
"github.com/hashicorp/boundary/internal/target/store"
"github.com/hashicorp/boundary/internal/target/tcp"
tcpStore "github.com/hashicorp/boundary/internal/target/tcp/store"
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/targets"
)
@@ -129,5 +129,5 @@ func init() {
panic(err)
}
targets.Register(tcp.Subtype, maskManager, newAttribute, setAttributes, noopSessionValidation)
targets.Register(globals.TcpSubtype, maskManager, newAttribute, setAttributes, noopSessionValidation)
}
+1 -6
View File
@@ -14,16 +14,11 @@ import (
)
func init() {
if err := subtypes.Register(host.Domain, Subtype, globals.PluginHostCatalogPrefix, globals.PluginHostCatalogPreviousPrefix, globals.PluginHostSetPrefix, globals.PluginHostSetPreviousPrefix, globals.PluginHostPrefix, globals.PluginHostPreviousPrefix); err != nil {
if err := subtypes.Register(host.Domain, globals.PluginSubtype, globals.PluginHostCatalogPrefix, globals.PluginHostCatalogPreviousPrefix, globals.PluginHostSetPrefix, globals.PluginHostSetPreviousPrefix, globals.PluginHostPrefix, globals.PluginHostPreviousPrefix); err != nil {
panic(err)
}
}
// PublicId prefixes for the resources in the plugin package.
const (
Subtype = subtypes.Subtype("plugin")
)
func newHostCatalogId(ctx context.Context) (string, error) {
id, err := db.NewPublicId(ctx, globals.PluginHostCatalogPrefix)
if err != nil {
+1 -6
View File
@@ -14,16 +14,11 @@ import (
)
func init() {
if err := subtypes.Register(host.Domain, Subtype, globals.StaticHostCatalogPrefix, globals.StaticHostSetPrefix, globals.StaticHostPrefix); err != nil {
if err := subtypes.Register(host.Domain, globals.StaticSubtype, globals.StaticHostCatalogPrefix, globals.StaticHostSetPrefix, globals.StaticHostPrefix); err != nil {
panic(err)
}
}
// PublicId prefixes for the resources in the static package.
const (
Subtype = subtypes.Subtype("static")
)
func newHostCatalogId(ctx context.Context) (string, error) {
id, err := db.NewPublicId(ctx, globals.StaticHostCatalogPrefix)
if err != nil {
+2 -2
View File
@@ -207,7 +207,7 @@ func (a ACL) Allowed(r Resource, aType action.Type, userId string, opt ...Option
case grant.id == r.Id &&
grant.id != "" &&
grant.id != "*" &&
(grant.typ == resource.Unknown || grant.typ == globals.ResourceTypeFromPrefix(grant.id)) &&
(grant.typ == resource.Unknown || grant.typ == globals.ResourceInfoFromPrefix(grant.id).Type) &&
!action.List.IsActionOrParent(aType) &&
!action.Create.IsActionOrParent(aType):
@@ -306,7 +306,7 @@ func (a ACL) ListPermissions(requestedScopes map[string]*scopes.ScopeInfo,
grants := a.scopeMap[scopeId]
for _, grant := range grants {
// This grant doesn't match what we're looking for, ignore.
if grant.typ != requestedType && grant.typ != resource.All && globals.ResourceTypeFromPrefix(grant.id) != requestedType {
if grant.typ != requestedType && grant.typ != resource.All && globals.ResourceInfoFromPrefix(grant.id).Type != requestedType {
continue
}
+3 -3
View File
@@ -439,10 +439,10 @@ func Parse(ctx context.Context, scopeId, grantString string, opt ...Option) (Gra
var seenType resource.Type
for i, id := range grantIds {
if i == 0 {
seenType = globals.ResourceTypeFromPrefix(id)
seenType = globals.ResourceInfoFromPrefix(id).Type
continue
}
if seenType != globals.ResourceTypeFromPrefix(id) {
if seenType != globals.ResourceInfoFromPrefix(id).Type {
return Grant{}, errors.New(ctx, errors.InvalidParameter, op, fmt.Sprintf("input grant string %q contains ids of differently-typed resources", grantString))
}
}
@@ -524,7 +524,7 @@ func Parse(ctx context.Context, scopeId, grantString string, opt ...Option) (Gra
// the second example the type corresponding to the ID must have the
// specified type as a child type; in the third the ID must be a
// type that has child types.
idType := globals.ResourceTypeFromPrefix(grantIds[i])
idType := globals.ResourceInfoFromPrefix(grantIds[i]).Type
if idType == resource.Unknown {
return Grant{}, errors.New(ctx, errors.InvalidParameter, op, fmt.Sprintf("parsed grant string %q contains an id %q of an unknown resource type", grant.CanonicalString(), grantIds[i]))
}
+1 -5
View File
@@ -15,15 +15,11 @@ import (
const StorageDomain = "storage"
func init() {
if err := subtypes.Register(StorageDomain, Subtype, globals.PluginStorageBucketPrefix); err != nil {
if err := subtypes.Register(StorageDomain, globals.PluginSubtype, globals.PluginStorageBucketPrefix); err != nil {
panic(err)
}
}
const (
Subtype = subtypes.Subtype("plugin")
)
func newStorageBucketId(ctx context.Context) (string, error) {
const op = "plugin.newStorageBucketId"
id, err := db.NewPublicId(ctx, globals.PluginStorageBucketPrefix)
+3 -3
View File
@@ -7,9 +7,9 @@ import (
"net"
"time"
"github.com/hashicorp/boundary/globals"
intglobals "github.com/hashicorp/boundary/internal/globals"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/types/subtypes"
)
// GetOpts - iterate the inbound Options and return a struct
@@ -35,7 +35,7 @@ type options struct {
WithProjectIds []string
WithProjectName string
WithUserId string
WithType subtypes.Subtype
WithType globals.Subtype
WithHostSources []string
WithCredentialLibraries []*CredentialLibrary
WithStaticCredentials []*StaticCredential
@@ -148,7 +148,7 @@ func WithUserId(userId string) Option {
}
// WithType provides an option to search by a target type
func WithType(t subtypes.Subtype) Option {
func WithType(t globals.Subtype) Option {
return func(o *options) {
o.WithType = t
}
+2 -2
View File
@@ -6,10 +6,10 @@ package target
import (
"testing"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/credential"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/target/store"
"github.com/hashicorp/boundary/internal/types/subtypes"
"github.com/stretchr/testify/assert"
)
@@ -103,7 +103,7 @@ func Test_GetOpts(t *testing.T) {
assert.Equal(opts, testOpts)
})
t.Run("WithType", func(t *testing.T) {
subtype := subtypes.Subtype("testtype")
subtype := globals.Subtype("testtype")
assert := assert.New(t)
opts := GetOpts(WithType(subtype))
testOpts := getDefaultOptions()
+15 -14
View File
@@ -8,6 +8,7 @@ import (
"fmt"
"sync"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/types/subtypes"
)
@@ -57,12 +58,12 @@ type registryEntry struct {
}
type registry struct {
m map[subtypes.Subtype]*registryEntry
m map[globals.Subtype]*registryEntry
sync.RWMutex
}
func (r *registry) set(s subtypes.Subtype, entry *registryEntry) {
func (r *registry) set(s globals.Subtype, entry *registryEntry) {
r.Lock()
defer r.Unlock()
@@ -78,7 +79,7 @@ func (r *registry) set(s subtypes.Subtype, entry *registryEntry) {
r.m[s] = entry
}
func (r *registry) get(s subtypes.Subtype) (*registryEntry, bool) {
func (r *registry) get(s globals.Subtype) (*registryEntry, bool) {
r.RLock()
defer r.RUnlock()
@@ -89,7 +90,7 @@ func (r *registry) get(s subtypes.Subtype) (*registryEntry, bool) {
return nil, ok
}
func (r *registry) newFunc(s subtypes.Subtype) (NewFunc, bool) {
func (r *registry) newFunc(s globals.Subtype) (NewFunc, bool) {
entry, ok := r.get(s)
if !ok {
return nil, ok
@@ -97,7 +98,7 @@ func (r *registry) newFunc(s subtypes.Subtype) (NewFunc, bool) {
return entry.targetHooks.NewTarget, ok
}
func (r *registry) allocFunc(s subtypes.Subtype) (AllocFunc, bool) {
func (r *registry) allocFunc(s globals.Subtype) (AllocFunc, bool) {
entry, ok := r.get(s)
if !ok {
return nil, ok
@@ -105,7 +106,7 @@ func (r *registry) allocFunc(s subtypes.Subtype) (AllocFunc, bool) {
return entry.targetHooks.AllocTarget, ok
}
func (r *registry) vetFunc(s subtypes.Subtype) (VetFunc, bool) {
func (r *registry) vetFunc(s globals.Subtype) (VetFunc, bool) {
entry, ok := r.get(s)
if !ok {
return nil, ok
@@ -113,7 +114,7 @@ func (r *registry) vetFunc(s subtypes.Subtype) (VetFunc, bool) {
return entry.targetHooks.Vet, ok
}
func (r *registry) vetForUpdateFunc(s subtypes.Subtype) (VetForUpdateFunc, bool) {
func (r *registry) vetForUpdateFunc(s globals.Subtype) (VetForUpdateFunc, bool) {
entry, ok := r.get(s)
if !ok {
return nil, ok
@@ -121,7 +122,7 @@ func (r *registry) vetForUpdateFunc(s subtypes.Subtype) (VetForUpdateFunc, bool)
return entry.targetHooks.VetForUpdate, ok
}
func (r *registry) vetCredentialSourcesFunc(s subtypes.Subtype) (VetCredentialSourcesFunc, bool) {
func (r *registry) vetCredentialSourcesFunc(s globals.Subtype) (VetCredentialSourcesFunc, bool) {
entry, ok := r.get(s)
if !ok {
return nil, ok
@@ -130,7 +131,7 @@ func (r *registry) vetCredentialSourcesFunc(s subtypes.Subtype) (VetCredentialSo
return entry.targetHooks.VetCredentialSources, ok
}
func (r *registry) idPrefix(s subtypes.Subtype) (string, bool) {
func (r *registry) idPrefix(s globals.Subtype) (string, bool) {
entry, ok := r.get(s)
if !ok {
return "", ok
@@ -139,18 +140,18 @@ func (r *registry) idPrefix(s subtypes.Subtype) (string, bool) {
}
var subtypeRegistry = registry{
m: make(map[subtypes.Subtype]*registryEntry),
m: make(map[globals.Subtype]*registryEntry),
}
// SubtypeFromType returns the Subtype from the provided string or if
// no Subtype was registered with that string Unknown is returned.
func SubtypeFromType(t string) subtypes.Subtype {
func SubtypeFromType(t string) globals.Subtype {
return subtypes.SubtypeFromType(domain, t)
}
// SubtypeFromId returns the Subtype from the provided id if the id's prefix
// was registered with a Subtype. Otherwise Unknown is returned.
func SubtypeFromId(id string) subtypes.Subtype {
func SubtypeFromId(id string) globals.Subtype {
return subtypes.SubtypeFromId(domain, id)
}
@@ -160,7 +161,7 @@ func Prefixes() []string {
}
// New creates a Target of the given subtype and projectId.
func New(ctx context.Context, subtype subtypes.Subtype, projectId string, opt ...Option) (Target, error) {
func New(ctx context.Context, subtype globals.Subtype, projectId string, opt ...Option) (Target, error) {
const op = "target.New"
nf, ok := subtypeRegistry.newFunc(subtype)
if !ok {
@@ -172,7 +173,7 @@ func New(ctx context.Context, subtype subtypes.Subtype, projectId string, opt ..
// Register registers repository hooks and the prefixes for a provided Subtype. Register
// panics if the subtype has already been registered or if any of the
// prefixes are associated with another subtype.
func Register(s subtypes.Subtype, th targetHooks, prefix string) {
func Register(s globals.Subtype, th targetHooks, prefix string) {
subtypeRegistry.set(s, &registryEntry{
targetHooks: th,
prefix: prefix,
@@ -9,12 +9,12 @@ import (
"fmt"
"strings"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/credential"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/oplog"
"github.com/hashicorp/boundary/internal/types/subtypes"
"github.com/hashicorp/go-secure-stdlib/strutil"
)
@@ -536,7 +536,7 @@ func fetchCredentialSources(ctx context.Context, r db.Reader, targetId string) (
return ret, nil
}
func (r *Repository) createSources(ctx context.Context, tId string, tSubtype subtypes.Subtype, credSources CredentialSources) ([]*CredentialLibrary, []*StaticCredential, error) {
func (r *Repository) createSources(ctx context.Context, tId string, tSubtype globals.Subtype, credSources CredentialSources) ([]*CredentialLibrary, []*StaticCredential, error) {
const op = "target.(Repository).createSources"
// Get a list of unique ids being attached to the target, to be used for looking up the source type (library or static)
@@ -46,7 +46,7 @@ func (h hooks) VetCredentialSources(ctx context.Context, cls []*target.Credentia
func TestRepository_SetTargetCredentialSources(t *testing.T) {
ctx := context.Background()
target.Register(targettest.Subtype, hooks{}, globals.TcpTargetPrefix)
target.Register(globals.TcpSubtype, hooks{}, globals.TcpTargetPrefix)
t.Parallel()
conn, _ := db.TestSetup(t, "postgres")
+4 -4
View File
@@ -8,12 +8,12 @@ import (
goerrs "errors"
"fmt"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/boundary"
"github.com/hashicorp/boundary/internal/db/timestamp"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/oplog"
"github.com/hashicorp/boundary/internal/target/store"
"github.com/hashicorp/boundary/internal/types/subtypes"
)
// Target is a commmon interface for all target subtypes
@@ -25,7 +25,7 @@ type Target interface {
GetName() string
GetDescription() string
GetVersion() uint32
GetType() subtypes.Subtype
GetType() globals.Subtype
GetCreateTime() *timestamp.Timestamp
GetUpdateTime() *timestamp.Timestamp
GetSessionMaxSeconds() uint32
@@ -140,8 +140,8 @@ func (t targetView) GetUserId() string {
return ""
}
func (t *targetView) Subtype() subtypes.Subtype {
return subtypes.Subtype(t.Type)
func (t *targetView) Subtype() globals.Subtype {
return globals.Subtype(t.Type)
}
// targetSubtype converts the target view to the concrete subtype
+2 -7
View File
@@ -18,15 +18,10 @@ import (
"github.com/hashicorp/boundary/internal/oplog"
"github.com/hashicorp/boundary/internal/target"
"github.com/hashicorp/boundary/internal/target/targettest/store"
"github.com/hashicorp/boundary/internal/types/subtypes"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"
)
const (
Subtype = subtypes.Subtype("tcp")
)
// Target is a target.Target used for tests.
type Target struct {
*store.Target
@@ -103,8 +98,8 @@ func (t *Target) GetVersion() uint32 {
return t.Version
}
func (t *Target) GetType() subtypes.Subtype {
return Subtype
func (t *Target) GetType() globals.Subtype {
return globals.TcpSubtype
}
func (t *Target) GetCreateTime() *timestamp.Timestamp {
+2 -1
View File
@@ -9,6 +9,7 @@ import (
"math"
"strings"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/credential"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/target"
@@ -17,7 +18,7 @@ import (
type targetHooks struct{}
func init() {
target.Register(Subtype, targetHooks{}, TargetPrefix)
target.Register(globals.TcpSubtype, targetHooks{}, TargetPrefix)
}
const (
@@ -59,7 +59,7 @@ func TestRepository_CreateTarget(t *testing.T) {
name: "valid-org",
args: args{
target: func() target.Target {
target, err := target.New(ctx, tcp.Subtype, proj.PublicId,
target, err := target.New(ctx, globals.TcpSubtype, proj.PublicId,
target.WithName("valid-org"),
target.WithDescription("valid-org"),
target.WithDefaultPort(uint32(22)))
@@ -73,7 +73,7 @@ func TestRepository_CreateTarget(t *testing.T) {
name: "with-address",
args: args{
target: func() target.Target {
target, err := target.New(ctx, tcp.Subtype, proj.PublicId,
target, err := target.New(ctx, globals.TcpSubtype, proj.PublicId,
target.WithName("with-address"),
target.WithDescription("with-address"),
target.WithDefaultPort(80),
@@ -88,7 +88,7 @@ func TestRepository_CreateTarget(t *testing.T) {
name: "with-address-whitespace",
args: args{
target: func() target.Target {
target, err := target.New(ctx, tcp.Subtype, proj.PublicId,
target, err := target.New(ctx, globals.TcpSubtype, proj.PublicId,
target.WithName("with-address-whitespace"),
target.WithDescription("with-address-whitespace"),
target.WithDefaultPort(80),
@@ -125,7 +125,7 @@ func TestRepository_CreateTarget(t *testing.T) {
target: func() target.Target {
tar, err := target.New(
ctx,
tcp.Subtype,
globals.TcpSubtype,
proj.PublicId,
target.WithName("valid-org"),
target.WithDescription("valid-org"),
@@ -147,7 +147,7 @@ func TestRepository_CreateTarget(t *testing.T) {
target: func() target.Target {
tar, err := target.New(
ctx,
tcp.Subtype,
globals.TcpSubtype,
proj.PublicId,
target.WithName("empty-project-id"),
)
@@ -163,7 +163,7 @@ func TestRepository_CreateTarget(t *testing.T) {
name: "valid-with-egress-filter",
args: args{
target: func() target.Target {
target, err := target.New(ctx, tcp.Subtype, proj.PublicId,
target, err := target.New(ctx, globals.TcpSubtype, proj.PublicId,
target.WithName("valid-egress-filter"),
target.WithDescription("valid-org"),
target.WithDefaultPort(uint32(22)),
@@ -178,7 +178,7 @@ func TestRepository_CreateTarget(t *testing.T) {
name: "deprecated-worker-filter",
args: args{
target: func() target.Target {
target, err := target.New(ctx, tcp.Subtype, proj.PublicId,
target, err := target.New(ctx, globals.TcpSubtype, proj.PublicId,
target.WithName("bad-worker-filter"),
target.WithDescription("valid-org"),
target.WithDefaultPort(uint32(22)),
@@ -194,7 +194,7 @@ func TestRepository_CreateTarget(t *testing.T) {
name: "invalid-setting-egress-and-worker-filter",
args: args{
target: func() target.Target {
target, err := target.New(ctx, tcp.Subtype, proj.PublicId,
target, err := target.New(ctx, globals.TcpSubtype, proj.PublicId,
target.WithName("bad-filters"),
target.WithDescription("valid-org"),
target.WithDefaultPort(uint32(22)),
+2 -2
View File
@@ -223,7 +223,7 @@ func TestRepository_DeleteTarget(t *testing.T) {
name: "no-public-id",
args: args{
target: func() target.Target {
tar, _ := target.New(ctx, tcp.Subtype, proj.PublicId)
tar, _ := target.New(ctx, globals.TcpSubtype, proj.PublicId)
return tar
}(),
},
@@ -237,7 +237,7 @@ func TestRepository_DeleteTarget(t *testing.T) {
target: func() target.Target {
id, err := db.NewPublicId(ctx, globals.TcpTargetPrefix)
require.NoError(t, err)
tar, _ := target.New(ctx, tcp.Subtype, proj.PublicId)
tar, _ := target.New(ctx, globals.TcpSubtype, proj.PublicId)
tar.SetPublicId(ctx, id)
return tar
}(),
+3 -4
View File
@@ -11,19 +11,18 @@ import (
"fmt"
"strings"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/db/timestamp"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/oplog"
"github.com/hashicorp/boundary/internal/target"
"github.com/hashicorp/boundary/internal/target/tcp/store"
"github.com/hashicorp/boundary/internal/types/subtypes"
"google.golang.org/protobuf/proto"
)
const (
defaultTableName = "target_tcp"
Subtype = subtypes.Subtype("tcp")
)
// Target is a resources that represets a networked service
@@ -132,8 +131,8 @@ func (t *Target) Oplog(op oplog.OpType) oplog.Metadata {
return metadata
}
func (t *Target) GetType() subtypes.Subtype {
return Subtype
func (t *Target) GetType() globals.Subtype {
return globals.TcpSubtype
}
func (t *Target) GetAddress() string {
+7 -7
View File
@@ -55,7 +55,7 @@ func TestTarget_Create(t *testing.T) {
want: func() target.Target {
t, _ := target.New(
ctx,
tcp.Subtype,
globals.TcpSubtype,
prj.PublicId,
target.WithName("valid-proj-id"),
target.WithSessionMaxSeconds(uint32((8 * time.Hour).Seconds())),
@@ -69,7 +69,7 @@ func TestTarget_Create(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
got, err := target.New(ctx, tcp.Subtype, tt.args.projectId, tt.args.opt...)
got, err := target.New(ctx, globals.TcpSubtype, tt.args.projectId, tt.args.opt...)
if tt.wantErr {
require.Error(err)
assert.True(errors.Match(errors.T(tt.wantIsErr), err))
@@ -117,7 +117,7 @@ func TestTarget_Delete(t *testing.T) {
{
name: "bad-id",
target: func() target.Target {
tar, _ := target.New(ctx, tcp.Subtype, proj.PublicId)
tar, _ := target.New(ctx, globals.TcpSubtype, proj.PublicId)
id, err := db.NewPublicId(ctx, globals.TcpTargetPrefix)
require.NoError(t, err)
@@ -312,7 +312,7 @@ func TestTarget_Update(t *testing.T) {
require.NoError(err)
assert.Equal(1, updatedRows)
foundTarget, _ := target.New(ctx, tcp.Subtype, proj2.PublicId)
foundTarget, _ := target.New(ctx, globals.TcpSubtype, proj2.PublicId)
foundTarget.SetPublicId(ctx, projTarget.GetPublicId())
err = rw.LookupByPublicId(ctx, foundTarget)
require.NoError(err)
@@ -369,9 +369,9 @@ func TestTable_SetTableName(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
def, _ := target.New(ctx, tcp.Subtype, "testScope")
def, _ := target.New(ctx, globals.TcpSubtype, "testScope")
require.Equal(defaultTableName, def.(*tcp.Target).TableName())
ss, _ := target.New(ctx, tcp.Subtype, "testScope")
ss, _ := target.New(ctx, globals.TcpSubtype, "testScope")
s := ss.(*tcp.Target)
s.SetTableName(tt.setNameTo)
assert.Equal(tt.want, s.TableName())
@@ -391,7 +391,7 @@ func TestTarget_oplog(t *testing.T) {
{
name: "simple",
target: func() target.Target {
tar, _ := target.New(ctx, tcp.Subtype, id)
tar, _ := target.New(ctx, globals.TcpSubtype, id)
if err := tar.SetPublicId(ctx, id); err != nil {
t.Fatalf("failed to set public id: %s", err)
}
+2 -1
View File
@@ -8,6 +8,7 @@ import (
"fmt"
"testing"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/target"
"github.com/hashicorp/go-uuid"
@@ -21,7 +22,7 @@ func TestTarget(ctx context.Context, t testing.TB, conn *db.DB, projectId, name
opts := target.GetOpts(opt...)
require := require.New(t)
rw := db.New(conn)
tar, err := target.New(ctx, Subtype, projectId, opt...)
tar, err := target.New(ctx, globals.TcpSubtype, projectId, opt...)
require.NoError(err)
id, err := db.NewPublicId(ctx, TargetPrefix)
require.NoError(err)
@@ -19,7 +19,6 @@ import (
"github.com/hashicorp/boundary/api/scopes"
"github.com/hashicorp/boundary/api/targets"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/credential"
"github.com/hashicorp/boundary/internal/daemon/controller"
tg "github.com/hashicorp/boundary/internal/daemon/controller/handlers/targets"
_ "github.com/hashicorp/boundary/internal/daemon/controller/handlers/targets/tcp"
@@ -52,7 +51,7 @@ func TestList(t *testing.T) {
require.NoError(err)
assert.Empty(ul.Items)
cred, err := credClient.Create(tc.Context(), credential.UsernamePasswordSubtype.String(), cs.Item.Id,
cred, err := credClient.Create(tc.Context(), globals.UsernamePasswordSubtype.String(), cs.Item.Id,
credentials.WithName("0"),
credentials.WithDescription("description"),
credentials.WithUsernamePasswordCredentialUsername("user"),
@@ -67,7 +66,7 @@ func TestList(t *testing.T) {
assert.ElementsMatch(comparableCatalogSlice(expected[:1]), comparableCatalogSlice(ul.Items))
for i := 1; i < 10; i++ {
cred, err := credClient.Create(tc.Context(), credential.UsernamePasswordSubtype.String(), cs.Item.Id,
cred, err := credClient.Create(tc.Context(), globals.UsernamePasswordSubtype.String(), cs.Item.Id,
credentials.WithName(fmt.Sprintf("%d", i)),
credentials.WithDescription("description"),
credentials.WithUsernamePasswordCredentialUsername("user"),
@@ -127,7 +126,7 @@ func TestCrud(t *testing.T) {
}
credClient := credentials.NewClient(client)
cred, err := credClient.Create(tc.Context(), credential.UsernamePasswordSubtype.String(), cs.Item.Id, credentials.WithName("foo"),
cred, err := credClient.Create(tc.Context(), globals.UsernamePasswordSubtype.String(), cs.Item.Id, credentials.WithName("foo"),
credentials.WithUsernamePasswordCredentialUsername("user"), credentials.WithUsernamePasswordCredentialPassword("pass"))
require.NoError(err)
require.NotNil(cs)
@@ -197,7 +196,7 @@ func TestCrudSpk(t *testing.T) {
spkWithPass := string(testdata.PEMEncryptedKeys[0].PEMBytes)
pass := testdata.PEMEncryptedKeys[0].EncryptionKey
cred, err := credClient.Create(tc.Context(), credential.SshPrivateKeySubtype.String(), cs.Item.Id, credentials.WithName("foo"),
cred, err := credClient.Create(tc.Context(), globals.SshPrivateKeySubtype.String(), cs.Item.Id, credentials.WithName("foo"),
credentials.WithSshPrivateKeyCredentialUsername("user"),
credentials.WithSshPrivateKeyCredentialPrivateKey(spkWithPass),
credentials.WithSshPrivateKeyCredentialPrivateKeyPassphrase(pass))
@@ -275,7 +274,7 @@ func TestCrudJson(t *testing.T) {
"username": "admin",
"password": "pass",
}
cred, err := credClient.Create(tc.Context(), credential.JsonSubtype.String(), cs.Item.Id, credentials.WithName("foo"), credentials.WithJsonCredentialObject(obj))
cred, err := credClient.Create(tc.Context(), globals.JsonSubtype.String(), cs.Item.Id, credentials.WithName("foo"), credentials.WithJsonCredentialObject(obj))
require.NoError(err)
require.NotNil(cred)
checkResource("create", cred.Item, "foo", 1)
@@ -361,7 +360,7 @@ func TestErrors(t *testing.T) {
c := credentials.NewClient(client)
cred, err := c.Create(tc.Context(), credential.UsernamePasswordSubtype.String(), cs.Item.Id, credentials.WithName("foo"),
cred, err := c.Create(tc.Context(), globals.UsernamePasswordSubtype.String(), cs.Item.Id, credentials.WithName("foo"),
credentials.WithUsernamePasswordCredentialUsername("user"), credentials.WithUsernamePasswordCredentialPassword("pass"))
require.NoError(err)
require.NotNil(cred)
@@ -383,7 +382,7 @@ func TestErrors(t *testing.T) {
assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode())
// Same name
_, err = c.Create(tc.Context(), credential.UsernamePasswordSubtype.String(), proj.GetPublicId(), credentials.WithName("foo"))
_, err = c.Create(tc.Context(), globals.UsernamePasswordSubtype.String(), proj.GetPublicId(), credentials.WithName("foo"))
require.Error(err)
apiErr = api.AsServerError(err)
assert.NotNil(apiErr)
@@ -442,7 +441,7 @@ func TestUpdateAfterKeyRotation(t *testing.T) {
"username": "admin",
"password": "pass",
}
cred, err := credsClient.Create(ctx, credential.JsonSubtype.String(), cs.Item.Id, credentials.WithName("foo"), credentials.WithJsonCredentialObject(obj))
cred, err := credsClient.Create(ctx, globals.JsonSubtype.String(), cs.Item.Id, credentials.WithName("foo"), credentials.WithJsonCredentialObject(obj))
require.NoError(err)
targ, err := tgClient.Create(ctx, "tcp", proj.PublicId, targets.WithName("my-target"), targets.WithTcpTargetDefaultPort(22))
require.NoError(err)
@@ -6,13 +6,14 @@ package subtypes
import (
"fmt"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/daemon/controller/handlers"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/types/known/structpb"
)
func convertAttributesToSubtype(msg proto.Message, st Subtype) error {
func convertAttributesToSubtype(msg proto.Message, st globals.Subtype) error {
r := msg.ProtoReflect()
d := r.Descriptor()
@@ -55,7 +56,7 @@ func convertAttributesToSubtype(msg proto.Message, st Subtype) error {
return nil
}
func convertAttributesToDefault(msg proto.Message, st Subtype) error {
func convertAttributesToDefault(msg proto.Message, st globals.Subtype) error {
r := msg.ProtoReflect()
d := r.Descriptor()
+5 -4
View File
@@ -7,6 +7,7 @@ import (
"fmt"
"sync"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/sdk/pbs/controller/protooptions"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
@@ -33,7 +34,7 @@ func init() {
})
}
type fieldMap map[Subtype]protoreflect.FieldDescriptor
type fieldMap map[globals.Subtype]protoreflect.FieldDescriptor
type attributeRegistry struct {
sync.RWMutex
@@ -72,7 +73,7 @@ func (ak *attributeRegistry) register(d protoreflect.MessageDescriptor) error {
opts := f.Options().(*descriptorpb.FieldOptions)
st := proto.GetExtension(opts, protooptions.E_Subtype).(string)
if st != "" {
km[Subtype(st)] = f
km[globals.Subtype(st)] = f
}
}
@@ -99,7 +100,7 @@ func (ak *attributeRegistry) register(d protoreflect.MessageDescriptor) error {
// attributeField retrieves the FieldDescriptor for a given subtype's
// attribute fields. If the corresponding protobuf message has not been
// registered it will return an error.
func (ak *attributeRegistry) attributeField(d protoreflect.MessageDescriptor, t Subtype) (protoreflect.FieldDescriptor, error) {
func (ak *attributeRegistry) attributeField(d protoreflect.MessageDescriptor, t globals.Subtype) (protoreflect.FieldDescriptor, error) {
ak.RLock()
defer ak.RUnlock()
@@ -124,6 +125,6 @@ func (ak *attributeRegistry) attributeField(d protoreflect.MessageDescriptor, t
// attributeField is used by the AttributeTransformInterceptor to retrieve
// the proto FieldDescriptor for a given subtype.
func attributeField(d protoreflect.MessageDescriptor, t Subtype) (protoreflect.FieldDescriptor, error) {
func attributeField(d protoreflect.MessageDescriptor, t globals.Subtype) (protoreflect.FieldDescriptor, error) {
return globalAttributeRegistry.attributeField(d, t)
}
+5 -4
View File
@@ -6,6 +6,7 @@ package subtypes
import (
"testing"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/gen/testing/attribute"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -17,7 +18,7 @@ func TestProtoAttributeKey(t *testing.T) {
cases := []struct {
name string
msg proto.Message
subtype Subtype
subtype globals.Subtype
expected protoreflect.FullName
}{
{
@@ -35,7 +36,7 @@ func TestProtoAttributeKey(t *testing.T) {
{
"TestResource/unknown",
&attribute.TestResource{},
UnknownSubtype,
globals.UnknownSubtype,
"testing.attribute.v1.TestResource.attributes",
},
}
@@ -54,7 +55,7 @@ func TestProtoAttributeKeyErrors(t *testing.T) {
cases := []struct {
name string
msg proto.Message
subtype Subtype
subtype globals.Subtype
expectedErr string
}{
{
@@ -72,7 +73,7 @@ func TestProtoAttributeKeyErrors(t *testing.T) {
{
"TestNoAttributes/unknown",
&attribute.TestNoAttributes{},
UnknownSubtype,
globals.UnknownSubtype,
"proto message testing.attribute.v1.TestNoAttributes not registered",
},
}
+4 -3
View File
@@ -7,6 +7,7 @@ import (
"context"
"errors"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/daemon/controller/handlers"
"github.com/hashicorp/boundary/sdk/pbs/controller/protooptions"
"google.golang.org/grpc"
@@ -114,7 +115,7 @@ func transformRequestAttributes(req proto.Message) error {
return m.Get(fd).String()
}
var st Subtype
var st globals.Subtype
switch {
case itemField != nil:
itemR := itemField.Message()
@@ -138,7 +139,7 @@ func transformRequestAttributes(req proto.Message) error {
case sourceIdField != nil && sourceId != "":
st = SubtypeFromId(domain, sourceId)
case typeField != nil && t != "":
st = Subtype(t)
st = globals.Subtype(t)
default: // need either type or id
return nil
}
@@ -172,7 +173,7 @@ func transformResponseItemAttributes(item proto.Message) error {
return nil
}
st := Subtype(item.ProtoReflect().Get(typeField).String())
st := globals.Subtype(item.ProtoReflect().Get(typeField).String())
return convertAttributesToDefault(item, st)
}
-681
View File
@@ -1,681 +0,0 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package subtypes
import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/boundary/internal/daemon/controller/handlers"
"github.com/hashicorp/boundary/internal/gen/testing/attribute"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/testing/protocmp"
"google.golang.org/protobuf/types/known/structpb"
)
func init() {
Register("test", Subtype("sub_resource"), "trsr")
Register("test", Subtype("resource_plugin"), "trrp")
}
func TestTransformRequestAttributes(t *testing.T) {
cases := []struct {
name string
req proto.Message
expected proto.Message
}{
{
"TestCreateResource/SubResourceRequest",
&attribute.TestCreateResourceRequest{
Item: &attribute.TestResource{
Type: "sub_resource",
Attrs: &attribute.TestResource_Attributes{
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
},
},
&attribute.TestCreateResourceRequest{
Item: &attribute.TestResource{
Type: "sub_resource",
Attrs: &attribute.TestResource_SubResourceAttributes{
SubResourceAttributes: &attribute.TestSubResourceAttributes{
Name: "test",
},
},
},
},
},
{
"TestCreateResource/DefaultResourceRequest",
&attribute.TestCreateResourceRequest{
Item: &attribute.TestResource{
Type: "default",
Attrs: &attribute.TestResource_Attributes{
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
},
},
&attribute.TestCreateResourceRequest{
Item: &attribute.TestResource{
Type: "default",
Attrs: &attribute.TestResource_Attributes{
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
},
},
},
{
"TestCreateResource/UnknownResourceRequest",
&attribute.TestCreateResourceRequest{
Item: &attribute.TestResource{
Type: "unknown",
Attrs: &attribute.TestResource_Attributes{
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
},
},
&attribute.TestCreateResourceRequest{
Item: &attribute.TestResource{
Type: "unknown",
Attrs: &attribute.TestResource_Attributes{
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
},
},
},
{
"TestUpdateResource/SubResourceRequest",
&attribute.TestUpdateResourceRequest{
Id: "trsr_one",
Item: &attribute.TestResource{
Attrs: &attribute.TestResource_Attributes{
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
},
},
&attribute.TestUpdateResourceRequest{
Id: "trsr_one",
Item: &attribute.TestResource{
Attrs: &attribute.TestResource_SubResourceAttributes{
SubResourceAttributes: &attribute.TestSubResourceAttributes{
Name: "test",
},
},
},
},
},
{
"TestUpdateResource/PluginResourceRequest",
&attribute.TestUpdateResourceRequest{
Id: "trdp_one",
Item: &attribute.TestResource{
Attrs: &attribute.TestResource_Attributes{
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
},
},
&attribute.TestUpdateResourceRequest{
Id: "trdp_one",
Item: &attribute.TestResource{
Attrs: &attribute.TestResource_Attributes{
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
},
},
},
{
"TestUpdateResource/UnknownResourceRequest",
&attribute.TestUpdateResourceRequest{
Id: "unknown",
Item: &attribute.TestResource{
Attrs: &attribute.TestResource_Attributes{
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
},
},
&attribute.TestUpdateResourceRequest{
Id: "unknown",
Item: &attribute.TestResource{
Attrs: &attribute.TestResource_Attributes{
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
},
},
},
{
"TestRequestNoItem",
&attribute.TestRequestNoItem{
Name: "test",
},
&attribute.TestRequestNoItem{
Name: "test",
},
},
{
"TestRequestItemNotMessage",
&attribute.TestRequestItemNotMessage{
Item: "test",
},
&attribute.TestRequestItemNotMessage{
Item: "test",
},
},
{
"TestRequestItemNoType",
&attribute.TestRequestItemNoType{
Item: &attribute.TestItemNoType{
Id: "test",
},
},
&attribute.TestRequestItemNoType{
Item: &attribute.TestItemNoType{
Id: "test",
},
},
},
{
"TestNoItemAttributes/SubResourceRequest",
&attribute.TestNoItemAttributes{
Id: "trsr_one",
Attrs: &attribute.TestNoItemAttributes_Attributes{
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
},
&attribute.TestNoItemAttributes{
Id: "trsr_one",
Attrs: &attribute.TestNoItemAttributes_SubResourceAttributes{
SubResourceAttributes: &attribute.TestSubResourceAttributes{
Name: "test",
},
},
},
},
{
"TestCreateNoOneOfRequest",
&attribute.TestCreateNoOneOfRequest{
Item: &attribute.TestNoOneOf{
Type: "sub_resource",
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
},
&attribute.TestCreateNoOneOfRequest{
Item: &attribute.TestNoOneOf{
Type: "sub_resource",
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
},
},
{
"TestUpdateNoOneOfRequest",
&attribute.TestUpdateNoOneOfRequest{
Id: "trsr_one",
Item: &attribute.TestNoOneOf{
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
},
&attribute.TestUpdateNoOneOfRequest{
Id: "trsr_one",
Item: &attribute.TestNoOneOf{
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
},
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
err := transformRequest(tc.req)
require.NoError(t, err)
assert.Empty(t, cmp.Diff(tc.req, tc.expected, protocmp.Transform()))
})
}
}
func TestTransformResponseAttributes(t *testing.T) {
cases := []struct {
name string
resp proto.Message
expected proto.Message
}{
{
"TestListResourceResponse",
&attribute.TestListResourceResponse{
Items: []*attribute.TestResource{
{
Type: "sub_resource",
Attrs: &attribute.TestResource_SubResourceAttributes{
SubResourceAttributes: &attribute.TestSubResourceAttributes{
Name: "test",
},
},
},
{
Type: "default",
Attrs: &attribute.TestResource_Attributes{
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
},
},
},
&attribute.TestListResourceResponse{
Items: []*attribute.TestResource{
{
Type: "sub_resource",
Attrs: &attribute.TestResource_Attributes{
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
},
{
Type: "default",
Attrs: &attribute.TestResource_Attributes{
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
},
},
},
},
{
"TestGetResourceResponse/SubResourceAttributes",
&attribute.TestGetResourceResponse{
Item: &attribute.TestResource{
Id: "trsr_one",
Type: "sub_resource",
Attrs: &attribute.TestResource_SubResourceAttributes{
SubResourceAttributes: &attribute.TestSubResourceAttributes{
Name: "test",
},
},
},
},
&attribute.TestGetResourceResponse{
Item: &attribute.TestResource{
Id: "trsr_one",
Type: "sub_resource",
Attrs: &attribute.TestResource_Attributes{
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
},
},
},
{
"TestGetResourceResponse/PluginAttributes",
&attribute.TestGetResourceResponse{
Item: &attribute.TestResource{
Id: "trrp_one",
Type: "plugin",
Attrs: &attribute.TestResource_Attributes{
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
},
},
&attribute.TestGetResourceResponse{
Item: &attribute.TestResource{
Id: "trrp_one",
Type: "plugin",
Attrs: &attribute.TestResource_Attributes{
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
},
},
},
{
"TestCreateResourceResponse",
&attribute.TestCreateResourceResponse{
Item: &attribute.TestResource{
Id: "trsr_one",
Type: "sub_resource",
Attrs: &attribute.TestResource_SubResourceAttributes{
SubResourceAttributes: &attribute.TestSubResourceAttributes{
Name: "test",
},
},
},
},
&attribute.TestCreateResourceResponse{
Item: &attribute.TestResource{
Id: "trsr_one",
Type: "sub_resource",
Attrs: &attribute.TestResource_Attributes{
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
},
},
},
{
"TestUpdateResourceResponse",
&attribute.TestUpdateResourceResponse{
Item: &attribute.TestResource{
Id: "trsr_one",
Type: "sub_resource",
Attrs: &attribute.TestResource_SubResourceAttributes{
SubResourceAttributes: &attribute.TestSubResourceAttributes{
Name: "test",
},
},
},
},
&attribute.TestUpdateResourceResponse{
Item: &attribute.TestResource{
Id: "trsr_one",
Type: "sub_resource",
Attrs: &attribute.TestResource_Attributes{
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
},
},
},
{
"TestResponseNoItem",
&attribute.TestResponseNoItem{
Name: "test",
},
&attribute.TestResponseNoItem{
Name: "test",
},
},
{
"TestResponseItemNotMessage",
&attribute.TestResponseItemNotMessage{
Item: "test",
},
&attribute.TestResponseItemNotMessage{
Item: "test",
},
},
{
"TestResponseItemNoType",
&attribute.TestResponseItemNoType{
Item: &attribute.TestItemNoType{
Id: "test",
},
},
&attribute.TestResponseItemNoType{
Item: &attribute.TestItemNoType{
Id: "test",
},
},
},
{
"TestCreateNoOneOfResponse",
&attribute.TestCreateNoOneOfResponse{
Item: &attribute.TestNoOneOf{
Id: "trsr_one",
Type: "sub_resource",
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
},
&attribute.TestCreateNoOneOfResponse{
Item: &attribute.TestNoOneOf{
Id: "trsr_one",
Type: "sub_resource",
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
},
},
{
"TestUpdateNoOneOfResponse",
&attribute.TestUpdateNoOneOfResponse{
Item: &attribute.TestNoOneOf{
Id: "trsr_one",
Type: "sub_resource",
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
},
&attribute.TestUpdateNoOneOfResponse{
Item: &attribute.TestNoOneOf{
Id: "trsr_one",
Type: "sub_resource",
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
},
},
{
"TestCreateResourceOneofUnset",
&attribute.TestCreateResourceResponse{
Item: &attribute.TestResource{
Id: "trsr_one",
Type: "sub_resource",
},
},
&attribute.TestCreateResourceResponse{
Item: &attribute.TestResource{
Id: "trsr_one",
Type: "sub_resource",
},
},
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
err := transformResponse(tc.resp)
require.NoError(t, err)
assert.Empty(t, cmp.Diff(tc.resp, tc.expected, protocmp.Transform()))
})
}
}
func TestCustomTransformRequest(t *testing.T) {
RegisterRequestTransformationFunc(
&attribute.TestCustomTransformation{},
func(m proto.Message) error {
msg, ok := m.(*attribute.TestCustomTransformation)
require.True(t, ok, "wrong message passed to request transformation callback")
if msg.SomeRandomId == "some_random_id" && msg.SecondaryId == "secondary_id" {
newAttrs := &attribute.TestSubResourceAttributes{}
err := handlers.StructToProto(msg.GetAttributes(), newAttrs)
require.NoError(t, err)
msg.Attrs = &attribute.TestCustomTransformation_SubResourceAttributes{
SubResourceAttributes: newAttrs,
}
}
return nil
},
)
request := &attribute.TestCustomTransformation{
SomeRandomId: "some_random_id",
SecondaryId: "secondary_id",
Attrs: &attribute.TestCustomTransformation_Attributes{
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
}
expected := &attribute.TestCustomTransformation{
SomeRandomId: "some_random_id",
SecondaryId: "secondary_id",
Attrs: &attribute.TestCustomTransformation_SubResourceAttributes{
SubResourceAttributes: &attribute.TestSubResourceAttributes{
Name: "test",
},
},
}
err := transformRequest(request)
require.NoError(t, err)
assert.Empty(t, cmp.Diff(request, expected, protocmp.Transform()))
}
func TestCustomTransformResponse(t *testing.T) {
RegisterResponseTransformationFunc(
&attribute.TestCustomTransformation{},
func(m proto.Message) error {
msg, ok := m.(*attribute.TestCustomTransformation)
require.True(t, ok, "wrong message passed to response transformation callback")
if msg.SomeRandomId == "some_random_id" && msg.SecondaryId == "secondary_id" {
newAttrs, err := handlers.ProtoToStruct(msg.GetSubResourceAttributes())
require.NoError(t, err)
msg.Attrs = &attribute.TestCustomTransformation_Attributes{
Attributes: newAttrs,
}
}
return nil
},
)
response := &attribute.TestCustomTransformation{
SomeRandomId: "some_random_id",
SecondaryId: "secondary_id",
Attrs: &attribute.TestCustomTransformation_SubResourceAttributes{
SubResourceAttributes: &attribute.TestSubResourceAttributes{
Name: "test",
},
},
}
expected := &attribute.TestCustomTransformation{
SomeRandomId: "some_random_id",
SecondaryId: "secondary_id",
Attrs: &attribute.TestCustomTransformation_Attributes{
Attributes: func() *structpb.Struct {
attrs, _ := structpb.NewStruct(map[string]any{
"name": "test",
})
return attrs
}(),
},
}
err := transformResponse(response)
require.NoError(t, err)
assert.Empty(t, cmp.Diff(response, expected, protocmp.Transform()))
}
+12 -23
View File
@@ -10,26 +10,15 @@ import (
"strings"
"sync"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/errors"
)
// Subtype variables identify a boundary resource subtype.
type Subtype string
const (
UnknownSubtype Subtype = "unknown"
)
// String returns the string representation of a Subtype
func (t Subtype) String() string {
return string(t)
}
// Registry stores a collection of boundary resource subtypes along with their
// prefixes and allows for translating prefixes back to registered subtypes.
type Registry struct {
subtypesPrefixes map[string]Subtype
knownSubtypes map[Subtype]any
subtypesPrefixes map[string]globals.Subtype
knownSubtypes map[globals.Subtype]any
sync.RWMutex
}
@@ -37,39 +26,39 @@ type Registry struct {
// NewRegistry creates a new boundary resource subtype registry.
func NewRegistry() *Registry {
return &Registry{
subtypesPrefixes: make(map[string]Subtype),
knownSubtypes: make(map[Subtype]any),
subtypesPrefixes: make(map[string]globals.Subtype),
knownSubtypes: make(map[globals.Subtype]any),
}
}
// SubtypeFromType returns the Subtype from the provided string or if
// no Subtype was registered with that string Unknown is returned.
func (r *Registry) SubtypeFromType(t string) Subtype {
func (r *Registry) SubtypeFromType(t string) globals.Subtype {
r.RLock()
defer r.RUnlock()
st := Subtype(t)
st := globals.Subtype(t)
if _, ok := r.knownSubtypes[st]; !ok {
return UnknownSubtype
return globals.UnknownSubtype
}
return st
}
// SubtypeFromId returns the Subtype from the provided id if the id's prefix
// was registered with a Subtype. Otherwise Unknown is returned.
func (r *Registry) SubtypeFromId(id string) Subtype {
func (r *Registry) SubtypeFromId(id string) globals.Subtype {
r.RLock()
defer r.RUnlock()
i := strings.Index(id, "_")
if i == -1 {
return UnknownSubtype
return globals.UnknownSubtype
}
prefix := id[:i]
subtype, ok := r.subtypesPrefixes[prefix]
if !ok {
return UnknownSubtype
return globals.UnknownSubtype
}
return subtype
}
@@ -89,7 +78,7 @@ func (r *Registry) Prefixes() []string {
// Register registers all the prefixes for a provided Subtype. Register returns
// an error if the subtype has already been registered or if any of the
// prefixes are associated with another subtype.
func (r *Registry) Register(ctx context.Context, subtype Subtype, prefixes ...string) error {
func (r *Registry) Register(ctx context.Context, subtype globals.Subtype, prefixes ...string) error {
r.Lock()
defer r.Unlock()
+19 -18
View File
@@ -9,6 +9,7 @@ import (
"strings"
"sync"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/errors"
)
@@ -17,58 +18,58 @@ var globalRegistry = newRegistry()
// newGlobalRegistry creates a new boundary resource subtype registry.
func newRegistry() *registry {
return &registry{
subtypesPrefixes: make(map[string]map[string]Subtype),
knownSubtypes: make(map[string]map[Subtype]any),
subtypesPrefixes: make(map[string]map[string]globals.Subtype),
knownSubtypes: make(map[string]map[globals.Subtype]any),
}
}
// registry stores a collection of boundary resource subtypes along with their
// prefixes and allows for translating prefixes back to registered subtypes.
type registry struct {
subtypesPrefixes map[string]map[string]Subtype
knownSubtypes map[string]map[Subtype]any
subtypesPrefixes map[string]map[string]globals.Subtype
knownSubtypes map[string]map[globals.Subtype]any
sync.RWMutex
}
// SubtypeFromType returns the Subtype from the provided string or if
// no Subtype was registered with that string Unknown is returned.
func (r *registry) subtypeFromType(domain, t string) Subtype {
func (r *registry) subtypeFromType(domain, t string) globals.Subtype {
r.RLock()
defer r.RUnlock()
knownSubtypes, ok := r.knownSubtypes[domain]
if !ok {
return UnknownSubtype
return globals.UnknownSubtype
}
st := Subtype(t)
st := globals.Subtype(t)
if _, ok := knownSubtypes[st]; !ok {
return UnknownSubtype
return globals.UnknownSubtype
}
return st
}
// SubtypeFromId returns the Subtype from the provided id if the id's prefix
// was registered with a Subtype. Otherwise Unknown is returned.
func (r *registry) subtypeFromId(domain, id string) Subtype {
func (r *registry) subtypeFromId(domain, id string) globals.Subtype {
r.RLock()
defer r.RUnlock()
i := strings.Index(id, "_")
if i == -1 {
return UnknownSubtype
return globals.UnknownSubtype
}
prefix := id[:i]
subtypePrefixes, ok := r.subtypesPrefixes[domain]
if !ok {
return UnknownSubtype
return globals.UnknownSubtype
}
subtype, ok := subtypePrefixes[prefix]
if !ok {
return UnknownSubtype
return globals.UnknownSubtype
}
return subtype
}
@@ -92,7 +93,7 @@ func (r *registry) prefixes(domain string) []string {
// Register registers all the prefixes for a provided Subtype. Register returns
// an error if the subtype has already been registered or if any of the
// prefixes are associated with another subtype.
func (r *registry) register(ctx context.Context, domain string, subtype Subtype, prefixes ...string) error {
func (r *registry) register(ctx context.Context, domain string, subtype globals.Subtype, prefixes ...string) error {
r.Lock()
defer r.Unlock()
@@ -100,9 +101,9 @@ func (r *registry) register(ctx context.Context, domain string, subtype Subtype,
knownSubtypes, present := r.knownSubtypes[domain]
if !present {
knownSubtypes = make(map[Subtype]any)
knownSubtypes = make(map[globals.Subtype]any)
r.knownSubtypes[domain] = knownSubtypes
r.subtypesPrefixes[domain] = make(map[string]Subtype)
r.subtypesPrefixes[domain] = make(map[string]globals.Subtype)
}
if _, present := knownSubtypes[subtype]; present {
@@ -132,13 +133,13 @@ func (r *registry) register(ctx context.Context, domain string, subtype Subtype,
// SubtypeFromType returns the Subtype from the provided string or if
// no Subtype was registered with that string Unknown is returned.
func SubtypeFromType(domain, t string) Subtype {
func SubtypeFromType(domain, t string) globals.Subtype {
return globalRegistry.subtypeFromType(domain, t)
}
// SubtypeFromId returns the Subtype from the provided id if the id's prefix
// was registered with a Subtype. Otherwise Unknown is returned.
func SubtypeFromId(domain, id string) Subtype {
func SubtypeFromId(domain, id string) globals.Subtype {
return globalRegistry.subtypeFromId(domain, id)
}
@@ -150,7 +151,7 @@ func Prefixes(domain string) []string {
// Register registers all the prefixes for a provided Subtype. Register returns
// an error if the subtype has already been registered or if any of the
// prefixes are associated with another subtype.
func Register(domain string, subtype Subtype, prefixes ...string) error {
func Register(domain string, subtype globals.Subtype, prefixes ...string) error {
ctx := context.TODO()
return globalRegistry.register(ctx, domain, subtype, prefixes...)
}
+13 -12
View File
@@ -7,26 +7,27 @@ import (
"context"
"testing"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/types/subtypes"
"github.com/stretchr/testify/assert"
)
func TestSubtypeFromId(t *testing.T) {
testSubtype := subtypes.Subtype("test")
testSubtype := globals.Subtype("test")
r := subtypes.NewRegistry()
r.Register(context.Background(), testSubtype, "tttst")
tests := []struct {
name string
given string
want subtypes.Subtype
want globals.Subtype
}{
{"empty-string", "", subtypes.UnknownSubtype},
{"no-prefix-delimiter", "tttst1234", subtypes.UnknownSubtype},
{"prefix-first", "_tttst_1234", subtypes.UnknownSubtype},
{"unknown-prefix", "kaz_1234", subtypes.UnknownSubtype},
{"empty-string", "", globals.UnknownSubtype},
{"no-prefix-delimiter", "tttst1234", globals.UnknownSubtype},
{"prefix-first", "_tttst_1234", globals.UnknownSubtype},
{"unknown-prefix", "kaz_1234", globals.UnknownSubtype},
{"prefix-no-id", "tttst_", testSubtype},
{"vault-prefix", "tttst_1234", testSubtype},
{"prefix-no-delimiter-no-id", "tttst", subtypes.UnknownSubtype},
{"prefix-no-delimiter-no-id", "tttst", globals.UnknownSubtype},
}
for _, tt := range tests {
tt := tt
@@ -41,18 +42,18 @@ func TestSubtypeFromId(t *testing.T) {
}
func TestSubtypeFromType(t *testing.T) {
testSubtype := subtypes.Subtype("test")
testSubtype := globals.Subtype("test")
r := subtypes.NewRegistry()
r.Register(context.Background(), testSubtype, "tttst")
tests := []struct {
name string
given string
want subtypes.Subtype
want globals.Subtype
}{
{"empty-string", "", subtypes.UnknownSubtype},
{"empty-string", "", globals.UnknownSubtype},
{"correct-string", "test", testSubtype},
{"captialized", "TEST", subtypes.UnknownSubtype},
{"typo", "testt", subtypes.UnknownSubtype},
{"captialized", "TEST", globals.UnknownSubtype},
{"typo", "testt", globals.UnknownSubtype},
}
for _, tt := range tests {
tt := tt