@datadog/datadog-ci 0.17.13 → 1.0.0

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 (52) hide show
  1. package/LICENSE-3rdparty.csv +1 -0
  2. package/README.md +0 -2
  3. package/dist/commands/git-metadata/__tests__/git.test.js +44 -2
  4. package/dist/commands/{dependencies/__tests__/upload.test.d.ts → git-metadata/__tests__/library.test.d.ts} +0 -0
  5. package/dist/commands/git-metadata/__tests__/library.test.js +82 -0
  6. package/dist/commands/git-metadata/git.d.ts +1 -2
  7. package/dist/commands/git-metadata/git.js +13 -25
  8. package/dist/commands/git-metadata/index.d.ts +1 -0
  9. package/dist/commands/git-metadata/index.js +13 -0
  10. package/dist/commands/git-metadata/library.d.ts +6 -0
  11. package/dist/commands/git-metadata/library.js +68 -0
  12. package/dist/commands/git-metadata/upload.d.ts +1 -2
  13. package/dist/commands/git-metadata/upload.js +31 -27
  14. package/dist/commands/lambda/__tests__/functions/commons.test.js +46 -2
  15. package/dist/commands/lambda/__tests__/functions/uninstrument.test.js +34 -0
  16. package/dist/commands/lambda/__tests__/instrument.test.js +219 -1
  17. package/dist/commands/lambda/constants.d.ts +36 -16
  18. package/dist/commands/lambda/constants.js +31 -17
  19. package/dist/commands/lambda/functions/commons.d.ts +6 -4
  20. package/dist/commands/lambda/functions/commons.js +14 -10
  21. package/dist/commands/lambda/functions/instrument.js +57 -24
  22. package/dist/commands/lambda/functions/uninstrument.js +22 -7
  23. package/dist/commands/lambda/instrument.js +4 -1
  24. package/dist/commands/lambda/tags.js +1 -5
  25. package/dist/commands/synthetics/__tests__/utils.test.js +27 -0
  26. package/dist/commands/synthetics/crypto.d.ts +2 -1
  27. package/dist/commands/synthetics/interfaces.d.ts +5 -1
  28. package/dist/commands/synthetics/run-test.d.ts +2 -0
  29. package/dist/commands/synthetics/utils.d.ts +1 -0
  30. package/dist/commands/synthetics/utils.js +25 -16
  31. package/dist/commands/{dependencies → version}/cli.d.ts +0 -0
  32. package/dist/commands/version/cli.js +27 -0
  33. package/dist/helpers/git.js +1 -1
  34. package/dist/index.d.ts +2 -1
  35. package/dist/index.js +3 -1
  36. package/package.json +5 -2
  37. package/dist/commands/dependencies/__tests__/helpers/context.d.ts +0 -12
  38. package/dist/commands/dependencies/__tests__/helpers/context.js +0 -31
  39. package/dist/commands/dependencies/__tests__/helpers/stream.d.ts +0 -2
  40. package/dist/commands/dependencies/__tests__/helpers/stream.js +0 -24
  41. package/dist/commands/dependencies/__tests__/helpers/upload.run.d.ts +0 -13
  42. package/dist/commands/dependencies/__tests__/helpers/upload.run.js +0 -40
  43. package/dist/commands/dependencies/__tests__/upload.test.js +0 -264
  44. package/dist/commands/dependencies/api.d.ts +0 -2
  45. package/dist/commands/dependencies/api.js +0 -27
  46. package/dist/commands/dependencies/cli.js +0 -4
  47. package/dist/commands/dependencies/interfaces.d.ts +0 -10
  48. package/dist/commands/dependencies/interfaces.js +0 -2
  49. package/dist/commands/dependencies/renderer.d.ts +0 -13
  50. package/dist/commands/dependencies/renderer.js +0 -57
  51. package/dist/commands/dependencies/upload.d.ts +0 -16
  52. package/dist/commands/dependencies/upload.js +0 -171
@@ -30,6 +30,7 @@ inquirer,import,MIT,Copyright (c) 2012 Simon Boudrias
30
30
  jest,dev,MIT,Copyright (c) Facebook, Inc. and its affiliates.
31
31
  jest-environment-node,dev,MIT,Copyright (c) Facebook, Inc. and its affiliates.
32
32
  jest-matcher-specific-error,dev,MIT,Copyright (c) 2020 Daniel Hreben
33
+ nexe,dev,MIT,Copyright (c) 2013-2018 Nexe Contributors
33
34
  prettier,dev,MIT,Copyright © James Long and contributors
34
35
  proxy,dev,MIT,Copyright (c) 2013 Nathan Rajlich <nathan@tootallnate.net>
35
36
  proxy-agent,import,MIT,Copyright (c) 2013 Nathan Rajlich <nathan@tootallnate.net>
package/README.md CHANGED
@@ -35,7 +35,6 @@ yarn global add @datadog/datadog-ci
35
35
  Usage: datadog-ci <command> <subcommand> [options]
36
36
 
37
37
  Available commands:
38
- - dependencies
39
38
  - lambda
40
39
  - sourcemaps
41
40
  - synthetics
@@ -49,7 +48,6 @@ Each command allows interacting with a product of the Datadog platform. The comm
49
48
 
50
49
  Further documentation for each command can be found in its folder, ie:
51
50
 
52
- - [Dependencies](src/commands/dependencies)
53
51
  - [Lambda](src/commands/lambda)
54
52
  - [Sourcemaps](src/commands/sourcemaps/)
55
53
  - [Synthetics CI/CD Testing](src/commands/synthetics/)
@@ -1,4 +1,23 @@
1
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
+ };
2
21
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
22
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
23
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -9,6 +28,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
28
  });
10
29
  };
11
30
  Object.defineProperty(exports, "__esModule", { value: true });
31
+ const simpleGit = __importStar(require("simple-git"));
12
32
  const git_1 = require("../git");
13
33
  const createMockSimpleGit = (conf) => ({
14
34
  getRemotes: (_) => __awaiter(void 0, void 0, void 0, function* () {
@@ -84,7 +104,7 @@ describe('git', () => {
84
104
  remotes: [{ name: 'first', refs: { push: 'https://git-repo' } }],
85
105
  trackedFiles: ['myfile.js'],
86
106
  });
87
- const commitInfo = yield git_1.getCommitInfo(mock, process.stdout);
107
+ const commitInfo = yield git_1.getCommitInfo(mock);
88
108
  expect(commitInfo).toBeDefined();
89
109
  expect(commitInfo.hash).toBe('abcd');
90
110
  expect(commitInfo.trackedFiles).toStrictEqual(['myfile.js']);
@@ -95,11 +115,33 @@ describe('git', () => {
95
115
  hash: 'abcd',
96
116
  trackedFiles: ['myfile.js'],
97
117
  });
98
- const commitInfo = yield git_1.getCommitInfo(mock, process.stdout, 'https://overridden');
118
+ const commitInfo = yield git_1.getCommitInfo(mock, 'https://overridden');
99
119
  expect(commitInfo).toBeDefined();
100
120
  expect(commitInfo.hash).toBe('abcd');
101
121
  expect(commitInfo.trackedFiles).toStrictEqual(['myfile.js']);
102
122
  expect(commitInfo.remote).toBe('https://overridden');
103
123
  }));
104
124
  });
125
+ describe('newSimpleGit', () => {
126
+ test('should throw an error if git is not installed', () => __awaiter(void 0, void 0, void 0, function* () {
127
+ jest.spyOn(simpleGit, 'gitP').mockImplementation(() => {
128
+ throw Error('gitp error');
129
+ });
130
+ yield expect(git_1.newSimpleGit()).rejects.toThrow('gitp error');
131
+ }));
132
+ test('should throw an error if revparse throws an error', () => __awaiter(void 0, void 0, void 0, function* () {
133
+ const mock = createMockSimpleGit({});
134
+ jest.spyOn(simpleGit, 'gitP').mockReturnValue(mock);
135
+ jest.spyOn(mock, 'revparse').mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () {
136
+ throw Error('revparse error');
137
+ }));
138
+ yield expect(git_1.newSimpleGit()).rejects.toThrow('revparse error');
139
+ }));
140
+ test('should not throw any errors', () => __awaiter(void 0, void 0, void 0, function* () {
141
+ const mock = createMockSimpleGit({});
142
+ jest.spyOn(simpleGit, 'gitP').mockReturnValue(mock);
143
+ jest.spyOn(mock, 'revparse').mockResolvedValue('1234');
144
+ yield expect(git_1.newSimpleGit()).resolves.not.toThrow();
145
+ }));
146
+ });
105
147
  });
@@ -0,0 +1,82 @@
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
+ const apikey = __importStar(require("../../../helpers/apikey"));
32
+ const upload = __importStar(require("../../../helpers/upload"));
33
+ const git = __importStar(require("../git"));
34
+ const interfaces_1 = require("../interfaces");
35
+ const library_1 = require("../library");
36
+ describe('library', () => {
37
+ describe('isGitRepo', () => {
38
+ test('should return false if checkIsRepo fails', () => __awaiter(void 0, void 0, void 0, function* () {
39
+ const simpleGitClient = {
40
+ checkIsRepo: () => {
41
+ throw Error();
42
+ },
43
+ };
44
+ jest.spyOn(git, 'newSimpleGit').mockResolvedValue(simpleGitClient);
45
+ yield expect(library_1.isGitRepo()).resolves.toEqual(false);
46
+ }));
47
+ test('should return false git is not installed', () => __awaiter(void 0, void 0, void 0, function* () {
48
+ jest.spyOn(git, 'newSimpleGit').mockImplementation(() => {
49
+ throw new Error('git is not installed');
50
+ });
51
+ yield expect(library_1.isGitRepo()).resolves.toEqual(false);
52
+ }));
53
+ test('should return true if datadog API key is set, git is installed, and we are in a repo', () => __awaiter(void 0, void 0, void 0, function* () {
54
+ const simpleGitClient = { checkIsRepo: () => true };
55
+ jest.spyOn(git, 'newSimpleGit').mockResolvedValue(simpleGitClient);
56
+ yield expect(library_1.isGitRepo()).resolves.toEqual(true);
57
+ }));
58
+ });
59
+ describe('addSourceCodeIntegration', () => {
60
+ test('source code integration fails if simpleGitOrFail throws an exception', () => __awaiter(void 0, void 0, void 0, function* () {
61
+ jest.spyOn(git, 'newSimpleGit').mockImplementation(() => {
62
+ throw new Error('git is not installed');
63
+ });
64
+ jest.spyOn(apikey, 'newApiKeyValidator').mockReturnValue({});
65
+ yield expect(library_1.uploadGitCommitHash('dummy', 'fake.site')).rejects.toThrowError('git is not installed');
66
+ }));
67
+ test('source code integration returns the correct hash', () => __awaiter(void 0, void 0, void 0, function* () {
68
+ const simpleGitClient = { checkIsRepo: () => true };
69
+ jest.spyOn(git, 'newSimpleGit').mockResolvedValue(simpleGitClient);
70
+ jest.spyOn(git, 'getCommitInfo').mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return new interfaces_1.CommitInfo('hash', 'url', ['file1', 'file2']); }));
71
+ jest.spyOn(upload, 'upload').mockReturnValue((a, b) => {
72
+ {
73
+ return new Promise((resolve) => {
74
+ resolve(upload.UploadStatus.Success);
75
+ });
76
+ }
77
+ });
78
+ jest.spyOn(apikey, 'newApiKeyValidator').mockReturnValue({});
79
+ expect(yield library_1.uploadGitCommitHash('dummy', 'fake.site')).toBe('hash');
80
+ }));
81
+ });
82
+ });
@@ -1,8 +1,7 @@
1
1
  import * as simpleGit from 'simple-git';
2
- import { Writable } from 'stream';
3
2
  import { CommitInfo } from './interfaces';
4
3
  export declare const newSimpleGit: () => Promise<simpleGit.SimpleGit>;
5
4
  export declare const gitRemote: (git: simpleGit.SimpleGit) => Promise<string>;
6
5
  export declare const stripCredentials: (remote: string) => string;
7
6
  export declare const gitTrackedFiles: (git: simpleGit.SimpleGit) => Promise<string[]>;
8
- export declare const getCommitInfo: (git: simpleGit.SimpleGit, stdout: Writable, repositoryURL?: string | undefined) => Promise<CommitInfo | undefined>;
7
+ export declare const getCommitInfo: (git: simpleGit.SimpleGit, repositoryURL?: string | undefined) => Promise<CommitInfo>;
@@ -31,7 +31,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
31
31
  exports.getCommitInfo = exports.gitTrackedFiles = exports.stripCredentials = exports.gitRemote = exports.newSimpleGit = void 0;
32
32
  const simpleGit = __importStar(require("simple-git"));
33
33
  const url_1 = require("url");
34
- const renderer_1 = require("./renderer");
35
34
  const interfaces_1 = require("./interfaces");
36
35
  // Returns a configured SimpleGit.
37
36
  const newSimpleGit = () => __awaiter(void 0, void 0, void 0, function* () {
@@ -40,16 +39,11 @@ const newSimpleGit = () => __awaiter(void 0, void 0, void 0, function* () {
40
39
  binary: 'git',
41
40
  maxConcurrentProcesses: 1,
42
41
  };
43
- try {
44
- // Attempt to set the baseDir to the root of the repository so the 'git ls-files' command
45
- // returns the tracked files paths relative to the root of the repository.
46
- const git = simpleGit.gitP(options);
47
- const root = yield git.revparse('--show-toplevel');
48
- options.baseDir = root;
49
- }
50
- catch (_a) {
51
- // Ignore exception as it will fail if we are not inside a git repository.
52
- }
42
+ // Attempt to set the baseDir to the root of the repository so the 'git ls-files' command
43
+ // returns the tracked files paths relative to the root of the repository.
44
+ const git = simpleGit.gitP(options);
45
+ const root = yield git.revparse('--show-toplevel');
46
+ options.baseDir = root;
53
47
  return simpleGit.gitP(options);
54
48
  });
55
49
  exports.newSimpleGit = newSimpleGit;
@@ -91,27 +85,21 @@ const gitTrackedFiles = (git) => __awaiter(void 0, void 0, void 0, function* ()
91
85
  });
92
86
  exports.gitTrackedFiles = gitTrackedFiles;
93
87
  // Returns the current hash, remote URL and tracked files paths.
94
- const getCommitInfo = (git, stdout, repositoryURL) => __awaiter(void 0, void 0, void 0, function* () {
88
+ const getCommitInfo = (git, repositoryURL) => __awaiter(void 0, void 0, void 0, function* () {
95
89
  // Invoke git commands to retrieve the remote, hash and tracked files.
96
90
  // We're using Promise.all instead of Promive.allSettled since we want to fail early if
97
91
  // any of the promises fails.
98
92
  let remote;
99
93
  let hash;
100
94
  let trackedFiles;
101
- try {
102
- if (repositoryURL) {
103
- ;
104
- [hash, trackedFiles] = yield Promise.all([gitHash(git), exports.gitTrackedFiles(git)]);
105
- remote = repositoryURL;
106
- }
107
- else {
108
- ;
109
- [remote, hash, trackedFiles] = yield Promise.all([exports.gitRemote(git), gitHash(git), exports.gitTrackedFiles(git)]);
110
- }
95
+ if (repositoryURL) {
96
+ ;
97
+ [hash, trackedFiles] = yield Promise.all([gitHash(git), exports.gitTrackedFiles(git)]);
98
+ remote = repositoryURL;
111
99
  }
112
- catch (e) {
113
- stdout.write(renderer_1.renderGitError(e));
114
- return;
100
+ else {
101
+ ;
102
+ [remote, hash, trackedFiles] = yield Promise.all([exports.gitRemote(git), gitHash(git), exports.gitTrackedFiles(git)]);
115
103
  }
116
104
  return new interfaces_1.CommitInfo(hash, remote, trackedFiles);
117
105
  });
@@ -0,0 +1 @@
1
+ export * from './library';
@@ -0,0 +1,13 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./library"), exports);
@@ -0,0 +1,6 @@
1
+ import { RequestBuilder } from '../../helpers/interfaces';
2
+ import { UploadOptions, UploadStatus } from '../../helpers/upload';
3
+ import { CommitInfo } from './interfaces';
4
+ export declare const isGitRepo: () => Promise<boolean>;
5
+ export declare const uploadGitCommitHash: (apiKey: string, datadogSite: string) => Promise<string>;
6
+ export declare const uploadRepository: (requestBuilder: RequestBuilder, libraryVersion: string) => (commitInfo: CommitInfo, opts: UploadOptions) => Promise<UploadStatus>;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.uploadRepository = exports.uploadGitCommitHash = exports.isGitRepo = void 0;
13
+ const apikey_1 = require("../../helpers/apikey");
14
+ const upload_1 = require("../../helpers/upload");
15
+ const utils_1 = require("../../helpers/utils");
16
+ const git_1 = require("./git");
17
+ const isGitRepo = () => __awaiter(void 0, void 0, void 0, function* () {
18
+ try {
19
+ const simpleGit = yield git_1.newSimpleGit();
20
+ const isRepo = simpleGit.checkIsRepo();
21
+ return isRepo;
22
+ }
23
+ catch (_a) {
24
+ return false;
25
+ }
26
+ });
27
+ exports.isGitRepo = isGitRepo;
28
+ const uploadGitCommitHash = (apiKey, datadogSite) => __awaiter(void 0, void 0, void 0, function* () {
29
+ const apiKeyValidator = apikey_1.newApiKeyValidator({
30
+ apiKey,
31
+ datadogSite,
32
+ });
33
+ const simpleGit = yield git_1.newSimpleGit();
34
+ const payload = yield git_1.getCommitInfo(simpleGit);
35
+ const version = require('../../../package.json').version;
36
+ const requestBuilder = utils_1.getRequestBuilder({
37
+ apiKey,
38
+ baseUrl: 'https://sourcemap-intake.' + datadogSite,
39
+ headers: new Map([
40
+ ['DD-EVP-ORIGIN', 'datadog-ci sci'],
41
+ ['DD-EVP-ORIGIN-VERSION', version],
42
+ ]),
43
+ overrideUrl: 'api/v2/srcmap',
44
+ });
45
+ const status = yield exports.uploadRepository(requestBuilder, version)(payload, {
46
+ apiKeyValidator,
47
+ onError: (e) => {
48
+ throw e;
49
+ },
50
+ onRetry: () => {
51
+ // Do nothing
52
+ },
53
+ onUpload: () => {
54
+ return;
55
+ },
56
+ retries: 5,
57
+ });
58
+ if (status !== upload_1.UploadStatus.Success) {
59
+ throw new Error('Error uploading commit information.');
60
+ }
61
+ return payload.hash;
62
+ });
63
+ exports.uploadGitCommitHash = uploadGitCommitHash;
64
+ const uploadRepository = (requestBuilder, libraryVersion) => (commitInfo, opts) => __awaiter(void 0, void 0, void 0, function* () {
65
+ const payload = commitInfo.asMultipartPayload(libraryVersion);
66
+ return upload_1.upload(requestBuilder)(payload, opts);
67
+ });
68
+ exports.uploadRepository = uploadRepository;
@@ -6,7 +6,6 @@ export declare class UploadCommand extends Command {
6
6
  private config;
7
7
  private dryRun;
8
8
  constructor();
9
- execute(): Promise<1 | 0>;
9
+ execute(): Promise<1 | 0 | undefined>;
10
10
  private getRequestBuilder;
11
- private uploadRepository;
12
11
  }
@@ -23,6 +23,7 @@ const upload_1 = require("../../helpers/upload");
23
23
  const utils_1 = require("../../helpers/utils");
24
24
  const api_1 = require("./api");
25
25
  const git_1 = require("./git");
26
+ const library_1 = require("./library");
26
27
  const renderer_1 = require("./renderer");
27
28
  class UploadCommand extends clipanion_1.Command {
28
29
  constructor() {
@@ -49,28 +50,40 @@ class UploadCommand extends clipanion_1.Command {
49
50
  datadogSite: api_1.datadogSite,
50
51
  metricsLogger: metricsLogger.logger,
51
52
  });
52
- const payload = yield git_1.getCommitInfo(yield git_1.newSimpleGit(), this.context.stdout, this.repositoryURL);
53
- if (payload === undefined) {
54
- return 1;
53
+ let payload;
54
+ try {
55
+ payload = yield git_1.getCommitInfo(yield git_1.newSimpleGit(), this.repositoryURL);
56
+ }
57
+ catch (e) {
58
+ if (e instanceof Error) {
59
+ this.context.stdout.write(renderer_1.renderFailedUpload(e.message));
60
+ }
61
+ return;
55
62
  }
56
63
  this.context.stdout.write(renderer_1.renderCommandInfo(payload));
64
+ let status;
57
65
  try {
58
66
  const requestBuilder = this.getRequestBuilder();
59
- const status = yield this.uploadRepository(requestBuilder)(payload, {
60
- apiKeyValidator,
61
- onError: (e) => {
62
- this.context.stdout.write(renderer_1.renderFailedUpload(e.message));
63
- metricsLogger.logger.increment('failed', 1);
64
- },
65
- onRetry: (e, attempt) => {
66
- this.context.stdout.write(renderer_1.renderRetriedUpload(e.message, attempt));
67
- metricsLogger.logger.increment('retries', 1);
68
- },
69
- onUpload: () => {
70
- return;
71
- },
72
- retries: 5,
73
- });
67
+ if (this.dryRun) {
68
+ status = upload_1.UploadStatus.Success;
69
+ }
70
+ else {
71
+ status = yield library_1.uploadRepository(requestBuilder, this.cliVersion)(payload, {
72
+ apiKeyValidator,
73
+ onError: (e) => {
74
+ this.context.stdout.write(renderer_1.renderFailedUpload(e.message));
75
+ metricsLogger.logger.increment('failed', 1);
76
+ },
77
+ onRetry: (e, attempt) => {
78
+ this.context.stdout.write(renderer_1.renderRetriedUpload(e.message, attempt));
79
+ metricsLogger.logger.increment('retries', 1);
80
+ },
81
+ onUpload: () => {
82
+ return;
83
+ },
84
+ retries: 5,
85
+ });
86
+ }
74
87
  metricsLogger.logger.increment('success', 1);
75
88
  const totalTime = (Date.now() - initialTime) / 1000;
76
89
  if (status !== upload_1.UploadStatus.Success) {
@@ -113,15 +126,6 @@ class UploadCommand extends clipanion_1.Command {
113
126
  overrideUrl: 'api/v2/srcmap',
114
127
  });
115
128
  }
116
- uploadRepository(requestBuilder) {
117
- return (commitInfo, opts) => __awaiter(this, void 0, void 0, function* () {
118
- const payload = commitInfo.asMultipartPayload(this.cliVersion);
119
- if (this.dryRun) {
120
- return upload_1.UploadStatus.Success;
121
- }
122
- return upload_1.upload(requestBuilder)(payload, opts);
123
- });
124
- }
125
129
  }
126
130
  exports.UploadCommand = UploadCommand;
127
131
  UploadCommand.usage = clipanion_1.Command.Usage({
@@ -28,7 +28,7 @@ describe('commons', () => {
28
28
  'arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:10',
29
29
  ];
30
30
  const region = 'sa-east-1';
31
- const lambdaLibraryLayerName = constants_1.RUNTIME_LAYER_LOOKUP[runtime];
31
+ const lambdaLibraryLayerName = constants_1.LAYER_LOOKUP[runtime];
32
32
  const fullLambdaLibraryLayerArn = commons_1.getLayerArn(config, config.Runtime, region) + ':49';
33
33
  const fullExtensionLayerArn = commons_1.getLayerArn(config, constants_1.EXTENSION_LAYER_KEY, region) + ':11';
34
34
  layerARNs = commons_1.addLayerArn(fullLambdaLibraryLayerArn, lambdaLibraryLayerName, layerARNs);
@@ -49,7 +49,7 @@ describe('commons', () => {
49
49
  'arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:11',
50
50
  ];
51
51
  const region = 'sa-east-1';
52
- const lambdaLibraryLayerName = constants_1.RUNTIME_LAYER_LOOKUP[runtime];
52
+ const lambdaLibraryLayerName = constants_1.LAYER_LOOKUP[runtime];
53
53
  const fullLambdaLibraryLayerArn = commons_1.getLayerArn(config, config.Runtime, region) + ':49';
54
54
  const fullExtensionLayerArn = commons_1.getLayerArn(config, constants_1.EXTENSION_LAYER_KEY, region) + ':11';
55
55
  layerARNs = commons_1.addLayerArn(fullLambdaLibraryLayerArn, lambdaLibraryLayerName, layerARNs);
@@ -568,4 +568,48 @@ describe('commons', () => {
568
568
  });
569
569
  }));
570
570
  });
571
+ describe('Correctly handles multiple runtimes', () => {
572
+ test('returns true if all runtimes are uniform', () => __awaiter(void 0, void 0, void 0, function* () {
573
+ const configs = [
574
+ {
575
+ functionARN: 'arn:aws:lambda:us-east-1:000000000000:function:func1',
576
+ lambdaConfig: {
577
+ FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:func1',
578
+ Handler: 'index.handler',
579
+ Runtime: 'nodejs14.x',
580
+ },
581
+ },
582
+ {
583
+ functionARN: 'arn:aws:lambda:us-east-1:000000000000:function:func2',
584
+ lambdaConfig: {
585
+ FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:func2',
586
+ Handler: 'index.handler',
587
+ Runtime: 'nodejs12.x',
588
+ },
589
+ },
590
+ ];
591
+ expect(commons_1.checkRuntimeTypesAreUniform(configs)).toBe(true);
592
+ }));
593
+ test('returns false if runtimes are not uniform', () => __awaiter(void 0, void 0, void 0, function* () {
594
+ const configs = [
595
+ {
596
+ functionARN: 'arn:aws:lambda:us-east-1:000000000000:function:func1',
597
+ lambdaConfig: {
598
+ FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:func1',
599
+ Handler: 'index.handler',
600
+ Runtime: 'nodejs14.x',
601
+ },
602
+ },
603
+ {
604
+ functionARN: 'arn:aws:lambda:us-east-1:000000000000:function:func2',
605
+ lambdaConfig: {
606
+ FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:func2',
607
+ Handler: 'index.handler',
608
+ Runtime: 'python3.9',
609
+ },
610
+ },
611
+ ];
612
+ expect(commons_1.checkRuntimeTypesAreUniform(configs)).toBe(false);
613
+ }));
614
+ });
571
615
  });
@@ -235,6 +235,40 @@ describe('uninstrument', () => {
235
235
  }
236
236
  `);
237
237
  }));
238
+ test('correctly removes .NET env vars', () => __awaiter(void 0, void 0, void 0, function* () {
239
+ const lambda = fixtures_1.makeMockLambda({
240
+ 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument': {
241
+ Environment: {
242
+ Variables: {
243
+ [constants_1.FLUSH_TO_LOG_ENV_VAR]: 'false',
244
+ [constants_1.LOG_LEVEL_ENV_VAR]: 'debug',
245
+ [constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
246
+ [constants_1.SITE_ENV_VAR]: 'datadoghq.com',
247
+ [constants_1.TRACE_ENABLED_ENV_VAR]: 'false',
248
+ [constants_1.SERVICE_ENV_VAR]: 'middletier',
249
+ [constants_1.ENVIRONMENT_ENV_VAR]: 'staging',
250
+ [constants_1.VERSION_ENV_VAR]: '0.2',
251
+ [constants_1.ENABLE_PROFILING_ENV_VAR]: '1',
252
+ [constants_1.PROFILER_ENV_VAR]: '{846F5F1C-F9AE-4B07-969E-05C26BC060D8}',
253
+ [constants_1.PROFILER_PATH_ENV_VAR]: '/opt/datadog/Datadog.Trace.ClrProfiler.Native.so',
254
+ [constants_1.DOTNET_TRACER_HOME_ENV_VAR]: '/opt/datadog',
255
+ },
256
+ },
257
+ FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:uninstrument',
258
+ Runtime: 'dotnetcore3.1',
259
+ },
260
+ });
261
+ const cloudWatch = fixtures_1.makeMockCloudWatchLogs({});
262
+ const result = yield uninstrument_1.getUninstrumentedFunctionConfigs(lambda, cloudWatch, ['arn:aws:lambda:us-east-1:000000000000:function:uninstrument'], undefined);
263
+ expect(result[0].updateRequest).toMatchInlineSnapshot(`
264
+ Object {
265
+ "Environment": Object {
266
+ "Variables": Object {},
267
+ },
268
+ "FunctionName": "arn:aws:lambda:us-east-1:000000000000:function:uninstrument",
269
+ }
270
+ `);
271
+ }));
238
272
  });
239
273
  describe('getUninstrumentedFunctionConfig', () => {
240
274
  const OLD_ENV = process.env;