@lelu-auth/lelu 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @lelu-auth/lelu might be problematic. Click here for more details.
- package/dist/{client-DY93sy4F.d.mts → client-DauLJ9a4.d.mts} +90 -0
- package/dist/{client-DY93sy4F.d.ts → client-DauLJ9a4.d.ts} +90 -0
- package/dist/express/index.d.mts +1 -1
- package/dist/express/index.d.ts +1 -1
- package/dist/express/index.js +84 -2
- package/dist/express/index.js.map +1 -1
- package/dist/express/index.mjs +84 -2
- package/dist/express/index.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +84 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +84 -2
- package/dist/index.mjs.map +1 -1
- package/dist/langchain/index.d.mts +1 -1
- package/dist/langchain/index.d.ts +1 -1
- package/dist/react/index.js +84 -2
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +84 -2
- package/dist/react/index.mjs.map +1 -1
- package/package.json +1 -1
- package/scripts/audit-log.js +52 -11
- package/scripts/lelu.js +31 -8
- package/scripts/policies.js +241 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Lelu Policies CLI
|
|
4
|
+
async function main() {
|
|
5
|
+
try {
|
|
6
|
+
// Dynamic import to handle ESM module
|
|
7
|
+
const { createClient } = await import('@lelu-auth/lelu');
|
|
8
|
+
|
|
9
|
+
const baseUrl = process.env.LELU_PLATFORM_URL || 'http://localhost:9091';
|
|
10
|
+
const apiKey = process.env.LELU_PLATFORM_API_KEY || 'platform-dev-key';
|
|
11
|
+
const tenantId = process.env.LELU_TENANT_ID || 'default';
|
|
12
|
+
|
|
13
|
+
const command = process.argv[2] || 'list';
|
|
14
|
+
const policyName = process.argv[3];
|
|
15
|
+
const filePath = process.argv[4];
|
|
16
|
+
|
|
17
|
+
const lelu = createClient({ baseUrl, apiKey });
|
|
18
|
+
|
|
19
|
+
// First check if the service is reachable
|
|
20
|
+
try {
|
|
21
|
+
const healthResponse = await fetch(`${baseUrl}/healthz`, {
|
|
22
|
+
method: 'GET',
|
|
23
|
+
signal: AbortSignal.timeout(3000)
|
|
24
|
+
});
|
|
25
|
+
if (!healthResponse.ok) {
|
|
26
|
+
throw new Error('Service not healthy');
|
|
27
|
+
}
|
|
28
|
+
} catch (healthError) {
|
|
29
|
+
console.log('❌ Lelu platform service is not running or not reachable');
|
|
30
|
+
console.log('');
|
|
31
|
+
console.log('To manage policies, you need the Lelu platform service running.');
|
|
32
|
+
console.log('');
|
|
33
|
+
console.log('🚀 Quick start with Docker:');
|
|
34
|
+
console.log(' git clone https://github.com/lelu-auth/lelu.git');
|
|
35
|
+
console.log(' cd lelu');
|
|
36
|
+
console.log(' docker compose up -d');
|
|
37
|
+
console.log(' lelu policies list # Try again');
|
|
38
|
+
console.log('');
|
|
39
|
+
console.log('🌐 Or set LELU_PLATFORM_URL to point to your hosted instance:');
|
|
40
|
+
console.log(' LELU_PLATFORM_URL=https://your-lelu-platform.com lelu policies list');
|
|
41
|
+
console.log('');
|
|
42
|
+
console.log(`💡 Currently trying to connect to: ${baseUrl}`);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
switch (command) {
|
|
47
|
+
case 'list':
|
|
48
|
+
await listPolicies(lelu, tenantId);
|
|
49
|
+
break;
|
|
50
|
+
case 'get':
|
|
51
|
+
if (!policyName) {
|
|
52
|
+
console.log('❌ Policy name is required');
|
|
53
|
+
console.log('Usage: lelu policies get <policy-name>');
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
await getPolicy(lelu, policyName, tenantId);
|
|
57
|
+
break;
|
|
58
|
+
case 'set':
|
|
59
|
+
if (!policyName || !filePath) {
|
|
60
|
+
console.log('❌ Policy name and file path are required');
|
|
61
|
+
console.log('Usage: lelu policies set <policy-name> <file-path>');
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
await setPolicy(lelu, policyName, filePath, tenantId);
|
|
65
|
+
break;
|
|
66
|
+
case 'delete':
|
|
67
|
+
if (!policyName) {
|
|
68
|
+
console.log('❌ Policy name is required');
|
|
69
|
+
console.log('Usage: lelu policies delete <policy-name>');
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
await deletePolicy(lelu, policyName, tenantId);
|
|
73
|
+
break;
|
|
74
|
+
case 'help':
|
|
75
|
+
case '--help':
|
|
76
|
+
case '-h':
|
|
77
|
+
showHelp();
|
|
78
|
+
break;
|
|
79
|
+
default:
|
|
80
|
+
console.log(`❌ Unknown command: ${command}`);
|
|
81
|
+
showHelp();
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
} catch (err) {
|
|
86
|
+
// Handle other types of errors
|
|
87
|
+
if (err.message && (err.message.includes('ECONNREFUSED') || err.message.includes('fetch failed'))) {
|
|
88
|
+
console.log('❌ Connection failed to Lelu platform service');
|
|
89
|
+
console.log('');
|
|
90
|
+
console.log('🔧 Troubleshooting steps:');
|
|
91
|
+
console.log('1. Ensure the Lelu platform service is running');
|
|
92
|
+
console.log('2. Check the platform URL is correct');
|
|
93
|
+
console.log('3. Verify your network connection');
|
|
94
|
+
console.log('4. Check if firewall is blocking the connection');
|
|
95
|
+
} else {
|
|
96
|
+
console.error('❌ Error:', err.message || err);
|
|
97
|
+
}
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async function listPolicies(lelu, tenantId) {
|
|
103
|
+
console.log(`Fetching policies from ${lelu.baseUrl}...`);
|
|
104
|
+
|
|
105
|
+
const result = await lelu.listPolicies({ tenantId });
|
|
106
|
+
|
|
107
|
+
if (!result.policies.length) {
|
|
108
|
+
console.log('📋 No policies found.');
|
|
109
|
+
console.log('');
|
|
110
|
+
console.log('This could mean:');
|
|
111
|
+
console.log('- No policies have been created yet');
|
|
112
|
+
console.log('- You are looking at the wrong tenant');
|
|
113
|
+
console.log('- The policies are stored elsewhere');
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
console.log(`\n📊 Policies (${result.count} total)`);
|
|
118
|
+
console.log('─'.repeat(80));
|
|
119
|
+
|
|
120
|
+
for (const policy of result.policies) {
|
|
121
|
+
const createdAt = new Date(policy.createdAt).toLocaleString();
|
|
122
|
+
const updatedAt = new Date(policy.updatedAt).toLocaleString();
|
|
123
|
+
|
|
124
|
+
console.log(`📄 ${policy.name} (v${policy.version})`);
|
|
125
|
+
console.log(` ID: ${policy.id}`);
|
|
126
|
+
console.log(` Created: ${createdAt}`);
|
|
127
|
+
console.log(` Updated: ${updatedAt}`);
|
|
128
|
+
console.log(` Content: ${policy.content.length} characters`);
|
|
129
|
+
console.log('');
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async function getPolicy(lelu, name, tenantId) {
|
|
134
|
+
console.log(`Fetching policy "${name}"...`);
|
|
135
|
+
|
|
136
|
+
try {
|
|
137
|
+
const policy = await lelu.getPolicy({ name, tenantId });
|
|
138
|
+
|
|
139
|
+
console.log(`\n📄 Policy: ${policy.name} (v${policy.version})`);
|
|
140
|
+
console.log('─'.repeat(80));
|
|
141
|
+
console.log(`ID: ${policy.id}`);
|
|
142
|
+
console.log(`Tenant: ${policy.tenantId}`);
|
|
143
|
+
console.log(`Created: ${new Date(policy.createdAt).toLocaleString()}`);
|
|
144
|
+
console.log(`Updated: ${new Date(policy.updatedAt).toLocaleString()}`);
|
|
145
|
+
console.log(`HMAC: ${policy.hmacSha256}`);
|
|
146
|
+
console.log('');
|
|
147
|
+
console.log('Content:');
|
|
148
|
+
console.log('─'.repeat(40));
|
|
149
|
+
console.log(policy.content);
|
|
150
|
+
|
|
151
|
+
} catch (err) {
|
|
152
|
+
if (err.status === 404) {
|
|
153
|
+
console.log(`❌ Policy "${name}" not found`);
|
|
154
|
+
console.log('');
|
|
155
|
+
console.log('💡 Use "lelu policies list" to see available policies');
|
|
156
|
+
} else {
|
|
157
|
+
throw err;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async function setPolicy(lelu, name, filePath, tenantId) {
|
|
163
|
+
const fs = await import('fs/promises');
|
|
164
|
+
|
|
165
|
+
try {
|
|
166
|
+
const content = await fs.readFile(filePath, 'utf8');
|
|
167
|
+
|
|
168
|
+
console.log(`Setting policy "${name}" from ${filePath}...`);
|
|
169
|
+
|
|
170
|
+
const policy = await lelu.upsertPolicy({
|
|
171
|
+
name,
|
|
172
|
+
content,
|
|
173
|
+
tenantId
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
console.log(`✅ Policy "${name}" saved successfully`);
|
|
177
|
+
console.log(` ID: ${policy.id}`);
|
|
178
|
+
console.log(` Version: ${policy.version}`);
|
|
179
|
+
console.log(` Updated: ${new Date(policy.updatedAt).toLocaleString()}`);
|
|
180
|
+
console.log(` Content: ${content.length} characters`);
|
|
181
|
+
|
|
182
|
+
} catch (err) {
|
|
183
|
+
if (err.code === 'ENOENT') {
|
|
184
|
+
console.log(`❌ File not found: ${filePath}`);
|
|
185
|
+
} else if (err.code === 'EACCES') {
|
|
186
|
+
console.log(`❌ Permission denied reading file: ${filePath}`);
|
|
187
|
+
} else {
|
|
188
|
+
throw err;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async function deletePolicy(lelu, name, tenantId) {
|
|
194
|
+
console.log(`Deleting policy "${name}"...`);
|
|
195
|
+
|
|
196
|
+
try {
|
|
197
|
+
const result = await lelu.deletePolicy({ name, tenantId });
|
|
198
|
+
|
|
199
|
+
if (result.deleted) {
|
|
200
|
+
console.log(`✅ Policy "${name}" deleted successfully`);
|
|
201
|
+
} else {
|
|
202
|
+
console.log(`❌ Failed to delete policy "${name}"`);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
} catch (err) {
|
|
206
|
+
if (err.status === 404) {
|
|
207
|
+
console.log(`❌ Policy "${name}" not found`);
|
|
208
|
+
console.log('');
|
|
209
|
+
console.log('💡 Use "lelu policies list" to see available policies');
|
|
210
|
+
} else {
|
|
211
|
+
throw err;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function showHelp() {
|
|
217
|
+
console.log(`
|
|
218
|
+
Lelu Policies CLI
|
|
219
|
+
|
|
220
|
+
Usage:
|
|
221
|
+
lelu policies list List all policies
|
|
222
|
+
lelu policies get <name> Get a specific policy
|
|
223
|
+
lelu policies set <name> <file> Create or update a policy from file
|
|
224
|
+
lelu policies delete <name> Delete a policy
|
|
225
|
+
lelu policies help Show this help
|
|
226
|
+
|
|
227
|
+
Environment Variables:
|
|
228
|
+
LELU_PLATFORM_URL Platform API URL (default: http://localhost:9091)
|
|
229
|
+
LELU_PLATFORM_API_KEY Platform API key (default: platform-dev-key)
|
|
230
|
+
LELU_TENANT_ID Tenant ID (default: default)
|
|
231
|
+
|
|
232
|
+
Examples:
|
|
233
|
+
lelu policies list # List all policies
|
|
234
|
+
lelu policies get auth # View the "auth" policy
|
|
235
|
+
lelu policies set auth ./auth.rego # Create/update auth policy from file
|
|
236
|
+
lelu policies delete old-policy # Delete a policy
|
|
237
|
+
LELU_TENANT_ID=prod lelu policies list # List policies for prod tenant
|
|
238
|
+
`);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
main();
|