Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions cmd/seed.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"connectrpc.com/connect"
"github.com/MakeNowJust/heredoc"
"github.com/raystack/frontier/config"
"github.com/raystack/frontier/internal/bootstrap/schema"
frontierv1beta1 "github.com/raystack/frontier/proto/v1beta1"
frontierv1beta1connect "github.com/raystack/frontier/proto/v1beta1/frontierv1beta1connect"
"github.com/raystack/salt/cli/printer"
Expand Down Expand Up @@ -112,10 +113,10 @@ func createCustomRolesAndPermissions(ctx context.Context, client frontierv1beta1
}

str := "created custom permissions : "
//nolint:staticcheck
for _, v := range permissionBodies {
str = fmt.Sprintf("%s %s:%s", str, v.GetNamespace(), v.GetName())
resourceNamespaces = append(resourceNamespaces, v.GetNamespace())
permNamespace, permName := schema.PermissionNamespaceAndNameFromKey(v.GetKey())
str = fmt.Sprintf("%s %s:%s", str, permNamespace, permName)
resourceNamespaces = append(resourceNamespaces, permNamespace)
}
fmt.Println(str)

Expand Down
30 changes: 11 additions & 19 deletions cmd/seed/permissions.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,42 @@
[
{
"name": "create",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of these seed JSON files? It looks like dummy data. If they are not needed, we can think of removing them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The six JSON files under cmd/seed/ (permissions, roles, users, organizations, projects, resource) are compiled into the binary with go:embed and used by exactly one thing: the frontier seed CLI command, documented in the CLI reference. Running it against a live server creates a sample world through the public API — the compute/order and database/order permissions, two custom roles, a sample org with users, projects, a resource, and policies. Its purpose is stated in its own help text: making it easier to get started — demo data for someone evaluating Frontier locally.

Removing the command and its fixtures is doable, but that's its own discussion — keeping this PR to the request-field change.

"key": "compute.order.create",
"title": "Create Order",
"namespace": "compute/order",
"metadata": {}
},
{
"name": "get",
"key": "compute.order.get",
"title": "Read Order",
"namespace": "compute/order",
"metadata": {}
},
{
"name": "update",
"key": "compute.order.update",
"title": "Update Order",
"namespace": "compute/order",
"metadata": {}
},
{
"name": "delete",
"key": "compute.order.delete",
"title": "Delete Order",
"namespace": "compute/order",
"metadata": {}
},
{
"name": "list",
"key": "compute.order.list",
"title": "List Orders",
"namespace": "compute/order",
"metadata": {}
},
{
"name": "get",
"key": "database.order.get",
"title": "List Database Order",
"namespace": "database/order",
"metadata":{}
"metadata": {}
},
{
"name": "update",
"key": "database.order.update",
"title": "Update Database Order",
"namespace": "database/order",
"metadata":{}
"metadata": {}
},
{
"name": "delete",
"key": "database.order.delete",
"title": "Delete Database Order",
"namespace": "database/order",
"metadata":{}
"metadata": {}
}
]
1 change: 1 addition & 0 deletions internal/api/v1beta1connect/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ var (
ErrAlreadyApplied = errors.New("credits already applied")
ErrInvalidRoleID = errors.New("role id is invalid")
ErrNamespaceSplitNotation = errors.New("subject/object should be provided as 'namespace:uuid'")
ErrPermissionKeyNotation = errors.New("permission key should be provided as 'service.resource.verb'")
ErrPolicyNotFound = errors.New("policy doesn't exist")
ErrProjectNotFound = errors.New("project doesn't exist")
ErrGroupNotFound = errors.New("group doesn't exist")
Expand Down
18 changes: 10 additions & 8 deletions internal/api/v1beta1connect/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,14 @@ func (h *ConnectHandler) CreatePermission(ctx context.Context, request *connect.
var permissionSlugs []string
for _, permBody := range request.Msg.GetBodies() {
permNamespace, permName := schema.PermissionNamespaceAndNameFromKey(permBody.GetKey())
if permNamespace == "" || permName == "" {
permNamespace, permName = permBody.GetNamespace(), permBody.GetName() //nolint:staticcheck
}
if permName == "" || permNamespace == "" {
return nil, connect.NewError(connect.CodeInvalidArgument, ErrBadRequest)
return nil, connect.NewError(connect.CodeInvalidArgument, ErrPermissionKeyNotation)
}
if !schema.IsValidPermissionName(permName) {
return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("permission name cannot contain special characters"))
}

if permNamespace == schema.DefaultNamespace {
return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("permission namespace cannot be "+schema.DefaultNamespace))
if !schema.IsValidPermissionNamespace(permNamespace) {
return nil, connect.NewError(connect.CodeInvalidArgument, ErrPermissionKeyNotation)
}
permissionSlugs = append(permissionSlugs, schema.FQPermissionNameFromNamespace(permNamespace, permName))

Expand Down Expand Up @@ -125,7 +121,13 @@ func (h *ConnectHandler) UpdatePermission(ctx context.Context, request *connect.

permNamespace, permName := schema.PermissionNamespaceAndNameFromKey(request.Msg.GetBody().GetKey())
if permNamespace == "" || permName == "" {
permNamespace, permName = request.Msg.GetBody().GetNamespace(), request.Msg.GetBody().GetName() //nolint:staticcheck
return nil, connect.NewError(connect.CodeInvalidArgument, ErrPermissionKeyNotation)
}
if !schema.IsValidPermissionName(permName) {
return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("permission name cannot contain special characters"))
}
if !schema.IsValidPermissionNamespace(permNamespace) {
return nil, connect.NewError(connect.CodeInvalidArgument, ErrPermissionKeyNotation)
}
updatedPermission, err := h.permissionService.Update(ctx, permission.Permission{
ID: request.Msg.GetId(),
Expand Down
Loading
Loading