@pi-r/azure 0.2.3 → 0.2.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/LICENSE +1 -1
- package/README.md +4 -2
- package/client/index.js +15 -15
- package/download/index.js +3 -4
- package/package.json +7 -7
- package/upload/index.js +3 -4
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2020-24 Code Geass
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
package/README.md
CHANGED
package/client/index.js
CHANGED
|
@@ -11,11 +11,11 @@ function validateStorage(credential) {
|
|
|
11
11
|
if (credential.accountName && credential.accountKey || credential.connectionString || credential.sharedAccessSignature || env.AZURE_TENANT_ID && env.AZURE_CLIENT_ID && env.AZURE_CLIENT_SECRET && (credential.accountName || env.AZURE_STORAGE_ACCOUNT)) {
|
|
12
12
|
return true;
|
|
13
13
|
}
|
|
14
|
-
return Module.enabled("process.env.apply"
|
|
14
|
+
return Module.enabled("process.env.apply") && !!((credential.connectionString = env.AZURE_STORAGE_CONNECTION_STRING) || (credential.sharedAccessSignature = env.AZURE_STORAGE_SAS_TOKEN) || (credential.accountName = env.AZURE_STORAGE_ACCOUNT) && (credential.accountKey = env.AZURE_STORAGE_KEY));
|
|
15
15
|
}
|
|
16
16
|
exports.validateStorage = validateStorage;
|
|
17
17
|
function validateDatabase(credential, data) {
|
|
18
|
-
return !!(data.name && data.table && (credential.endpoint && credential.key || Module.enabled("process.env.apply"
|
|
18
|
+
return !!(data.name && data.table && (credential.endpoint && credential.key || Module.enabled("process.env.apply") && (credential.endpoint = process.env.AZURE_COSMOS_ENDPOINT) && (credential.key = process.env.AZURE_COSMOS_KEY)));
|
|
19
19
|
}
|
|
20
20
|
exports.validateDatabase = validateDatabase;
|
|
21
21
|
function createStorageClient(credential) {
|
|
@@ -72,7 +72,7 @@ async function createBucketV2(credential, bucket, access, options, service = 'az
|
|
|
72
72
|
break;
|
|
73
73
|
}
|
|
74
74
|
const containerClient = createStorageClient.call(this, credential).getContainerClient(bucket);
|
|
75
|
-
const setAccessPolicy = () => containerClient.setAccessPolicy(access).catch(err => this.formatMessage(64
|
|
75
|
+
const setAccessPolicy = () => containerClient.setAccessPolicy(access).catch(err => this.formatMessage(64, service, ["Unable to configure container", bucket], err, { ...Cloud.LOG_CLOUD_WARN }));
|
|
76
76
|
if (await containerClient.exists().catch(() => false)) {
|
|
77
77
|
if (access) {
|
|
78
78
|
await setAccessPolicy();
|
|
@@ -87,10 +87,10 @@ async function createBucketV2(credential, bucket, access, options, service = 'az
|
|
|
87
87
|
return containerClient.create(options)
|
|
88
88
|
.then(response => {
|
|
89
89
|
if (response.errorCode) {
|
|
90
|
-
this.formatMessage(64
|
|
90
|
+
this.formatMessage(64, service, ['Container created with errors', bucket], (0, types_1.errorMessage)("Error code", response.errorCode), { ...Cloud.LOG_CLOUD_WARN });
|
|
91
91
|
}
|
|
92
92
|
else {
|
|
93
|
-
this.formatMessage(64
|
|
93
|
+
this.formatMessage(64, service, ['Container created', bucket], response.requestId, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
94
94
|
}
|
|
95
95
|
return true;
|
|
96
96
|
})
|
|
@@ -101,7 +101,7 @@ async function createBucketV2(credential, bucket, access, options, service = 'az
|
|
|
101
101
|
}
|
|
102
102
|
return true;
|
|
103
103
|
}
|
|
104
|
-
this.formatFail(64
|
|
104
|
+
this.formatFail(64, service, ["Unable to create container", bucket], err, { ...Cloud.LOG_CLOUD_FAIL });
|
|
105
105
|
return false;
|
|
106
106
|
});
|
|
107
107
|
}
|
|
@@ -119,11 +119,11 @@ function setBucketWebsite(credential, bucket, options, service = 'azure') {
|
|
|
119
119
|
}
|
|
120
120
|
return createStorageClient.call(this, credential).setProperties({ staticWebsite })
|
|
121
121
|
.then(() => {
|
|
122
|
-
this.formatMessage(64
|
|
122
|
+
this.formatMessage(64, service, ["Bucket configured", bucket], options, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
123
123
|
return true;
|
|
124
124
|
})
|
|
125
125
|
.catch(err => {
|
|
126
|
-
this.formatFail(64
|
|
126
|
+
this.formatFail(64, service, ["Unable to configure bucket", bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
127
127
|
return false;
|
|
128
128
|
});
|
|
129
129
|
}
|
|
@@ -145,13 +145,13 @@ async function deleteObjectsV2(credential, bucket, recursive = true, service = '
|
|
|
145
145
|
tasks.push(containerClient.deleteBlob(blob.name, { versionId: blob.versionId }).catch(() => { --fileCount; }));
|
|
146
146
|
}
|
|
147
147
|
fileCount = tasks.length;
|
|
148
|
-
return this.allSettled(tasks, ["Unable to delete blob"
|
|
148
|
+
return this.allSettled(tasks, ["Unable to delete blob", bucket], 64).then(() => {
|
|
149
149
|
const files = fileCount + ' files';
|
|
150
|
-
this.formatMessage(64
|
|
150
|
+
this.formatMessage(64, service, [`Container emptied (${recursive ? 'recursive' : files})`, bucket], recursive ? files : '', { ...Cloud.LOG_CLOUD_COMMAND });
|
|
151
151
|
});
|
|
152
152
|
}
|
|
153
153
|
catch (err) {
|
|
154
|
-
this.formatFail(64
|
|
154
|
+
this.formatFail(64, service, ["Unable to list bucket", bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
}
|
|
@@ -176,7 +176,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
176
176
|
const { service, name, table, id, query, storedProcedureId, partitionKey, params, limit = 0, update, ignoreCache } = item;
|
|
177
177
|
if (!name || !table) {
|
|
178
178
|
closeClient();
|
|
179
|
-
throw (0, util_1.formatError)(item, name ? "Missing database table"
|
|
179
|
+
throw (0, util_1.formatError)(item, name ? "Missing database table" : "Missing database name");
|
|
180
180
|
}
|
|
181
181
|
const renewCache = ignoreCache === 0;
|
|
182
182
|
const getCache = (value) => {
|
|
@@ -194,7 +194,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
194
194
|
continue;
|
|
195
195
|
}
|
|
196
196
|
const { statusCode, resource } = await createClient(name, table).scripts.storedProcedure(storedProcedureId).execute(partitionKey, params, options);
|
|
197
|
-
if (statusCode === 200
|
|
197
|
+
if (statusCode === 200) {
|
|
198
198
|
rows = Array.isArray(resource) ? resource : [resource];
|
|
199
199
|
}
|
|
200
200
|
}
|
|
@@ -209,7 +209,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
209
209
|
}
|
|
210
210
|
const db = createClient(name, table).item(id, partitionKey);
|
|
211
211
|
const { statusCode, resource } = update ? await db.patch(update, options) : await db.read(options);
|
|
212
|
-
if (statusCode === 200
|
|
212
|
+
if (statusCode === 200) {
|
|
213
213
|
rows = [resource];
|
|
214
214
|
}
|
|
215
215
|
}
|
|
@@ -226,7 +226,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
226
226
|
}
|
|
227
227
|
else {
|
|
228
228
|
closeClient();
|
|
229
|
-
throw (0, util_1.formatError)(item, "Missing database query"
|
|
229
|
+
throw (0, util_1.formatError)(item, "Missing database query");
|
|
230
230
|
}
|
|
231
231
|
result[i] = this.setQueryResult(service, credential, queryString, rows, cacheValue);
|
|
232
232
|
}
|
package/download/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
const client_1 = require("../client");
|
|
2
|
+
const client_1 = require("@pi-r/azure");
|
|
4
3
|
const types_1 = require("@e-mc/types");
|
|
5
4
|
const Module = require("@e-mc/module");
|
|
6
5
|
const Cloud = require("@e-mc/cloud");
|
|
@@ -21,10 +20,10 @@ function download(credential, service = 'azure') {
|
|
|
21
20
|
const deleteObject = target.deleteObject;
|
|
22
21
|
if (target.deleteObject) {
|
|
23
22
|
blobClient.delete((0, types_1.isPlainObject)(deleteObject) && (deleteObject.abortSignal = this.signal) ? deleteObject : undefined)
|
|
24
|
-
.then(() => this.formatMessage(64
|
|
23
|
+
.then(() => this.formatMessage(64, service, "Delete success", location, { ...Cloud.LOG_CLOUD_DELETE }))
|
|
25
24
|
.catch((err) => {
|
|
26
25
|
if (!(err instanceof Error && err.code === 'BlobNotFound')) {
|
|
27
|
-
this.formatFail(64
|
|
26
|
+
this.formatFail(64, service, ["Delete failed", location], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: !!target.active });
|
|
28
27
|
}
|
|
29
28
|
});
|
|
30
29
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/azure",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
4
4
|
"description": "Azure cloud functions for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/anpham6/pi-r.git",
|
|
11
|
+
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
12
12
|
"directory": "src/cloud/azure"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/cloud": "^0.5.
|
|
24
|
-
"@e-mc/module": "^0.5.
|
|
25
|
-
"@e-mc/types": "^0.5.
|
|
23
|
+
"@e-mc/cloud": "^0.5.5",
|
|
24
|
+
"@e-mc/module": "^0.5.5",
|
|
25
|
+
"@e-mc/types": "^0.5.5",
|
|
26
26
|
"@azure/cosmos": "^3.17.3",
|
|
27
|
-
"@azure/identity": "^3.2
|
|
28
|
-
"@azure/storage-blob": "^12.
|
|
27
|
+
"@azure/identity": "^3.4.2",
|
|
28
|
+
"@azure/storage-blob": "^12.17.0"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/upload/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
2
|
const path = require("path");
|
|
4
3
|
const fs = require("fs");
|
|
5
|
-
const client_1 = require("
|
|
4
|
+
const client_1 = require("@pi-r/azure");
|
|
6
5
|
const util_1 = require("@e-mc/cloud/util");
|
|
7
6
|
const types_1 = require("@e-mc/types");
|
|
8
7
|
const Module = require("@e-mc/module");
|
|
@@ -58,7 +57,7 @@ function upload(credential, service = 'azure') {
|
|
|
58
57
|
}
|
|
59
58
|
} while (exists && ++i);
|
|
60
59
|
if (i > 0) {
|
|
61
|
-
this.formatMessage(64
|
|
60
|
+
this.formatMessage(64, service, ["File renamed", current], filename, { ...Cloud.LOG_CLOUD_WARN });
|
|
62
61
|
}
|
|
63
62
|
}
|
|
64
63
|
catch (err) {
|
|
@@ -99,7 +98,7 @@ function upload(credential, service = 'azure') {
|
|
|
99
98
|
.then(result => {
|
|
100
99
|
let requestUrl = result._response.request.url;
|
|
101
100
|
const url = endpoint ? Module.joinPath(endpoint, blobName) : Module.isFile(requestUrl = decodeURIComponent(requestUrl), 'http/s') ? requestUrl : Module.joinPath(`https://${credential.accountName}.blob.core.windows.net`, bucket, blobName);
|
|
102
|
-
this.formatMessage(64
|
|
101
|
+
this.formatMessage(64, service, "Upload success", url, { ...Cloud.LOG_CLOUD_UPLOAD });
|
|
103
102
|
if (first) {
|
|
104
103
|
cleanup();
|
|
105
104
|
callback(null, url);
|