@datadog/datadog-ci 2.3.2 → 2.4.1

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.
Files changed (42) hide show
  1. package/LICENSE-3rdparty.csv +1 -0
  2. package/README.md +3 -2
  3. package/dist/commands/git-metadata/library.d.ts +1 -0
  4. package/dist/commands/git-metadata/library.js +14 -1
  5. package/dist/commands/git-metadata/library.js.map +1 -1
  6. package/dist/commands/lambda/__tests__/functions/commons.test.js +97 -2
  7. package/dist/commands/lambda/__tests__/functions/commons.test.js.map +1 -1
  8. package/dist/commands/lambda/__tests__/instrument.test.js +141 -420
  9. package/dist/commands/lambda/__tests__/instrument.test.js.map +1 -1
  10. package/dist/commands/lambda/__tests__/loggroup.test.js +68 -2
  11. package/dist/commands/lambda/__tests__/loggroup.test.js.map +1 -1
  12. package/dist/commands/lambda/__tests__/uninstrument.test.js +615 -551
  13. package/dist/commands/lambda/__tests__/uninstrument.test.js.map +1 -1
  14. package/dist/commands/lambda/functions/commons.d.ts +4 -2
  15. package/dist/commands/lambda/functions/commons.js +71 -12
  16. package/dist/commands/lambda/functions/commons.js.map +1 -1
  17. package/dist/commands/lambda/instrument.d.ts +2 -1
  18. package/dist/commands/lambda/instrument.js +29 -23
  19. package/dist/commands/lambda/instrument.js.map +1 -1
  20. package/dist/commands/lambda/interfaces.d.ts +6 -0
  21. package/dist/commands/lambda/loggroup.js +7 -1
  22. package/dist/commands/lambda/loggroup.js.map +1 -1
  23. package/dist/commands/lambda/renderer.d.ts +83 -2
  24. package/dist/commands/lambda/renderer.js +108 -5
  25. package/dist/commands/lambda/renderer.js.map +1 -1
  26. package/dist/commands/lambda/uninstrument.js +13 -17
  27. package/dist/commands/lambda/uninstrument.js.map +1 -1
  28. package/dist/commands/synthetics/index.d.ts +1 -0
  29. package/dist/commands/synthetics/index.js +3 -1
  30. package/dist/commands/synthetics/index.js.map +1 -1
  31. package/dist/helpers/__tests__/user-provided-git.test.js +2 -1
  32. package/dist/helpers/__tests__/user-provided-git.test.js.map +1 -1
  33. package/dist/helpers/__tests__/utils.test.js +7 -0
  34. package/dist/helpers/__tests__/utils.test.js.map +1 -1
  35. package/dist/helpers/ci.js +27 -29
  36. package/dist/helpers/ci.js.map +1 -1
  37. package/dist/helpers/user-provided-git.js +0 -3
  38. package/dist/helpers/user-provided-git.js.map +1 -1
  39. package/dist/helpers/utils.d.ts +2 -1
  40. package/dist/helpers/utils.js +13 -2
  41. package/dist/helpers/utils.js.map +1 -1
  42. package/package.json +7 -5
@@ -38,577 +38,641 @@ const constants_1 = require("../constants");
38
38
  const prompt_1 = require("../prompt");
39
39
  const uninstrument_1 = require("../uninstrument");
40
40
  const fixtures_1 = require("./fixtures");
41
- describe('uninstrument', () => {
42
- describe('execute', () => {
43
- const OLD_ENV = process.env;
44
- beforeEach(() => {
45
- jest.resetModules();
46
- process.env = {};
47
- });
48
- afterAll(() => {
49
- process.env = OLD_ENV;
50
- });
51
- test('prints dry run data for a valid uninstrumentation', () => __awaiter(void 0, void 0, void 0, function* () {
52
- ;
53
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
54
- aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
55
- 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument': {
56
- Architectures: ['x86_64'],
57
- Environment: {
58
- Variables: {
59
- [constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
60
- [constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
61
- [constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
62
- [constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
63
- [constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
64
- [constants_1.SERVICE_ENV_VAR]: 'middletier',
65
- [constants_1.SITE_ENV_VAR]: 'datadoghq.com',
66
- [constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
67
- [constants_1.VERSION_ENV_VAR]: '0.2',
68
- USER_VARIABLE: 'shouldnt be deleted by uninstrumentation',
41
+ describe('lambda', () => {
42
+ describe('uninstrument', () => {
43
+ describe('execute', () => {
44
+ const OLD_ENV = process.env;
45
+ beforeEach(() => {
46
+ jest.resetModules();
47
+ process.env = {};
48
+ });
49
+ afterAll(() => {
50
+ process.env = OLD_ENV;
51
+ });
52
+ test('prints dry run data for a valid uninstrumentation', () => __awaiter(void 0, void 0, void 0, function* () {
53
+ ;
54
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
55
+ aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
56
+ 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument': {
57
+ Architectures: ['x86_64'],
58
+ Environment: {
59
+ Variables: {
60
+ [constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
61
+ [constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
62
+ [constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
63
+ [constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
64
+ [constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
65
+ [constants_1.SERVICE_ENV_VAR]: 'middletier',
66
+ [constants_1.SITE_ENV_VAR]: 'datadoghq.com',
67
+ [constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
68
+ [constants_1.VERSION_ENV_VAR]: '0.2',
69
+ USER_VARIABLE: 'shouldnt be deleted by uninstrumentation',
70
+ },
69
71
  },
72
+ FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument',
73
+ Handler: 'datadog_lambda.handler.handler',
74
+ Layers: [
75
+ {
76
+ Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Extension:11',
77
+ CodeSize: 0,
78
+ SigningJobArn: 'some-signing-job-arn',
79
+ SigningProfileVersionArn: 'some-signing-profile',
80
+ },
81
+ {
82
+ Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Python38:49',
83
+ CodeSize: 0,
84
+ SigningJobArn: 'some-signing-job-arn',
85
+ SigningProfileVersionArn: 'some-signing-profile',
86
+ },
87
+ ],
88
+ Runtime: 'python3.8',
70
89
  },
71
- FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument',
72
- Handler: 'datadog_lambda.handler.handler',
73
- Layers: [
74
- {
75
- Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Extension:11',
76
- CodeSize: 0,
77
- SigningJobArn: 'some-signing-job-arn',
78
- SigningProfileVersionArn: 'some-signing-profile',
79
- },
80
- {
81
- Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Python38:49',
82
- CodeSize: 0,
83
- SigningJobArn: 'some-signing-job-arn',
84
- SigningProfileVersionArn: 'some-signing-profile',
85
- },
86
- ],
87
- Runtime: 'python3.8',
88
- },
90
+ }));
91
+ const cli = fixtures_1.makeCli();
92
+ const context = fixtures_1.createMockContext();
93
+ const functionARN = 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument';
94
+ process.env.DATADOG_API_KEY = '1234';
95
+ const code = yield cli.run(['lambda', 'uninstrument', '-f', functionARN, '-r', 'us-east-1', '-d'], context);
96
+ const output = context.stdout.toString();
97
+ expect(code).toBe(0);
98
+ expect(output).toMatchInlineSnapshot(`
99
+ "
100
+ [Dry Run] 🐶 Uninstrumenting Lambda function
101
+
102
+ [!] Functions to be updated:
103
+ - arn:aws:lambda:us-east-1:000000000000:function:uninstrument
104
+
105
+ [Dry Run] Will apply the following updates:
106
+ UpdateFunctionConfiguration -> arn:aws:lambda:us-east-1:000000000000:function:uninstrument
107
+ {
108
+ \\"FunctionName\\": \\"arn:aws:lambda:us-east-1:000000000000:function:uninstrument\\",
109
+ \\"Handler\\": \\"lambda_function.lambda_handler\\",
110
+ \\"Environment\\": {
111
+ \\"Variables\\": {
112
+ \\"USER_VARIABLE\\": \\"shouldnt be deleted by uninstrumentation\\"
113
+ }
114
+ },
115
+ \\"Layers\\": []
116
+ }
117
+ "
118
+ `);
89
119
  }));
90
- const cli = fixtures_1.makeCli();
91
- const context = fixtures_1.createMockContext();
92
- const functionARN = 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument';
93
- process.env.DATADOG_API_KEY = '1234';
94
- const code = yield cli.run(['lambda', 'uninstrument', '-f', functionARN, '-r', 'us-east-1', '-d'], context);
95
- const output = context.stdout.toString();
96
- expect(code).toBe(0);
97
- expect(output).toMatchInlineSnapshot(`
98
- "\n[Dry Run] 🐶 Uninstrumenting Lambda function
99
- \n[!] Functions to be updated:
100
- \t- arn:aws:lambda:us-east-1:000000000000:function:uninstrument\n
101
- [Dry Run] Will apply the following updates:
102
- UpdateFunctionConfiguration -> arn:aws:lambda:us-east-1:000000000000:function:uninstrument
103
- {
104
- \\"FunctionName\\": \\"arn:aws:lambda:us-east-1:000000000000:function:uninstrument\\",
105
- \\"Handler\\": \\"lambda_function.lambda_handler\\",
106
- \\"Environment\\": {
107
- \\"Variables\\": {
108
- \\"USER_VARIABLE\\": \\"shouldnt be deleted by uninstrumentation\\"
109
- }
110
- },
111
- \\"Layers\\": []
112
- }
113
- "
114
- `);
115
- }));
116
- test('runs function update command for valid uninstrumentation', () => __awaiter(void 0, void 0, void 0, function* () {
117
- ;
118
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
119
- const lambda = fixtures_1.makeMockLambda({
120
- 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument': {
121
- Environment: {
122
- Variables: {
123
- [constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
124
- [constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
125
- [constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
126
- [constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
127
- [constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
128
- [constants_1.SERVICE_ENV_VAR]: 'middletier',
129
- [constants_1.SITE_ENV_VAR]: 'datadoghq.com',
130
- [constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
131
- [constants_1.VERSION_ENV_VAR]: '0.2',
132
- USER_VARIABLE: 'shouldnt be deleted by uninstrumentation',
120
+ test('runs function update command for valid uninstrumentation', () => __awaiter(void 0, void 0, void 0, function* () {
121
+ ;
122
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
123
+ const lambda = fixtures_1.makeMockLambda({
124
+ 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument': {
125
+ Environment: {
126
+ Variables: {
127
+ [constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
128
+ [constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
129
+ [constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
130
+ [constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
131
+ [constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
132
+ [constants_1.SERVICE_ENV_VAR]: 'middletier',
133
+ [constants_1.SITE_ENV_VAR]: 'datadoghq.com',
134
+ [constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
135
+ [constants_1.VERSION_ENV_VAR]: '0.2',
136
+ USER_VARIABLE: 'shouldnt be deleted by uninstrumentation',
137
+ },
133
138
  },
139
+ FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument',
140
+ Handler: 'datadog_lambda.handler.handler',
141
+ Layers: [
142
+ {
143
+ Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Extension:11',
144
+ CodeSize: 0,
145
+ SigningJobArn: 'some-signing-job-arn',
146
+ SigningProfileVersionArn: 'some-signing-profile',
147
+ },
148
+ {
149
+ Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Python38:49',
150
+ CodeSize: 0,
151
+ SigningJobArn: 'some-signing-job-arn',
152
+ SigningProfileVersionArn: 'some-signing-profile',
153
+ },
154
+ ],
155
+ Runtime: 'python3.8',
134
156
  },
135
- FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument',
136
- Handler: 'datadog_lambda.handler.handler',
137
- Layers: [
138
- {
139
- Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Extension:11',
140
- CodeSize: 0,
141
- SigningJobArn: 'some-signing-job-arn',
142
- SigningProfileVersionArn: 'some-signing-profile',
143
- },
144
- {
145
- Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Python38:49',
146
- CodeSize: 0,
147
- SigningJobArn: 'some-signing-job-arn',
148
- SigningProfileVersionArn: 'some-signing-profile',
149
- },
150
- ],
151
- Runtime: 'python3.8',
152
- },
153
- });
154
- aws_sdk_1.Lambda.mockImplementation(() => lambda);
155
- const cli = fixtures_1.makeCli();
156
- const context = fixtures_1.createMockContext();
157
- const functionARN = 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument';
158
- process.env.DATADOG_API_KEY = '1234';
159
- yield cli.run(['lambda', 'uninstrument', '-f', functionARN, '-r', 'us-east-1'], context);
160
- expect(lambda.updateFunctionConfiguration).toHaveBeenCalled();
161
- }));
162
- test('aborts early when the aws-sdk throws an error', () => __awaiter(void 0, void 0, void 0, function* () {
163
- ;
164
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
165
- aws_sdk_1.Lambda.mockImplementation(() => ({
166
- getFunction: jest.fn().mockImplementation(() => ({ promise: () => Promise.reject('Lambda failed') })),
157
+ });
158
+ aws_sdk_1.Lambda.mockImplementation(() => lambda);
159
+ const cli = fixtures_1.makeCli();
160
+ const context = fixtures_1.createMockContext();
161
+ const functionARN = 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument';
162
+ process.env.DATADOG_API_KEY = '1234';
163
+ yield cli.run(['lambda', 'uninstrument', '-f', functionARN, '-r', 'us-east-1'], context);
164
+ expect(lambda.updateFunctionConfiguration).toHaveBeenCalled();
165
+ }));
166
+ test('aborts early when the aws-sdk throws an error', () => __awaiter(void 0, void 0, void 0, function* () {
167
+ ;
168
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
169
+ aws_sdk_1.Lambda.mockImplementation(() => ({
170
+ getFunction: jest.fn().mockImplementation(() => ({ promise: () => Promise.reject('Lambda failed') })),
171
+ }));
172
+ process.env = {};
173
+ const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
174
+ command['functions'] = ['my-func'];
175
+ command['region'] = 'us-east-1';
176
+ const code = yield command['execute']();
177
+ const output = command.context.stdout.toString();
178
+ expect(code).toBe(1);
179
+ expect(output).toMatch("[Error] Couldn't fetch Lambda functions. Lambda failed\n");
167
180
  }));
168
- process.env = {};
169
- const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
170
- command['functions'] = ['my-func'];
171
- command['region'] = 'us-east-1';
172
- const code = yield command['execute']();
173
- const output = command.context.stdout.toString();
174
- expect(code).toBe(1);
175
- expect(output).toMatch("[Error] Couldn't fetch Lambda functions. Lambda failed\n");
176
- }));
177
- test("aborts early when function regions can't be found", () => __awaiter(void 0, void 0, void 0, function* () {
178
- ;
179
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
180
- aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}));
181
- const cli = fixtures_1.makeCli();
182
- const context = fixtures_1.createMockContext();
183
- const code = yield cli.run(['lambda', 'uninstrument', '--function', 'my-func'], context);
184
- const output = context.stdout.toString();
185
- expect(code).toBe(1);
186
- expect(output).toMatch('No default region specified for ["my-func"]. Use -r, --region, or use a full functionARN');
187
- }));
188
- test('aborts early when no functions are specified', () => __awaiter(void 0, void 0, void 0, function* () {
189
- ;
190
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
191
- aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}));
192
- const cli = fixtures_1.makeCli();
193
- const context = fixtures_1.createMockContext();
194
- const code = yield cli.run(['lambda', 'uninstrument'], context);
195
- const output = context.stdout.toString();
196
- expect(code).toBe(1);
197
- expect(output).toMatchInlineSnapshot(`
198
- "\n🐶 Uninstrumenting Lambda function
199
- [Error] No functions specified to remove instrumentation.
200
- "
201
- `);
202
- }));
203
- test('aborts early when no functions are specified while using config file', () => __awaiter(void 0, void 0, void 0, function* () {
204
- ;
205
- fs.readFile.mockImplementation((a, b, callback) => callback({}));
206
- process.env = {};
207
- const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
208
- command['config']['region'] = 'ap-southeast-1';
209
- yield command['execute']();
210
- const output = command.context.stdout.toString();
211
- expect(output).toMatchInlineSnapshot(`
212
- "\n🐶 Uninstrumenting Lambda function
213
- [Error] No functions specified to remove instrumentation.
214
- "
215
- `);
216
- }));
217
- test('aborts if functions and a pattern are set at the same time', () => __awaiter(void 0, void 0, void 0, function* () {
218
- ;
219
- fs.readFile.mockImplementation((a, b, callback) => callback({}));
220
- process.env = {};
221
- let command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
222
- command['config']['region'] = 'ap-southeast-1';
223
- command['config']['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
224
- command['regExPattern'] = 'valid-pattern';
225
- yield command['execute']();
226
- let output = command.context.stdout.toString();
227
- expect(output).toMatch('Functions in config file and "--functions-regex" should not be used at the same time.\n');
228
- command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
229
- command['region'] = 'ap-southeast-1';
230
- command['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
231
- command['regExPattern'] = 'valid-pattern';
232
- yield command['execute']();
233
- output = command.context.stdout.toString();
234
- expect(output).toMatch('"--functions" and "--functions-regex" should not be used at the same time.\n');
235
- }));
236
- test('aborts if the regEx pattern is an ARN', () => __awaiter(void 0, void 0, void 0, function* () {
237
- ;
238
- fs.readFile.mockImplementation((a, b, callback) => callback({}));
239
- process.env = {};
240
- const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
241
- command['region'] = 'ap-southeast-1';
242
- command['regExPattern'] = 'arn:aws:lambda:ap-southeast-1:123456789012:function:*';
243
- const code = yield command['execute']();
244
- const output = command.context.stdout.toString();
245
- expect(code).toBe(1);
246
- expect(output).toMatch(`"--functions-regex" isn't meant to be used with ARNs.\n`);
247
- }));
248
- test('aborts if the regEx pattern is set but no region is specified', () => __awaiter(void 0, void 0, void 0, function* () {
249
- ;
250
- fs.readFile.mockImplementation((a, b, callback) => callback({}));
251
- process.env = {};
252
- const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
253
- command['regExPattern'] = 'my-function';
254
- const code = yield command['execute']();
255
- const output = command.context.stdout.toString();
256
- expect(code).toBe(1);
257
- expect(output).toMatch('No default region specified. Use `-r`, `--region`.');
258
- }));
259
- test('aborts if the the aws-sdk fails', () => __awaiter(void 0, void 0, void 0, function* () {
260
- ;
261
- fs.readFile.mockImplementation((a, b, callback) => callback({}));
262
- aws_sdk_1.Lambda.mockImplementation(() => ({
263
- listFunctions: jest.fn().mockImplementation(() => ({ promise: () => Promise.reject('ListFunctionsError') })),
181
+ test("aborts early when function regions can't be found", () => __awaiter(void 0, void 0, void 0, function* () {
182
+ ;
183
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
184
+ aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}));
185
+ const cli = fixtures_1.makeCli();
186
+ const context = fixtures_1.createMockContext();
187
+ const code = yield cli.run(['lambda', 'uninstrument', '--function', 'my-func'], context);
188
+ const output = context.stdout.toString();
189
+ expect(code).toBe(1);
190
+ expect(output).toMatch('No default region specified for ["my-func"]. Use -r, --region, or use a full functionARN');
264
191
  }));
265
- process.env = {};
266
- aws_sdk_1.Lambda.mockImplementation(() => ({
267
- listFunctions: jest.fn().mockImplementation(() => ({ promise: () => Promise.reject('ListFunctionsError') })),
192
+ test('aborts early when no functions are specified', () => __awaiter(void 0, void 0, void 0, function* () {
193
+ ;
194
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
195
+ aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}));
196
+ const cli = fixtures_1.makeCli();
197
+ const context = fixtures_1.createMockContext();
198
+ const code = yield cli.run(['lambda', 'uninstrument'], context);
199
+ const output = context.stdout.toString();
200
+ expect(code).toBe(1);
201
+ expect(output).toMatchInlineSnapshot(`
202
+ "
203
+ 🐶 Uninstrumenting Lambda function
204
+ [Error] No functions specified to remove instrumentation.
205
+ "
206
+ `);
268
207
  }));
269
- const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
270
- command['region'] = 'ap-southeast-1';
271
- command['regExPattern'] = 'my-function';
272
- const code = yield command['execute']();
273
- const output = command.context.stdout.toString();
274
- expect(code).toBe(1);
275
- expect(output).toMatch("\n[Error] Couldn't fetch Lambda functions. Error: Max retry count exceeded. ListFunctionsError\n");
276
- }));
277
- test('uninstrument multiple functions interactively', () => __awaiter(void 0, void 0, void 0, function* () {
278
- ;
279
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
280
- aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
281
- 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world': {
282
- Architectures: ['x86_64'],
283
- Environment: {
284
- Variables: {
285
- [constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
286
- [constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
287
- [constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
288
- [constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
289
- [constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
290
- [constants_1.SERVICE_ENV_VAR]: 'middletier',
291
- [constants_1.SITE_ENV_VAR]: 'datadoghq.com',
292
- [constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
293
- [constants_1.VERSION_ENV_VAR]: '0.2',
294
- USER_VARIABLE: 'shouldnt be deleted by uninstrumentation',
208
+ test('aborts early when no functions are specified while using config file', () => __awaiter(void 0, void 0, void 0, function* () {
209
+ ;
210
+ fs.readFile.mockImplementation((a, b, callback) => callback({}));
211
+ process.env = {};
212
+ const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
213
+ command['config']['region'] = 'ap-southeast-1';
214
+ yield command['execute']();
215
+ const output = command.context.stdout.toString();
216
+ expect(output).toMatchInlineSnapshot(`
217
+ "
218
+ 🐶 Uninstrumenting Lambda function
219
+ [Error] No functions specified to remove instrumentation.
220
+ "
221
+ `);
222
+ }));
223
+ test('aborts if functions and a pattern are set at the same time', () => __awaiter(void 0, void 0, void 0, function* () {
224
+ ;
225
+ fs.readFile.mockImplementation((a, b, callback) => callback({}));
226
+ process.env = {};
227
+ let command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
228
+ command['config']['region'] = 'ap-southeast-1';
229
+ command['config']['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
230
+ command['regExPattern'] = 'valid-pattern';
231
+ yield command['execute']();
232
+ let output = command.context.stdout.toString();
233
+ expect(output).toMatch('Functions in config file and "--functions-regex" should not be used at the same time.\n');
234
+ command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
235
+ command['region'] = 'ap-southeast-1';
236
+ command['functions'] = ['arn:aws:lambda:ap-southeast-1:123456789012:function:lambda-hello-world'];
237
+ command['regExPattern'] = 'valid-pattern';
238
+ yield command['execute']();
239
+ output = command.context.stdout.toString();
240
+ expect(output).toMatch('"--functions" and "--functions-regex" should not be used at the same time.\n');
241
+ }));
242
+ test('aborts if the regEx pattern is an ARN', () => __awaiter(void 0, void 0, void 0, function* () {
243
+ ;
244
+ fs.readFile.mockImplementation((a, b, callback) => callback({}));
245
+ process.env = {};
246
+ const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
247
+ command['region'] = 'ap-southeast-1';
248
+ command['regExPattern'] = 'arn:aws:lambda:ap-southeast-1:123456789012:function:*';
249
+ const code = yield command['execute']();
250
+ const output = command.context.stdout.toString();
251
+ expect(code).toBe(1);
252
+ expect(output).toMatch(`"--functions-regex" isn't meant to be used with ARNs.\n`);
253
+ }));
254
+ test('aborts if the regEx pattern is set but no region is specified', () => __awaiter(void 0, void 0, void 0, function* () {
255
+ ;
256
+ fs.readFile.mockImplementation((a, b, callback) => callback({}));
257
+ process.env = {};
258
+ const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
259
+ command['regExPattern'] = 'my-function';
260
+ const code = yield command['execute']();
261
+ const output = command.context.stdout.toString();
262
+ expect(code).toBe(1);
263
+ expect(output).toMatch('No default region specified. Use `-r`, `--region`.');
264
+ }));
265
+ test('aborts if the the aws-sdk fails', () => __awaiter(void 0, void 0, void 0, function* () {
266
+ ;
267
+ fs.readFile.mockImplementation((a, b, callback) => callback({}));
268
+ aws_sdk_1.Lambda.mockImplementation(() => ({
269
+ listFunctions: jest.fn().mockImplementation(() => ({ promise: () => Promise.reject('ListFunctionsError') })),
270
+ }));
271
+ process.env = {};
272
+ aws_sdk_1.Lambda.mockImplementation(() => ({
273
+ listFunctions: jest.fn().mockImplementation(() => ({ promise: () => Promise.reject('ListFunctionsError') })),
274
+ }));
275
+ const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
276
+ command['region'] = 'ap-southeast-1';
277
+ command['regExPattern'] = 'my-function';
278
+ const code = yield command['execute']();
279
+ const output = command.context.stdout.toString();
280
+ expect(code).toBe(1);
281
+ expect(output).toMatch("\n[Error] Couldn't fetch Lambda functions. Error: Max retry count exceeded. ListFunctionsError\n");
282
+ }));
283
+ test('uninstrument multiple functions interactively', () => __awaiter(void 0, void 0, void 0, function* () {
284
+ ;
285
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
286
+ aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
287
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world': {
288
+ Architectures: ['x86_64'],
289
+ Environment: {
290
+ Variables: {
291
+ [constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
292
+ [constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
293
+ [constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
294
+ [constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
295
+ [constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
296
+ [constants_1.SERVICE_ENV_VAR]: 'middletier',
297
+ [constants_1.SITE_ENV_VAR]: 'datadoghq.com',
298
+ [constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
299
+ [constants_1.VERSION_ENV_VAR]: '0.2',
300
+ USER_VARIABLE: 'shouldnt be deleted by uninstrumentation',
301
+ },
295
302
  },
303
+ FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
304
+ FunctionName: 'lambda-hello-world',
305
+ Handler: 'datadog_lambda.handler.handler',
306
+ Layers: [
307
+ {
308
+ Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Extension:11',
309
+ CodeSize: 0,
310
+ SigningJobArn: 'some-signing-job-arn',
311
+ SigningProfileVersionArn: 'some-signing-profile',
312
+ },
313
+ {
314
+ Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Python38:49',
315
+ CodeSize: 0,
316
+ SigningJobArn: 'some-signing-job-arn',
317
+ SigningProfileVersionArn: 'some-signing-profile',
318
+ },
319
+ ],
320
+ Runtime: 'python3.8',
296
321
  },
297
- FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
298
- FunctionName: 'lambda-hello-world',
299
- Handler: 'datadog_lambda.handler.handler',
300
- Layers: [
301
- {
302
- Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Extension:11',
303
- CodeSize: 0,
304
- SigningJobArn: 'some-signing-job-arn',
305
- SigningProfileVersionArn: 'some-signing-profile',
306
- },
307
- {
308
- Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Python38:49',
309
- CodeSize: 0,
310
- SigningJobArn: 'some-signing-job-arn',
311
- SigningProfileVersionArn: 'some-signing-profile',
312
- },
313
- ],
314
- Runtime: 'python3.8',
315
- },
316
- 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2': {
317
- Architectures: ['x86_64'],
318
- Environment: {
319
- Variables: {
320
- [constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
321
- [constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
322
- [constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
323
- [constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
324
- [constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
325
- [constants_1.SERVICE_ENV_VAR]: 'middletier',
326
- [constants_1.SITE_ENV_VAR]: 'datadoghq.com',
327
- [constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
328
- [constants_1.VERSION_ENV_VAR]: '0.2',
322
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2': {
323
+ Architectures: ['x86_64'],
324
+ Environment: {
325
+ Variables: {
326
+ [constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
327
+ [constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
328
+ [constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
329
+ [constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
330
+ [constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
331
+ [constants_1.SERVICE_ENV_VAR]: 'middletier',
332
+ [constants_1.SITE_ENV_VAR]: 'datadoghq.com',
333
+ [constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
334
+ [constants_1.VERSION_ENV_VAR]: '0.2',
335
+ },
329
336
  },
337
+ FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
338
+ FunctionName: 'lambda-hello-world-2',
339
+ Handler: 'datadog_lambda.handler.handler',
340
+ Layers: [
341
+ {
342
+ Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Extension:11',
343
+ CodeSize: 0,
344
+ SigningJobArn: 'some-signing-job-arn',
345
+ SigningProfileVersionArn: 'some-signing-profile',
346
+ },
347
+ {
348
+ Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Python39:49',
349
+ CodeSize: 0,
350
+ SigningJobArn: 'some-signing-job-arn',
351
+ SigningProfileVersionArn: 'some-signing-profile',
352
+ },
353
+ ],
354
+ Runtime: 'python3.9',
330
355
  },
331
- FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
332
- FunctionName: 'lambda-hello-world-2',
333
- Handler: 'datadog_lambda.handler.handler',
334
- Layers: [
335
- {
336
- Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Extension:11',
337
- CodeSize: 0,
338
- SigningJobArn: 'some-signing-job-arn',
339
- SigningProfileVersionArn: 'some-signing-profile',
340
- },
341
- {
342
- Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Python39:49',
343
- CodeSize: 0,
344
- SigningJobArn: 'some-signing-job-arn',
345
- SigningProfileVersionArn: 'some-signing-profile',
346
- },
347
- ],
348
- Runtime: 'python3.9',
349
- },
356
+ }));
357
+ prompt_1.requestAWSCredentials.mockImplementation(() => {
358
+ process.env[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR] = fixtures_1.mockAwsAccessKeyId;
359
+ process.env[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR] = fixtures_1.mockAwsSecretAccessKey;
360
+ process.env[constants_1.AWS_DEFAULT_REGION_ENV_VAR] = 'sa-east-1';
361
+ });
362
+ prompt_1.requestFunctionSelection.mockImplementation(() => [
363
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
364
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
365
+ ]);
366
+ prompt_1.requestChangesConfirmation.mockImplementation(() => true);
367
+ const cli = fixtures_1.makeCli();
368
+ const context = fixtures_1.createMockContext();
369
+ const code = yield cli.run(['lambda', 'uninstrument', '-i'], context);
370
+ const output = context.stdout.toString();
371
+ expect(code).toBe(0);
372
+ expect(output).toMatchSnapshot();
350
373
  }));
351
- prompt_1.requestAWSCredentials.mockImplementation(() => {
352
- process.env[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR] = fixtures_1.mockAwsAccessKeyId;
353
- process.env[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR] = fixtures_1.mockAwsSecretAccessKey;
354
- process.env[constants_1.AWS_DEFAULT_REGION_ENV_VAR] = 'sa-east-1';
355
- });
356
- prompt_1.requestFunctionSelection.mockImplementation(() => [
357
- 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
358
- 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
359
- ]);
360
- prompt_1.requestChangesConfirmation.mockImplementation(() => true);
361
- const cli = fixtures_1.makeCli();
362
- const context = fixtures_1.createMockContext();
363
- const code = yield cli.run(['lambda', 'uninstrument', '-i'], context);
364
- const output = context.stdout.toString();
365
- expect(code).toBe(0);
366
- expect(output).toMatchInlineSnapshot(`
367
- "\n🐶 Uninstrumenting Lambda function
368
- [!] No AWS credentials found, let's set them up! Or you can re-run the command and supply the AWS credentials in the same way when you invoke the AWS CLI.
369
- \n[!] Functions to be updated:
370
- \t- arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
371
- \t- arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2\n
372
- Will apply the following updates:
373
- UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
374
- {
375
- \\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world\\",
376
- \\"Handler\\": \\"lambda_function.lambda_handler\\",
377
- \\"Environment\\": {
378
- \\"Variables\\": {
379
- \\"USER_VARIABLE\\": \\"shouldnt be deleted by uninstrumentation\\"
380
- }
381
- },
382
- \\"Layers\\": []
383
- }
384
- UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2
385
- {
386
- \\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2\\",
387
- \\"Handler\\": \\"lambda_function.lambda_handler\\",
388
- \\"Environment\\": {
389
- \\"Variables\\": {}
390
- },
391
- \\"Layers\\": []
392
- }
393
- [!] Confirmation needed.
394
- [!] Uninstrumenting functions.
395
- "
396
- `);
397
- }));
398
- test('uninstrument multiple specified functions interactively', () => __awaiter(void 0, void 0, void 0, function* () {
399
- ;
400
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
401
- aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
402
- 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world': {
403
- Architectures: ['x86_64'],
404
- Environment: {
405
- Variables: {
406
- [constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
407
- [constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
408
- [constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
409
- [constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
410
- [constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
411
- [constants_1.SERVICE_ENV_VAR]: 'middletier',
412
- [constants_1.SITE_ENV_VAR]: 'datadoghq.com',
413
- [constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
414
- [constants_1.VERSION_ENV_VAR]: '0.2',
415
- USER_VARIABLE: 'shouldnt be deleted by uninstrumentation',
374
+ test('uninstrument multiple specified functions interactively', () => __awaiter(void 0, void 0, void 0, function* () {
375
+ ;
376
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
377
+ aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({
378
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world': {
379
+ Architectures: ['x86_64'],
380
+ Environment: {
381
+ Variables: {
382
+ [constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
383
+ [constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
384
+ [constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
385
+ [constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
386
+ [constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
387
+ [constants_1.SERVICE_ENV_VAR]: 'middletier',
388
+ [constants_1.SITE_ENV_VAR]: 'datadoghq.com',
389
+ [constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
390
+ [constants_1.VERSION_ENV_VAR]: '0.2',
391
+ USER_VARIABLE: 'shouldnt be deleted by uninstrumentation',
392
+ },
416
393
  },
394
+ FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
395
+ FunctionName: 'lambda-hello-world',
396
+ Handler: 'datadog_lambda.handler.handler',
397
+ Layers: [
398
+ {
399
+ Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Extension:11',
400
+ CodeSize: 0,
401
+ SigningJobArn: 'some-signing-job-arn',
402
+ SigningProfileVersionArn: 'some-signing-profile',
403
+ },
404
+ {
405
+ Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Python38:49',
406
+ CodeSize: 0,
407
+ SigningJobArn: 'some-signing-job-arn',
408
+ SigningProfileVersionArn: 'some-signing-profile',
409
+ },
410
+ ],
411
+ Runtime: 'python3.8',
417
412
  },
418
- FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
419
- FunctionName: 'lambda-hello-world',
420
- Handler: 'datadog_lambda.handler.handler',
421
- Layers: [
422
- {
423
- Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Extension:11',
424
- CodeSize: 0,
425
- SigningJobArn: 'some-signing-job-arn',
426
- SigningProfileVersionArn: 'some-signing-profile',
427
- },
428
- {
429
- Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Python38:49',
430
- CodeSize: 0,
431
- SigningJobArn: 'some-signing-job-arn',
432
- SigningProfileVersionArn: 'some-signing-profile',
433
- },
434
- ],
435
- Runtime: 'python3.8',
436
- },
437
- 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2': {
438
- Architectures: ['x86_64'],
439
- Environment: {
440
- Variables: {
441
- [constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
442
- [constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
443
- [constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
444
- [constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
445
- [constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
446
- [constants_1.SERVICE_ENV_VAR]: 'middletier',
447
- [constants_1.SITE_ENV_VAR]: 'datadoghq.com',
448
- [constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
449
- [constants_1.VERSION_ENV_VAR]: '0.2',
413
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2': {
414
+ Architectures: ['x86_64'],
415
+ Environment: {
416
+ Variables: {
417
+ [constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
418
+ [constants_1.FLUSH_TO_LOG_ENV_VAR]: 'true',
419
+ [constants_1.LAMBDA_HANDLER_ENV_VAR]: 'lambda_function.lambda_handler',
420
+ [constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
421
+ [constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
422
+ [constants_1.SERVICE_ENV_VAR]: 'middletier',
423
+ [constants_1.SITE_ENV_VAR]: 'datadoghq.com',
424
+ [constants_1.TRACE_ENABLED_ENV_VAR]: 'true',
425
+ [constants_1.VERSION_ENV_VAR]: '0.2',
426
+ },
450
427
  },
428
+ FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
429
+ FunctionName: 'lambda-hello-world-2',
430
+ Handler: 'datadog_lambda.handler.handler',
431
+ Layers: [
432
+ {
433
+ Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Extension:11',
434
+ CodeSize: 0,
435
+ SigningJobArn: 'some-signing-job-arn',
436
+ SigningProfileVersionArn: 'some-signing-profile',
437
+ },
438
+ {
439
+ Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Python39:49',
440
+ CodeSize: 0,
441
+ SigningJobArn: 'some-signing-job-arn',
442
+ SigningProfileVersionArn: 'some-signing-profile',
443
+ },
444
+ ],
445
+ Runtime: 'python3.9',
451
446
  },
452
- FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
453
- FunctionName: 'lambda-hello-world-2',
454
- Handler: 'datadog_lambda.handler.handler',
455
- Layers: [
456
- {
457
- Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Extension:11',
458
- CodeSize: 0,
459
- SigningJobArn: 'some-signing-job-arn',
460
- SigningProfileVersionArn: 'some-signing-profile',
461
- },
462
- {
463
- Arn: 'arn:aws:lambda:sa-east-1:000000000000:layer:Datadog-Python39:49',
464
- CodeSize: 0,
465
- SigningJobArn: 'some-signing-job-arn',
466
- SigningProfileVersionArn: 'some-signing-profile',
467
- },
468
- ],
469
- Runtime: 'python3.9',
470
- },
447
+ }));
448
+ prompt_1.requestAWSCredentials.mockImplementation(() => {
449
+ process.env[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR] = fixtures_1.mockAwsAccessKeyId;
450
+ process.env[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR] = fixtures_1.mockAwsSecretAccessKey;
451
+ process.env[constants_1.AWS_DEFAULT_REGION_ENV_VAR] = 'sa-east-1';
452
+ });
453
+ prompt_1.requestFunctionSelection.mockImplementation(() => [
454
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
455
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
456
+ ]);
457
+ prompt_1.requestChangesConfirmation.mockImplementation(() => true);
458
+ const cli = fixtures_1.makeCli();
459
+ const context = fixtures_1.createMockContext();
460
+ const code = yield cli.run([
461
+ 'lambda',
462
+ 'uninstrument',
463
+ '-i',
464
+ '-f',
465
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
466
+ '-f',
467
+ 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
468
+ ], context);
469
+ const output = context.stdout.toString();
470
+ expect(code).toBe(0);
471
+ expect(output).toMatchSnapshot();
471
472
  }));
472
- prompt_1.requestAWSCredentials.mockImplementation(() => {
473
- process.env[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR] = fixtures_1.mockAwsAccessKeyId;
474
- process.env[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR] = fixtures_1.mockAwsSecretAccessKey;
475
- process.env[constants_1.AWS_DEFAULT_REGION_ENV_VAR] = 'sa-east-1';
476
- });
477
- prompt_1.requestFunctionSelection.mockImplementation(() => [
478
- 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
479
- 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
480
- ]);
481
- prompt_1.requestChangesConfirmation.mockImplementation(() => true);
482
- const cli = fixtures_1.makeCli();
483
- const context = fixtures_1.createMockContext();
484
- const code = yield cli.run([
485
- 'lambda',
486
- 'uninstrument',
487
- '-i',
488
- '-f',
489
- 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
490
- '-f',
491
- 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2',
492
- ], context);
493
- const output = context.stdout.toString();
494
- expect(code).toBe(0);
495
- expect(output).toMatchInlineSnapshot(`
496
- "\n🐶 Uninstrumenting Lambda function
497
- [!] No AWS credentials found, let's set them up! Or you can re-run the command and supply the AWS credentials in the same way when you invoke the AWS CLI.\n
498
- [!] Functions to be updated:
499
- \t- arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
500
- \t- arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2\n
501
- Will apply the following updates:
502
- UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world
503
- {
504
- \\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world\\",
505
- \\"Handler\\": \\"lambda_function.lambda_handler\\",
506
- \\"Environment\\": {
507
- \\"Variables\\": {
508
- \\"USER_VARIABLE\\": \\"shouldnt be deleted by uninstrumentation\\"
509
- }
510
- },
511
- \\"Layers\\": []
512
- }
513
- UpdateFunctionConfiguration -> arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2
514
- {
515
- \\"FunctionName\\": \\"arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world-2\\",
516
- \\"Handler\\": \\"lambda_function.lambda_handler\\",
517
- \\"Environment\\": {
518
- \\"Variables\\": {}
519
- },
520
- \\"Layers\\": []
521
- }
522
- [!] Confirmation needed.
523
- [!] Uninstrumenting functions.
524
- "
525
- `);
526
- }));
527
- test('aborts if a problem occurs while setting the AWS credentials interactively', () => __awaiter(void 0, void 0, void 0, function* () {
528
- ;
529
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
530
- prompt_1.requestAWSCredentials.mockImplementation(() => Promise.reject('Unexpected error'));
531
- const cli = fixtures_1.makeCli();
532
- const context = fixtures_1.createMockContext();
533
- const code = yield cli.run(['lambda', 'uninstrument', '-i'], context);
534
- const output = context.stdout.toString();
535
- expect(code).toBe(1);
536
- expect(output).toMatchInlineSnapshot(`
537
- "\n🐶 Uninstrumenting Lambda function
538
- [!] No AWS credentials found, let's set them up! Or you can re-run the command and supply the AWS credentials in the same way when you invoke the AWS CLI.
539
- [Error] Unexpected error
540
- "
541
- `);
542
- }));
543
- test('aborts if there are no functions to uninstrument in the user AWS account', () => __awaiter(void 0, void 0, void 0, function* () {
544
- process.env = {
545
- [constants_1.AWS_ACCESS_KEY_ID_ENV_VAR]: fixtures_1.mockAwsAccessKeyId,
546
- [constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR]: fixtures_1.mockAwsSecretAccessKey,
547
- [constants_1.AWS_DEFAULT_REGION_ENV_VAR]: 'sa-east-1',
548
- };
549
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
550
- aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}));
551
- const cli = fixtures_1.makeCli();
552
- const context = fixtures_1.createMockContext();
553
- const code = yield cli.run(['lambda', 'uninstrument', '-i'], context);
554
- const output = context.stdout.toString();
555
- expect(code).toBe(1);
556
- expect(output).toMatchInlineSnapshot(`
557
- "\n🐶 Uninstrumenting Lambda function
558
- [Error] Couldn't find any Lambda functions in the specified region.
559
- "
560
- `);
561
- }));
562
- test('aborts early when the aws-sdk throws an error while uninstrumenting interactively', () => __awaiter(void 0, void 0, void 0, function* () {
563
- process.env = {
564
- [constants_1.AWS_ACCESS_KEY_ID_ENV_VAR]: fixtures_1.mockAwsAccessKeyId,
565
- [constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR]: fixtures_1.mockAwsSecretAccessKey,
566
- [constants_1.AWS_DEFAULT_REGION_ENV_VAR]: 'sa-east-1',
567
- };
568
- fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
569
- aws_sdk_1.Lambda.mockImplementation(() => ({
570
- listFunctions: jest.fn().mockImplementation(() => ({ promise: () => Promise.reject('ListFunctionsError') })),
473
+ test('aborts if a problem occurs while setting the AWS credentials interactively', () => __awaiter(void 0, void 0, void 0, function* () {
474
+ ;
475
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
476
+ prompt_1.requestAWSCredentials.mockImplementation(() => Promise.reject('Unexpected error'));
477
+ const cli = fixtures_1.makeCli();
478
+ const context = fixtures_1.createMockContext();
479
+ const code = yield cli.run(['lambda', 'uninstrument', '-i'], context);
480
+ const output = context.stdout.toString();
481
+ expect(code).toBe(1);
482
+ expect(output).toMatchInlineSnapshot(`
483
+ "
484
+ 🐶 Uninstrumenting Lambda function
485
+ [!] No AWS credentials found, let's set them up! Or you can re-run the command and supply the AWS credentials in the same way when you invoke the AWS CLI.
486
+ [Error] Unexpected error
487
+ "
488
+ `);
489
+ }));
490
+ test('aborts if there are no functions to uninstrument in the user AWS account', () => __awaiter(void 0, void 0, void 0, function* () {
491
+ process.env = {
492
+ [constants_1.AWS_ACCESS_KEY_ID_ENV_VAR]: fixtures_1.mockAwsAccessKeyId,
493
+ [constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR]: fixtures_1.mockAwsSecretAccessKey,
494
+ [constants_1.AWS_DEFAULT_REGION_ENV_VAR]: 'sa-east-1',
495
+ };
496
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
497
+ aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}));
498
+ const cli = fixtures_1.makeCli();
499
+ const context = fixtures_1.createMockContext();
500
+ const code = yield cli.run(['lambda', 'uninstrument', '-i'], context);
501
+ const output = context.stdout.toString();
502
+ expect(code).toBe(1);
503
+ expect(output).toMatchInlineSnapshot(`
504
+ "
505
+ 🐶 Uninstrumenting Lambda function
506
+ [Error] Couldn't find any Lambda functions in the specified region.
507
+ "
508
+ `);
509
+ }));
510
+ test('aborts early when the aws-sdk throws an error while uninstrumenting interactively', () => __awaiter(void 0, void 0, void 0, function* () {
511
+ process.env = {
512
+ [constants_1.AWS_ACCESS_KEY_ID_ENV_VAR]: fixtures_1.mockAwsAccessKeyId,
513
+ [constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR]: fixtures_1.mockAwsSecretAccessKey,
514
+ [constants_1.AWS_DEFAULT_REGION_ENV_VAR]: 'sa-east-1',
515
+ };
516
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
517
+ aws_sdk_1.Lambda.mockImplementation(() => ({
518
+ listFunctions: jest.fn().mockImplementation(() => ({ promise: () => Promise.reject('ListFunctionsError') })),
519
+ }));
520
+ const cli = fixtures_1.makeCli();
521
+ const context = fixtures_1.createMockContext();
522
+ const code = yield cli.run(['lambda', 'uninstrument', '-i'], context);
523
+ const output = context.stdout.toString();
524
+ expect(code).toBe(1);
525
+ expect(output).toMatchInlineSnapshot(`
526
+ "
527
+ 🐶 Uninstrumenting Lambda function
528
+ [Error] Couldn't fetch Lambda functions. Error: Max retry count exceeded. ListFunctionsError
529
+ "
530
+ `);
531
+ }));
532
+ test('prints error when updating aws profile credentials fails', () => __awaiter(void 0, void 0, void 0, function* () {
533
+ ;
534
+ aws_sdk_1.SharedIniFileCredentials.mockImplementation(() => {
535
+ throw Error('Update failed!');
536
+ });
537
+ const cli = fixtures_1.makeCli();
538
+ const context = fixtures_1.createMockContext();
539
+ const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
540
+ const code = yield cli.run(['lambda', 'uninstrument', '-f', functionARN, '--profile', 'SOME-AWS-PROFILE'], context);
541
+ const output = context.stdout.toString();
542
+ expect(code).toBe(1);
543
+ expect(output).toMatchInlineSnapshot(`
544
+ "
545
+ 🐶 Uninstrumenting Lambda function
546
+ [Error] Error: Couldn't set AWS profile credentials. Update failed!
547
+ "
548
+ `);
549
+ }));
550
+ test('prints which functions failed to uninstrument without aborting when at least one function was uninstrumented correctly', () => __awaiter(void 0, void 0, void 0, function* () {
551
+ ;
552
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
553
+ const failingLambdas = [
554
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
555
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-2-us-east-1',
556
+ 'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
557
+ ];
558
+ aws_sdk_1.Lambda.mockImplementation(() => (Object.assign(Object.assign({}, fixtures_1.makeMockLambda({
559
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1': {
560
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
561
+ FunctionName: 'lambda-1-us-east-1',
562
+ Handler: 'index.handler',
563
+ Runtime: 'nodejs12.x',
564
+ },
565
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-2-us-east-1': {
566
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-2-us-east-1',
567
+ FunctionName: 'lambda-2-us-east-1',
568
+ Handler: 'index.handler',
569
+ Runtime: 'nodejs12.x',
570
+ },
571
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-3-us-east-1': {
572
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-3-us-east-1',
573
+ FunctionName: 'lambda-3-us-east-1',
574
+ Handler: 'index.handler',
575
+ Runtime: 'nodejs12.x',
576
+ },
577
+ 'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2': {
578
+ FunctionArn: 'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
579
+ FunctionName: 'lambda-1-us-east-2',
580
+ Handler: 'index.handler',
581
+ Runtime: 'nodejs14.x',
582
+ },
583
+ 'arn:aws:lambda:us-east-2:123456789012:function:lambda-2-us-east-2': {
584
+ FunctionArn: 'arn:aws:lambda:us-east-2:123456789012:function:lambda-2-us-east-2',
585
+ FunctionName: 'lambda-2-us-east-2',
586
+ Handler: 'index.handler',
587
+ Runtime: 'nodejs16.x',
588
+ },
589
+ 'arn:aws:lambda:us-east-2:123456789012:function:lambda-3-us-east-2': {
590
+ FunctionArn: 'arn:aws:lambda:us-east-2:123456789012:function:lambda-3-us-east-2',
591
+ FunctionName: 'lambda-3-us-east-2',
592
+ Handler: 'index.handler',
593
+ Runtime: 'nodejs18.x',
594
+ },
595
+ })), { updateFunctionConfiguration: jest.fn().mockImplementation((updateRequest) => {
596
+ if (failingLambdas.includes(updateRequest['FunctionName'])) {
597
+ return { promise: () => Promise.reject(Error('Unexpected error updating request')) };
598
+ }
599
+ return { promise: () => Promise.resolve() };
600
+ }) })));
601
+ const cli = fixtures_1.makeCli();
602
+ const context = fixtures_1.createMockContext();
603
+ const code = yield cli.run([
604
+ 'lambda',
605
+ 'instrument',
606
+ '-f',
607
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
608
+ '-f',
609
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-2-us-east-1',
610
+ '-f',
611
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-3-us-east-1',
612
+ '-f',
613
+ 'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
614
+ '-f',
615
+ 'arn:aws:lambda:us-east-2:123456789012:function:lambda-2-us-east-2',
616
+ '-f',
617
+ 'arn:aws:lambda:us-east-2:123456789012:function:lambda-3-us-east-2',
618
+ ], context);
619
+ const output = context.stdout.toString();
620
+ expect(code).toBe(0);
621
+ expect(output).toMatchSnapshot();
571
622
  }));
572
- const cli = fixtures_1.makeCli();
573
- const context = fixtures_1.createMockContext();
574
- const code = yield cli.run(['lambda', 'uninstrument', '-i'], context);
575
- const output = context.stdout.toString();
576
- expect(code).toBe(1);
577
- expect(output).toMatchInlineSnapshot(`
578
- "\n🐶 Uninstrumenting Lambda function
579
- [Error] Couldn't fetch Lambda functions. Error: Max retry count exceeded. ListFunctionsError
580
- "
581
- `);
582
- }));
583
- test('prints error when updating aws profile credentials fails', () => __awaiter(void 0, void 0, void 0, function* () {
584
- ;
585
- aws_sdk_1.SharedIniFileCredentials.mockImplementation(() => {
586
- throw Error('Update failed!');
623
+ test('aborts when every lambda function fails to update on uninstrument', () => __awaiter(void 0, void 0, void 0, function* () {
624
+ ;
625
+ fs.readFile.mockImplementation((a, b, callback) => callback({ code: 'ENOENT' }));
626
+ const failingLambdas = [
627
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
628
+ 'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
629
+ ];
630
+ aws_sdk_1.Lambda.mockImplementation(() => (Object.assign(Object.assign({}, fixtures_1.makeMockLambda({
631
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1': {
632
+ FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
633
+ FunctionName: 'lambda-1-us-east-1',
634
+ Handler: 'index.handler',
635
+ Runtime: 'nodejs12.x',
636
+ },
637
+ 'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2': {
638
+ FunctionArn: 'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
639
+ FunctionName: 'lambda-1-us-east-2',
640
+ Handler: 'index.handler',
641
+ Runtime: 'nodejs14.x',
642
+ },
643
+ })), { updateFunctionConfiguration: jest.fn().mockImplementation((updateRequest) => {
644
+ if (failingLambdas.includes(updateRequest['FunctionName'])) {
645
+ return { promise: () => Promise.reject(Error('Unexpected error updating request')) };
646
+ }
647
+ return { promise: () => Promise.resolve() };
648
+ }) })));
649
+ const cli = fixtures_1.makeCli();
650
+ const context = fixtures_1.createMockContext();
651
+ const code = yield cli.run([
652
+ 'lambda',
653
+ 'instrument',
654
+ '-f',
655
+ 'arn:aws:lambda:us-east-1:123456789012:function:lambda-1-us-east-1',
656
+ '-f',
657
+ 'arn:aws:lambda:us-east-2:123456789012:function:lambda-1-us-east-2',
658
+ ], context);
659
+ const output = context.stdout.toString();
660
+ expect(code).toBe(1);
661
+ expect(output).toMatchSnapshot();
662
+ }));
663
+ });
664
+ describe('printPlannedActions', () => {
665
+ test('prints no output when list is empty', () => {
666
+ process.env = {};
667
+ const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
668
+ command['printPlannedActions']([]);
669
+ const output = command.context.stdout.toString();
670
+ expect(output).toMatchInlineSnapshot(`
671
+ "
672
+ No updates will be applied.
673
+ "
674
+ `);
587
675
  });
588
- const cli = fixtures_1.makeCli();
589
- const context = fixtures_1.createMockContext();
590
- const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
591
- const code = yield cli.run(['lambda', 'uninstrument', '-f', functionARN, '--profile', 'SOME-AWS-PROFILE'], context);
592
- const output = context.stdout.toString();
593
- expect(code).toBe(1);
594
- expect(output).toMatchInlineSnapshot(`
595
- "\n🐶 Uninstrumenting Lambda function
596
- [Error] Error: Couldn't set AWS profile credentials. Update failed!
597
- "
598
- `);
599
- }));
600
- });
601
- describe('printPlannedActions', () => {
602
- test('prints no output when list is empty', () => {
603
- process.env = {};
604
- const command = fixtures_1.createCommand(uninstrument_1.UninstrumentCommand);
605
- command['printPlannedActions']([]);
606
- const output = command.context.stdout.toString();
607
- expect(output).toMatchInlineSnapshot(`
608
- "
609
- No updates will be applied.
610
- "
611
- `);
612
676
  });
613
677
  });
614
678
  });