@ostro-cloud/cli 1.0.0-alpha.8 → 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 +14 -3
- package/lib/commands/formation.js +2 -4
- package/package.json +1 -1
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
|
|
|
@@ -156,10 +157,8 @@ async function request(url, options = {}) {
|
|
|
156
157
|
const headers = {
|
|
157
158
|
'Accept': 'application/json',
|
|
158
159
|
'Content-Type': 'application/json',
|
|
159
|
-
...(authToken ? { 'Authorization': `Bearer ${authToken}` } :
|
|
160
|
+
...(authToken ? { 'Authorization': `Bearer ${authToken}` } : buildHmacHeaders(options.method || 'GET', new URL(url).pathname, config)),
|
|
160
161
|
...(config.sessionToken ? { 'X-Ostro-Session-Token': config.sessionToken } : {}),
|
|
161
|
-
...(config.accessKeyId ? { 'X-Ostro-Access-Key-Id': config.accessKeyId } : {}),
|
|
162
|
-
...(config.secretAccessKey ? { 'X-Ostro-Secret-Access-Key': config.secretAccessKey } : {}),
|
|
163
162
|
...(config.roleArn ? { 'X-Ostro-Role-Arn': config.roleArn } : {}),
|
|
164
163
|
...(config.clientId ? { 'X-Ostro-Client-Id': config.clientId } : {}),
|
|
165
164
|
...(options.headers || {})
|
|
@@ -178,11 +177,23 @@ async function request(url, options = {}) {
|
|
|
178
177
|
return text;
|
|
179
178
|
}
|
|
180
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
|
+
|
|
181
191
|
module.exports = {
|
|
182
192
|
getStoredConfig,
|
|
183
193
|
resolveServiceUrl,
|
|
184
194
|
saveConfig,
|
|
185
195
|
request,
|
|
196
|
+
buildHmacHeaders,
|
|
186
197
|
defaultServiceUrl,
|
|
187
198
|
DEFAULT_CLOUD_DOMAIN,
|
|
188
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');
|
|
@@ -55,9 +55,7 @@ async function buildImageViaApi(formationUrl, stackName, sourceDir) {
|
|
|
55
55
|
path: url.pathname + url.search,
|
|
56
56
|
method: 'POST',
|
|
57
57
|
headers: {
|
|
58
|
-
...(authToken ? { 'Authorization': `Bearer ${authToken}`, 'X-Ostro-Session-Token': authToken } :
|
|
59
|
-
...(config.accessKeyId ? { 'X-Ostro-Access-Key-Id': config.accessKeyId } : {}),
|
|
60
|
-
...(config.secretAccessKey ? { 'X-Ostro-Secret-Access-Key': config.secretAccessKey } : {}),
|
|
58
|
+
...(authToken ? { 'Authorization': `Bearer ${authToken}`, 'X-Ostro-Session-Token': authToken } : buildHmacHeaders('POST', url.pathname, config)),
|
|
61
59
|
'Content-Type': 'application/octet-stream',
|
|
62
60
|
'Accept': 'application/json',
|
|
63
61
|
'X-Stack-Name': stackName,
|
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.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": {
|