-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-god-key.js
More file actions
122 lines (106 loc) · 3.58 KB
/
Copy pathcreate-god-key.js
File metadata and controls
122 lines (106 loc) · 3.58 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import fetch from 'node-fetch';
const API_BASE = 'https://api.groundng.site';
async function makeRequest(url, options = {}) {
const fullUrl = url.startsWith('http') ? url : `${API_BASE}${url}`;
try {
const response = await fetch(fullUrl, {
...options,
headers: {
'Content-Type': 'application/json',
...options.headers
}
});
const data = await response.json();
return { response, data, success: response.ok };
} catch (error) {
return { error: error.message, success: false };
}
}
async function createGodKey() {
console.log('🚀 Creating GOD Key...\n');
// Step 1: Create admin tenant
console.log('1. Creating admin tenant...');
const { data: tenantData, success: tenantSuccess } = await makeRequest('/tenant', {
method: 'POST',
headers: { 'X-Test-Create-Admin': 'true' },
body: JSON.stringify({
name: 'Admin Organization',
email: 'admin@yourcompany.com',
initialCredits: 100000,
planType: 'pro'
})
});
if (!tenantSuccess) {
console.error('❌ Failed to create admin tenant');
return;
}
console.log('✅ Admin tenant created:', tenantData.tenantId);
// Step 2: Create GOD key
console.log('\n2. Creating GOD key...');
const { data: keyData, success: keySuccess } = await makeRequest('/keys/create', {
method: 'POST',
headers: { 'X-Test-Create-Admin': 'true' },
body: JSON.stringify({
tenantId: tenantData.tenantId,
name: 'Master Admin GOD Key',
roleType: 'admin',
planType: 'pro',
keyType: 'god',
expiresInDays: 365,
metadata: {
purpose: 'System administration',
createdBy: 'setup-script',
environment: 'production'
}
})
});
if (!keySuccess) {
console.error('❌ Failed to create GOD key');
return;
}
console.log('✅ GOD key created successfully!');
console.log(` Key ID: ${keyData.keyId}`);
console.log(` Key: ${keyData.key}`);
// Step 3: Verify the key
console.log('\n3. Verifying GOD key...');
const { data: verifyData, success: verifySuccess } = await makeRequest('/keys/verify', {
method: 'POST',
body: JSON.stringify({ key: keyData.key })
});
if (verifySuccess) {
console.log('✅ Key verification successful:');
console.log(` Type: ${verifyData.keyType}`);
console.log(` Role: ${verifyData.roleType}`);
console.log(` Plan: ${verifyData.planType}`);
console.log(` Credits: ${verifyData.credits?.remaining}`);
console.log(` Expires: ${new Date(verifyData.expires).toISOString()}`);
} else {
console.log('❌ Key verification failed');
}
// Step 4: Test GOD key capabilities
console.log('\n4. Testing GOD key capabilities...');
// Test creating a TENANT key
const { data: tenantKeyData, success: tenantKeySuccess } = await makeRequest('/keys/create', {
method: 'POST',
headers: { 'X-API-Key': keyData.key },
body: JSON.stringify({
tenantId: tenantData.tenantId,
name: 'Test TENANT Key',
roleType: 'admin',
planType: 'standard',
keyType: 'tenant',
expiresInDays: 30
})
});
if (tenantKeySuccess) {
console.log('✅ GOD key can create TENANT keys');
console.log(` Created TENANT key: ${tenantKeyData.key.substring(0, 15)}...`);
} else {
console.log('❌ Failed to create TENANT key with GOD key');
}
console.log('\n🎉 GOD Key Setup Complete!');
console.log('\n🔐 IMPORTANT: Store this key securely:');
console.log(`\nGOD_KEY="${keyData.key}"\n`);
console.log('This key has full system access. Keep it safe!');
}
createGodKey().catch(console.error);