@ostro-cloud/cli 1.0.0-alpha.10 → 1.0.0-alpha.11
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.
- package/bin/ostro.js +4 -33
- package/lib/client.js +34 -10
- package/lib/commands/formation.js +4 -3
- package/lib/commands/login.js +17 -20
- package/lib/commands/status.js +9 -35
- package/lib/health.js +48 -0
- package/package.json +9 -4
package/bin/ostro.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const { program } = require('commander');
|
|
4
|
-
const http = require('http');
|
|
5
4
|
|
|
6
5
|
const { validateTemplate, createStack, deployStack, listStacks, deleteStack, describeStack, packageStack, buildAndDeployService } = require('../lib/commands/formation');
|
|
7
6
|
const { universalDeploy } = require('../lib/commands/deploy');
|
|
@@ -192,42 +191,14 @@ program
|
|
|
192
191
|
.action(login);
|
|
193
192
|
|
|
194
193
|
// Doctor
|
|
195
|
-
const SERVICES = [
|
|
196
|
-
{ name: 'Unified Console', host: 'console.ostro-cloud.com', path: '/api/health' },
|
|
197
|
-
{ name: 'Kubernetes Engine', host: 'eks.ostro-cloud.com', path: '/api/health' },
|
|
198
|
-
{ name: 'Ostro Serverless', host: 'serverless.ostro-cloud.com', path: '/api/health' },
|
|
199
|
-
{ name: 'Ostro Bucket S3', host: 's3.ostro-cloud.com', path: '/api/health' },
|
|
200
|
-
{ name: 'Ostro Formation', host: 'formation.ostro-cloud.com', path: '/health' },
|
|
201
|
-
{ name: 'API Gateway', host: 'apigateway.ostro-cloud.com', path: '/api/health' },
|
|
202
|
-
{ name: 'Ostro DNS', host: 'route53.ostro-cloud.com', path: '/api/health' },
|
|
203
|
-
{ name: 'Message Broker', host: 'mq.ostro-cloud.com', path: '/api/health' },
|
|
204
|
-
{ name: 'CloudWatch Logs', host: 'logs.ostro-cloud.com', path: '/api/health' }
|
|
205
|
-
];
|
|
206
|
-
|
|
207
|
-
async function checkService(svc) {
|
|
208
|
-
return new Promise((resolve) => {
|
|
209
|
-
const req = http.get({
|
|
210
|
-
host: svc.host,
|
|
211
|
-
port: 80,
|
|
212
|
-
path: svc.path,
|
|
213
|
-
timeout: 1500
|
|
214
|
-
}, (res) => {
|
|
215
|
-
resolve(res.statusCode === 200);
|
|
216
|
-
});
|
|
217
|
-
req.on('error', () => resolve(false));
|
|
218
|
-
req.on('timeout', () => { req.destroy(); resolve(false); });
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
|
|
222
194
|
program
|
|
223
195
|
.command('doctor')
|
|
224
196
|
.description('Check connectivity to all core services')
|
|
225
197
|
.action(async () => {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
198
|
+
const { getStoredConfig } = require('../lib/client');
|
|
199
|
+
const { probeAll, printResults } = require('../lib/health');
|
|
200
|
+
console.log('Checking Ostro Cloud services...\n');
|
|
201
|
+
if (!printResults(await probeAll(getStoredConfig()))) process.exitCode = 1;
|
|
231
202
|
});
|
|
232
203
|
|
|
233
204
|
program.parse(process.argv);
|
package/lib/client.js
CHANGED
|
@@ -15,23 +15,23 @@ const DEFAULT_REGION = 'in-bihar-1';
|
|
|
15
15
|
const SERVICE_PATHS = {
|
|
16
16
|
formation: 'formation',
|
|
17
17
|
serverless: 'serverless',
|
|
18
|
-
storage: '
|
|
19
|
-
kubernetes: '
|
|
20
|
-
gateway: '
|
|
18
|
+
storage: 'storage',
|
|
19
|
+
kubernetes: 'kubernetes',
|
|
20
|
+
gateway: 'gateway',
|
|
21
21
|
tunnel: 'tunnel',
|
|
22
|
-
dns: '
|
|
22
|
+
dns: 'dns',
|
|
23
23
|
iam: 'iam',
|
|
24
24
|
ec2: 'ec2',
|
|
25
25
|
rds: 'rds',
|
|
26
|
-
cache: '
|
|
27
|
-
secrets: '
|
|
28
|
-
cloudwatch: '
|
|
26
|
+
cache: 'cache',
|
|
27
|
+
secrets: 'secrets',
|
|
28
|
+
cloudwatch: 'cloudwatch',
|
|
29
29
|
sns: 'sns',
|
|
30
30
|
sqs: 'sqs',
|
|
31
31
|
efs: 'efs',
|
|
32
32
|
elb: 'elb',
|
|
33
|
-
registry: '
|
|
34
|
-
broker: '
|
|
33
|
+
registry: 'registry',
|
|
34
|
+
broker: 'broker',
|
|
35
35
|
scheduler: 'scheduler',
|
|
36
36
|
organizations: 'organizations',
|
|
37
37
|
vpc: 'vpc',
|
|
@@ -163,7 +163,7 @@ async function request(url, options = {}) {
|
|
|
163
163
|
const headers = {
|
|
164
164
|
'Accept': 'application/json',
|
|
165
165
|
'Content-Type': 'application/json',
|
|
166
|
-
...(authToken ? { 'Authorization': `Bearer ${authToken}` } : buildHmacHeaders(options.method || 'GET',
|
|
166
|
+
...(authToken ? { 'Authorization': `Bearer ${authToken}` } : buildHmacHeaders(options.method || 'GET', serverSidePath(url, config), config)),
|
|
167
167
|
...(config.sessionToken ? { 'X-Ostro-Session-Token': config.sessionToken } : {}),
|
|
168
168
|
...(config.roleArn ? { 'X-Ostro-Role-Arn': config.roleArn } : {}),
|
|
169
169
|
...(config.clientId ? { 'X-Ostro-Client-Id': config.clientId } : {}),
|
|
@@ -225,6 +225,9 @@ async function resolveAuthTokenViaIam(config) {
|
|
|
225
225
|
const data = await res.json().catch(() => ({}));
|
|
226
226
|
const token = data.sessionToken;
|
|
227
227
|
if (!token) {
|
|
228
|
+
// IAM verified the keys but issues no session token: callers fall back to
|
|
229
|
+
// per-request OSTRO4-HMAC-SHA256 signing (see buildHmacHeaders).
|
|
230
|
+
if (data.valid) return null;
|
|
228
231
|
throw new Error('IAM verify-signature did not return a session token');
|
|
229
232
|
}
|
|
230
233
|
|
|
@@ -234,6 +237,26 @@ async function resolveAuthTokenViaIam(config) {
|
|
|
234
237
|
return token;
|
|
235
238
|
}
|
|
236
239
|
|
|
240
|
+
/**
|
|
241
|
+
* Path a service actually sees: with path-based routing the gateway strips the
|
|
242
|
+
* service prefix (e.g. console.<domain>/formation/api/x -> /api/x), and the
|
|
243
|
+
* OSTRO4-HMAC signature is verified against that stripped path.
|
|
244
|
+
*/
|
|
245
|
+
function serverSidePath(fullUrl, config) {
|
|
246
|
+
const u = new URL(fullUrl);
|
|
247
|
+
const cfg = config || getStoredConfig();
|
|
248
|
+
for (const [k, v] of Object.entries(cfg)) {
|
|
249
|
+
if (!k.endsWith('Url') || typeof v !== 'string') continue;
|
|
250
|
+
let base;
|
|
251
|
+
try { base = new URL(v); } catch { continue; }
|
|
252
|
+
const prefix = base.pathname.replace(/\/+$/, '');
|
|
253
|
+
if (prefix && base.host === u.host && (u.pathname === prefix || u.pathname.startsWith(prefix + '/'))) {
|
|
254
|
+
return u.pathname.slice(prefix.length) || '/';
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return u.pathname;
|
|
258
|
+
}
|
|
259
|
+
|
|
237
260
|
function buildHmacHeaders(method, pathname, config) {
|
|
238
261
|
if (!config?.accessKeyId || !config?.secretAccessKey) return {};
|
|
239
262
|
const xOstroDate = new Date().toISOString();
|
|
@@ -251,6 +274,7 @@ module.exports = {
|
|
|
251
274
|
saveConfig,
|
|
252
275
|
request,
|
|
253
276
|
buildHmacHeaders,
|
|
277
|
+
serverSidePath,
|
|
254
278
|
defaultServiceUrl,
|
|
255
279
|
DEFAULT_CLOUD_DOMAIN,
|
|
256
280
|
DEFAULT_REGION,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { getStoredConfig, resolveServiceUrl, request, buildHmacHeaders, resolveAuthTokenViaIam } = require('../client');
|
|
1
|
+
const { getStoredConfig, resolveServiceUrl, request, buildHmacHeaders, resolveAuthTokenViaIam, serverSidePath } = require('../client');
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const os = require('os');
|
|
@@ -58,8 +58,9 @@ async function buildImageViaApi(formationUrl, stackName, sourceDir) {
|
|
|
58
58
|
path: url.pathname + url.search,
|
|
59
59
|
method: 'POST',
|
|
60
60
|
headers: {
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
...(authToken
|
|
62
|
+
? { 'Authorization': `Bearer ${authToken}`, 'X-Ostro-Session-Token': authToken }
|
|
63
|
+
: buildHmacHeaders('POST', serverSidePath(url.href, config), config)),
|
|
63
64
|
'Content-Type': 'application/octet-stream',
|
|
64
65
|
'Accept': 'application/json',
|
|
65
66
|
'X-Stack-Name': stackName,
|
package/lib/commands/login.js
CHANGED
|
@@ -7,11 +7,6 @@ const os = require('os');
|
|
|
7
7
|
const CREDENTIALS_FILE = path.join(os.homedir(), '.ostro', 'credentials');
|
|
8
8
|
|
|
9
9
|
function ask(query, isPassword = false) {
|
|
10
|
-
const rl = readline.createInterface({
|
|
11
|
-
input: process.stdin,
|
|
12
|
-
output: process.stdout,
|
|
13
|
-
});
|
|
14
|
-
|
|
15
10
|
return new Promise((resolve) => {
|
|
16
11
|
if (isPassword) {
|
|
17
12
|
const stdin = process.stdin;
|
|
@@ -21,37 +16,38 @@ function ask(query, isPassword = false) {
|
|
|
21
16
|
stdin.setEncoding('utf8');
|
|
22
17
|
|
|
23
18
|
let password = '';
|
|
24
|
-
const onData = (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
19
|
+
const onData = (chunk) => {
|
|
20
|
+
// A paste arrives as one multi-character chunk: strip bracketed-paste
|
|
21
|
+
// markers and process every character individually.
|
|
22
|
+
const text = chunk.toString('utf8').replace(/\u001b\[20[01]~/g, '');
|
|
23
|
+
for (const ch of text) {
|
|
24
|
+
if (ch === '\n' || ch === '\r' || ch === '\u0004') {
|
|
30
25
|
stdin.setRawMode && stdin.setRawMode(false);
|
|
31
26
|
stdin.pause();
|
|
32
27
|
stdin.removeListener('data', onData);
|
|
33
28
|
process.stdout.write('\n');
|
|
34
|
-
rl.close();
|
|
35
29
|
resolve(password);
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (ch === '\u0003') {
|
|
38
33
|
process.exit();
|
|
39
|
-
|
|
40
|
-
case '\u007f':
|
|
41
|
-
case '\b':
|
|
34
|
+
} else if (ch === '\u007f' || ch === '\b') {
|
|
42
35
|
if (password.length > 0) {
|
|
43
36
|
password = password.slice(0, -1);
|
|
44
37
|
process.stdout.write('\b \b');
|
|
45
38
|
}
|
|
46
|
-
|
|
47
|
-
default:
|
|
39
|
+
} else if (ch >= ' ') {
|
|
48
40
|
password += ch;
|
|
49
41
|
process.stdout.write('*');
|
|
50
|
-
|
|
42
|
+
}
|
|
51
43
|
}
|
|
52
44
|
};
|
|
53
45
|
stdin.on('data', onData);
|
|
54
46
|
} else {
|
|
47
|
+
const rl = readline.createInterface({
|
|
48
|
+
input: process.stdin,
|
|
49
|
+
output: process.stdout,
|
|
50
|
+
});
|
|
55
51
|
rl.question(query, (ans) => {
|
|
56
52
|
rl.close();
|
|
57
53
|
resolve(ans.trim());
|
|
@@ -108,6 +104,7 @@ async function login(options) {
|
|
|
108
104
|
const loginUrl = `${endpoint}/api/auth/login`;
|
|
109
105
|
const res = await request(loginUrl, {
|
|
110
106
|
method: 'POST',
|
|
107
|
+
skipAuth: true,
|
|
111
108
|
body: JSON.stringify({
|
|
112
109
|
username,
|
|
113
110
|
password
|
package/lib/commands/status.js
CHANGED
|
@@ -1,41 +1,15 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const { getStoredConfig } = require('../client');
|
|
2
|
+
const { probeAll, printResults } = require('../health');
|
|
2
3
|
|
|
3
4
|
async function checkStatus() {
|
|
4
5
|
const config = getStoredConfig();
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
console.log(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
console.log(` Endpoint: \x1b[34m${base}\x1b[0m`);
|
|
13
|
-
console.log(` Region: \x1b[33m🇮🇳 ${config.region}\x1b[0m`);
|
|
14
|
-
console.log(` Environment: \x1b[32m${config.environment.toUpperCase()}\x1b[0m\n`);
|
|
15
|
-
|
|
16
|
-
const services = [
|
|
17
|
-
{ name: 'Unified Console', url: `${base}/api/health` },
|
|
18
|
-
{ name: 'Kubernetes Engine (EKS)', url: `${base}/kubernetes/api/health` },
|
|
19
|
-
{ name: 'Ostro Serverless (Lambda)', url: `${base}/serverless/api/health` },
|
|
20
|
-
{ name: 'Ostro Bucket (S3)', url: `${base}/storage/api/health` },
|
|
21
|
-
{ name: 'Ostro Formation (IaC)', url: `${base}/formation/api/health` },
|
|
22
|
-
{ name: 'Ostro Ingress Tunnel', url: `${base}/tunnel/api/health` },
|
|
23
|
-
{ name: 'Ostro DNS (Route 53)', url: `${base}/dns/api/health` },
|
|
24
|
-
{ name: 'Ostro EventBus IPC', url: `${base}/eventbus/health` }
|
|
25
|
-
];
|
|
26
|
-
|
|
27
|
-
for (const svc of services) {
|
|
28
|
-
const start = Date.now();
|
|
29
|
-
try {
|
|
30
|
-
await request(svc.url);
|
|
31
|
-
const latency = Date.now() - start;
|
|
32
|
-
console.log(` \x1b[32m✔\x1b[0m ${svc.name.padEnd(30)} \x1b[32mONLINE (${latency}ms)\x1b[0m — \x1b[90m${svc.url}\x1b[0m`);
|
|
33
|
-
} catch (err) {
|
|
34
|
-
console.log(` \x1b[31m✖\x1b[0m ${svc.name.padEnd(30)} \x1b[31mOFFLINE (${err.message})\x1b[0m — \x1b[90m${svc.url}\x1b[0m`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
console.log(`\n All microservices configured for automated GitLab CI/CD & Local Terminals.\n`);
|
|
6
|
+
console.log('\x1b[36m===================================================\x1b[0m');
|
|
7
|
+
console.log('\x1b[36m☁️ Ostro Cloud Cluster Health & Diagnostic Engine\x1b[0m');
|
|
8
|
+
console.log('\x1b[36m===================================================\x1b[0m');
|
|
9
|
+
console.log(` Console: \x1b[34m${config.consoleUrl}\x1b[0m`);
|
|
10
|
+
console.log(` Region: \x1b[33m🇮🇳 ${config.region}\x1b[0m\n`);
|
|
11
|
+
const ok = printResults(await probeAll(config));
|
|
12
|
+
if (!ok) process.exitCode = 1;
|
|
39
13
|
}
|
|
40
14
|
|
|
41
15
|
module.exports = { checkStatus };
|
package/lib/health.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const https = require('https');
|
|
3
|
+
const http = require('http');
|
|
4
|
+
|
|
5
|
+
// [label, key in getStoredConfig()] - every service reachable through the Cloudflare tunnel
|
|
6
|
+
const TARGETS = [
|
|
7
|
+
['Console', 'consoleUrl'], ['IAM', 'iamUrl'], ['Organizations', 'organizationsUrl'], ['VPC', 'vpcUrl'],
|
|
8
|
+
['EC2', 'ec2Url'], ['RDS', 'rdsUrl'], ['ElastiCache', 'cacheUrl'], ['EFS', 'efsUrl'], ['ELB', 'elbUrl'],
|
|
9
|
+
['Kubernetes (EKS)', 'k8sUrl'], ['Serverless', 'serverlessUrl'], ['Bucket (S3)', 's3Url'],
|
|
10
|
+
['Formation', 'formationUrl'], ['API Gateway', 'gatewayUrl'], ['Tunnel (served by VPC)', 'vpcUrl'], ['DNS', 'dnsUrl'],
|
|
11
|
+
['Secrets Manager', 'secretsUrl'], ['CloudWatch Logs', 'cloudwatchUrl'], ['SNS', 'snsUrl'], ['SQS', 'sqsUrl'],
|
|
12
|
+
['Registry (ECR)', 'registryUrl'], ['Message Broker', 'brokerUrl'], ['Scheduler', 'schedulerUrl'],
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
/** One GET. "Up" means the service answered (any status below 500): 401/403 is a healthy service behind a login. */
|
|
16
|
+
function probe(url, timeout = 5000) {
|
|
17
|
+
return new Promise((resolve) => {
|
|
18
|
+
const started = Date.now();
|
|
19
|
+
const lib = url.startsWith('https') ? https : http;
|
|
20
|
+
const req = lib.get(url, { timeout }, (res) => {
|
|
21
|
+
res.resume();
|
|
22
|
+
resolve({ up: res.statusCode < 500, code: res.statusCode, ms: Date.now() - started });
|
|
23
|
+
});
|
|
24
|
+
req.on('timeout', () => { req.destroy(); resolve({ up: false, code: 0, ms: Date.now() - started, error: 'timeout' }); });
|
|
25
|
+
req.on('error', (e) => resolve({ up: false, code: 0, ms: Date.now() - started, error: e.code || e.message }));
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function probeAll(config) {
|
|
30
|
+
return Promise.all(TARGETS.map(async ([name, key]) => {
|
|
31
|
+
const base = (config[key] || '').replace(/\/+$/, '');
|
|
32
|
+
const url = `${base}/api/health`;
|
|
33
|
+
return { name, url, ...(base ? await probe(url) : { up: false, code: 0, ms: 0, error: 'no URL configured' }) };
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function printResults(results) {
|
|
38
|
+
for (const r of results) {
|
|
39
|
+
const mark = r.up ? '\x1b[32m✔\x1b[0m' : '\x1b[31m✖\x1b[0m';
|
|
40
|
+
const state = r.up ? `\x1b[32mUP (${r.code}, ${r.ms}ms)\x1b[0m` : `\x1b[31mDOWN (${r.error || 'HTTP ' + r.code})\x1b[0m`;
|
|
41
|
+
console.log(` ${mark} ${r.name.padEnd(24)} ${state} \x1b[90m${r.url}\x1b[0m`);
|
|
42
|
+
}
|
|
43
|
+
const up = results.filter((r) => r.up).length;
|
|
44
|
+
console.log(`\n ${up}/${results.length} services reachable\n`);
|
|
45
|
+
return up === results.length;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module.exports = { probe, probeAll, printResults, TARGETS };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ostro-cloud/cli",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.11",
|
|
4
4
|
"description": "Enterprise Command Line Interface (CLI) for Ostro Cloud Serverless, S3 Buckets, Kubernetes, and CloudFormation Orchestration",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -25,15 +25,20 @@
|
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@ostro-cloud/cli": "^0.0.0-stage",
|
|
28
|
-
"@ostro/foundation": "^2.0.0-alpha.6",
|
|
29
28
|
"commander": "^12.1.0"
|
|
30
29
|
},
|
|
31
30
|
"engines": {
|
|
32
31
|
"node": ">=22.0.0"
|
|
33
32
|
},
|
|
34
33
|
"scripts": {
|
|
35
|
-
"
|
|
36
|
-
"
|
|
34
|
+
"dev": "npm run development",
|
|
35
|
+
"development": "echo 'No frontend build for CLI tool'",
|
|
36
|
+
"prod": "npm run production",
|
|
37
|
+
"production": "echo 'No frontend build for CLI tool'",
|
|
38
|
+
"build": "echo 'No frontend build for CLI tool'",
|
|
39
|
+
"build:clean": "echo 'No frontend build for CLI tool'",
|
|
40
|
+
"lint:check": "echo 'No lint config for CLI tool'",
|
|
41
|
+
"lint:fix": "echo 'No lint config for CLI tool'",
|
|
37
42
|
"test": "HEADLESS=true jest --runInBand"
|
|
38
43
|
}
|
|
39
44
|
}
|