azure-pipelines-task-lib 4.9.0 → 4.10.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.
package/internal.d.ts CHANGED
@@ -18,6 +18,7 @@ export declare enum IssueSource {
18
18
  }
19
19
  export declare function _startsWith(str: string, start: string): boolean;
20
20
  export declare function _endsWith(str: string, end: string): boolean;
21
+ export declare function _truncateBeforeSensitiveKeyword(str: string, sensitiveKeywordsPattern: RegExp): string;
21
22
  export declare function _writeLine(str: string): void;
22
23
  export declare function _setStdStream(stdStream: any): void;
23
24
  export declare function _setErrStream(errStream: any): void;
package/internal.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._exposeCertSettings = exports._exposeProxySettings = exports._normalizeSeparators = exports._isRooted = exports._getDirectoryName = exports._ensureRooted = exports._isUncPath = exports._loadData = exports._ensurePatternRooted = exports._getFindInfoFromPattern = exports._cloneMatchOptions = exports._legacyFindFiles_convertPatternToRegExp = exports._which = exports._checkPath = exports._exist = exports._debug = exports._error = exports._warning = exports._command = exports._getVariableKey = exports._getVariable = exports._loc = exports._setResourcePath = exports._setErrStream = exports._setStdStream = exports._writeLine = exports._endsWith = exports._startsWith = exports.IssueSource = exports._vault = exports._knownVariableMap = void 0;
3
+ exports._exposeCertSettings = exports._exposeProxySettings = exports._normalizeSeparators = exports._isRooted = exports._getDirectoryName = exports._ensureRooted = exports._isUncPath = exports._loadData = exports._ensurePatternRooted = exports._getFindInfoFromPattern = exports._cloneMatchOptions = exports._legacyFindFiles_convertPatternToRegExp = exports._which = exports._checkPath = exports._exist = exports._debug = exports._error = exports._warning = exports._command = exports._getVariableKey = exports._getVariable = exports._loc = exports._setResourcePath = exports._setErrStream = exports._setStdStream = exports._writeLine = exports._truncateBeforeSensitiveKeyword = exports._endsWith = exports._startsWith = exports.IssueSource = exports._vault = exports._knownVariableMap = void 0;
4
4
  var fs = require("fs");
5
5
  var path = require("path");
6
6
  var os = require("os");
@@ -20,6 +20,7 @@ var crypto = require("crypto");
20
20
  * 3) to know the real variable name and not just the formatted env var name.
21
21
  */
22
22
  exports._knownVariableMap = {};
23
+ var _taskSdkToken;
23
24
  //-----------------------------------------------------
24
25
  // Enums
25
26
  //-----------------------------------------------------
@@ -46,6 +47,17 @@ function _endsWith(str, end) {
46
47
  return str.slice(-end.length) == end;
47
48
  }
48
49
  exports._endsWith = _endsWith;
50
+ function _truncateBeforeSensitiveKeyword(str, sensitiveKeywordsPattern) {
51
+ if (!str) {
52
+ return str;
53
+ }
54
+ var index = str.search(sensitiveKeywordsPattern);
55
+ if (index <= 0) {
56
+ return str;
57
+ }
58
+ return str.substring(0, index) + "...";
59
+ }
60
+ exports._truncateBeforeSensitiveKeyword = _truncateBeforeSensitiveKeyword;
49
61
  //-----------------------------------------------------
50
62
  // General Helpers
51
63
  //-----------------------------------------------------
@@ -257,11 +269,13 @@ function _command(command, properties, message) {
257
269
  }
258
270
  exports._command = _command;
259
271
  function _warning(message, source) {
260
- _command('task.issue', { 'type': 'warning', 'source': source }, message);
272
+ if (source === void 0) { source = IssueSource.TaskInternal; }
273
+ _command('task.issue', { 'type': 'warning', 'source': source, 'token': _taskSdkToken }, message);
261
274
  }
262
275
  exports._warning = _warning;
263
276
  function _error(message, source) {
264
- _command('task.issue', { 'type': 'error', 'source': source }, message);
277
+ if (source === void 0) { source = IssueSource.TaskInternal; }
278
+ _command('task.issue', { 'type': 'error', 'source': source, 'token': _taskSdkToken }, message);
265
279
  }
266
280
  exports._error = _error;
267
281
  function _debug(message) {
@@ -650,6 +664,9 @@ function _loadData() {
650
664
  }
651
665
  }
652
666
  _debug('loaded ' + loaded);
667
+ var token = process.env["TASK_SDK_COMMAND_TOKEN"];
668
+ delete process.env["TASK_SDK_COMMAND_TOKEN"];
669
+ _taskSdkToken = token ? String(token) : "";
653
670
  // store public variable metadata
654
671
  var names;
655
672
  try {
package/mock-task.js CHANGED
@@ -27,6 +27,7 @@ module.exports.Platform = task.Platform;
27
27
  module.exports.setStdStream = task.setStdStream;
28
28
  module.exports.setErrStream = task.setErrStream;
29
29
  module.exports.setResult = task.setResult;
30
+ module.exports.setSanitizedResult = task.setSanitizedResult;
30
31
  //-----------------------------------------------------
31
32
  // Loc Helpers
32
33
  //-----------------------------------------------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "azure-pipelines-task-lib",
3
- "version": "4.9.0",
3
+ "version": "4.10.0",
4
4
  "description": "Azure Pipelines Task SDK",
5
5
  "main": "./task.js",
6
6
  "typings": "./task.d.ts",
package/task.d.ts CHANGED
@@ -61,6 +61,18 @@ export declare const setErrStream: typeof im._setErrStream;
61
61
  */
62
62
  export declare function setResult(result: TaskResult.Succeeded, message?: string, done?: boolean): void;
63
63
  export declare function setResult(result: Exclude<TaskResult, 'Succeeded'>, message: string, done?: boolean): void;
64
+ /**
65
+ * Sets the result of the task with sanitized message.
66
+ *
67
+ * @param result TaskResult enum of Succeeded, SucceededWithIssues, Failed, Cancelled or Skipped.
68
+ * @param message A message which will be logged as an error issue if the result is Failed. Message will be truncated
69
+ * before first occurence of wellknown sensitive keyword.
70
+ * @param done Optional. Instructs the agent the task is done. This is helpful when child processes
71
+ * may still be running and prevent node from fully exiting. This argument is supported
72
+ * from agent version 2.142.0 or higher (otherwise will no-op).
73
+ * @returns void
74
+ */
75
+ export declare function setSanitizedResult(result: TaskResult, message: string, done?: boolean): void;
64
76
  export declare const setResourcePath: typeof im._setResourcePath;
65
77
  export declare const loc: typeof im._loc;
66
78
  export declare const getVariable: typeof im._getVariable;
package/task.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateReleaseName = exports.addBuildTag = exports.updateBuildNumber = exports.uploadBuildLog = exports.associateArtifact = exports.uploadArtifact = exports.logIssue = exports.logDetail = exports.setProgress = exports.setEndpoint = exports.addAttachment = exports.uploadSummary = exports.prependPath = exports.uploadFile = exports.CodeCoverageEnabler = exports.CodeCoveragePublisher = exports.TestPublisher = exports.getHttpCertConfiguration = exports.getHttpProxyConfiguration = exports.findMatch = exports.filter = exports.match = exports.tool = exports.execSync = exports.exec = exports.execAsync = exports.rmRF = exports.legacyFindFiles = exports.find = exports.retry = exports.mv = exports.cp = exports.ls = exports.which = exports.resolve = exports.mkdirP = exports.popd = exports.pushd = exports.cd = exports.checkPath = exports.cwd = exports.getAgentMode = exports.getNodeMajorVersion = exports.getPlatform = exports.osType = exports.writeFile = exports.exist = exports.stats = exports.debug = exports.error = exports.warning = exports.command = exports.setTaskVariable = exports.getTaskVariable = exports.getSecureFileTicket = exports.getSecureFileName = exports.getEndpointAuthorization = exports.getEndpointAuthorizationParameterRequired = exports.getEndpointAuthorizationParameter = exports.getEndpointAuthorizationSchemeRequired = exports.getEndpointAuthorizationScheme = exports.getEndpointDataParameterRequired = exports.getEndpointDataParameter = exports.getEndpointUrlRequired = exports.getEndpointUrl = exports.getPathInputRequired = exports.getPathInput = exports.filePathSupplied = exports.getDelimitedInput = exports.getPipelineFeature = exports.getBoolFeatureFlag = exports.getBoolInput = exports.getInputRequired = exports.getInput = exports.setSecret = exports.setVariable = exports.getVariables = exports.assertAgent = exports.getVariable = exports.loc = exports.setResourcePath = exports.setResult = exports.setErrStream = exports.setStdStream = exports.AgentHostedMode = exports.Platform = exports.IssueSource = exports.FieldType = exports.ArtifactType = exports.IssueType = exports.TaskState = exports.TaskResult = void 0;
3
+ exports.updateReleaseName = exports.addBuildTag = exports.updateBuildNumber = exports.uploadBuildLog = exports.associateArtifact = exports.uploadArtifact = exports.logIssue = exports.logDetail = exports.setProgress = exports.setEndpoint = exports.addAttachment = exports.uploadSummary = exports.prependPath = exports.uploadFile = exports.CodeCoverageEnabler = exports.CodeCoveragePublisher = exports.TestPublisher = exports.getHttpCertConfiguration = exports.getHttpProxyConfiguration = exports.findMatch = exports.filter = exports.match = exports.tool = exports.execSync = exports.exec = exports.execAsync = exports.rmRF = exports.legacyFindFiles = exports.find = exports.retry = exports.mv = exports.cp = exports.ls = exports.which = exports.resolve = exports.mkdirP = exports.popd = exports.pushd = exports.cd = exports.checkPath = exports.cwd = exports.getAgentMode = exports.getNodeMajorVersion = exports.getPlatform = exports.osType = exports.writeFile = exports.exist = exports.stats = exports.debug = exports.error = exports.warning = exports.command = exports.setTaskVariable = exports.getTaskVariable = exports.getSecureFileTicket = exports.getSecureFileName = exports.getEndpointAuthorization = exports.getEndpointAuthorizationParameterRequired = exports.getEndpointAuthorizationParameter = exports.getEndpointAuthorizationSchemeRequired = exports.getEndpointAuthorizationScheme = exports.getEndpointDataParameterRequired = exports.getEndpointDataParameter = exports.getEndpointUrlRequired = exports.getEndpointUrl = exports.getPathInputRequired = exports.getPathInput = exports.filePathSupplied = exports.getDelimitedInput = exports.getPipelineFeature = exports.getBoolFeatureFlag = exports.getBoolInput = exports.getInputRequired = exports.getInput = exports.setSecret = exports.setVariable = exports.getVariables = exports.assertAgent = exports.getVariable = exports.loc = exports.setResourcePath = exports.setSanitizedResult = exports.setResult = exports.setErrStream = exports.setStdStream = exports.AgentHostedMode = exports.Platform = exports.IssueSource = exports.FieldType = exports.ArtifactType = exports.IssueType = exports.TaskState = exports.TaskResult = void 0;
4
4
  var shell = require("shelljs");
5
5
  var childProcess = require("child_process");
6
6
  var fs = require("fs");
@@ -81,6 +81,23 @@ function setResult(result, message, done) {
81
81
  exports.command('task.complete', properties, message);
82
82
  }
83
83
  exports.setResult = setResult;
84
+ /**
85
+ * Sets the result of the task with sanitized message.
86
+ *
87
+ * @param result TaskResult enum of Succeeded, SucceededWithIssues, Failed, Cancelled or Skipped.
88
+ * @param message A message which will be logged as an error issue if the result is Failed. Message will be truncated
89
+ * before first occurence of wellknown sensitive keyword.
90
+ * @param done Optional. Instructs the agent the task is done. This is helpful when child processes
91
+ * may still be running and prevent node from fully exiting. This argument is supported
92
+ * from agent version 2.142.0 or higher (otherwise will no-op).
93
+ * @returns void
94
+ */
95
+ function setSanitizedResult(result, message, done) {
96
+ var pattern = /password|key|secret|bearer|authorization|token|pat/i;
97
+ var sanitizedMessage = im._truncateBeforeSensitiveKeyword(message, pattern);
98
+ setResult(result, sanitizedMessage, done);
99
+ }
100
+ exports.setSanitizedResult = setSanitizedResult;
84
101
  //
85
102
  // Catching all exceptions
86
103
  //