Skip to content

Commit 0e3a550

Browse files
update (#73)
1 parent 2953905 commit 0e3a550

File tree

6 files changed

+42
-17
lines changed

6 files changed

+42
-17
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,6 @@ typings/
104104
.vscode
105105
.idea
106106
!.eslintrc.js
107-
*.d.ts
107+
*.d.ts
108+
109+
/dist/package.json

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 3.0.2 (August 26, 2022)
2+
* Updated @elasticio/maester-client to v4.0.3
3+
14
## 3.0.1 (August 12, 2022)
25
* Increase default values and limits for envs `API_RETRIES_COUNT` and `API_REQUEST_TIMEOUT`
36
* Add `axiosReqWithRetryOnServerError` function to proceed with most commons use cases of making query to external API

dist/src/attachment/AttachmentProcessor.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ const logger_1 = require("../logger/logger");
1313
const package_json_1 = __importDefault(require("../../package.json"));
1414
const logger = (0, logger_1.getLogger)();
1515
const maesterClientVersion = package_json_1.default.dependencies['@elastic.io/maester-client'];
16+
const axiosVersion = package_json_1.default.dependencies.axios;
1617
exports.STORAGE_TYPE_PARAMETER = 'storage_type';
1718
exports.DEFAULT_STORAGE_TYPE = 'steward';
1819
exports.MAESTER_OBJECT_ID_ENDPOINT = '/objects/';
1920
const { ELASTICIO_OBJECT_STORAGE_TOKEN = '', ELASTICIO_OBJECT_STORAGE_URI = '' } = process.env;
2021
const maesterCreds = { jwtSecret: ELASTICIO_OBJECT_STORAGE_TOKEN, uri: ELASTICIO_OBJECT_STORAGE_URI };
2122
const DEFAULT_ATTACHMENT_REQUEST_TIMEOUT = process.env.REQUEST_TIMEOUT ? parseInt(process.env.REQUEST_TIMEOUT, 10) : interfaces_1.REQUEST_TIMEOUT.maxValue; // 20s
2223
class AttachmentProcessor {
23-
constructor(userAgent) {
24-
this.userAgent = `${userAgent} maester-client/${maesterClientVersion}`;
24+
constructor(userAgent, msgId) {
25+
this.userAgent = userAgent;
26+
this.msgId = msgId;
2527
}
2628
async getAttachment(url, responseType) {
2729
const storageType = this.getStorageTypeByUrl(url);
@@ -31,7 +33,6 @@ class AttachmentProcessor {
3133
method: 'get',
3234
timeout: DEFAULT_ATTACHMENT_REQUEST_TIMEOUT,
3335
retry: interfaces_1.RETRIES_COUNT.defaultValue,
34-
headers: { 'User-Agent': this.userAgent }
3536
};
3637
switch (storageType) {
3738
case 'steward': return this.getStewardAttachment(axConfig);
@@ -58,10 +59,18 @@ class AttachmentProcessor {
5859
async getStewardAttachment(axConfig) {
5960
const ax = axios_1.default.create();
6061
this.addRetryCountInterceptorToAxios(ax);
61-
return ax(axConfig);
62+
const userAgent = `${this.userAgent} axios/${axiosVersion}`;
63+
return ax({
64+
...axConfig,
65+
headers: {
66+
'User-Agent': userAgent,
67+
'x-request-id': `f:${process.env.ELASTICIO_FLOW_ID};s:${process.env.ELASTICIO_STEP_ID};m:${this.msgId}`,
68+
}
69+
});
6270
}
6371
async getMaesterAttachment({ url, responseType }) {
64-
const objectStorage = new maester_client_1.ObjectStorage({ ...maesterCreds, userAgent: this.userAgent });
72+
const userAgent = `${this.userAgent} maester-client/${maesterClientVersion}`;
73+
const objectStorage = new maester_client_1.ObjectStorage({ ...maesterCreds, userAgent, msgId: this.msgId });
6574
const maesterAttachmentId = this.getMaesterAttachmentIdByUrl(url);
6675
const response = await objectStorage.getOne(maesterAttachmentId, { responseType });
6776
return { data: response };

package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@elastic.io/component-commons-library",
3-
"version": "3.0.1",
3+
"version": "3.0.2",
44
"description": "Library for most common component development cases",
55
"author": {
66
"name": "elastic.io GmbH",
@@ -24,7 +24,7 @@
2424
},
2525
"dependencies": {
2626
"@elastic.io/jsonata-moment": "1.1.4",
27-
"@elastic.io/maester-client": "4.0.2",
27+
"@elastic.io/maester-client": "4.0.3",
2828
"@elastic.io/ntlm-client": "1.0.0",
2929
"async": "3.2.3",
3030
"axios": "0.27.2",

src/attachment/AttachmentProcessor.ts

+16-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import packageJson from '../../package.json';
99

1010
const logger = getLogger();
1111
const maesterClientVersion = packageJson.dependencies['@elastic.io/maester-client'];
12+
const axiosVersion = packageJson.dependencies.axios;
1213

1314
export const STORAGE_TYPE_PARAMETER = 'storage_type';
1415
export const DEFAULT_STORAGE_TYPE = 'steward';
@@ -20,8 +21,11 @@ const DEFAULT_ATTACHMENT_REQUEST_TIMEOUT = process.env.REQUEST_TIMEOUT ? parseIn
2021
export class AttachmentProcessor {
2122
private userAgent: string;
2223

23-
public constructor(userAgent: string) {
24-
this.userAgent = `${userAgent} maester-client/${maesterClientVersion}`;
24+
private msgId: string;
25+
26+
public constructor(userAgent?: string, msgId?: string) {
27+
this.userAgent = userAgent;
28+
this.msgId = msgId;
2529
}
2630

2731
async getAttachment(url: string, responseType: string) {
@@ -32,7 +36,6 @@ export class AttachmentProcessor {
3236
method: 'get',
3337
timeout: DEFAULT_ATTACHMENT_REQUEST_TIMEOUT,
3438
retry: RETRIES_COUNT.defaultValue,
35-
headers: { 'User-Agent': this.userAgent }
3639
} as AxiosRequestConfig;
3740

3841
switch (storageType) {
@@ -62,11 +65,19 @@ export class AttachmentProcessor {
6265
private async getStewardAttachment(axConfig) {
6366
const ax = axios.create();
6467
this.addRetryCountInterceptorToAxios(ax);
65-
return ax(axConfig);
68+
const userAgent = `${this.userAgent} axios/${axiosVersion}`;
69+
return ax({
70+
...axConfig,
71+
headers: {
72+
'User-Agent': userAgent,
73+
'x-request-id': `f:${process.env.ELASTICIO_FLOW_ID};s:${process.env.ELASTICIO_STEP_ID};m:${this.msgId}`,
74+
}
75+
});
6676
}
6777

6878
private async getMaesterAttachment({ url, responseType }: { url: string, responseType: ResponseType }) {
69-
const objectStorage = new ObjectStorage({ ...maesterCreds, userAgent: this.userAgent });
79+
const userAgent = `${this.userAgent} maester-client/${maesterClientVersion}`;
80+
const objectStorage = new ObjectStorage({ ...maesterCreds, userAgent, msgId: this.msgId });
7081
const maesterAttachmentId = this.getMaesterAttachmentIdByUrl(url);
7182
const response = await objectStorage.getOne(maesterAttachmentId, { responseType });
7283
return { data: response };

0 commit comments

Comments
 (0)