@pi-r/azure 0.3.0 → 0.3.3
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 2023
|
|
1
|
+
Copyright 2023 Lisa Mishima
|
|
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
|
@@ -14,11 +14,11 @@ function validateStorage(credential) {
|
|
|
14
14
|
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)) {
|
|
15
15
|
return true;
|
|
16
16
|
}
|
|
17
|
-
return Module.enabled("process.env.apply"
|
|
17
|
+
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));
|
|
18
18
|
}
|
|
19
19
|
exports.validateStorage = validateStorage;
|
|
20
20
|
function validateDatabase(credential, data) {
|
|
21
|
-
return !!(data.name && data.table && (credential.endpoint && credential.key || Module.enabled("process.env.apply"
|
|
21
|
+
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)));
|
|
22
22
|
}
|
|
23
23
|
exports.validateDatabase = validateDatabase;
|
|
24
24
|
function createStorageClient(credential) {
|
|
@@ -60,7 +60,7 @@ async function createBucketV2(credential, bucket, access, options, service = 'az
|
|
|
60
60
|
break;
|
|
61
61
|
}
|
|
62
62
|
const containerClient = createStorageClient.call(this, credential).getContainerClient(bucket);
|
|
63
|
-
const setAccessPolicy = () => containerClient.setAccessPolicy(access).catch(err => this.formatMessage(64
|
|
63
|
+
const setAccessPolicy = () => containerClient.setAccessPolicy(access).catch(err => this.formatMessage(64, service, ["Unable to configure container", bucket], err, { ...Cloud.LOG_CLOUD_WARN }));
|
|
64
64
|
if (await containerClient.exists().catch(() => false)) {
|
|
65
65
|
if (access) {
|
|
66
66
|
await setAccessPolicy();
|
|
@@ -76,10 +76,10 @@ async function createBucketV2(credential, bucket, access, options, service = 'az
|
|
|
76
76
|
.then(response => {
|
|
77
77
|
const { requestId, errorCode } = response;
|
|
78
78
|
if (errorCode) {
|
|
79
|
-
this.formatMessage(64
|
|
79
|
+
this.formatMessage(64, service, ['Container created with errors', bucket], (0, types_1.errorMessage)("Error code", errorCode), { ...Cloud.LOG_CLOUD_WARN });
|
|
80
80
|
}
|
|
81
81
|
else {
|
|
82
|
-
this.formatMessage(64
|
|
82
|
+
this.formatMessage(64, service, ['Container created', bucket], requestId, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
83
83
|
}
|
|
84
84
|
return true;
|
|
85
85
|
})
|
|
@@ -90,7 +90,7 @@ async function createBucketV2(credential, bucket, access, options, service = 'az
|
|
|
90
90
|
}
|
|
91
91
|
return true;
|
|
92
92
|
}
|
|
93
|
-
this.formatFail(64
|
|
93
|
+
this.formatFail(64, service, ["Unable to create container", bucket], err, { ...Cloud.LOG_CLOUD_FAIL });
|
|
94
94
|
return false;
|
|
95
95
|
});
|
|
96
96
|
}
|
|
@@ -109,11 +109,11 @@ function setBucketWebsite(credential, bucket, options, service = 'azure') {
|
|
|
109
109
|
}
|
|
110
110
|
return createStorageClient.call(this, credential).setProperties({ staticWebsite })
|
|
111
111
|
.then(() => {
|
|
112
|
-
this.formatMessage(64
|
|
112
|
+
this.formatMessage(64, service, ["Bucket configured", bucket], options, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
113
113
|
return true;
|
|
114
114
|
})
|
|
115
115
|
.catch(err => {
|
|
116
|
-
this.formatFail(64
|
|
116
|
+
this.formatFail(64, service, ["Unable to configure bucket", bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
117
117
|
return false;
|
|
118
118
|
});
|
|
119
119
|
}
|
|
@@ -135,13 +135,13 @@ async function deleteObjectsV2(credential, bucket, recursive = true, service = '
|
|
|
135
135
|
tasks.push(containerClient.deleteBlob(blob.name, { versionId: blob.versionId }).catch(() => { --fileCount; }));
|
|
136
136
|
}
|
|
137
137
|
fileCount = tasks.length;
|
|
138
|
-
return this.allSettled(tasks, ["Unable to delete blob"
|
|
138
|
+
return this.allSettled(tasks, ["Unable to delete blob", bucket], 64).then(() => {
|
|
139
139
|
const files = fileCount + ' files';
|
|
140
|
-
this.formatMessage(64
|
|
140
|
+
this.formatMessage(64, service, [`Container emptied (${recursive ? 'recursive' : files})`, bucket], recursive ? files : '', { ...Cloud.LOG_CLOUD_COMMAND });
|
|
141
141
|
});
|
|
142
142
|
}
|
|
143
143
|
catch (err) {
|
|
144
|
-
this.formatFail(64
|
|
144
|
+
this.formatFail(64, service, ["Unable to list bucket", bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
}
|
|
@@ -166,7 +166,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
166
166
|
const { service, name, table, id, query, storedProcedureId, partitionKey, params, limit = 0, update, ignoreCache } = item;
|
|
167
167
|
if (!name || !table) {
|
|
168
168
|
closeClient();
|
|
169
|
-
throw (0, util_1.formatError)(item, name ? "Missing database table"
|
|
169
|
+
throw (0, util_1.formatError)(item, name ? "Missing database table" : "Missing database name");
|
|
170
170
|
}
|
|
171
171
|
const renewCache = ignoreCache === 0;
|
|
172
172
|
const getCache = (value) => {
|
|
@@ -184,7 +184,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
184
184
|
continue;
|
|
185
185
|
}
|
|
186
186
|
const { statusCode, resource } = await createClient(name, table).scripts.storedProcedure(storedProcedureId).execute(partitionKey, params, options);
|
|
187
|
-
if (statusCode === 200
|
|
187
|
+
if (statusCode === 200) {
|
|
188
188
|
rows = Array.isArray(resource) ? resource : [resource];
|
|
189
189
|
}
|
|
190
190
|
}
|
|
@@ -199,7 +199,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
199
199
|
}
|
|
200
200
|
const db = createClient(name, table).item(id, partitionKey);
|
|
201
201
|
const { statusCode, resource } = update ? await db.patch(update, options) : await db.read(options);
|
|
202
|
-
if (statusCode === 200
|
|
202
|
+
if (statusCode === 200) {
|
|
203
203
|
rows = [resource];
|
|
204
204
|
}
|
|
205
205
|
}
|
|
@@ -216,7 +216,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
216
216
|
}
|
|
217
217
|
else {
|
|
218
218
|
closeClient();
|
|
219
|
-
throw (0, util_1.formatError)(item, "Missing database query"
|
|
219
|
+
throw (0, util_1.formatError)(item, "Missing database query");
|
|
220
220
|
}
|
|
221
221
|
result[i] = this.setQueryResult(service, credential, queryString, rows, cacheValue);
|
|
222
222
|
}
|
package/download/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
2
|
const types_1 = require("@e-mc/types");
|
|
4
3
|
const Module = require("@e-mc/module");
|
|
5
4
|
const Cloud = require("@e-mc/cloud");
|
|
6
|
-
const client_1 = require("
|
|
5
|
+
const client_1 = require("@pi-r/azure");
|
|
7
6
|
function download(credential, service = 'azure') {
|
|
8
7
|
const blobServiceClient = client_1.createStorageClient.call(this, credential);
|
|
9
8
|
return (data, callback) => {
|
|
@@ -21,10 +20,10 @@ function download(credential, service = 'azure') {
|
|
|
21
20
|
const deleteObject = target.deleteObject;
|
|
22
21
|
if (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.3.
|
|
3
|
+
"version": "0.3.3",
|
|
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.6.
|
|
24
|
-
"@e-mc/module": "^0.6.
|
|
25
|
-
"@e-mc/types": "^0.6.
|
|
23
|
+
"@e-mc/cloud": "^0.6.2",
|
|
24
|
+
"@e-mc/module": "^0.6.2",
|
|
25
|
+
"@e-mc/types": "^0.6.2",
|
|
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,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
2
|
const path = require("path");
|
|
4
3
|
const fs = require("fs");
|
|
5
4
|
const util_1 = require("@e-mc/cloud/util");
|
|
6
5
|
const types_1 = require("@e-mc/types");
|
|
7
6
|
const Module = require("@e-mc/module");
|
|
8
7
|
const Cloud = require("@e-mc/cloud");
|
|
9
|
-
const client_1 = require("
|
|
8
|
+
const client_1 = require("@pi-r/azure");
|
|
10
9
|
const BUCKET_SESSION = new Set();
|
|
11
10
|
const BUCKET_RESPONSE = {};
|
|
12
11
|
const getBucketKey = (credential, bucket, acl = '') => Module.asString(credential, true) + bucket + '_' + acl;
|
|
@@ -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);
|