-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
53 lines (42 loc) · 1.72 KB
/
cli.js
File metadata and controls
53 lines (42 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { handleJwtAuth, handleLogout } from './src/controllers/jwtAuthController.js';
import { handleResourceMenu } from './src/controllers/resourceController.js';
import { handlePermissionMenu } from './src/controllers/permissionController.js';
import { promptLoggingOutMessage, promptMainMenu } from './src/helpers/promptHelper.js';
import logger from './src/libs/logger.js';
import dotenv from "dotenv";
async function main() {
try {
const passphrase = process.env.PRIVATE_KEY_PASSPHRASE;
if (!passphrase) {
throw new Error("Passphrase for private key is missing.");
}
const jwtAuth = await handleJwtAuth(passphrase);
logger.info(`JWT Auth details: AccessToken=${jwtAuth.accessToken}, RefreshToken=${jwtAuth.refreshToken}`);
let continueApp = true;
while (continueApp) {
const mainMenuAction = await promptMainMenu();
switch (mainMenuAction) {
case 'resources':
await handleResourceMenu(jwtAuth);
break;
case 'permissions':
await handlePermissionMenu(jwtAuth);
break;
case 'logout':
await promptLoggingOutMessage();
await handleLogout(jwtAuth);
logger.info('User has logged out.');
continueApp = false;
break;
default:
logger.info('Exiting CLI.');
continueApp = false;
}
}
} catch (error) {
logger.error(`Error occurred: ${error.message}`);
}
}
main().catch(error => {
logger.error(`Critical Error: ${error.message}`);
});