@datadog/datadog-ci 0.17.8 → 0.17.12
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-3rdparty.csv +2 -0
- package/README.md +3 -1
- package/dist/{commands/dependencies/index.d.ts → cli.d.ts} +0 -0
- package/dist/cli.js +34 -0
- package/dist/commands/{dsyms/index.d.ts → dependencies/cli.d.ts} +0 -0
- package/dist/commands/dependencies/{index.js → cli.js} +0 -0
- package/dist/commands/dependencies/upload.d.ts +1 -1
- package/dist/commands/{git-metadata/index.d.ts → dsyms/cli.d.ts} +0 -0
- package/dist/commands/dsyms/{index.js → cli.js} +0 -0
- package/dist/commands/dsyms/upload.d.ts +1 -1
- package/dist/commands/{junit/index.d.ts → git-metadata/cli.d.ts} +0 -0
- package/dist/commands/git-metadata/{index.js → cli.js} +0 -0
- package/dist/commands/git-metadata/upload.d.ts +1 -1
- package/dist/commands/git-metadata/upload.js +6 -1
- package/dist/commands/{lambda/__tests__/function.test.d.ts → junit/cli.d.ts} +0 -0
- package/dist/commands/junit/{index.js → cli.js} +0 -0
- package/dist/commands/junit/upload.d.ts +1 -1
- package/dist/commands/lambda/__tests__/fixtures.d.ts +42 -0
- package/dist/commands/lambda/__tests__/fixtures.js +73 -0
- package/dist/commands/lambda/{index.d.ts → __tests__/functions/commons.test.d.ts} +0 -0
- package/dist/commands/lambda/__tests__/functions/commons.test.js +350 -0
- package/dist/commands/{sourcemaps/index.d.ts → lambda/__tests__/functions/instrument.test.d.ts} +0 -0
- package/dist/commands/lambda/__tests__/{function.test.js → functions/instrument.test.js} +504 -476
- package/dist/commands/{trace/index.d.ts → lambda/__tests__/functions/uninstrument.test.d.ts} +0 -0
- package/dist/commands/lambda/__tests__/functions/uninstrument.test.js +371 -0
- package/dist/commands/lambda/__tests__/instrument.test.js +351 -234
- package/dist/commands/lambda/__tests__/loggroup.test.js +98 -34
- package/dist/commands/lambda/__tests__/tags.test.js +107 -31
- package/dist/commands/lambda/__tests__/uninstrument.test.d.ts +1 -0
- package/dist/commands/lambda/__tests__/uninstrument.test.js +281 -0
- package/dist/commands/lambda/cli.d.ts +1 -0
- package/dist/commands/lambda/cli.js +5 -0
- package/dist/commands/lambda/constants.d.ts +18 -6
- package/dist/commands/lambda/constants.js +30 -6
- package/dist/commands/lambda/functions/commons.d.ts +101 -0
- package/dist/commands/lambda/functions/commons.js +258 -0
- package/dist/commands/lambda/functions/instrument.d.ts +7 -0
- package/dist/commands/lambda/functions/instrument.js +186 -0
- package/dist/commands/lambda/functions/uninstrument.d.ts +7 -0
- package/dist/commands/lambda/functions/uninstrument.js +121 -0
- package/dist/commands/lambda/instrument.d.ts +4 -4
- package/dist/commands/lambda/instrument.js +103 -57
- package/dist/commands/lambda/interfaces.d.ts +53 -0
- package/dist/commands/lambda/loggroup.d.ts +4 -7
- package/dist/commands/lambda/loggroup.js +30 -5
- package/dist/commands/lambda/tags.d.ts +3 -4
- package/dist/commands/lambda/tags.js +19 -3
- package/dist/commands/lambda/uninstrument.d.ts +12 -0
- package/dist/commands/lambda/uninstrument.js +166 -0
- package/dist/commands/sourcemaps/cli.d.ts +1 -0
- package/dist/commands/sourcemaps/{index.js → cli.js} +0 -0
- package/dist/commands/sourcemaps/upload.d.ts +1 -1
- package/dist/commands/synthetics/__tests__/cli.test.js +35 -13
- package/dist/commands/synthetics/__tests__/utils.test.js +0 -4
- package/dist/commands/synthetics/__tests__/websocket.test.js +3 -3
- package/dist/commands/synthetics/cli.d.ts +1 -26
- package/dist/commands/synthetics/cli.js +2 -227
- package/dist/commands/synthetics/command.d.ts +26 -0
- package/dist/commands/synthetics/command.js +230 -0
- package/dist/commands/synthetics/index.d.ts +5 -1
- package/dist/commands/synthetics/index.js +31 -2
- package/dist/commands/synthetics/utils.d.ts +0 -3
- package/dist/commands/synthetics/utils.js +1 -11
- package/dist/commands/trace/cli.d.ts +1 -0
- package/dist/commands/trace/{index.js → cli.js} +0 -0
- package/dist/commands/trace/trace.d.ts +1 -1
- package/dist/helpers/__tests__/ci.test.js +51 -114
- package/dist/helpers/__tests__/user-provided-git.test.js +14 -2
- package/dist/helpers/__tests__/utils.test.js +4 -0
- package/dist/helpers/ci.js +62 -96
- package/dist/helpers/interfaces.d.ts +28 -2
- package/dist/helpers/user-provided-git.js +11 -2
- package/dist/helpers/utils.d.ts +4 -0
- package/dist/helpers/utils.js +18 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +23 -31
- package/package.json +10 -8
- package/dist/commands/lambda/function.d.ts +0 -43
- package/dist/commands/lambda/function.js +0 -273
- package/dist/commands/lambda/index.js +0 -4
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
// tslint:disable: no-string-literal
|
|
32
|
+
jest.mock('fs');
|
|
33
|
+
jest.mock('aws-sdk');
|
|
34
|
+
const aws_sdk_1 = require("aws-sdk");
|
|
35
|
+
const chalk_1 = require("chalk");
|
|
36
|
+
const fs = __importStar(require("fs"));
|
|
37
|
+
const constants_1 = require("../constants");
|
|
38
|
+
const uninstrument_1 = require("../uninstrument");
|
|
39
|
+
const fixtures_1 = require("./fixtures");
|
|
40
|
+
describe('uninstrument', () => {
|
|
41
|
+
describe('execute', () => {
|
|
42
|
+
const OLD_ENV = process.env;
|
|
43
|
+
beforeEach(() => {
|
|
44
|
+
jest.resetModules();
|
|
45
|
+
process.env = {};
|
|
46
|
+
});
|
|
47
|
+
afterAll(() => {
|
|
48
|
+
process.env = OLD_ENV;
|
|
49
|
+
});
|
|
50
|
+
test('prints dry run data for a valid uninstrumentation', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
|
+
;
|
|
52
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
53
|
+
aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
|
|
54
|
+
'arn:aws:lambda:us-east-1:000000000000:function:uninstrument': {
|
|
55
|
+
Architectures: ['x86_64'],
|
|
56
|
+
Environment: {
|
|
57
|
+
Variables: {
|
|
58
|
+
[constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
|
|
59
|
+
[constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
|
|
60
|
+
[constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
|
|
61
|
+
[constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
|
|
62
|
+
[constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
|
|
63
|
+
[constants_1.SERVICE_ENV_VAR]: 'middletier',
|
|
64
|
+
[constants_1.SITE_ENV_VAR]: 'datadoghq.com',
|
|
65
|
+
[constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
|
|
66
|
+
[constants_1.VERSION_ENV_VAR]: '0.2',
|
|
67
|
+
USER_VARIABLE: 'shouldnt be deleted by uninstrumentation',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument',
|
|
71
|
+
Handler: 'datadog_lambda.handler.handler',
|
|
72
|
+
Layers: [
|
|
73
|
+
{
|
|
74
|
+
Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Extension:11',
|
|
75
|
+
CodeSize: 0,
|
|
76
|
+
SigningJobArn: 'some-signing-job-arn',
|
|
77
|
+
SigningProfileVersionArn: 'some-signing-profile',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Python38:49',
|
|
81
|
+
CodeSize: 0,
|
|
82
|
+
SigningJobArn: 'some-signing-job-arn',
|
|
83
|
+
SigningProfileVersionArn: 'some-signing-profile',
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
Runtime: 'python3.8',
|
|
87
|
+
},
|
|
88
|
+
}));
|
|
89
|
+
const cli = fixtures_1.makeCli();
|
|
90
|
+
const context = fixtures_1.createMockContext();
|
|
91
|
+
const functionARN = 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument';
|
|
92
|
+
process.env.DATADOG_API_KEY = '1234';
|
|
93
|
+
const code = yield cli.run(['lambda', 'uninstrument', '-f', functionARN, '-r', 'us-east-1', '-d'], context);
|
|
94
|
+
const output = context.stdout.toString();
|
|
95
|
+
expect(code).toBe(0);
|
|
96
|
+
expect(output).toMatchInlineSnapshot(`
|
|
97
|
+
"\n${chalk_1.bold(chalk_1.yellow('[!]'))} Functions to be updated:
|
|
98
|
+
\t- ${chalk_1.bold('arn:aws:lambda:us-east-1:000000000000:function:uninstrument')}\n
|
|
99
|
+
${chalk_1.bold(chalk_1.cyan('[Dry Run] '))}Will apply the following updates:
|
|
100
|
+
UpdateFunctionConfiguration -> arn:aws:lambda:us-east-1:000000000000:function:uninstrument
|
|
101
|
+
{
|
|
102
|
+
\\"FunctionName\\": \\"arn:aws:lambda:us-east-1:000000000000:function:uninstrument\\",
|
|
103
|
+
\\"Handler\\": \\"lambda_function.lambda_handler\\",
|
|
104
|
+
\\"Environment\\": {
|
|
105
|
+
\\"Variables\\": {
|
|
106
|
+
\\"USER_VARIABLE\\": \\"shouldnt be deleted by uninstrumentation\\"
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
\\"Layers\\": []
|
|
110
|
+
}
|
|
111
|
+
"
|
|
112
|
+
`);
|
|
113
|
+
}));
|
|
114
|
+
test('runs function update command for valid uninstrumentation', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
115
|
+
;
|
|
116
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
117
|
+
const lambda = fixtures_1.makeMockLambda({
|
|
118
|
+
'arn:aws:lambda:us-east-1:000000000000:function:uninstrument': {
|
|
119
|
+
Environment: {
|
|
120
|
+
Variables: {
|
|
121
|
+
[constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
|
|
122
|
+
[constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
|
|
123
|
+
[constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
|
|
124
|
+
[constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
|
|
125
|
+
[constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
|
|
126
|
+
[constants_1.SERVICE_ENV_VAR]: 'middletier',
|
|
127
|
+
[constants_1.SITE_ENV_VAR]: 'datadoghq.com',
|
|
128
|
+
[constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
|
|
129
|
+
[constants_1.VERSION_ENV_VAR]: '0.2',
|
|
130
|
+
USER_VARIABLE: 'shouldnt be deleted by uninstrumentation',
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument',
|
|
134
|
+
Handler: 'datadog_lambda.handler.handler',
|
|
135
|
+
Layers: [
|
|
136
|
+
{
|
|
137
|
+
Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Extension:11',
|
|
138
|
+
CodeSize: 0,
|
|
139
|
+
SigningJobArn: 'some-signing-job-arn',
|
|
140
|
+
SigningProfileVersionArn: 'some-signing-profile',
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Python38:49',
|
|
144
|
+
CodeSize: 0,
|
|
145
|
+
SigningJobArn: 'some-signing-job-arn',
|
|
146
|
+
SigningProfileVersionArn: 'some-signing-profile',
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
Runtime: 'python3.8',
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
aws_sdk_1.Lambda.mockImplementation(() => lambda);
|
|
153
|
+
const cli = fixtures_1.makeCli();
|
|
154
|
+
const context = fixtures_1.createMockContext();
|
|
155
|
+
const functionARN = 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument';
|
|
156
|
+
process.env.DATADOG_API_KEY = '1234';
|
|
157
|
+
yield cli.run(['lambda', 'uninstrument', '-f', functionARN, '-r', 'us-east-1'], context);
|
|
158
|
+
expect(lambda.updateFunctionConfiguration).toHaveBeenCalled();
|
|
159
|
+
}));
|
|
160
|
+
test('aborts early when the aws-sdk throws an error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
161
|
+
;
|
|
162
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
163
|
+
aws_sdk_1.Lambda.mockImplementation(() => ({
|
|
164
|
+
getFunction: jest.fn().mockImplementation(() => ({ promise: () => Promise.reject('Lambda failed') })),
|
|
165
|
+
}));
|
|
166
|
+
process.env = {};
|
|
167
|
+
const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
|
|
168
|
+
command['functions'] = ['my-func'];
|
|
169
|
+
command['region'] = 'us-east-1';
|
|
170
|
+
const code = yield command['execute']();
|
|
171
|
+
const output = command.context.stdout.toString();
|
|
172
|
+
expect(code).toBe(1);
|
|
173
|
+
expect(output).toMatch(`${chalk_1.red('[Error]')} Couldn't fetch lambda functions. Lambda failed\n`);
|
|
174
|
+
}));
|
|
175
|
+
test("aborts early when function regions can't be found", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
176
|
+
;
|
|
177
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
178
|
+
aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}));
|
|
179
|
+
const cli = fixtures_1.makeCli();
|
|
180
|
+
const context = fixtures_1.createMockContext();
|
|
181
|
+
const code = yield cli.run(['lambda', 'uninstrument', '--function', 'my-func'], context);
|
|
182
|
+
const output = context.stdout.toString();
|
|
183
|
+
expect(code).toBe(1);
|
|
184
|
+
expect(output).toMatch('No default region specified for ["my-func"]. Use -r, --region, or use a full functionARN');
|
|
185
|
+
}));
|
|
186
|
+
test('aborts early when no functions are specified', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
187
|
+
;
|
|
188
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
|
|
189
|
+
aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}));
|
|
190
|
+
const cli = fixtures_1.makeCli();
|
|
191
|
+
const context = fixtures_1.createMockContext();
|
|
192
|
+
const code = yield cli.run(['lambda', 'uninstrument'], context);
|
|
193
|
+
const output = context.stdout.toString();
|
|
194
|
+
expect(code).toBe(1);
|
|
195
|
+
expect(output).toMatchInlineSnapshot(`
|
|
196
|
+
"No functions specified for un-instrumentation.
|
|
197
|
+
"
|
|
198
|
+
`);
|
|
199
|
+
}));
|
|
200
|
+
test('aborts early when no functions are specified while using config file', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
201
|
+
;
|
|
202
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({}));
|
|
203
|
+
process.env = {};
|
|
204
|
+
const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
|
|
205
|
+
command['config']['region'] = 'ap-southeast-1';
|
|
206
|
+
yield command['execute']();
|
|
207
|
+
const output = command.context.stdout.toString();
|
|
208
|
+
expect(output).toMatchInlineSnapshot(`
|
|
209
|
+
"No functions specified for un-instrumentation.
|
|
210
|
+
"
|
|
211
|
+
`);
|
|
212
|
+
}));
|
|
213
|
+
test('aborts if functions and a pattern are set at the same time', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
214
|
+
;
|
|
215
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({}));
|
|
216
|
+
process.env = {};
|
|
217
|
+
let command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
|
|
218
|
+
command['config']['region'] = 'ap-southeast-1';
|
|
219
|
+
command['config']['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
|
|
220
|
+
command['regExPattern'] = 'valid-pattern';
|
|
221
|
+
yield command['execute']();
|
|
222
|
+
let output = command.context.stdout.toString();
|
|
223
|
+
expect(output).toMatch('Functions in config file and "--functions-regex" should not be used at the same time.\n');
|
|
224
|
+
command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
|
|
225
|
+
command['region'] = 'ap-southeast-1';
|
|
226
|
+
command['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
|
|
227
|
+
command['regExPattern'] = 'valid-pattern';
|
|
228
|
+
yield command['execute']();
|
|
229
|
+
output = command.context.stdout.toString();
|
|
230
|
+
expect(output).toMatch('"--functions" and "--functions-regex" should not be used at the same time.\n');
|
|
231
|
+
}));
|
|
232
|
+
test('aborts if the regEx pattern is an ARN', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
233
|
+
;
|
|
234
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({}));
|
|
235
|
+
process.env = {};
|
|
236
|
+
const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
|
|
237
|
+
command['region'] = 'ap-southeast-1';
|
|
238
|
+
command['regExPattern'] = 'arn:aws:lambda:ap-southeast-1:123456789012:function:*';
|
|
239
|
+
const code = yield command['execute']();
|
|
240
|
+
const output = command.context.stdout.toString();
|
|
241
|
+
expect(code).toBe(1);
|
|
242
|
+
expect(output).toMatch(`"--functions-regex" isn't meant to be used with ARNs.\n`);
|
|
243
|
+
}));
|
|
244
|
+
test('aborts if the regEx pattern is set but no region is specified', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
245
|
+
;
|
|
246
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({}));
|
|
247
|
+
process.env = {};
|
|
248
|
+
const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
|
|
249
|
+
command['regExPattern'] = 'my-function';
|
|
250
|
+
const code = yield command['execute']();
|
|
251
|
+
const output = command.context.stdout.toString();
|
|
252
|
+
expect(code).toBe(1);
|
|
253
|
+
expect(output).toMatch('No default region specified. Use `-r`, `--region`.');
|
|
254
|
+
}));
|
|
255
|
+
test('aborts if the the aws-sdk fails', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
256
|
+
;
|
|
257
|
+
fs.readFile.mockImplementation((a, b, callback) => callback({}));
|
|
258
|
+
aws_sdk_1.Lambda.mockImplementation(() => ({ promise: Promise.reject() }));
|
|
259
|
+
process.env = {};
|
|
260
|
+
const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
|
|
261
|
+
command['region'] = 'ap-southeast-1';
|
|
262
|
+
command['regExPattern'] = 'my-function';
|
|
263
|
+
const code = yield command['execute']();
|
|
264
|
+
const output = command.context.stdout.toString();
|
|
265
|
+
expect(code).toBe(1);
|
|
266
|
+
expect(output).toMatch("Fetching lambda functions, this might take a while.\nCouldn't fetch lambda functions. Error: Max retry count exceeded.\n");
|
|
267
|
+
}));
|
|
268
|
+
});
|
|
269
|
+
describe('printPlannedActions', () => {
|
|
270
|
+
test('prints no output when list is empty', () => {
|
|
271
|
+
process.env = {};
|
|
272
|
+
const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
|
|
273
|
+
command['printPlannedActions']([]);
|
|
274
|
+
const output = command.context.stdout.toString();
|
|
275
|
+
expect(output).toMatchInlineSnapshot(`
|
|
276
|
+
"No updates will be applied
|
|
277
|
+
"
|
|
278
|
+
`);
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,30 +1,40 @@
|
|
|
1
|
+
export declare const DD_LAMBDA_EXTENSION_LAYER_NAME = "Datadog-Extension";
|
|
2
|
+
export declare const EXTENSION_LAYER_KEY = "extension";
|
|
1
3
|
export declare const RUNTIME_LAYER_LOOKUP: {
|
|
2
|
-
readonly
|
|
4
|
+
readonly extension: "Datadog-Extension";
|
|
3
5
|
readonly 'nodejs12.x': "Datadog-Node12-x";
|
|
4
6
|
readonly 'nodejs14.x': "Datadog-Node14-x";
|
|
5
|
-
readonly 'python2.7': "Datadog-Python27";
|
|
6
7
|
readonly 'python3.6': "Datadog-Python36";
|
|
7
8
|
readonly 'python3.7': "Datadog-Python37";
|
|
8
9
|
readonly 'python3.8': "Datadog-Python38";
|
|
9
10
|
readonly 'python3.9': "Datadog-Python39";
|
|
10
11
|
};
|
|
11
|
-
export declare type Runtime = keyof typeof RUNTIME_LAYER_LOOKUP
|
|
12
|
+
export declare type Runtime = Exclude<keyof typeof RUNTIME_LAYER_LOOKUP, typeof EXTENSION_LAYER_KEY>;
|
|
13
|
+
export declare const ARM_RUNTIMES: string[];
|
|
14
|
+
export declare const ARM64_ARCHITECTURE = "arm64";
|
|
15
|
+
export declare const ARM_LAYER_SUFFIX = "-ARM";
|
|
16
|
+
export declare enum RuntimeType {
|
|
17
|
+
NODE = 0,
|
|
18
|
+
PYTHON = 1
|
|
19
|
+
}
|
|
20
|
+
export declare const RUNTIME_LOOKUP: {
|
|
21
|
+
[key: string]: RuntimeType;
|
|
22
|
+
};
|
|
12
23
|
export declare const HANDLER_LOCATION: {
|
|
13
|
-
'nodejs10.x': string;
|
|
14
24
|
'nodejs12.x': string;
|
|
15
25
|
'nodejs14.x': string;
|
|
16
|
-
'python2.7': string;
|
|
17
26
|
'python3.6': string;
|
|
18
27
|
'python3.7': string;
|
|
19
28
|
'python3.8': string;
|
|
20
29
|
'python3.9': string;
|
|
21
30
|
};
|
|
31
|
+
export declare const SITES: string[];
|
|
22
32
|
export declare const DEFAULT_LAYER_AWS_ACCOUNT = "464622532012";
|
|
23
33
|
export declare const GOVCLOUD_LAYER_AWS_ACCOUNT = "002406178527";
|
|
24
34
|
export declare const SUBSCRIPTION_FILTER_NAME = "datadog-ci-filter";
|
|
25
35
|
export declare const TAG_VERSION_NAME = "dd_sls_ci";
|
|
26
|
-
export declare const DD_LAMBDA_EXTENSION_LAYER_NAME = "Datadog-Extension";
|
|
27
36
|
export declare const API_KEY_ENV_VAR = "DD_API_KEY";
|
|
37
|
+
export declare const API_KEY_SECRET_ARN_ENV_VAR = "DD_API_KEY_SECRET_ARN";
|
|
28
38
|
export declare const KMS_API_KEY_ENV_VAR = "DD_KMS_API_KEY";
|
|
29
39
|
export declare const SITE_ENV_VAR = "DD_SITE";
|
|
30
40
|
export declare const TRACE_ENABLED_ENV_VAR = "DD_TRACE_ENABLED";
|
|
@@ -38,6 +48,8 @@ export declare const ENVIRONMENT_ENV_VAR = "DD_ENV";
|
|
|
38
48
|
export declare const EXTRA_TAGS_ENV_VAR = "DD_TAGS";
|
|
39
49
|
export declare const CI_SITE_ENV_VAR = "DATADOG_SITE";
|
|
40
50
|
export declare const CI_API_KEY_ENV_VAR = "DATADOG_API_KEY";
|
|
51
|
+
export declare const CI_API_KEY_SECRET_ARN_ENV_VAR = "DATADOG_API_KEY_SECRET_ARN";
|
|
41
52
|
export declare const CI_KMS_API_KEY_ENV_VAR = "DATADOG_KMS_API_KEY";
|
|
42
53
|
export declare const LIST_FUNCTIONS_MAX_RETRY_COUNT = 2;
|
|
54
|
+
export declare const MAX_LAMBDA_STATE_CHECK_ATTEMPTS = 3;
|
|
43
55
|
export declare const EXTRA_TAGS_REG_EXP: RegExp;
|
|
@@ -1,35 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EXTRA_TAGS_REG_EXP = exports.LIST_FUNCTIONS_MAX_RETRY_COUNT = exports.CI_KMS_API_KEY_ENV_VAR = exports.CI_API_KEY_ENV_VAR = exports.CI_SITE_ENV_VAR = exports.EXTRA_TAGS_ENV_VAR = exports.ENVIRONMENT_ENV_VAR = exports.VERSION_ENV_VAR = exports.SERVICE_ENV_VAR = exports.LAMBDA_HANDLER_ENV_VAR = exports.LOG_LEVEL_ENV_VAR = exports.FLUSH_TO_LOG_ENV_VAR = exports.MERGE_XRAY_TRACES_ENV_VAR = exports.TRACE_ENABLED_ENV_VAR = exports.SITE_ENV_VAR = exports.KMS_API_KEY_ENV_VAR = exports.
|
|
3
|
+
exports.EXTRA_TAGS_REG_EXP = exports.MAX_LAMBDA_STATE_CHECK_ATTEMPTS = exports.LIST_FUNCTIONS_MAX_RETRY_COUNT = exports.CI_KMS_API_KEY_ENV_VAR = exports.CI_API_KEY_SECRET_ARN_ENV_VAR = exports.CI_API_KEY_ENV_VAR = exports.CI_SITE_ENV_VAR = exports.EXTRA_TAGS_ENV_VAR = exports.ENVIRONMENT_ENV_VAR = exports.VERSION_ENV_VAR = exports.SERVICE_ENV_VAR = exports.LAMBDA_HANDLER_ENV_VAR = exports.LOG_LEVEL_ENV_VAR = exports.FLUSH_TO_LOG_ENV_VAR = exports.MERGE_XRAY_TRACES_ENV_VAR = exports.TRACE_ENABLED_ENV_VAR = exports.SITE_ENV_VAR = exports.KMS_API_KEY_ENV_VAR = exports.API_KEY_SECRET_ARN_ENV_VAR = exports.API_KEY_ENV_VAR = exports.TAG_VERSION_NAME = exports.SUBSCRIPTION_FILTER_NAME = exports.GOVCLOUD_LAYER_AWS_ACCOUNT = exports.DEFAULT_LAYER_AWS_ACCOUNT = exports.SITES = exports.HANDLER_LOCATION = exports.RUNTIME_LOOKUP = exports.RuntimeType = exports.ARM_LAYER_SUFFIX = exports.ARM64_ARCHITECTURE = exports.ARM_RUNTIMES = exports.RUNTIME_LAYER_LOOKUP = exports.EXTENSION_LAYER_KEY = exports.DD_LAMBDA_EXTENSION_LAYER_NAME = void 0;
|
|
4
|
+
exports.DD_LAMBDA_EXTENSION_LAYER_NAME = 'Datadog-Extension';
|
|
5
|
+
exports.EXTENSION_LAYER_KEY = 'extension';
|
|
4
6
|
exports.RUNTIME_LAYER_LOOKUP = {
|
|
5
|
-
|
|
7
|
+
[exports.EXTENSION_LAYER_KEY]: exports.DD_LAMBDA_EXTENSION_LAYER_NAME,
|
|
6
8
|
'nodejs12.x': 'Datadog-Node12-x',
|
|
7
9
|
'nodejs14.x': 'Datadog-Node14-x',
|
|
8
|
-
'python2.7': 'Datadog-Python27',
|
|
9
10
|
'python3.6': 'Datadog-Python36',
|
|
10
11
|
'python3.7': 'Datadog-Python37',
|
|
11
12
|
'python3.8': 'Datadog-Python38',
|
|
12
13
|
'python3.9': 'Datadog-Python39',
|
|
13
14
|
};
|
|
15
|
+
exports.ARM_RUNTIMES = [exports.EXTENSION_LAYER_KEY, 'python3.8', 'python3.9'];
|
|
16
|
+
exports.ARM64_ARCHITECTURE = 'arm64';
|
|
17
|
+
exports.ARM_LAYER_SUFFIX = '-ARM';
|
|
18
|
+
var RuntimeType;
|
|
19
|
+
(function (RuntimeType) {
|
|
20
|
+
RuntimeType[RuntimeType["NODE"] = 0] = "NODE";
|
|
21
|
+
RuntimeType[RuntimeType["PYTHON"] = 1] = "PYTHON";
|
|
22
|
+
})(RuntimeType = exports.RuntimeType || (exports.RuntimeType = {}));
|
|
23
|
+
exports.RUNTIME_LOOKUP = {
|
|
24
|
+
'nodejs12.x': RuntimeType.NODE,
|
|
25
|
+
'nodejs14.x': RuntimeType.NODE,
|
|
26
|
+
'python3.6': RuntimeType.PYTHON,
|
|
27
|
+
'python3.7': RuntimeType.PYTHON,
|
|
28
|
+
'python3.8': RuntimeType.PYTHON,
|
|
29
|
+
'python3.9': RuntimeType.PYTHON,
|
|
30
|
+
};
|
|
14
31
|
const PYTHON_HANDLER_LOCATION = 'datadog_lambda.handler.handler';
|
|
15
32
|
const NODE_HANDLER_LOCATION = '/opt/nodejs/node_modules/datadog-lambda-js/handler.handler';
|
|
16
33
|
exports.HANDLER_LOCATION = {
|
|
17
|
-
'nodejs10.x': NODE_HANDLER_LOCATION,
|
|
18
34
|
'nodejs12.x': NODE_HANDLER_LOCATION,
|
|
19
35
|
'nodejs14.x': NODE_HANDLER_LOCATION,
|
|
20
|
-
'python2.7': PYTHON_HANDLER_LOCATION,
|
|
21
36
|
'python3.6': PYTHON_HANDLER_LOCATION,
|
|
22
37
|
'python3.7': PYTHON_HANDLER_LOCATION,
|
|
23
38
|
'python3.8': PYTHON_HANDLER_LOCATION,
|
|
24
39
|
'python3.9': PYTHON_HANDLER_LOCATION,
|
|
25
40
|
};
|
|
41
|
+
exports.SITES = [
|
|
42
|
+
'datadoghq.com',
|
|
43
|
+
'datadoghq.eu',
|
|
44
|
+
'us3.datadoghq.com',
|
|
45
|
+
'us5.datadoghq.com',
|
|
46
|
+
'ddog-gov.,com',
|
|
47
|
+
];
|
|
26
48
|
exports.DEFAULT_LAYER_AWS_ACCOUNT = '464622532012';
|
|
27
49
|
exports.GOVCLOUD_LAYER_AWS_ACCOUNT = '002406178527';
|
|
28
50
|
exports.SUBSCRIPTION_FILTER_NAME = 'datadog-ci-filter';
|
|
29
51
|
exports.TAG_VERSION_NAME = 'dd_sls_ci';
|
|
30
|
-
exports.DD_LAMBDA_EXTENSION_LAYER_NAME = 'Datadog-Extension';
|
|
31
52
|
// Environment variables used in the Lambda environment
|
|
32
53
|
exports.API_KEY_ENV_VAR = 'DD_API_KEY';
|
|
54
|
+
exports.API_KEY_SECRET_ARN_ENV_VAR = 'DD_API_KEY_SECRET_ARN';
|
|
33
55
|
exports.KMS_API_KEY_ENV_VAR = 'DD_KMS_API_KEY';
|
|
34
56
|
exports.SITE_ENV_VAR = 'DD_SITE';
|
|
35
57
|
exports.TRACE_ENABLED_ENV_VAR = 'DD_TRACE_ENABLED';
|
|
@@ -44,8 +66,10 @@ exports.EXTRA_TAGS_ENV_VAR = 'DD_TAGS';
|
|
|
44
66
|
// Environment variables used by Datadog CI
|
|
45
67
|
exports.CI_SITE_ENV_VAR = 'DATADOG_SITE';
|
|
46
68
|
exports.CI_API_KEY_ENV_VAR = 'DATADOG_API_KEY';
|
|
69
|
+
exports.CI_API_KEY_SECRET_ARN_ENV_VAR = 'DATADOG_API_KEY_SECRET_ARN';
|
|
47
70
|
exports.CI_KMS_API_KEY_ENV_VAR = 'DATADOG_KMS_API_KEY';
|
|
48
71
|
exports.LIST_FUNCTIONS_MAX_RETRY_COUNT = 2;
|
|
72
|
+
exports.MAX_LAMBDA_STATE_CHECK_ATTEMPTS = 3;
|
|
49
73
|
// DD_TAGS Regular Expression
|
|
50
74
|
// This RegExp ensures that the --extra-tags string
|
|
51
75
|
// matches a list of <key>:<value> separated by commas
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { CloudWatchLogs, Lambda } from 'aws-sdk';
|
|
2
|
+
import { Runtime } from '../constants';
|
|
3
|
+
import { FunctionConfiguration, InstrumentationSettings } from '../interfaces';
|
|
4
|
+
/**
|
|
5
|
+
* Returns an array of merged layer ARNs if given a Full Layer ARN,
|
|
6
|
+
* if not, it justs returns the layer ARNs provided.
|
|
7
|
+
*
|
|
8
|
+
* @param fullLayerARN a complete layer ARN.
|
|
9
|
+
* @param partialLayerARN a partial layer ARN.
|
|
10
|
+
* @param layerARNs an array of layer ARNs.
|
|
11
|
+
* @returns an array of layer ARNs.
|
|
12
|
+
*/
|
|
13
|
+
export declare const addLayerArn: (fullLayerArn: string | undefined, previousLayerName: string, layerARNs: string[]) => string[];
|
|
14
|
+
/**
|
|
15
|
+
* Returns a coerced boolean given string booleans or booleans in
|
|
16
|
+
* an spread array. Every other value will be ignored.
|
|
17
|
+
*
|
|
18
|
+
* @param fallback default value if none of the provided `values` comply.
|
|
19
|
+
* @param values an spread array of string booleans or booleans.
|
|
20
|
+
* @returns a coerced boolean.
|
|
21
|
+
*/
|
|
22
|
+
export declare const coerceBoolean: (fallback: boolean, ...values: any[]) => boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Returns an array of functions grouped by its region, it
|
|
25
|
+
* throws an error if there are functions without a region.
|
|
26
|
+
*
|
|
27
|
+
* @param functions an array of strings comprised by
|
|
28
|
+
* Functions ARNs, Partial ARNs, or Function Names.
|
|
29
|
+
* @param defaultRegion a fallback region
|
|
30
|
+
* @returns an array of functions grouped by region
|
|
31
|
+
*/
|
|
32
|
+
export declare const collectFunctionsByRegion: (functions: string[], defaultRegion: string | undefined) => {
|
|
33
|
+
[key: string]: string[];
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Given a Lambda instance and a regular expression,
|
|
37
|
+
* returns all the Function Configurations that match.
|
|
38
|
+
*
|
|
39
|
+
* @param lambda an instance of Lambda from aws-sdk.
|
|
40
|
+
* @param pattern a regular expression
|
|
41
|
+
* @returns an array of Lambda FunctionConfiguration's that match the pattern above.
|
|
42
|
+
*/
|
|
43
|
+
export declare const getLambdaFunctionConfigsFromRegex: (lambda: Lambda, pattern: string) => Promise<Lambda.FunctionConfiguration[]>;
|
|
44
|
+
/**
|
|
45
|
+
* Given a Lambda instance and an array of Lambda names,
|
|
46
|
+
* return all the Lambda Function Configurations.
|
|
47
|
+
*
|
|
48
|
+
* @param lambda an instance of Lambda from aws-sdk.
|
|
49
|
+
* @param functionARNs an array of strings comprised by
|
|
50
|
+
* Functions ARNs, Partial ARNs, or Function Names.
|
|
51
|
+
* @returns an array of Lambda FunctionConfiguration's.
|
|
52
|
+
*/
|
|
53
|
+
export declare const getLambdaFunctionConfigs: (lambda: Lambda, functionARNs: string[]) => Promise<Lambda.FunctionConfiguration[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Returns the correct ARN of a **Specific Runtime Layer** given its configuration, region,
|
|
56
|
+
* and settings (optional).
|
|
57
|
+
*
|
|
58
|
+
* @param config a Lambda FunctionConfiguration.
|
|
59
|
+
* @param region a region where the layer is hosted.
|
|
60
|
+
* @param settings instrumentation settings, mainly used to change the AWS account that contains the Layer.
|
|
61
|
+
* @returns the ARN of a **Specific Runtime Layer** with the correct region, account, architecture, and name.
|
|
62
|
+
*/
|
|
63
|
+
export declare const getLayerArn: (config: Lambda.FunctionConfiguration, runtime: Runtime, region: string, settings?: InstrumentationSettings | undefined) => string;
|
|
64
|
+
export declare const getLayers: (config: Lambda.FunctionConfiguration) => string[];
|
|
65
|
+
/**
|
|
66
|
+
* Call the aws-sdk Lambda api to get a Function given
|
|
67
|
+
* an ARN and then return its Configuration.
|
|
68
|
+
*
|
|
69
|
+
* @param lambda an instance of Lambda from aws-sdk.
|
|
70
|
+
* @param functionARN a string, can be Function ARN, Partial ARN, or a Function Name.
|
|
71
|
+
* @returns the Lambda FunctionConfiguration of the given ARN.
|
|
72
|
+
*/
|
|
73
|
+
export declare const getLambdaFunctionConfig: (lambda: Lambda, functionARN: string) => Promise<Lambda.FunctionConfiguration>;
|
|
74
|
+
/**
|
|
75
|
+
* Given a Function ARN, return its region by splitting the string,
|
|
76
|
+
* can return undefined if it is doesn't exist.
|
|
77
|
+
*
|
|
78
|
+
* @param functionARN a string, can be Function ARN, Partial ARN, or a Function Name.
|
|
79
|
+
* @returns the region of an ARN.
|
|
80
|
+
*/
|
|
81
|
+
export declare const getRegion: (functionARN: string) => string | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Returns whether a Lambda Function is active or throws an error if
|
|
84
|
+
* the FunctionConfiguration does not comply with `Successful` or `Active`.
|
|
85
|
+
*
|
|
86
|
+
* @param lambda an instance of Lambda from aws-sdk.
|
|
87
|
+
* @param config a Lambda FunctionConfiguration.
|
|
88
|
+
* @param functionArn a string, can be Function ARN, Partial ARN, or a Function Name.
|
|
89
|
+
* @param attempts the number of attemps that have passed since the last retry.
|
|
90
|
+
* @returns if a Lambda Function is active.
|
|
91
|
+
*/
|
|
92
|
+
export declare const isLambdaActive: (lambda: Lambda, config: Lambda.FunctionConfiguration, functionArn: string, attempts?: number) => Promise<boolean>;
|
|
93
|
+
/**
|
|
94
|
+
* Returns whether the runtime given is supported by the Datadog CI Lambda.
|
|
95
|
+
*
|
|
96
|
+
* @param runtime a string representing a Lambda FunctionConfiguration Runtime.
|
|
97
|
+
* @returns if a runtime is supported.
|
|
98
|
+
*/
|
|
99
|
+
export declare const isSupportedRuntime: (runtime?: string | undefined) => runtime is Runtime;
|
|
100
|
+
export declare const sentenceMatchesRegEx: (sentence: string, regex: RegExp) => RegExpMatchArray | null;
|
|
101
|
+
export declare const updateLambdaFunctionConfigs: (lambda: Lambda, cloudWatch: CloudWatchLogs, configs: FunctionConfiguration[]) => Promise<void>;
|