Skip to content

Commit

Permalink
feat(rbac): role overview
Browse files Browse the repository at this point in the history
  • Loading branch information
debsmita1 committed Nov 28, 2023
1 parent 8722056 commit 86893c7
Show file tree
Hide file tree
Showing 25 changed files with 1,301 additions and 53 deletions.
5 changes: 5 additions & 0 deletions plugins/rbac-common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ export type UpdatePolicy = {
oldPolicy: Policy;
newPolicy: Policy;
};

export type PermissionPolicy = {
pluginId?: string;
policies?: Policy[];
};
357 changes: 356 additions & 1 deletion plugins/rbac/dev/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ import {
} from '@backstage/plugin-permission-react';
import { TestApiProvider } from '@backstage/test-utils';

import { Role, RoleBasedPolicy } from '@janus-idp/backstage-plugin-rbac-common';
import {
PermissionPolicy,
Policy,
Role,
RoleBasedPolicy,
} from '@janus-idp/backstage-plugin-rbac-common';

import { RBACAPI, rbacApiRef } from '../src/api/RBACBackendClient';
import { RbacPage, rbacPlugin } from '../src/plugin';
import { MemberEntity } from '../src/types';

class MockPermissionApi implements PermissionApi {
readonly result;
Expand Down Expand Up @@ -116,9 +122,358 @@ class MockRBACApi implements RBACAPI {
};
}

async getRole(role: string): Promise<Role[]> {
const roleresource = this.resources.find(res => res.name === role);
return roleresource ? [roleresource] : [];
}

async deleteRole(_roleName: string): Promise<any> {
return { status: 204 };
}

async getMembers(): Promise<MemberEntity[]> {
return [
{
metadata: {
namespace: 'default',
annotations: {},
name: 'team-d',
description: 'Team D',
},
apiVersion: 'backstage.io/v1alpha1',
kind: 'Group',
spec: {
type: 'team',
profile: {
displayName: 'Team D',
},
parent: 'boxoffice',
children: [],
},
relations: [
{
type: 'childOf',
targetRef: 'group:default/boxoffice',
},
{
type: 'hasMember',
targetRef: 'user:default/eva.macdowell',
},
{
type: 'hasMember',
targetRef: 'user:default/lucy.sheehan',
},
],
},
{
metadata: {
namespace: 'default',
annotations: {},
name: 'infrastructure',
description: 'The infra department',
},
apiVersion: 'backstage.io/v1alpha1',
kind: 'Group',
spec: {
type: 'department',
parent: 'acme-corp',
children: ['backstage', 'boxoffice'],
},
relations: [],
},
{
metadata: {
namespace: 'default',
annotations: {},
name: 'guest',
},
apiVersion: 'backstage.io/v1alpha1',
kind: 'User',
spec: {
profile: {
displayName: 'Guest User',
},
memberOf: ['team-a'],
},
relations: [
{
type: 'memberOf',
targetRef: 'group:default/team-a',
},
],
},
{
metadata: {
namespace: 'default',
annotations: {},
name: 'janus-authors',
title: 'Janus-IDP Authors',
},
apiVersion: 'backstage.io/v1alpha1',
kind: 'Group',
spec: {
type: 'team',
children: [],
},
relations: [],
},
{
metadata: {
namespace: 'default',
annotations: {},
name: 'team-a',
description: 'Team A',
},
apiVersion: 'backstage.io/v1alpha1',
kind: 'Group',
spec: {
type: 'team',
profile: {},
parent: 'backstage',
children: [],
},
relations: [
{
type: 'childOf',
targetRef: 'group:default/backstage',
},
{
type: 'hasMember',
targetRef: 'user:default/breanna.davison',
},
{
type: 'hasMember',
targetRef: 'user:default/guest',
},
{
type: 'hasMember',
targetRef: 'user:default/janelle.dawe',
},
{
type: 'hasMember',
targetRef: 'user:default/nigel.manning',
},
],
},
{
metadata: {
namespace: 'default',
annotations: {},
name: 'backstage',
description: 'The backstage sub-department',
},
apiVersion: 'backstage.io/v1alpha1',
kind: 'Group',
spec: {
type: 'sub-department',
profile: {
displayName: 'Backstage',
},
parent: 'infrastructure',
children: ['team-a', 'team-b'],
},
relations: [],
},
{
metadata: {
namespace: 'default',
annotations: {},
name: 'team-b',
description: 'Team B',
},
apiVersion: 'backstage.io/v1alpha1',
kind: 'Group',
spec: {
type: 'team',
profile: {
displayName: 'Team B',
},
parent: 'backstage',
children: [],
},
relations: [
{
type: 'hasMember',
targetRef: 'user:default/amelia.park',
},
{
type: 'hasMember',
targetRef: 'user:default/colette.brock',
},
{
type: 'hasMember',
targetRef: 'user:default/jenny.doe',
},
{
type: 'hasMember',
targetRef: 'user:default/jonathon.page',
},
{
type: 'hasMember',
targetRef: 'user:default/justine.barrow',
},
],
},
{
metadata: {
namespace: 'default',
annotations: {},
name: 'lucy.sheehan',
},
apiVersion: 'backstage.io/v1alpha1',
kind: 'User',
spec: {
profile: {
displayName: 'Lucy Sheehan',
},
memberOf: ['team-d'],
},
relations: [
{
type: 'memberOf',
targetRef: 'group:default/team-d',
},
],
},
{
metadata: {
namespace: 'default',
annotations: {},
name: 'boxoffice',
description: 'The boxoffice sub-department',
},
apiVersion: 'backstage.io/v1alpha1',
kind: 'Group',
spec: {
type: 'sub-department',
profile: {
displayName: 'Box Office',
},
parent: 'infrastructure',
children: ['team-c', 'team-d'],
},
relations: [
{
type: 'childOf',
targetRef: 'group:default/infrastructure',
},
{
type: 'parentOf',
targetRef: 'group:default/team-c',
},
{
type: 'parentOf',
targetRef: 'group:default/team-d',
},
],
},
{
metadata: {
namespace: 'default',
annotations: {},
name: 'amelia.park',
},
apiVersion: 'backstage.io/v1alpha1',
kind: 'User',
spec: {
profile: {
displayName: 'Amelia Park',
},
memberOf: ['team-b'],
},
relations: [
{
type: 'memberOf',
targetRef: 'group:default/team-b',
},
],
},
];
}

async listPermissions(): Promise<PermissionPolicy[]> {
return [
{
pluginId: 'catalog',
policies: [
{
permission: 'catalog-entity',
policy: 'read',
},
{
permission: 'catalog.entity.create',
policy: 'create',
},
{
permission: 'catalog-entity',
policy: 'delete',
},
{
permission: 'catalog-entity',
policy: 'update',
},
{
permission: 'catalog.location.read',
policy: 'read',
},
{
permission: 'catalog.location.create',
policy: 'create',
},
{
permission: 'catalog.location.delete',
policy: 'delete',
},
],
},
{
pluginId: 'scaffolder',
policies: [
{
permission: 'scaffolder-template',
policy: 'read',
},
{
permission: 'scaffolder-template',
policy: 'read',
},
{
permission: 'scaffolder-action',
policy: 'use',
},
],
},
{
pluginId: 'permission',
policies: [
{
permission: 'policy-entity',
policy: 'read',
},
{
permission: 'policy-entity',
policy: 'create',
},
{
permission: 'policy-entity',
policy: 'delete',
},
{
permission: 'policy-entity',
policy: 'update',
},
],
},
];
}

async deletePolicy(
_entityRef: string,
_permission: string,
_policies: Policy[],
): Promise<number> {
return 204;
}
}

const mockPermissionApi = new MockPermissionApi({ result: 'ALLOW' });
Expand Down
Loading

0 comments on commit 86893c7

Please sign in to comment.