-
-
Notifications
You must be signed in to change notification settings - Fork 403
/
Copy pathPinePermManage.js
67 lines (48 loc) · 1.69 KB
/
PinePermManage.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const { PinePermManager } = require('../main');
/**
* This example creates a pine permission manager
* and tests all the available functions
*/
if (!process.env.SESSION || !process.env.SIGNATURE) {
throw Error('Please set your sessionid and signature cookies');
}
const pineid = process.argv[2];
if (!pineid) throw Error('Please specify a pine id as first argument');
console.log('Pine ID:', pineid);
const manager = new PinePermManager(
process.env.SESSION,
process.env.SIGNATURE,
pineid,
);
(async () => {
console.log('Users:', await manager.getUsers());
console.log('Adding user \'TradingView\'...');
switch (await manager.addUser('TradingView')) {
case 'ok':
console.log('Done !');
break;
case 'exists':
console.log('This user is already authorized');
break;
default:
console.error('Unknown error...');
break;
}
console.log('Users:', await manager.getUsers());
console.log('Modifying expiration date...');
const newDate = new Date(Date.now() + 24 * 3600000); // Add one day
if (await manager.modifyExpiration('TradingView', newDate) === 'ok') {
console.log('Done !');
} else console.error('Unknown error...');
console.log('Users:', await manager.getUsers());
console.log('Removing expiration date...');
if (await manager.modifyExpiration('TradingView') === 'ok') {
console.log('Done !');
} else console.error('Unknown error...');
console.log('Users:', await manager.getUsers());
console.log('Removing user \'TradingView\'...');
if (await manager.removeUser('TradingView') === 'ok') {
console.log('Done !');
} else console.error('Unknown error...');
console.log('Users:', await manager.getUsers());
})();