@ostro-cloud/cli 0.0.0-stage → 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.
@@ -0,0 +1,44 @@
1
+ const { getStoredConfig, resolveServiceUrl, request } = require('../client');
2
+ const fs = require('fs');
3
+
4
+ async function applyManifest(manifestPath, options = {}) {
5
+ const config = getStoredConfig();
6
+ const k8sUrl = resolveServiceUrl('kubernetes', options.k8sUrl);
7
+ const namespace = options.namespace || 'default';
8
+
9
+ console.log(`\x1b[36m☸️ Applying Kubernetes Manifest [${manifestPath}] in namespace [${namespace}]...\x1b[0m`);
10
+
11
+ if (!fs.existsSync(manifestPath)) {
12
+ console.error(`\x1b[31m✖ Manifest file not found:\x1b[0m ${manifestPath}`);
13
+ return;
14
+ }
15
+
16
+ const yamlContent = fs.readFileSync(manifestPath, 'utf-8');
17
+
18
+ try {
19
+ const result = await request(`${k8sUrl}/api/v1/applications/deploy`, {
20
+ method: 'POST',
21
+ body: JSON.stringify({
22
+ yaml: yamlContent,
23
+ namespace
24
+ })
25
+ });
26
+
27
+ const regionStr = config.region ? ` (${config.region})` : '';
28
+ console.log(`\x1b[32m✔ Manifest successfully applied to Ostro K8s Cluster${regionStr}!\x1b[0m`);
29
+ if (result && result.vip) {
30
+ console.log(` Workload Static VIP: \x1b[33mhttp://${result.vip}\x1b[0m`);
31
+ }
32
+ const app = result?.appliedResources?.find(r => r.kind === 'Deployment');
33
+ if (app) {
34
+ console.log(` Live Ingress Domain: \x1b[34mhttp://${app.name}.ostro-cloud.com\x1b[0m`);
35
+ }
36
+ console.log(` Target Namespace: \x1b[35m${result?.namespace || namespace}\x1b[0m\n`);
37
+ } catch (err) {
38
+ console.error(`\x1b[31m✖ kubectl apply failed:\x1b[0m`, err.message);
39
+ }
40
+ }
41
+
42
+ module.exports = {
43
+ applyManifest
44
+ };
@@ -0,0 +1,151 @@
1
+ const { saveConfig, request, getStoredConfig } = require('../client');
2
+ const readline = require('readline');
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const os = require('os');
6
+
7
+ const CREDENTIALS_FILE = path.join(os.homedir(), '.ostro', 'credentials');
8
+
9
+ function ask(query, isPassword = false) {
10
+ return new Promise((resolve) => {
11
+ if (isPassword) {
12
+ const stdin = process.stdin;
13
+ process.stdout.write(query);
14
+ stdin.resume();
15
+ stdin.setRawMode && stdin.setRawMode(true);
16
+ stdin.setEncoding('utf8');
17
+
18
+ let password = '';
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') {
25
+ stdin.setRawMode && stdin.setRawMode(false);
26
+ stdin.pause();
27
+ stdin.removeListener('data', onData);
28
+ process.stdout.write('\n');
29
+ resolve(password);
30
+ return;
31
+ }
32
+ if (ch === '\u0003') {
33
+ process.exit();
34
+ } else if (ch === '\u007f' || ch === '\b') {
35
+ if (password.length > 0) {
36
+ password = password.slice(0, -1);
37
+ process.stdout.write('\b \b');
38
+ }
39
+ } else if (ch >= ' ') {
40
+ password += ch;
41
+ process.stdout.write('*');
42
+ }
43
+ }
44
+ };
45
+ stdin.on('data', onData);
46
+ } else {
47
+ const rl = readline.createInterface({
48
+ input: process.stdin,
49
+ output: process.stdout,
50
+ });
51
+ rl.question(query, (ans) => {
52
+ rl.close();
53
+ resolve(ans.trim());
54
+ });
55
+ }
56
+ });
57
+ }
58
+
59
+ function writeAwsStyleCredentials(profile, accessKeyId, secretAccessKey, sessionToken, roleArn) {
60
+ const dir = path.dirname(CREDENTIALS_FILE);
61
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
62
+
63
+ const content = `[${profile}]
64
+ ostro_access_key_id = ${accessKeyId || ''}
65
+ ostro_secret_access_key = ${secretAccessKey || ''}
66
+ ostro_session_token = ${sessionToken || ''}
67
+ ostro_role_arn = ${roleArn || ''}
68
+ `;
69
+ fs.writeFileSync(CREDENTIALS_FILE, content, { mode: 0o600 });
70
+ }
71
+
72
+ async function login(options) {
73
+ const config = getStoredConfig();
74
+ // Derive IAM login URL from domain — no endpoint flag needed
75
+ const domain = config.domain || process.env.OSTRO_DOMAIN || 'ostro-cloud.com';
76
+ const region = config.region || process.env.OSTRO_REGION || 'in-bihar-1';
77
+ const consoleHost = `https://console.${domain}`;
78
+ const iamBase = config.iamUrl || process.env.OSTRO_IAM_URL || `${consoleHost}/iam`;
79
+ // --endpoint kept for backwards-compat; it overrides the domain-derived URL
80
+ const endpoint = options.endpoint || iamBase;
81
+ const profile = options.profile || config.environment || 'default';
82
+
83
+ let username = options.username;
84
+ let password = options.password;
85
+
86
+ console.log(`\x1b[36m🔑 Ostro Cloud Login\x1b[0m`);
87
+ console.log(` IAM: \x1b[34m${iamBase}\x1b[0m`);
88
+ console.log(` Region: \x1b[33m${region}\x1b[0m`);
89
+ console.log(` Profile: \x1b[35m${profile}\x1b[0m\n`);
90
+
91
+ if (!username) {
92
+ username = await ask('Username or Email: ');
93
+ }
94
+ if (!password) {
95
+ password = await ask('Password: ', true);
96
+ }
97
+
98
+ if (!username || !password) {
99
+ console.error('\x1b[31m✖ Username and password are required.\x1b[0m');
100
+ return;
101
+ }
102
+
103
+ try {
104
+ const loginUrl = `${endpoint}/api/auth/login`;
105
+ const res = await request(loginUrl, {
106
+ method: 'POST',
107
+ skipAuth: true,
108
+ body: JSON.stringify({
109
+ username,
110
+ password
111
+ })
112
+ });
113
+
114
+ if (res && res.sessionToken) {
115
+ // 1. Update ~/.ostro/config.json
116
+ saveConfig({
117
+ endpoint,
118
+ sessionToken: res.sessionToken,
119
+ token: res.sessionToken,
120
+ accessKeyId: res.accessKeyId || null,
121
+ secretAccessKey: res.secretAccessKey || null,
122
+ roleArn: res.role || null
123
+ });
124
+
125
+ // 2. Update ~/.ostro/credentials in AWS format
126
+ writeAwsStyleCredentials(
127
+ profile,
128
+ res.accessKeyId,
129
+ res.secretAccessKey,
130
+ res.sessionToken,
131
+ res.role
132
+ );
133
+
134
+ console.log(`\x1b[32m✔ Successfully authenticated to Ostro Cloud!\x1b[0m`);
135
+ console.log(` User: \x1b[33m${res.user?.username || username}\x1b[0m (${res.user?.email || 'N/A'})`);
136
+ console.log(` Account ID: \x1b[35m${res.accountId || res.user?.accountId}\x1b[0m`);
137
+ console.log(` Role: \x1b[36m${res.roleName || res.role || 'User'}\x1b[0m`);
138
+ console.log(` Key ID: \x1b[90m${res.accessKeyId || 'N/A'}\x1b[0m`);
139
+ console.log(` Credentials Saved: \x1b[32m~/.ostro/credentials\x1b[0m`);
140
+ console.log(` Expires: \x1b[90m${res.expiresAt || '24h'}\x1b[0m\n`);
141
+ } else {
142
+ console.error('\x1b[31m✖ Authentication failed: No session token received.\x1b[0m');
143
+ }
144
+ } catch (err) {
145
+ console.error(`\x1b[31m✖ Login failed:\x1b[0m`, err.message);
146
+ }
147
+ }
148
+
149
+ module.exports = {
150
+ login
151
+ };
@@ -0,0 +1,88 @@
1
+ const { getStoredConfig, resolveServiceUrl, request } = require('../client');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+
5
+ async function listBuckets(options = {}) {
6
+ const config = getStoredConfig();
7
+ const s3Url = resolveServiceUrl('storage', options.s3Url);
8
+ const region = options.region || config.region || null;
9
+
10
+ const headerInfo = [];
11
+ if (region) headerInfo.push(`REGION: ${region}`);
12
+ const headerStr = headerInfo.length > 0 ? ` [${headerInfo.join(', ')}]` : '';
13
+
14
+ console.log(`\x1b[36m💽 Ostro S3 Buckets${headerStr}\x1b[0m\n`);
15
+
16
+ try {
17
+ const queryParams = new URLSearchParams();
18
+ if (region) queryParams.set('region', region);
19
+ const queryStr = queryParams.toString() ? `?${queryParams.toString()}` : '';
20
+
21
+ const list = await request(`${s3Url}/api/s3/buckets${queryStr}`);
22
+ if (!Array.isArray(list) || list.length === 0) {
23
+ console.log(` \x1b[33m(No buckets created)\x1b[0m`);
24
+ return;
25
+ }
26
+
27
+ console.log(` ${'CREATION DATE'.padEnd(24)} ${'BUCKET NAME'.padEnd(35)} ${'OBJECTS'}`);
28
+ console.log(` ${'-'.repeat(70)}`);
29
+ list.forEach(b => {
30
+ console.log(` ${(b.creationDate || b.created_at || '—').padEnd(24)} \x1b[32m${b.name.padEnd(35)}\x1b[0m ${b.objectCount || 0} objects`);
31
+ });
32
+ } catch (err) {
33
+ console.error(`\x1b[31m✖ Error listing buckets:\x1b[0m`, err.message);
34
+ }
35
+ }
36
+
37
+ async function syncDirectory(localDir, bucketUri, options = {}) {
38
+ const config = getStoredConfig();
39
+ const s3Url = resolveServiceUrl('storage', options.s3Url);
40
+ const bucketName = bucketUri.replace('s3://', '').replace('/', '');
41
+
42
+ console.log(`\x1b[36m📂 Syncing directory [${localDir}] to s3://${bucketName}...\x1b[0m`);
43
+
44
+ if (!fs.existsSync(localDir)) {
45
+ console.error(`\x1b[31m✖ Directory not found:\x1b[0m ${localDir}`);
46
+ return;
47
+ }
48
+
49
+ function getAllFiles(dirPath, arrayOfFiles = []) {
50
+ const files = fs.readdirSync(dirPath);
51
+ files.forEach(file => {
52
+ const fullPath = path.join(dirPath, file);
53
+ if (fs.statSync(fullPath).isDirectory()) {
54
+ getAllFiles(fullPath, arrayOfFiles);
55
+ } else {
56
+ arrayOfFiles.push(fullPath);
57
+ }
58
+ });
59
+ return arrayOfFiles;
60
+ }
61
+
62
+ const files = getAllFiles(localDir);
63
+ console.log(` Found ${files.length} files to upload...`);
64
+
65
+ for (const file of files) {
66
+ const relativeKey = path.relative(localDir, file);
67
+ const content = fs.readFileSync(file, 'utf-8');
68
+ try {
69
+ await request(`${s3Url}/api/s3/buckets/${bucketName}/objects`, {
70
+ method: 'POST',
71
+ body: JSON.stringify({
72
+ key: relativeKey,
73
+ content
74
+ })
75
+ });
76
+ console.log(` \x1b[32m✔ Uploaded:\x1b[0m ${relativeKey}`);
77
+ } catch (err) {
78
+ console.error(` \x1b[31m✖ Failed:\x1b[0m ${relativeKey} (${err.message})`);
79
+ }
80
+ }
81
+
82
+ console.log(`\x1b[32m\n✔ S3 sync complete! Static web hosting available at: ${s3Url}/site/${bucketName}/index.html\x1b[0m\n`);
83
+ }
84
+
85
+ module.exports = {
86
+ listBuckets,
87
+ syncDirectory
88
+ };
@@ -0,0 +1,104 @@
1
+ const { getStoredConfig, resolveServiceUrl, request } = require('../client');
2
+ const fs = require('fs');
3
+
4
+ async function listFunctions(options = {}) {
5
+ const config = getStoredConfig();
6
+ const serverlessUrl = resolveServiceUrl('serverless', options.serverlessUrl);
7
+ const region = options.region || config.region || null;
8
+
9
+ const headerInfo = [];
10
+ if (region) headerInfo.push(`REGION: ${region}`);
11
+ const headerStr = headerInfo.length > 0 ? ` [${headerInfo.join(', ')}]` : '';
12
+
13
+ console.log(`\x1b[36m⚡ Ostro Serverless — Functions${headerStr}\x1b[0m\n`);
14
+
15
+ try {
16
+ const queryParams = new URLSearchParams();
17
+ if (region) queryParams.set('region', region);
18
+ const queryStr = queryParams.toString() ? `?${queryParams.toString()}` : '';
19
+
20
+ const list = await request(`${serverlessUrl}/api/functions${queryStr}`);
21
+ if (!Array.isArray(list) || list.length === 0) {
22
+ console.log(` \x1b[33m(No functions deployed)\x1b[0m`);
23
+ return;
24
+ }
25
+
26
+ console.log(` ${'FUNCTION NAME'.padEnd(30)} ${'RUNTIME'.padEnd(16)} ${'MEMORY'.padEnd(10)} ${'TIMEOUT'.padEnd(10)} ${'UPDATED'}`);
27
+ console.log(` ${'-'.repeat(80)}`);
28
+ list.forEach(fn => {
29
+ console.log(` \x1b[32m${fn.name.padEnd(30)}\x1b[0m ${fn.runtime.padEnd(16)} ${(fn.memory + ' MB').padEnd(10)} ${(fn.timeout + 's').padEnd(10)} ${fn.updatedAt || 'N/A'}`);
30
+ });
31
+ console.log(`\n Total: ${list.length} function(s) active`);
32
+ } catch (err) {
33
+ console.error(`\x1b[31m✖ Error fetching functions:\x1b[0m`, err.message);
34
+ }
35
+ }
36
+
37
+ async function deployFunction(name, options = {}) {
38
+ const config = getStoredConfig();
39
+ const serverlessUrl = resolveServiceUrl('serverless', options.serverlessUrl);
40
+ const region = options.region || config.region || null;
41
+ const runtime = options.runtime || 'nodejs20.x';
42
+ const handler = options.handler || 'index.handler';
43
+ const filePath = options.file || 'index.js';
44
+
45
+ if (!fs.existsSync(filePath)) {
46
+ throw new Error(`Source file not found: ${filePath}`);
47
+ }
48
+ const code = fs.readFileSync(filePath, 'utf-8');
49
+
50
+ const regionLabel = region ? ` in ${region}` : '';
51
+ console.log(`\x1b[36m🚀 Deploying Serverless Function [${name}]${regionLabel}...\x1b[0m`);
52
+
53
+ try {
54
+ const result = await request(`${serverlessUrl}/api/functions`, {
55
+ method: 'POST',
56
+ body: JSON.stringify({
57
+ name,
58
+ runtime,
59
+ handler,
60
+ code,
61
+ ...(region ? { region } : {})
62
+ })
63
+ });
64
+
65
+ console.log(`\x1b[32m✔ Function [${name}] deployed successfully!\x1b[0m`);
66
+ const arnRegion = region || 'global';
67
+ console.log(` ARN: \x1b[33marn:ostro:serverless:${arnRegion}:function:${name}\x1b[0m`);
68
+ console.log(` Gateway Endpoint: \x1b[34m${serverlessUrl}/gateway/${name}\x1b[0m\n`);
69
+ } catch (err) {
70
+ console.error(`\x1b[31m✖ Deployment failed:\x1b[0m`, err.message);
71
+ }
72
+ }
73
+
74
+ async function invokeFunction(name, options = {}) {
75
+ const config = getStoredConfig();
76
+ const serverlessUrl = resolveServiceUrl('serverless', options.serverlessUrl);
77
+ let payload = {};
78
+
79
+ if (options.data) {
80
+ try { payload = JSON.parse(options.data); } catch { payload = { text: options.data }; }
81
+ }
82
+
83
+ console.log(`\x1b[36m⚡ Invoking Function [${name}]...\x1b[0m`);
84
+
85
+ try {
86
+ const startTime = Date.now();
87
+ const result = await request(`${serverlessUrl}/api/functions/${name}/invoke`, {
88
+ method: 'POST',
89
+ body: JSON.stringify({ payload })
90
+ });
91
+ const duration = Date.now() - startTime;
92
+
93
+ console.log(`\x1b[32m✔ Execution Complete (${duration}ms)\x1b[0m\n`);
94
+ console.log(JSON.stringify(result, null, 2));
95
+ } catch (err) {
96
+ console.error(`\x1b[31m✖ Invocation failed:\x1b[0m`, err.message);
97
+ }
98
+ }
99
+
100
+ module.exports = {
101
+ listFunctions,
102
+ deployFunction,
103
+ invokeFunction
104
+ };
@@ -0,0 +1,15 @@
1
+ const { getStoredConfig } = require('../client');
2
+ const { probeAll, printResults } = require('../health');
3
+
4
+ async function checkStatus() {
5
+ const config = getStoredConfig();
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;
13
+ }
14
+
15
+ module.exports = { checkStatus };
@@ -0,0 +1,129 @@
1
+ const { getStoredConfig, resolveServiceUrl, request } = require('../client');
2
+
3
+ async function listTunnels(options = {}) {
4
+ const config = getStoredConfig();
5
+ const tunnelUrl = resolveServiceUrl('tunnel', options.tunnelUrl);
6
+ const region = options.region || config.region || null;
7
+
8
+ const headerInfo = [];
9
+ if (region) headerInfo.push(`REGION: ${region}`);
10
+ const headerStr = headerInfo.length > 0 ? ` [${headerInfo.join(', ')}]` : '';
11
+
12
+ console.log(`\x1b[36m⚡ Ostro Ingress Tunnels & DNS${headerStr}\x1b[0m\n`);
13
+
14
+ try {
15
+ const queryParams = new URLSearchParams();
16
+ if (region) queryParams.set('region', region);
17
+ const queryStr = queryParams.toString() ? `?${queryParams.toString()}` : '';
18
+
19
+ const list = await request(`${tunnelUrl}/api/tunnels${queryStr}`);
20
+ if (!Array.isArray(list) || list.length === 0) {
21
+ console.log(` \x1b[33m(No active tunnels mapped)\x1b[0m`);
22
+ return;
23
+ }
24
+
25
+ console.log(` ${'TUNNEL ID'.padEnd(24)} ${'NAME'.padEnd(25)} ${'STATUS'.padEnd(10)} ${'HOSTNAME'.padEnd(30)} ${'TARGET HOST:PORT'}`);
26
+ console.log(` ${'-'.repeat(105)}`);
27
+ list.forEach(t => {
28
+ const id = (t.id || '').padEnd(24);
29
+ const name = (t.name || '').padEnd(25);
30
+ const statusColor = t.status === 'ACTIVE' ? '\x1b[32m' : '\x1b[33m';
31
+ const status = `${statusColor}${(t.status || 'ACTIVE').padEnd(10)}\x1b[0m`;
32
+ const hostname = (t.hostname || t.publicUrl || '').padEnd(30);
33
+ const target = t.target_host ? `${t.target_host}:${t.target_port}` : (t.targetUrl || '—');
34
+ console.log(` ${id} \x1b[32m${name}\x1b[0m ${status} \x1b[36m${hostname}\x1b[0m ${target}`);
35
+ });
36
+ console.log(`\n Total: ${list.length} ingress tunnel(s) active`);
37
+ } catch (err) {
38
+ console.error(`\x1b[31m✖ Error listing tunnels:\x1b[0m`, err.message);
39
+ }
40
+ }
41
+
42
+ async function createTunnel(name, options = {}) {
43
+ const config = getStoredConfig();
44
+ const tunnelUrl = resolveServiceUrl('tunnel', options.tunnelUrl);
45
+
46
+ const rawTarget = options.target;
47
+ if (!rawTarget) {
48
+ throw new Error('Target origin is required. Pass --target <host:port>.');
49
+ }
50
+
51
+ const hostname = options.hostname || options.publicUrl;
52
+ if (!hostname) {
53
+ throw new Error('Public hostname is required. Pass --hostname <domain>.');
54
+ }
55
+
56
+ const provider = options.provider ? String(options.provider).toUpperCase() : 'CLOUDFLARE';
57
+ const region = options.region || config.region || null;
58
+
59
+ let targetHost = rawTarget;
60
+ let targetPort = 80;
61
+ const targetClean = rawTarget.replace(/^https?:\/\//, '');
62
+ if (targetClean.includes(':')) {
63
+ const parts = targetClean.split(':');
64
+ targetHost = parts[0];
65
+ targetPort = parseInt(parts[1], 10);
66
+ if (isNaN(targetPort)) {
67
+ throw new Error(`Invalid port in target: ${rawTarget}`);
68
+ }
69
+ } else {
70
+ targetHost = targetClean;
71
+ }
72
+
73
+ console.log(`\x1b[36m🚀 Creating [${provider}] Ingress Tunnel [${name}] -> ${hostname} -> [${targetHost}:${targetPort}]...\x1b[0m`);
74
+
75
+ try {
76
+ const queryParams = new URLSearchParams();
77
+ if (region) queryParams.set('region', region);
78
+ const queryStr = queryParams.toString() ? `?${queryParams.toString()}` : '';
79
+
80
+ const result = await request(`${tunnelUrl}/api/tunnels${queryStr}`, {
81
+ method: 'POST',
82
+ body: JSON.stringify({
83
+ name,
84
+ provider,
85
+ hostname,
86
+ target_host: targetHost,
87
+ target_port: targetPort,
88
+ ...(region ? { region } : {})
89
+ })
90
+ });
91
+
92
+ const tunnel = result.data || result;
93
+ console.log(`\x1b[32m✔ Ingress Tunnel created successfully!\x1b[0m`);
94
+ console.log(` ID: \x1b[36m${tunnel.id}\x1b[0m`);
95
+ console.log(` Name: \x1b[32m${tunnel.name}\x1b[0m`);
96
+ console.log(` Public Hostname: \x1b[36m${tunnel.hostname}\x1b[0m`);
97
+ console.log(` Target Origin: \x1b[32m${tunnel.target_host}:${tunnel.target_port}\x1b[0m`);
98
+ console.log(` Status: \x1b[32m${tunnel.status}\x1b[0m\n`);
99
+ } catch (err) {
100
+ console.error(`\x1b[31m✖ Failed to create tunnel:\x1b[0m`, err.message);
101
+ }
102
+ }
103
+
104
+ async function deleteTunnel(nameOrId, options = {}) {
105
+ const config = getStoredConfig();
106
+ const tunnelUrl = resolveServiceUrl('tunnel', options.tunnelUrl);
107
+ const region = options.region || config.region || null;
108
+
109
+ console.log(`\x1b[33m⚡ Deleting Ingress Tunnel [${nameOrId}]...\x1b[0m`);
110
+
111
+ try {
112
+ const queryParams = new URLSearchParams();
113
+ if (region) queryParams.set('region', region);
114
+ const queryStr = queryParams.toString() ? `?${queryParams.toString()}` : '';
115
+
116
+ const result = await request(`${tunnelUrl}/api/tunnels/${encodeURIComponent(nameOrId)}${queryStr}`, {
117
+ method: 'DELETE'
118
+ });
119
+ console.log(`\x1b[32m✔ ${result.message || `Tunnel ${nameOrId} deleted successfully`}\x1b[0m`);
120
+ } catch (err) {
121
+ console.error(`\x1b[31m✖ Failed to delete tunnel:\x1b[0m`, err.message);
122
+ }
123
+ }
124
+
125
+ module.exports = {
126
+ listTunnels,
127
+ createTunnel,
128
+ deleteTunnel
129
+ };
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,44 @@
1
1
  {
2
- "name": "@ostro-cloud/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@ostro-cloud/cli",
3
+ "version": "1.0.0-alpha.11",
4
+ "description": "Enterprise Command Line Interface (CLI) for Ostro Cloud Serverless, S3 Buckets, Kubernetes, and CloudFormation Orchestration",
5
+ "main": "lib/index.js",
6
+ "bin": {
7
+ "ocs": "bin/ostro.js",
8
+ "ostro-cloud": "bin/ostro.js",
9
+ "ostro-cfn": "bin/ostro.js"
10
+ },
11
+ "keywords": [
12
+ "ostro",
13
+ "cloud",
14
+ "serverless",
15
+ "aws",
16
+ "lambda",
17
+ "s3",
18
+ "cloudformation",
19
+ "kubernetes",
20
+ "cicd",
21
+ "gitlab-ci",
22
+ "cli"
23
+ ],
24
+ "author": "Ostro Cloud Systems",
25
+ "license": "MIT",
26
+ "dependencies": {
27
+ "@ostro-cloud/cli": "^0.0.0-stage",
28
+ "commander": "^12.1.0"
29
+ },
30
+ "engines": {
31
+ "node": ">=22.0.0"
32
+ },
33
+ "scripts": {
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'",
42
+ "test": "HEADLESS=true jest --runInBand"
43
+ }
44
+ }