forked from permitio/permit-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9210ac5
commit 351bb02
Showing
7 changed files
with
131 additions
and
40 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Command } from 'commander'; | ||
import { fetchResources, fetchRelationships, fetchRoleAssignments } from '../lib/api.ts'; | ||
import { createGraph } from '../utils/graphUtils.ts'; | ||
|
||
const program = new Command(); | ||
|
||
program | ||
.command('fga graph') | ||
.description('Show the graph of the Permit permissions in ReBAC') | ||
.action(async () => { | ||
const getToken = async () => { | ||
return process.env['PERMIT_API_TOKEN'] || 'your_default_token'; // Use bracket notation to access the environment variable | ||
}; | ||
const token = await getToken(); | ||
try { | ||
const resourcesResponse = await fetchResources(token); | ||
const relationshipsResponse = await fetchRelationships(token); | ||
const roleAssignmentsResponse = await fetchRoleAssignments(token); | ||
|
||
const graphData = createGraph( | ||
resourcesResponse.response, | ||
relationshipsResponse.response, | ||
roleAssignmentsResponse.response | ||
); | ||
|
||
// Output the graph data in a user-friendly format | ||
console.log('Graph Data:', JSON.stringify(graphData, null, 2)); // Pretty print the graph data | ||
} catch (error) { | ||
console.error('Error fetching data:', error); | ||
} | ||
}); | ||
|
||
export default program; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
interface Resource { | ||
id: string; | ||
name: string; | ||
} | ||
|
||
interface Relationship { | ||
sourceId: string; | ||
targetId: string; | ||
type: string; | ||
} | ||
|
||
interface RoleAssignment { | ||
// Define the structure based on actual role assignment data | ||
userId: string; | ||
roleId: string; | ||
} | ||
|
||
export const createGraph = (resources: Resource[], relationships: Relationship[], roleAssignments: RoleAssignment[]) => { | ||
const graph = { | ||
nodes: resources.map(resource => ({ id: resource.id, label: resource.name })), | ||
edges: relationships.map(rel => ({ | ||
from: rel.sourceId, | ||
to: rel.targetId, | ||
label: rel.type, | ||
})), | ||
roleAssignments: roleAssignments, | ||
}; | ||
|
||
return graph; | ||
}; |