@adobe/helix-admin-support 2.9.2 → 2.9.4
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/CHANGELOG.md +14 -0
- package/package.json +7 -7
- package/src/auditlog/AuditLog.js +14 -4
- package/src/auditlog/Reader.js +15 -11
- package/src/auditlog/Writer.js +16 -7
- package/src/auditlog/utils.js +14 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [2.9.4](https://github.com/adobe/helix-admin-support/compare/v2.9.3...v2.9.4) (2024-09-07)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **deps:** update external fixes ([3555009](https://github.com/adobe/helix-admin-support/commit/3555009254fef76cbffc330384b1a3b9da2f61ab))
|
|
7
|
+
|
|
8
|
+
## [2.9.3](https://github.com/adobe/helix-admin-support/compare/v2.9.2...v2.9.3) (2024-08-29)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* add bucketName option for auditlog reader/writer ([#303](https://github.com/adobe/helix-admin-support/issues/303)) ([cac5f6f](https://github.com/adobe/helix-admin-support/commit/cac5f6ff406e8fcfc77c37cdcf1ad6f4fa93ba31))
|
|
14
|
+
|
|
1
15
|
## [2.9.2](https://github.com/adobe/helix-admin-support/compare/v2.9.1...v2.9.2) (2024-08-24)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/helix-admin-support",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.4",
|
|
4
4
|
"description": "Helix Admin Support Library",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"@adobe/fetch": "4.1.8",
|
|
40
40
|
"@adobe/helix-shared-config": "10.6.7",
|
|
41
41
|
"@adobe/helix-shared-utils": "3.0.2",
|
|
42
|
-
"@aws-sdk/client-s3": "3.
|
|
43
|
-
"@aws-sdk/client-sqs": "3.
|
|
42
|
+
"@aws-sdk/client-s3": "3.645.0",
|
|
43
|
+
"@aws-sdk/client-sqs": "3.645.0",
|
|
44
44
|
"@smithy/node-http-handler": "3.1.4"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
@@ -52,17 +52,17 @@
|
|
|
52
52
|
"c8": "10.1.2",
|
|
53
53
|
"eslint": "8.57.0",
|
|
54
54
|
"husky": "9.1.5",
|
|
55
|
-
"jsdoc-to-markdown": "
|
|
56
|
-
"json-schema-to-typescript": "15.0.
|
|
55
|
+
"jsdoc-to-markdown": "9.0.0",
|
|
56
|
+
"json-schema-to-typescript": "15.0.2",
|
|
57
57
|
"junit-report-builder": "5.0.0",
|
|
58
|
-
"lint-staged": "15.2.
|
|
58
|
+
"lint-staged": "15.2.10",
|
|
59
59
|
"mocha": "10.7.3",
|
|
60
60
|
"mocha-multi-reporters": "1.5.1",
|
|
61
61
|
"mocha-suppress-logs": "0.5.1",
|
|
62
62
|
"nock": "13.5.5",
|
|
63
63
|
"semantic-release": "24.1.0",
|
|
64
64
|
"xml2js": "0.6.2",
|
|
65
|
-
"yaml": "2.5.
|
|
65
|
+
"yaml": "2.5.1"
|
|
66
66
|
},
|
|
67
67
|
"lint-staged": {
|
|
68
68
|
"*.js": "eslint",
|
package/src/auditlog/AuditLog.js
CHANGED
|
@@ -9,19 +9,28 @@
|
|
|
9
9
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
+
|
|
12
13
|
import AuditLogReader from './Reader.js';
|
|
14
|
+
import { resolveOptions } from './utils.js';
|
|
13
15
|
import AuditLogWriter from './Writer.js';
|
|
14
16
|
|
|
17
|
+
/**
|
|
18
|
+
* @typedef {{
|
|
19
|
+
* bucketName?: string;
|
|
20
|
+
* }} Options
|
|
21
|
+
*/
|
|
22
|
+
|
|
15
23
|
/**
|
|
16
24
|
* Create an audit log reader of an org and site.
|
|
17
25
|
*
|
|
18
26
|
* @param {String} org org
|
|
19
27
|
* @param {String|undefined} site site, optional
|
|
20
28
|
* @param {Logger} log logger
|
|
29
|
+
* @param {Options} [opts] options
|
|
21
30
|
* @returns {AuditLogReader} reader
|
|
22
31
|
*/
|
|
23
|
-
function createReader(org, site, log) {
|
|
24
|
-
return new AuditLogReader(org, site, log);
|
|
32
|
+
function createReader(org, site, log, opts) {
|
|
33
|
+
return new AuditLogReader(org, site, log, resolveOptions(opts));
|
|
25
34
|
}
|
|
26
35
|
|
|
27
36
|
/**
|
|
@@ -30,10 +39,11 @@ function createReader(org, site, log) {
|
|
|
30
39
|
* @param {String} org org
|
|
31
40
|
* @param {String|undefined} site site, optional
|
|
32
41
|
* @param {Logger} log logger
|
|
42
|
+
* @param {Options} [opts] options
|
|
33
43
|
* @returns {AuditLogWriter} writer
|
|
34
44
|
*/
|
|
35
|
-
function createWriter(org, site, log) {
|
|
36
|
-
return new AuditLogWriter(org, site, log);
|
|
45
|
+
function createWriter(org, site, log, opts) {
|
|
46
|
+
return new AuditLogWriter(org, site, log, resolveOptions(opts));
|
|
37
47
|
}
|
|
38
48
|
|
|
39
49
|
export const AuditLog = {
|
package/src/auditlog/Reader.js
CHANGED
|
@@ -9,11 +9,12 @@
|
|
|
9
9
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
+
|
|
12
13
|
import { promisify } from 'util';
|
|
13
14
|
import zlib from 'zlib';
|
|
14
15
|
import { GetObjectCommand, S3Client } from '@aws-sdk/client-s3';
|
|
15
16
|
import { Response } from '@adobe/fetch';
|
|
16
|
-
import {
|
|
17
|
+
import { INDEX_FILE } from './utils.js';
|
|
17
18
|
import DateFormat from './DateFormat.js';
|
|
18
19
|
|
|
19
20
|
const gunzip = promisify(zlib.gunzip);
|
|
@@ -35,15 +36,18 @@ const gunzip = promisify(zlib.gunzip);
|
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
38
|
* Audit log reader implemented in S3.
|
|
38
|
-
*
|
|
39
|
-
* @param {String} org org
|
|
40
|
-
* @param {String|undefined} site site, optional
|
|
41
|
-
* @param {import('@adobe/helix-universal').Logger} log logger
|
|
42
39
|
*/
|
|
43
40
|
export default class Reader {
|
|
44
|
-
|
|
41
|
+
/**
|
|
42
|
+
* @param {String} org org
|
|
43
|
+
* @param {String|undefined} site site, optional
|
|
44
|
+
* @param {import('@adobe/helix-universal').Logger} log logger
|
|
45
|
+
* @param {Required<import('./AuditLog.js').Options>} opts options
|
|
46
|
+
*/
|
|
47
|
+
constructor(org, site, log, opts) {
|
|
45
48
|
this.prefix = site ? `${org}/${site}` : `${org}/.all`;
|
|
46
49
|
this.log = log;
|
|
50
|
+
this.bucketName = opts.bucketName;
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
/**
|
|
@@ -56,7 +60,7 @@ export default class Reader {
|
|
|
56
60
|
|
|
57
61
|
try {
|
|
58
62
|
const res = await this.s3.send(new GetObjectCommand({
|
|
59
|
-
Bucket:
|
|
63
|
+
Bucket: this.bucketName,
|
|
60
64
|
Key: `${prefix}/${INDEX_FILE}`,
|
|
61
65
|
}));
|
|
62
66
|
const logContents = await new Response(res.Body, {}).text();
|
|
@@ -79,7 +83,7 @@ export default class Reader {
|
|
|
79
83
|
*
|
|
80
84
|
* @param {number} fileIndex file index
|
|
81
85
|
*
|
|
82
|
-
* @returns array of entries
|
|
86
|
+
* @returns {Promise<LogEntry[]>} array of entries
|
|
83
87
|
*/
|
|
84
88
|
async #getLogContents(fileIndex) {
|
|
85
89
|
const {
|
|
@@ -89,7 +93,7 @@ export default class Reader {
|
|
|
89
93
|
const key = `${prefix}/${logFiles[fileIndex].name}.gz`;
|
|
90
94
|
try {
|
|
91
95
|
const res = await s3.send(new GetObjectCommand({
|
|
92
|
-
Bucket:
|
|
96
|
+
Bucket: this.bucketName,
|
|
93
97
|
Key: key,
|
|
94
98
|
}));
|
|
95
99
|
const buf = await new Response(res.Body, {}).buffer();
|
|
@@ -105,7 +109,7 @@ export default class Reader {
|
|
|
105
109
|
*
|
|
106
110
|
* @param {number} after timestamp
|
|
107
111
|
*
|
|
108
|
-
* @returns {LogEntries>} entries, fileIndex and entryIndex
|
|
112
|
+
* @returns {Promise<LogEntries>} entries, fileIndex and entryIndex
|
|
109
113
|
*/
|
|
110
114
|
async #findEntries(after) {
|
|
111
115
|
const { logFiles } = this;
|
|
@@ -146,7 +150,7 @@ export default class Reader {
|
|
|
146
150
|
* Locate entries given a previously saved location
|
|
147
151
|
*
|
|
148
152
|
* @param {LogLocation} location location
|
|
149
|
-
* @returns {LogEntries>} entries, fileIndex and entryIndex
|
|
153
|
+
* @returns {Promise<LogEntries>} entries, fileIndex and entryIndex
|
|
150
154
|
*/
|
|
151
155
|
async #locateEntries(location) {
|
|
152
156
|
const { log, logFiles } = this;
|
package/src/auditlog/Writer.js
CHANGED
|
@@ -15,7 +15,7 @@ import { promisify } from 'util';
|
|
|
15
15
|
import zlib from 'zlib';
|
|
16
16
|
import { GetObjectCommand, PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
|
|
17
17
|
import { Response } from '@adobe/fetch';
|
|
18
|
-
import {
|
|
18
|
+
import { INDEX_FILE } from './utils.js';
|
|
19
19
|
import DateFormat from './DateFormat.js';
|
|
20
20
|
|
|
21
21
|
const gzip = promisify(zlib.gzip);
|
|
@@ -45,9 +45,16 @@ function generateID() {
|
|
|
45
45
|
* Audit log implemented in S3
|
|
46
46
|
*/
|
|
47
47
|
export default class Writer {
|
|
48
|
-
|
|
48
|
+
/**
|
|
49
|
+
* @param {string} org
|
|
50
|
+
* @param {string|undefined} site
|
|
51
|
+
* @param {Logger} log
|
|
52
|
+
* @param {Required<import('./AuditLog.js').Options>} opts
|
|
53
|
+
*/
|
|
54
|
+
constructor(org, site, log, opts) {
|
|
49
55
|
this.prefix = site ? `${org}/${site}` : `${org}/.all`;
|
|
50
56
|
this.log = log;
|
|
57
|
+
this.bucketName = opts.bucketName;
|
|
51
58
|
}
|
|
52
59
|
|
|
53
60
|
/**
|
|
@@ -61,7 +68,7 @@ export default class Writer {
|
|
|
61
68
|
/**
|
|
62
69
|
* Fetch index file
|
|
63
70
|
*
|
|
64
|
-
* @returns {String[]} log entry file names array
|
|
71
|
+
* @returns {Promise<String[]>} log entry file names array
|
|
65
72
|
*/
|
|
66
73
|
async #fetchIndex() {
|
|
67
74
|
const { prefix, s3 } = this;
|
|
@@ -69,7 +76,7 @@ export default class Writer {
|
|
|
69
76
|
// fetch name of last log object
|
|
70
77
|
try {
|
|
71
78
|
const res = await s3.send(new GetObjectCommand({
|
|
72
|
-
Bucket:
|
|
79
|
+
Bucket: this.bucketName,
|
|
73
80
|
Key: `${prefix}/${INDEX_FILE}`,
|
|
74
81
|
}));
|
|
75
82
|
const logContents = await new Response(res.Body, {}).text();
|
|
@@ -86,13 +93,15 @@ export default class Writer {
|
|
|
86
93
|
/**
|
|
87
94
|
* Fetch log file. Returns null if the log file is not found or too large to accomodate
|
|
88
95
|
* another record.
|
|
96
|
+
*
|
|
97
|
+
* @param {string} key
|
|
89
98
|
*/
|
|
90
99
|
async #fetchLogFile(key) {
|
|
91
100
|
const { s3 } = this;
|
|
92
101
|
|
|
93
102
|
try {
|
|
94
103
|
const res = await s3.send(new GetObjectCommand({
|
|
95
|
-
Bucket:
|
|
104
|
+
Bucket: this.bucketName,
|
|
96
105
|
Key: `${key}.gz`,
|
|
97
106
|
}));
|
|
98
107
|
if (res.ContentLength < MAX_OBJECT_SIZE) {
|
|
@@ -132,7 +141,7 @@ export default class Writer {
|
|
|
132
141
|
logFiles.push(generateID());
|
|
133
142
|
await s3.send(new PutObjectCommand({
|
|
134
143
|
Body: logFiles.join('\n'),
|
|
135
|
-
Bucket:
|
|
144
|
+
Bucket: this.bucketName,
|
|
136
145
|
ContentType: 'text/plain',
|
|
137
146
|
Key: `${prefix}/${INDEX_FILE}`,
|
|
138
147
|
}));
|
|
@@ -150,7 +159,7 @@ export default class Writer {
|
|
|
150
159
|
const { s3 } = this;
|
|
151
160
|
await s3.send(new PutObjectCommand({
|
|
152
161
|
Body: await gzip(JSON.stringify(contents)),
|
|
153
|
-
Bucket:
|
|
162
|
+
Bucket: this.bucketName,
|
|
154
163
|
ContentEncoding: 'gzip',
|
|
155
164
|
ContentType: 'application/json',
|
|
156
165
|
Key: `${key}.gz`,
|
package/src/auditlog/utils.js
CHANGED
|
@@ -13,10 +13,23 @@
|
|
|
13
13
|
/**
|
|
14
14
|
* Bucket to use for logging.
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
const DEFAULT_BUCKET_NAME = 'helix-adobe-logs';
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Index file in project folder. This is a LF separated text file with
|
|
20
20
|
* the list of all log files in ascending order.
|
|
21
21
|
*/
|
|
22
22
|
export const INDEX_FILE = '.index';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Resolve options object to contain all properties.
|
|
26
|
+
*
|
|
27
|
+
* @param {import("./AuditLog").Options} [popts]
|
|
28
|
+
* @returns {Required<import("./AuditLog").Options>}
|
|
29
|
+
*/
|
|
30
|
+
export function resolveOptions(opts = {}) {
|
|
31
|
+
return {
|
|
32
|
+
bucketName: DEFAULT_BUCKET_NAME,
|
|
33
|
+
...opts,
|
|
34
|
+
};
|
|
35
|
+
}
|