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.
Add fga graph command to display Permit permissions
Related to permitio#16 Add `permit fga graph` command to display Permit permissions graph in ReBAC. * **CLI Integration** - Add import for `fgaGraph` command in `source/cli.tsx`. - Register `fgaGraph` command with Pastel in `source/cli.tsx`. * **API Methods** - Add methods in `source/lib/api.ts` to fetch resource instances, roles, and relationships from Permit API. * **Graph Command Implementation** - Create `source/commands/fgaGraph.tsx` to define `fgaGraph` command. - Use Ink components to render graph data interactively in CLI. * **Documentation** - Update `README.md` to include usage instructions for `permit fga graph` command.
- Loading branch information
1 parent
f70b563
commit 4e92aee
Showing
4 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
#!/usr/bin/env node | ||
import Pastel from 'pastel'; | ||
import fgaGraph from './commands/fgaGraph.js'; | ||
|
||
const app = new Pastel({ | ||
importMeta: import.meta, | ||
}); | ||
|
||
app.command('fga graph', fgaGraph); | ||
|
||
await app.run(); |
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,58 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { Text, Box } from 'ink'; | ||
import Spinner from 'ink-spinner'; | ||
import { fetchResourceInstances, fetchRoles, fetchRelationships } from '../lib/api.js'; | ||
import { loadAuthToken } from '../lib/auth.js'; | ||
|
||
const fgaGraph = () => { | ||
const [loading, setLoading] = useState(true); | ||
const [error, setError] = useState(null); | ||
const [graphData, setGraphData] = useState(null); | ||
|
||
useEffect(() => { | ||
const fetchData = async () => { | ||
try { | ||
const token = await loadAuthToken(); | ||
const [resourceInstances, roles, relationships] = await Promise.all([ | ||
fetchResourceInstances(token), | ||
fetchRoles(token), | ||
fetchRelationships(token), | ||
]); | ||
|
||
setGraphData({ | ||
resourceInstances: resourceInstances.response, | ||
roles: roles.response, | ||
relationships: relationships.response, | ||
}); | ||
} catch (err) { | ||
setError(err); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
fetchData(); | ||
}, []); | ||
|
||
if (loading) { | ||
return ( | ||
<Box> | ||
<Spinner type="dots" /> | ||
<Text>Loading graph data...</Text> | ||
</Box> | ||
); | ||
} | ||
|
||
if (error) { | ||
return <Text color="red">Error: {error.message}</Text>; | ||
} | ||
|
||
return ( | ||
<Box flexDirection="column"> | ||
<Text>Graph Data:</Text> | ||
<Text>{JSON.stringify(graphData, null, 2)}</Text> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default fgaGraph; |
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