@ostro-cloud/cli 1.0.0-alpha.7 → 1.0.0-alpha.9
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/lib/client.js +17 -3
- package/lib/commands/formation.js +6 -4
- package/package.json +1 -2
package/lib/client.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const os = require('os');
|
|
4
|
+
const crypto = require('crypto');
|
|
4
5
|
|
|
5
6
|
const CONFIG_FILE = path.join(os.homedir(), '.ostro', 'config.json');
|
|
6
7
|
|
|
@@ -148,14 +149,15 @@ function saveConfig(newConfig) {
|
|
|
148
149
|
async function request(url, options = {}) {
|
|
149
150
|
const config = getStoredConfig();
|
|
150
151
|
const authToken = config.sessionToken || config.token;
|
|
151
|
-
|
|
152
|
-
|
|
152
|
+
const hasAccessKeys = Boolean(config.accessKeyId && config.secretAccessKey);
|
|
153
|
+
if (!authToken && !hasAccessKeys && !options.skipAuth) {
|
|
154
|
+
throw new Error('Authentication required. Run "ostro-cloud login" or set OSTRO_ACCESS_KEY_ID / OSTRO_SECRET_ACCESS_KEY / OSTRO_SESSION_TOKEN.');
|
|
153
155
|
}
|
|
154
156
|
|
|
155
157
|
const headers = {
|
|
156
158
|
'Accept': 'application/json',
|
|
157
159
|
'Content-Type': 'application/json',
|
|
158
|
-
...(authToken ? { 'Authorization': `Bearer ${authToken}` } :
|
|
160
|
+
...(authToken ? { 'Authorization': `Bearer ${authToken}` } : buildHmacHeaders(options.method || 'GET', new URL(url).pathname, config)),
|
|
159
161
|
...(config.sessionToken ? { 'X-Ostro-Session-Token': config.sessionToken } : {}),
|
|
160
162
|
...(config.roleArn ? { 'X-Ostro-Role-Arn': config.roleArn } : {}),
|
|
161
163
|
...(config.clientId ? { 'X-Ostro-Client-Id': config.clientId } : {}),
|
|
@@ -175,11 +177,23 @@ async function request(url, options = {}) {
|
|
|
175
177
|
return text;
|
|
176
178
|
}
|
|
177
179
|
|
|
180
|
+
function buildHmacHeaders(method, pathname, config) {
|
|
181
|
+
if (!config?.accessKeyId || !config?.secretAccessKey) return {};
|
|
182
|
+
const xOstroDate = new Date().toISOString();
|
|
183
|
+
const canonical = `${String(method).toUpperCase()}\n${String(pathname)}\n${xOstroDate}`;
|
|
184
|
+
const signature = crypto.createHmac('sha256', config.secretAccessKey).update(canonical).digest('hex');
|
|
185
|
+
return {
|
|
186
|
+
'X-Ostro-Date': xOstroDate,
|
|
187
|
+
'Authorization': `OSTRO4-HMAC-SHA256 Credential=${config.accessKeyId}, Signature=${signature}`,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
178
191
|
module.exports = {
|
|
179
192
|
getStoredConfig,
|
|
180
193
|
resolveServiceUrl,
|
|
181
194
|
saveConfig,
|
|
182
195
|
request,
|
|
196
|
+
buildHmacHeaders,
|
|
183
197
|
defaultServiceUrl,
|
|
184
198
|
DEFAULT_CLOUD_DOMAIN,
|
|
185
199
|
DEFAULT_REGION,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { getStoredConfig, resolveServiceUrl, request } = require('../client');
|
|
1
|
+
const { getStoredConfig, resolveServiceUrl, request, buildHmacHeaders } = require('../client');
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const os = require('os');
|
|
@@ -40,7 +40,10 @@ async function buildImageViaApi(formationUrl, stackName, sourceDir) {
|
|
|
40
40
|
|
|
41
41
|
const config = getStoredConfig();
|
|
42
42
|
const authToken = config.sessionToken || config.token;
|
|
43
|
-
|
|
43
|
+
const hasAccessKeys = Boolean(config.accessKeyId && config.secretAccessKey);
|
|
44
|
+
if (!authToken && !hasAccessKeys) {
|
|
45
|
+
throw new Error('Authentication required. Run "ostro-cloud login" or set OSTRO_ACCESS_KEY_ID / OSTRO_SECRET_ACCESS_KEY / OSTRO_SESSION_TOKEN.');
|
|
46
|
+
}
|
|
44
47
|
|
|
45
48
|
// Use Node's http/https directly — global fetch (undici) rejects Node Buffers as binary body
|
|
46
49
|
const statusCode = await new Promise((resolve, reject) => {
|
|
@@ -52,8 +55,7 @@ async function buildImageViaApi(formationUrl, stackName, sourceDir) {
|
|
|
52
55
|
path: url.pathname + url.search,
|
|
53
56
|
method: 'POST',
|
|
54
57
|
headers: {
|
|
55
|
-
'Authorization': `Bearer ${authToken}`,
|
|
56
|
-
'X-Ostro-Session-Token': authToken,
|
|
58
|
+
...(authToken ? { 'Authorization': `Bearer ${authToken}`, 'X-Ostro-Session-Token': authToken } : buildHmacHeaders('POST', url.pathname, config)),
|
|
57
59
|
'Content-Type': 'application/octet-stream',
|
|
58
60
|
'Accept': 'application/json',
|
|
59
61
|
'X-Stack-Name': stackName,
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ostro-cloud/cli",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.9",
|
|
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": {
|
|
7
|
-
"ostro": "bin/ostro.js",
|
|
8
7
|
"ocs": "bin/ostro.js",
|
|
9
8
|
"ostro-cloud": "bin/ostro.js",
|
|
10
9
|
"ostro-cfn": "bin/ostro.js"
|