Move prefixes for many packages into the globals package (#3069)

This is a prerequisite for some enhancements to grant validation
This commit is contained in:
Jeff Mitchell authored and GitHub committed 2023-03-10 15:06:39 -05:00
1 parent 6adc0c86b5
commit b76b24a4ad
115 files changed
+796 -729

No files matched your search

@@ -16,7 +16,6 @@ import (
"github.com/hashicorp/boundary/internal/daemon/controller/handlers"
"github.com/hashicorp/boundary/internal/errors"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/types/action"
@@ -583,7 +582,7 @@ func validateGetRequest(req *pbs.GetManagedGroupRequest) error {
if req == nil {
return errors.NewDeprecated(errors.InvalidParameter, op, "nil request")
}
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, intglobals.OidcManagedGroupPrefix)
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, globals.OidcManagedGroupPrefix)
}
func validateCreateRequest(req *pbs.CreateManagedGroupRequest) error {
@@ -651,7 +650,7 @@ func validateUpdateRequest(req *pbs.UpdateManagedGroupRequest) error {
badFields[globals.IdField] = "Unrecognized resource type."
}
return badFields
}, intglobals.OidcManagedGroupPrefix)
}, globals.OidcManagedGroupPrefix)
}
func validateDeleteRequest(req *pbs.DeleteManagedGroupRequest) error {
@@ -659,7 +658,7 @@ func validateDeleteRequest(req *pbs.DeleteManagedGroupRequest) error {
if req == nil {
return errors.NewDeprecated(errors.InvalidParameter, op, "nil request")
}
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, intglobals.OidcManagedGroupPrefix)
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, globals.OidcManagedGroupPrefix)
}
func validateListRequest(req *pbs.ListManagedGroupsRequest) error {
@@ -668,7 +667,7 @@ func validateListRequest(req *pbs.ListManagedGroupsRequest) error {
return errors.NewDeprecated(errors.InvalidParameter, op, "nil request")
}
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetAuthMethodId()), oidc.AuthMethodPrefix) {
if !handlers.ValidId(handlers.Id(req.GetAuthMethodId()), globals.OidcAuthMethodPrefix) {
badFields[globals.AuthMethodIdField] = "Invalid formatted identifier."
}
if _, err := handlers.NewFilter(req.GetFilter()); err != nil {
@@ -16,7 +16,6 @@ import (
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/auth/password"
"github.com/hashicorp/boundary/internal/authtoken"
"github.com/hashicorp/boundary/internal/daemon/controller/auth"
"github.com/hashicorp/boundary/internal/daemon/controller/common"
"github.com/hashicorp/boundary/internal/daemon/controller/handlers"
@@ -24,7 +23,6 @@ import (
"github.com/hashicorp/boundary/internal/db"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/types/action"
"github.com/hashicorp/boundary/internal/types/scope"
@@ -155,7 +153,7 @@ func TestGet(t *testing.T) {
},
{
name: "Get a non existing oidc managed group",
req: &pbs.GetManagedGroupRequest{Id: intglobals.OidcManagedGroupPrefix + "_DoesntExis"},
req: &pbs.GetManagedGroupRequest{Id: globals.OidcManagedGroupPrefix + "_DoesntExis"},
res: nil,
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -167,7 +165,7 @@ func TestGet(t *testing.T) {
},
{
name: "space in id",
req: &pbs.GetManagedGroupRequest{Id: authtoken.AuthTokenPrefix + "_1 23456789"},
req: &pbs.GetManagedGroupRequest{Id: globals.AuthTokenPrefix + "_1 23456789"},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
@@ -276,7 +274,7 @@ func TestListOidc(t *testing.T) {
},
{
name: "Unfound Auth Method",
req: &pbs.ListManagedGroupsRequest{AuthMethodId: oidc.AuthMethodPrefix + "_DoesntExis"},
req: &pbs.ListManagedGroupsRequest{AuthMethodId: globals.OidcAuthMethodPrefix + "_DoesntExis"},
err: handlers.ApiErrorWithCode(codes.NotFound),
},
{
@@ -384,7 +382,7 @@ func TestDelete(t *testing.T) {
{
name: "Delete bad oidc managed group id",
req: &pbs.DeleteManagedGroupRequest{
Id: intglobals.OidcManagedGroupPrefix + "_doesntexis",
Id: globals.OidcManagedGroupPrefix + "_doesntexis",
},
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -499,7 +497,7 @@ func TestCreateOidc(t *testing.T) {
},
},
res: &pbs.CreateManagedGroupResponse{
Uri: fmt.Sprintf("managed-groups/%s_", intglobals.OidcManagedGroupPrefix),
Uri: fmt.Sprintf("managed-groups/%s_", globals.OidcManagedGroupPrefix),
Item: &pb.ManagedGroup{
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "name"},
@@ -529,7 +527,7 @@ func TestCreateOidc(t *testing.T) {
},
},
res: &pbs.CreateManagedGroupResponse{
Uri: fmt.Sprintf("managed-groups/%s_", intglobals.OidcManagedGroupPrefix),
Uri: fmt.Sprintf("managed-groups/%s_", globals.OidcManagedGroupPrefix),
Item: &pb.ManagedGroup{
AuthMethodId: am.GetPublicId(),
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
@@ -565,7 +563,7 @@ func TestCreateOidc(t *testing.T) {
req: &pbs.CreateManagedGroupRequest{
Item: &pb.ManagedGroup{
AuthMethodId: am.GetPublicId(),
Id: intglobals.OidcManagedGroupPrefix + "_notallowed",
Id: globals.OidcManagedGroupPrefix + "_notallowed",
Type: oidc.Subtype.String(),
Attrs: &pb.ManagedGroup_OidcManagedGroupAttributes{
OidcManagedGroupAttributes: &pb.OidcManagedGroupAttributes{
@@ -641,7 +639,7 @@ func TestCreateOidc(t *testing.T) {
require.NoError(gErr)
if got != nil {
assert.Contains(got.GetUri(), tc.res.Uri)
assert.True(strings.HasPrefix(got.GetItem().GetId(), intglobals.OidcManagedGroupPrefix+"_"))
assert.True(strings.HasPrefix(got.GetItem().GetId(), globals.OidcManagedGroupPrefix+"_"))
// Clear all values which are hard to compare against.
got.Uri, tc.res.Uri = "", ""
got.Item.Id, tc.res.Item.Id = "", ""
@@ -886,7 +884,7 @@ func TestUpdateOidc(t *testing.T) {
{
name: "Update a Non Existing ManagedGroup",
req: &pbs.UpdateManagedGroupRequest{
Id: intglobals.OidcManagedGroupPrefix + "_DoesntExis",
Id: globals.OidcManagedGroupPrefix + "_DoesntExis",
UpdateMask: &field_mask.FieldMask{
Paths: []string{globals.DescriptionField},
},
@@ -904,7 +902,7 @@ func TestUpdateOidc(t *testing.T) {
Paths: []string{"id"},
},
Item: &pb.ManagedGroup{
Id: intglobals.OidcManagedGroupPrefix + "_somethinge",
Id: globals.OidcManagedGroupPrefix + "_somethinge",
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "new desc"},
},
@@ -12,7 +12,6 @@ import (
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/auth/password"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/intglobals"
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/managedgroups"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -41,7 +40,7 @@ func TestValidateCreateRequest(t *testing.T) {
name: "mismatched oidc authmethod pw type",
item: &pb.ManagedGroup{
Type: "ldap",
AuthMethodId: oidc.AuthMethodPrefix + "_1234567890",
AuthMethodId: globals.OidcAuthMethodPrefix + "_1234567890",
},
errContains: fieldError(globals.TypeField, "Doesn't match the parent resource's type."),
},
@@ -49,7 +48,7 @@ func TestValidateCreateRequest(t *testing.T) {
name: "missing oidc attributes",
item: &pb.ManagedGroup{
Type: oidc.Subtype.String(),
AuthMethodId: oidc.AuthMethodPrefix + "_1234567890",
AuthMethodId: globals.OidcAuthMethodPrefix + "_1234567890",
Attrs: nil,
},
errContains: fieldError(globals.AttributesField, "Attribute fields is required."),
@@ -58,7 +57,7 @@ func TestValidateCreateRequest(t *testing.T) {
name: "bad oidc attributes",
item: &pb.ManagedGroup{
Type: oidc.Subtype.String(),
AuthMethodId: oidc.AuthMethodPrefix + "_1234567890",
AuthMethodId: globals.OidcAuthMethodPrefix + "_1234567890",
Attrs: &pb.ManagedGroup_OidcManagedGroupAttributes{
OidcManagedGroupAttributes: &pb.OidcManagedGroupAttributes{
Filter: "foobar",
@@ -71,7 +70,7 @@ func TestValidateCreateRequest(t *testing.T) {
name: "no oidc errors",
item: &pb.ManagedGroup{
Type: oidc.Subtype.String(),
AuthMethodId: oidc.AuthMethodPrefix + "_1234567890",
AuthMethodId: globals.OidcAuthMethodPrefix + "_1234567890",
Attrs: &pb.ManagedGroup_OidcManagedGroupAttributes{
OidcManagedGroupAttributes: &pb.OidcManagedGroupAttributes{
Filter: `"/foo/bar" == "zipzap"`,
@@ -106,7 +105,7 @@ func TestValidateUpdateRequest(t *testing.T) {
{
name: "oidc to password change type",
req: &pbs.UpdateManagedGroupRequest{
Id: intglobals.OidcManagedGroupPrefix + "_1234567890",
Id: globals.OidcManagedGroupPrefix + "_1234567890",
Item: &pb.ManagedGroup{
Type: password.Subtype.String(),
},
@@ -116,7 +115,7 @@ func TestValidateUpdateRequest(t *testing.T) {
{
name: "no error",
req: &pbs.UpdateManagedGroupRequest{
Id: intglobals.OidcManagedGroupPrefix + "_1234567890",
Id: globals.OidcManagedGroupPrefix + "_1234567890",
UpdateMask: &fieldmaskpb.FieldMask{Paths: []string{}},
Item: &pb.ManagedGroup{
Version: 1,