Move actions, resource (types), and scopes to packages. (#149)
This commit is contained in:
1 parent
9d1d0ba08e
commit
d8f11af4d7
37 files changed
+721
-460
No files matched your search
@@ -12,6 +12,7 @@ import (
|
||||
pbs "github.com/hashicorp/watchtower/internal/gen/controller/api/services"
|
||||
"github.com/hashicorp/watchtower/internal/iam"
|
||||
"github.com/hashicorp/watchtower/internal/servers/controller/handlers"
|
||||
"github.com/hashicorp/watchtower/internal/types/scope"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||
@@ -347,7 +348,7 @@ func validateAncestors(r ancestorProvider) map[string]string {
|
||||
if r.GetOrgId() == "" {
|
||||
return map[string]string{orgIdFieldName: "Missing organization id."}
|
||||
}
|
||||
if !validId(r.GetOrgId(), iam.OrganizationScope.Prefix()+"_") {
|
||||
if !validId(r.GetOrgId(), scope.Organization.Prefix()+"_") {
|
||||
return map[string]string{orgIdFieldName: "Improperly formatted identifier."}
|
||||
}
|
||||
return map[string]string{}
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
pbs "github.com/hashicorp/watchtower/internal/gen/controller/api/services"
|
||||
"github.com/hashicorp/watchtower/internal/iam"
|
||||
"github.com/hashicorp/watchtower/internal/servers/controller/handlers/groups"
|
||||
"github.com/hashicorp/watchtower/internal/types/scope"
|
||||
"google.golang.org/genproto/protobuf/field_mask"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
@@ -155,14 +156,14 @@ func TestList(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Invalid Org Id",
|
||||
req: &pbs.ListGroupsRequest{OrgId: iam.OrganizationScope.Prefix() + "_this is invalid"},
|
||||
req: &pbs.ListGroupsRequest{OrgId: scope.Organization.Prefix() + "_this is invalid"},
|
||||
res: nil,
|
||||
errCode: codes.InvalidArgument,
|
||||
},
|
||||
// TODO: When an org doesn't exist, we should return a 404 instead of an empty list.
|
||||
{
|
||||
name: "Unfound Org",
|
||||
req: &pbs.ListGroupsRequest{OrgId: iam.OrganizationScope.Prefix() + "_DoesntExis"},
|
||||
req: &pbs.ListGroupsRequest{OrgId: scope.Organization.Prefix() + "_DoesntExis"},
|
||||
res: &pbs.ListGroupsResponse{},
|
||||
errCode: codes.OK,
|
||||
},
|
||||
|
||||
@@ -9,9 +9,9 @@ import (
|
||||
pb "github.com/hashicorp/watchtower/internal/gen/controller/api/resources/hosts"
|
||||
pbs "github.com/hashicorp/watchtower/internal/gen/controller/api/services"
|
||||
"github.com/hashicorp/watchtower/internal/host/static"
|
||||
"github.com/hashicorp/watchtower/internal/iam"
|
||||
"github.com/hashicorp/watchtower/internal/servers/controller/common"
|
||||
"github.com/hashicorp/watchtower/internal/servers/controller/handlers"
|
||||
"github.com/hashicorp/watchtower/internal/types/scope"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||
@@ -391,10 +391,10 @@ func validateAncestors(r ancestorProvider) map[string]string {
|
||||
return badFields
|
||||
}
|
||||
|
||||
if !validId(r.GetOrgId(), iam.OrganizationScope.Prefix()+"_") {
|
||||
if !validId(r.GetOrgId(), scope.Organization.Prefix()+"_") {
|
||||
badFields[orgIdFieldName] = "The field is incorrectly formatted."
|
||||
}
|
||||
if !validId(r.GetProjectId(), iam.ProjectScope.Prefix()+"_") {
|
||||
if !validId(r.GetProjectId(), scope.Project.Prefix()+"_") {
|
||||
badFields[projectIdFieldName] = "The field is incorrectly formatted."
|
||||
}
|
||||
return badFields
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/hashicorp/watchtower/internal/iam"
|
||||
"github.com/hashicorp/watchtower/internal/servers/controller/common"
|
||||
"github.com/hashicorp/watchtower/internal/servers/controller/handlers"
|
||||
"github.com/hashicorp/watchtower/internal/types/scope"
|
||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||
)
|
||||
|
||||
@@ -109,7 +110,7 @@ func toProto(in *iam.Scope) *pb.Organization {
|
||||
// * There are no conflicting parameters provided
|
||||
func validateGetRequest(req *pbs.GetOrganizationRequest) error {
|
||||
badFields := make(map[string]string)
|
||||
if !validId(req.GetId(), iam.OrganizationScope.Prefix()+"_") {
|
||||
if !validId(req.GetId(), scope.Organization.Prefix()+"_") {
|
||||
badFields["id"] = "Invalid formatted organization id."
|
||||
}
|
||||
if len(badFields) > 0 {
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
pbs "github.com/hashicorp/watchtower/internal/gen/controller/api/services"
|
||||
"github.com/hashicorp/watchtower/internal/iam"
|
||||
"github.com/hashicorp/watchtower/internal/servers/controller/handlers/organizations"
|
||||
"github.com/hashicorp/watchtower/internal/types/scope"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/proto"
|
||||
@@ -77,7 +78,7 @@ func TestGet(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Get a non existing organization",
|
||||
req: &pbs.GetOrganizationRequest{Id: iam.OrganizationScope.Prefix() + "_DoesntExis"},
|
||||
req: &pbs.GetOrganizationRequest{Id: scope.Organization.Prefix() + "_DoesntExis"},
|
||||
res: nil,
|
||||
errCode: codes.NotFound,
|
||||
},
|
||||
@@ -89,7 +90,7 @@ func TestGet(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "space in id",
|
||||
req: &pbs.GetOrganizationRequest{Id: iam.OrganizationScope.Prefix() + "_1 23456789"},
|
||||
req: &pbs.GetOrganizationRequest{Id: scope.Organization.Prefix() + "_1 23456789"},
|
||||
res: nil,
|
||||
errCode: codes.InvalidArgument,
|
||||
},
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/hashicorp/watchtower/internal/iam"
|
||||
"github.com/hashicorp/watchtower/internal/servers/controller/common"
|
||||
"github.com/hashicorp/watchtower/internal/servers/controller/handlers"
|
||||
"github.com/hashicorp/watchtower/internal/types/scope"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||
@@ -246,7 +247,7 @@ func toProto(in *iam.Scope) *pb.Project {
|
||||
// * There are no conflicting parameters provided
|
||||
func validateGetRequest(req *pbs.GetProjectRequest) error {
|
||||
badFields := validateAncestors(req)
|
||||
if !validId(req.GetId(), iam.ProjectScope.Prefix()+"_") {
|
||||
if !validId(req.GetId(), scope.Project.Prefix()+"_") {
|
||||
badFields["id"] = "Invalid formatted project id."
|
||||
}
|
||||
if len(badFields) > 0 {
|
||||
@@ -275,7 +276,7 @@ func validateCreateRequest(req *pbs.CreateProjectRequest) error {
|
||||
|
||||
func validateUpdateRequest(req *pbs.UpdateProjectRequest) error {
|
||||
badFields := validateAncestors(req)
|
||||
if !validId(req.GetId(), iam.ProjectScope.Prefix()+"_") {
|
||||
if !validId(req.GetId(), scope.Project.Prefix()+"_") {
|
||||
badFields["project_id"] = "Improperly formatted path identifier."
|
||||
}
|
||||
if req.GetUpdateMask() == nil {
|
||||
@@ -309,7 +310,7 @@ func validateUpdateRequest(req *pbs.UpdateProjectRequest) error {
|
||||
|
||||
func validateDeleteRequest(req *pbs.DeleteProjectRequest) error {
|
||||
badFields := validateAncestors(req)
|
||||
if !validId(req.GetId(), iam.ProjectScope.Prefix()+"_") {
|
||||
if !validId(req.GetId(), scope.Project.Prefix()+"_") {
|
||||
badFields["id"] = "Incorrectly formatted project."
|
||||
}
|
||||
if len(badFields) > 0 {
|
||||
@@ -343,7 +344,7 @@ func validateAncestors(r ancestorProvider) map[string]string {
|
||||
if r.GetOrgId() == "" {
|
||||
return map[string]string{orgIdFieldName: "Missing organization id."}
|
||||
}
|
||||
if !validId(r.GetOrgId(), iam.OrganizationScope.Prefix()+"_") {
|
||||
if !validId(r.GetOrgId(), scope.Organization.Prefix()+"_") {
|
||||
return map[string]string{orgIdFieldName: "Improperly formatted identifier."}
|
||||
}
|
||||
return map[string]string{}
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
pbs "github.com/hashicorp/watchtower/internal/gen/controller/api/services"
|
||||
"github.com/hashicorp/watchtower/internal/iam"
|
||||
"github.com/hashicorp/watchtower/internal/servers/controller/handlers/projects"
|
||||
"github.com/hashicorp/watchtower/internal/types/scope"
|
||||
"google.golang.org/genproto/protobuf/field_mask"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
@@ -172,14 +173,14 @@ func TestList(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Invalid Org Id",
|
||||
req: &pbs.ListProjectsRequest{OrgId: iam.OrganizationScope.Prefix() + "_this is invalid"},
|
||||
req: &pbs.ListProjectsRequest{OrgId: scope.Organization.Prefix() + "_this is invalid"},
|
||||
res: nil,
|
||||
errCode: codes.InvalidArgument,
|
||||
},
|
||||
// TODO: When an org doesn't exist, we should return a 404 instead of an empty list.
|
||||
{
|
||||
name: "Unfound Org",
|
||||
req: &pbs.ListProjectsRequest{OrgId: iam.OrganizationScope.Prefix() + "_DoesntExis"},
|
||||
req: &pbs.ListProjectsRequest{OrgId: scope.Organization.Prefix() + "_DoesntExis"},
|
||||
res: &pbs.ListProjectsResponse{},
|
||||
errCode: codes.OK,
|
||||
},
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
pbs "github.com/hashicorp/watchtower/internal/gen/controller/api/services"
|
||||
"github.com/hashicorp/watchtower/internal/iam"
|
||||
"github.com/hashicorp/watchtower/internal/servers/controller/handlers"
|
||||
"github.com/hashicorp/watchtower/internal/types/scope"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||
@@ -347,7 +348,7 @@ func validateAncestors(r ancestorProvider) map[string]string {
|
||||
if r.GetOrgId() == "" {
|
||||
return map[string]string{orgIdFieldName: "Missing organization id."}
|
||||
}
|
||||
if !validId(r.GetOrgId(), iam.OrganizationScope.Prefix()+"_") {
|
||||
if !validId(r.GetOrgId(), scope.Organization.Prefix()+"_") {
|
||||
return map[string]string{orgIdFieldName: "Improperly formatted identifier."}
|
||||
}
|
||||
return map[string]string{}
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
pbs "github.com/hashicorp/watchtower/internal/gen/controller/api/services"
|
||||
"github.com/hashicorp/watchtower/internal/iam"
|
||||
"github.com/hashicorp/watchtower/internal/servers/controller/handlers/roles"
|
||||
"github.com/hashicorp/watchtower/internal/types/scope"
|
||||
"google.golang.org/genproto/protobuf/field_mask"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
@@ -155,14 +156,14 @@ func TestList(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Invalid Org Id",
|
||||
req: &pbs.ListRolesRequest{OrgId: iam.OrganizationScope.Prefix() + "_this is invalid"},
|
||||
req: &pbs.ListRolesRequest{OrgId: scope.Organization.Prefix() + "_this is invalid"},
|
||||
res: nil,
|
||||
errCode: codes.InvalidArgument,
|
||||
},
|
||||
// TODO: When an org doesn't exist, we should return a 404 instead of an empty list.
|
||||
{
|
||||
name: "Unfound Org",
|
||||
req: &pbs.ListRolesRequest{OrgId: iam.OrganizationScope.Prefix() + "_DoesntExis"},
|
||||
req: &pbs.ListRolesRequest{OrgId: scope.Organization.Prefix() + "_DoesntExis"},
|
||||
res: &pbs.ListRolesResponse{},
|
||||
errCode: codes.OK,
|
||||
},
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
pbs "github.com/hashicorp/watchtower/internal/gen/controller/api/services"
|
||||
"github.com/hashicorp/watchtower/internal/iam"
|
||||
"github.com/hashicorp/watchtower/internal/servers/controller/handlers"
|
||||
"github.com/hashicorp/watchtower/internal/types/scope"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||
@@ -316,7 +317,7 @@ func validateAncestors(r ancestorProvider) map[string]string {
|
||||
if r.GetOrgId() == "" {
|
||||
return map[string]string{orgIdFieldName: "Missing organization id."}
|
||||
}
|
||||
if !validId(r.GetOrgId(), iam.OrganizationScope.Prefix()+"_") {
|
||||
if !validId(r.GetOrgId(), scope.Organization.Prefix()+"_") {
|
||||
return map[string]string{orgIdFieldName: "Improperly formatted identifier."}
|
||||
}
|
||||
return map[string]string{}
|
||||
|
||||
Reference in new issue
Block a user