@datadog/datadog-ci-plugin-terraform 5.28.0 → 5.29.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/README.md CHANGED
@@ -16,6 +16,7 @@ datadog-ci terraform upload [plan|state] <path/to/terraform-file.json> [addition
16
16
  ### Optional arguments
17
17
 
18
18
  - `--repo-id` (optional): Repository identifier override (e.g., github.com/datadog/my-repo)
19
+ - `--expected-plans` (optional): Total number of plans the pipeline uploads for this commit, across all jobs combined. Only valid for `plan` uploads. Defaults to the number of plan files passed to the command, which is correct when a single command uploads every plan of the commit. If the plans are uploaded by several commands (for example, one per job), pass the same total to every command. If the value is lower than the number of plan files passed to the command, the number of files is used instead (with a warning).
19
20
  - `--dry-run` (default: `false`): Run the command without uploading any data to Datadog
20
21
  - `--verbose` (default: `false`): Enable verbose logging
21
22
  - `--skip-git-metadata-upload` (default: `false`): Skip the upload of git metadata
@@ -50,6 +51,12 @@ datadog-ci terraform upload state ./terraform.tfstate
50
51
  # Upload with manual repo-id override
51
52
  datadog-ci terraform upload plan ./terraform-plan.json --repo-id "github.com/my-org/my-repo"
52
53
 
54
+ # Declare that the pipeline uploads 3 plans in total for this commit (for example, one per job) using the flag
55
+ datadog-ci terraform upload plan ./terraform-plan.json --expected-plans 3
56
+
57
+ # In a shared CI template (sh/bash), forward an optional pipeline variable as the flag
58
+ datadog-ci terraform upload plan ./terraform-plan.json ${EXPECTED_PLANS:+--expected-plans "$EXPECTED_PLANS"}
59
+
53
60
  # Dry run mode
54
61
  datadog-ci terraform upload plan ./terraform-plan.json --dry-run
55
62
 
package/dist/bundle.d.ts CHANGED
@@ -297,6 +297,19 @@ declare abstract class Command<Context extends BaseContext = BaseContext> {
297
297
  static Default: never[];
298
298
  }
299
299
  //#endregion
300
+ //#region ../base/dist/helpers/auth.d.ts
301
+ /**
302
+ * The authentication requirement of a command, declared with `public static authRequirement` on its base command class
303
+ * in `packages/base/src/commands/**`, next to the options it describes. A test checks that every registered command
304
+ * declares one.
305
+ */
306
+ type AuthRequirement = {
307
+ kind: 'orgAction' | 'apiKey' | 'none';
308
+ } /** A command-specific text, for example the cloud credentials and Datadog variables a Serverless command reads. */ | {
309
+ kind: 'custom';
310
+ help: string;
311
+ };
312
+ //#endregion
300
313
  //#region ../base/dist/helpers/logger.d.ts
301
314
  declare enum LogLevel {
302
315
  DEBUG = 1,
@@ -339,6 +352,11 @@ type CommandContext = BaseContext & {
339
352
  * This command should be extended by **every** command in the monorepo.
340
353
  */
341
354
  declare abstract class BaseCommand<Context extends CommandContext = CommandContext> extends Command<Context> {
355
+ /**
356
+ * The credentials the command needs, shown in the "Authentication" section of its `--help`.
357
+ * Every command declares one; plugin commands inherit it from their base command.
358
+ */
359
+ static authRequirement?: AuthRequirement;
342
360
  protected logFormat: "text" | "json";
343
361
  private _logger?;
344
362
  get logger(): Logger;
@@ -348,9 +366,11 @@ declare abstract class BaseCommand<Context extends CommandContext = CommandConte
348
366
  declare class TerraformUploadCommand extends BaseCommand {
349
367
  static paths: string[][];
350
368
  static usage: Usage;
369
+ static authRequirement: AuthRequirement;
351
370
  protected artifactType: "plan" | "state";
352
371
  protected filePaths: string[];
353
372
  protected repoId: string | undefined;
373
+ protected expectedPlans: number | undefined;
354
374
  protected skipGitMetadataUpload: boolean;
355
375
  protected verbose: boolean;
356
376
  protected fips: boolean;
@@ -363,6 +383,7 @@ declare class TerraformUploadCommand extends BaseCommand {
363
383
  declare class PluginCommand extends TerraformUploadCommand {
364
384
  private config;
365
385
  private git;
386
+ private expectedPlanCount;
366
387
  execute(): Promise<1 | 0>;
367
388
  private syncGitMetadata;
368
389
  private uploadToGitDB;
package/dist/bundle.js CHANGED
@@ -12921,7 +12921,7 @@ var require_glob = /* @__PURE__ */ __commonJSMin(((exports) => {
12921
12921
  var require_package$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
12922
12922
  module.exports = {
12923
12923
  "name": "@datadog/datadog-ci-base",
12924
- "version": "5.28.0",
12924
+ "version": "5.29.0",
12925
12925
  "description": "Base package for Datadog CI",
12926
12926
  "license": "Apache-2.0",
12927
12927
  "keywords": ["datadog", "datadog-ci"],
@@ -39152,7 +39152,8 @@ var require_request = /* @__PURE__ */ __commonJSMin(((exports) => {
39152
39152
  if (!response.ok) throw new RequestError(`Request failed with status code ${response.status}`, config, {
39153
39153
  data,
39154
39154
  status: response.status,
39155
- statusText: response.statusText
39155
+ statusText: response.statusText,
39156
+ headers: responseHeaders
39156
39157
  });
39157
39158
  return {
39158
39159
  config,
@@ -46672,7 +46673,7 @@ var require_Client = /* @__PURE__ */ __commonJSMin(((exports) => {
46672
46673
  const fs_1$5 = require("fs");
46673
46674
  const path_1 = require("path");
46674
46675
  const tls_1 = require("tls");
46675
- const util_1$1 = require("util");
46676
+ const util_1$2 = require("util");
46676
46677
  const FtpContext_1 = require_FtpContext();
46677
46678
  const netUtils_1 = require_netUtils();
46678
46679
  const parseControlResponse_1 = require_parseControlResponse();
@@ -46682,13 +46683,13 @@ var require_Client = /* @__PURE__ */ __commonJSMin(((exports) => {
46682
46683
  const safePathNames_1 = require_safePathNames();
46683
46684
  const StringWriter_1 = require_StringWriter();
46684
46685
  const transfer_1 = require_transfer();
46685
- const fsReadDir = (0, util_1$1.promisify)(fs_1$5.readdir);
46686
- const fsMkDir = (0, util_1$1.promisify)(fs_1$5.mkdir);
46687
- const fsStat = (0, util_1$1.promisify)(fs_1$5.stat);
46688
- const fsFStat = (0, util_1$1.promisify)(fs_1$5.fstat);
46689
- const fsOpen = (0, util_1$1.promisify)(fs_1$5.open);
46690
- const fsClose = (0, util_1$1.promisify)(fs_1$5.close);
46691
- const fsUnlink = (0, util_1$1.promisify)(fs_1$5.unlink);
46686
+ const fsReadDir = (0, util_1$2.promisify)(fs_1$5.readdir);
46687
+ const fsMkDir = (0, util_1$2.promisify)(fs_1$5.mkdir);
46688
+ const fsStat = (0, util_1$2.promisify)(fs_1$5.stat);
46689
+ const fsFStat = (0, util_1$2.promisify)(fs_1$5.fstat);
46690
+ const fsOpen = (0, util_1$2.promisify)(fs_1$5.open);
46691
+ const fsClose = (0, util_1$2.promisify)(fs_1$5.close);
46692
+ const fsUnlink = (0, util_1$2.promisify)(fs_1$5.unlink);
46692
46693
  const defaultClientOptions = {
46693
46694
  allowSeparateTransferHost: false,
46694
46695
  maxListingBytes: 40 * 1024 * 1024
@@ -64756,7 +64757,7 @@ var require_utils = /* @__PURE__ */ __commonJSMin(((exports) => {
64756
64757
  exports.isFile = exports.getGitHubEventPayload = exports.execute = exports.maskString = exports.formatBytes = exports.timedExecAsync = exports.filterAndFormatGithubRemote = exports.filterSensitiveInfoFromRepository = exports.performSubCommand = exports.pluralize = exports.normalizeRef = exports.recursivelyRemoveUndefinedValues = exports.removeUndefinedValues = exports.removeEmptyValues = exports.buildPath = exports.getApiHostForSite = exports.getProxyAgent = exports.getRequestBuilder = exports.getProxyUrl = exports.resolveConfigFromFile = exports.resolveConfigFromFileAndEnvironment = exports.getConfig = exports.pick = exports.DEFAULT_CONFIG_PATHS = void 0;
64757
64758
  const child_process_1$1 = require("child_process");
64758
64759
  const fs_1$4 = require("fs");
64759
- const util_1 = require("util");
64760
+ const util_1$1 = require("util");
64760
64761
  const clipanion_1 = require_advanced();
64761
64762
  const deep_extend_1 = __importDefault(require_deep_extend());
64762
64763
  const request_1 = require_request();
@@ -64770,7 +64771,7 @@ var require_utils = /* @__PURE__ */ __commonJSMin(((exports) => {
64770
64771
  exports.pick = pick;
64771
64772
  const getConfig = (configPath) => __awaiter(void 0, void 0, void 0, function* () {
64772
64773
  try {
64773
- const configFile = yield (0, util_1.promisify)(fs_1$4.readFile)(configPath, "utf-8");
64774
+ const configFile = yield (0, util_1$1.promisify)(fs_1$4.readFile)(configPath, "utf-8");
64774
64775
  return JSON.parse(configFile);
64775
64776
  } catch (error) {
64776
64777
  if (error instanceof SyntaxError) throw new Error("Config file is not correct JSON");
@@ -64811,14 +64812,14 @@ var require_utils = /* @__PURE__ */ __commonJSMin(((exports) => {
64811
64812
  };
64812
64813
  exports.getProxyUrl = getProxyUrl;
64813
64814
  const getRequestBuilder = (options) => {
64814
- const { apiKey, appKey, baseUrl, overrideUrl, proxyOpts } = options;
64815
+ const { accessToken, apiKey, appKey, baseUrl, overrideUrl, proxyOpts } = options;
64815
64816
  const proxyUrlFromConfiguration = (0, exports.getProxyUrl)(proxyOpts);
64816
64817
  const dispatcher = (0, request_1.getProxyDispatcher)(proxyUrlFromConfiguration);
64817
64818
  const overrideArgs = (args) => {
64818
64819
  const newArguments = Object.assign(Object.assign({}, args), {
64819
64820
  baseURL: baseUrl,
64820
64821
  dispatcher,
64821
- headers: Object.assign(Object.assign({ "DD-API-KEY": apiKey }, appKey ? { "DD-APPLICATION-KEY": appKey } : {}), args.headers)
64822
+ headers: Object.assign(Object.assign(Object.assign({}, apiKey ? { "DD-API-KEY": apiKey } : {}), accessToken ? { Authorization: `Bearer ${accessToken}` } : appKey ? { "DD-APPLICATION-KEY": appKey } : {}), args.headers)
64822
64823
  });
64823
64824
  if (overrideUrl !== void 0) newArguments.url = overrideUrl;
64824
64825
  if (options.headers !== void 0) options.headers.forEach((value, key) => {
@@ -64956,7 +64957,7 @@ var require_utils = /* @__PURE__ */ __commonJSMin(((exports) => {
64956
64957
  return value.slice(0, 2) + "*".repeat(10) + value.slice(-4);
64957
64958
  };
64958
64959
  exports.maskString = maskString;
64959
- const execProc = (0, util_1.promisify)(child_process_1$1.exec);
64960
+ const execProc = (0, util_1$1.promisify)(child_process_1$1.exec);
64960
64961
  const execute = (cmd, cwd) => execProc(cmd, {
64961
64962
  cwd,
64962
64963
  maxBuffer: 5 * 1024 * 5e3
@@ -79037,6 +79038,341 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
79037
79038
  exports.getTempPath = getTempPath;
79038
79039
  }));
79039
79040
  //#endregion
79041
+ //#region ../../node_modules/ansi-escapes/index.js
79042
+ var require_ansi_escapes = /* @__PURE__ */ __commonJSMin(((exports, module) => {
79043
+ const ansiEscapes = module.exports;
79044
+ module.exports.default = ansiEscapes;
79045
+ const ESC = "\x1B[";
79046
+ const OSC = "\x1B]";
79047
+ const BEL = "\x07";
79048
+ const SEP = ";";
79049
+ const isTerminalApp = process.env.TERM_PROGRAM === "Apple_Terminal";
79050
+ ansiEscapes.cursorTo = (x, y) => {
79051
+ if (typeof x !== "number") throw new TypeError("The `x` argument is required");
79052
+ if (typeof y !== "number") return ESC + (x + 1) + "G";
79053
+ return ESC + (y + 1) + ";" + (x + 1) + "H";
79054
+ };
79055
+ ansiEscapes.cursorMove = (x, y) => {
79056
+ if (typeof x !== "number") throw new TypeError("The `x` argument is required");
79057
+ let ret = "";
79058
+ if (x < 0) ret += ESC + -x + "D";
79059
+ else if (x > 0) ret += ESC + x + "C";
79060
+ if (y < 0) ret += ESC + -y + "A";
79061
+ else if (y > 0) ret += ESC + y + "B";
79062
+ return ret;
79063
+ };
79064
+ ansiEscapes.cursorUp = (count = 1) => ESC + count + "A";
79065
+ ansiEscapes.cursorDown = (count = 1) => ESC + count + "B";
79066
+ ansiEscapes.cursorForward = (count = 1) => ESC + count + "C";
79067
+ ansiEscapes.cursorBackward = (count = 1) => ESC + count + "D";
79068
+ ansiEscapes.cursorLeft = ESC + "G";
79069
+ ansiEscapes.cursorSavePosition = isTerminalApp ? "\x1B7" : ESC + "s";
79070
+ ansiEscapes.cursorRestorePosition = isTerminalApp ? "\x1B8" : ESC + "u";
79071
+ ansiEscapes.cursorGetPosition = ESC + "6n";
79072
+ ansiEscapes.cursorNextLine = ESC + "E";
79073
+ ansiEscapes.cursorPrevLine = ESC + "F";
79074
+ ansiEscapes.cursorHide = ESC + "?25l";
79075
+ ansiEscapes.cursorShow = ESC + "?25h";
79076
+ ansiEscapes.eraseLines = (count) => {
79077
+ let clear = "";
79078
+ for (let i = 0; i < count; i++) clear += ansiEscapes.eraseLine + (i < count - 1 ? ansiEscapes.cursorUp() : "");
79079
+ if (count) clear += ansiEscapes.cursorLeft;
79080
+ return clear;
79081
+ };
79082
+ ansiEscapes.eraseEndLine = ESC + "K";
79083
+ ansiEscapes.eraseStartLine = ESC + "1K";
79084
+ ansiEscapes.eraseLine = ESC + "2K";
79085
+ ansiEscapes.eraseDown = ESC + "J";
79086
+ ansiEscapes.eraseUp = ESC + "1J";
79087
+ ansiEscapes.eraseScreen = ESC + "2J";
79088
+ ansiEscapes.scrollUp = ESC + "S";
79089
+ ansiEscapes.scrollDown = ESC + "T";
79090
+ ansiEscapes.clearScreen = "\x1Bc";
79091
+ ansiEscapes.clearTerminal = process.platform === "win32" ? `${ansiEscapes.eraseScreen}${ESC}0f` : `${ansiEscapes.eraseScreen}${ESC}3J${ESC}H`;
79092
+ ansiEscapes.beep = BEL;
79093
+ ansiEscapes.link = (text, url) => {
79094
+ return [
79095
+ OSC,
79096
+ "8",
79097
+ SEP,
79098
+ SEP,
79099
+ url,
79100
+ BEL,
79101
+ text,
79102
+ OSC,
79103
+ "8",
79104
+ SEP,
79105
+ SEP,
79106
+ BEL
79107
+ ].join("");
79108
+ };
79109
+ ansiEscapes.image = (buffer, options = {}) => {
79110
+ let ret = `${OSC}1337;File=inline=1`;
79111
+ if (options.width) ret += `;width=${options.width}`;
79112
+ if (options.height) ret += `;height=${options.height}`;
79113
+ if (options.preserveAspectRatio === false) ret += ";preserveAspectRatio=0";
79114
+ return ret + ":" + buffer.toString("base64") + BEL;
79115
+ };
79116
+ ansiEscapes.iTerm = {
79117
+ setCwd: (cwd = process.cwd()) => `${OSC}50;CurrentDir=${cwd}${BEL}`,
79118
+ annotation: (message, options = {}) => {
79119
+ let ret = `${OSC}1337;`;
79120
+ const hasX = typeof options.x !== "undefined";
79121
+ const hasY = typeof options.y !== "undefined";
79122
+ if ((hasX || hasY) && !(hasX && hasY && typeof options.length !== "undefined")) throw new Error("`x`, `y` and `length` must be defined when `x` or `y` is defined");
79123
+ message = message.replace(/\|/g, "");
79124
+ ret += options.isHidden ? "AddHiddenAnnotation=" : "AddAnnotation=";
79125
+ if (options.length > 0) ret += (hasX ? [
79126
+ message,
79127
+ options.length,
79128
+ options.x,
79129
+ options.y
79130
+ ] : [options.length, message]).join("|");
79131
+ else ret += message;
79132
+ return ret + BEL;
79133
+ }
79134
+ };
79135
+ }));
79136
+ //#endregion
79137
+ //#region ../../node_modules/supports-hyperlinks/index.js
79138
+ var require_supports_hyperlinks = /* @__PURE__ */ __commonJSMin(((exports, module) => {
79139
+ const supportsColor = require_supports_color();
79140
+ const hasFlag = require_has_flag();
79141
+ function parseVersion(versionString) {
79142
+ if (/^\d{3,4}$/.test(versionString)) {
79143
+ const m = /(\d{1,2})(\d{2})/.exec(versionString);
79144
+ return {
79145
+ major: 0,
79146
+ minor: parseInt(m[1], 10),
79147
+ patch: parseInt(m[2], 10)
79148
+ };
79149
+ }
79150
+ const versions = (versionString || "").split(".").map((n) => parseInt(n, 10));
79151
+ return {
79152
+ major: versions[0],
79153
+ minor: versions[1],
79154
+ patch: versions[2]
79155
+ };
79156
+ }
79157
+ function supportsHyperlink(stream) {
79158
+ const { env } = process;
79159
+ if ("FORCE_HYPERLINK" in env) return !(env.FORCE_HYPERLINK.length > 0 && parseInt(env.FORCE_HYPERLINK, 10) === 0);
79160
+ if (hasFlag("no-hyperlink") || hasFlag("no-hyperlinks") || hasFlag("hyperlink=false") || hasFlag("hyperlink=never")) return false;
79161
+ if (hasFlag("hyperlink=true") || hasFlag("hyperlink=always")) return true;
79162
+ if ("NETLIFY" in env) return true;
79163
+ if (!supportsColor.supportsColor(stream)) return false;
79164
+ if (stream && !stream.isTTY) return false;
79165
+ if (process.platform === "win32") return false;
79166
+ if ("CI" in env) return false;
79167
+ if ("TEAMCITY_VERSION" in env) return false;
79168
+ if ("TERM_PROGRAM" in env) {
79169
+ const version = parseVersion(env.TERM_PROGRAM_VERSION);
79170
+ switch (env.TERM_PROGRAM) {
79171
+ case "iTerm.app":
79172
+ if (version.major === 3) return version.minor >= 1;
79173
+ return version.major > 3;
79174
+ case "WezTerm": return version.major >= 20200620;
79175
+ case "vscode": return version.major > 1 || version.major === 1 && version.minor >= 72;
79176
+ }
79177
+ }
79178
+ if ("VTE_VERSION" in env) {
79179
+ if (env.VTE_VERSION === "0.50.0") return false;
79180
+ const version = parseVersion(env.VTE_VERSION);
79181
+ return version.major > 0 || version.minor >= 50;
79182
+ }
79183
+ return false;
79184
+ }
79185
+ module.exports = {
79186
+ supportsHyperlink,
79187
+ stdout: supportsHyperlink(process.stdout),
79188
+ stderr: supportsHyperlink(process.stderr)
79189
+ };
79190
+ }));
79191
+ //#endregion
79192
+ //#region ../../node_modules/terminal-link/index.js
79193
+ var require_terminal_link$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
79194
+ const ansiEscapes = require_ansi_escapes();
79195
+ const supportsHyperlinks = require_supports_hyperlinks();
79196
+ const terminalLink = (text, url, { target = "stdout", ...options } = {}) => {
79197
+ if (!supportsHyperlinks[target]) {
79198
+ if (options.fallback === false) return text;
79199
+ return typeof options.fallback === "function" ? options.fallback(text, url) : `${text} (\u200B${url}\u200B)`;
79200
+ }
79201
+ return ansiEscapes.link(text, url);
79202
+ };
79203
+ module.exports = (text, url, options = {}) => terminalLink(text, url, options);
79204
+ module.exports.stderr = (text, url, options = {}) => terminalLink(text, url, {
79205
+ target: "stderr",
79206
+ ...options
79207
+ });
79208
+ module.exports.isSupported = supportsHyperlinks.stdout;
79209
+ module.exports.stderr.isSupported = supportsHyperlinks.stderr;
79210
+ }));
79211
+ //#endregion
79212
+ //#region ../base/dist/helpers/terminal-link.js
79213
+ var require_terminal_link = /* @__PURE__ */ __commonJSMin(((exports) => {
79214
+ var __importDefault = exports && exports.__importDefault || function(mod) {
79215
+ return mod && mod.__esModule ? mod : { "default": mod };
79216
+ };
79217
+ Object.defineProperty(exports, "__esModule", { value: true });
79218
+ exports.makeTerminalLink = void 0;
79219
+ const terminal_link_1 = __importDefault(require_terminal_link$1());
79220
+ const makeTerminalLink = (url) => {
79221
+ return ((strings) => (0, terminal_link_1.default)(strings[0], url));
79222
+ };
79223
+ exports.makeTerminalLink = makeTerminalLink;
79224
+ }));
79225
+ //#endregion
79226
+ //#region ../base/dist/helpers/auth.js
79227
+ var require_auth = /* @__PURE__ */ __commonJSMin(((exports) => {
79228
+ Object.defineProperty(exports, "__esModule", { value: true });
79229
+ exports.CliWithAuthHelp = exports.formatAuthHelp = exports.getAuthHelpForCommand = exports.getAuthRequirement = exports.getAuthHelp = exports.customAuth = exports.noAuth = exports.apiKeyAuth = exports.orgActionAuth = exports.getFlareAuthHelp = exports.getCloudCredentialsOnlyAuthHelp = exports.getServerlessInstrumentAuthHelp = exports.AUTH_HELP = exports.seeReadme = exports.wifLink = exports.WORKLOAD_IDENTITY_FEDERATION_DOCS_URL = exports.getMissingOrgCredentialsMessage = exports.hasOrgCredentials = exports.resolveOrgCredentials = exports.getAccessTokenFromEnv = exports.AUTHENTICATION_DOCS_URL = void 0;
79230
+ const util_1 = require("util");
79231
+ const clipanion_1 = require_advanced();
79232
+ const terminal_link_1 = require_terminal_link();
79233
+ /**
79234
+ * Shared Datadog credential handling.
79235
+ *
79236
+ * - "Data upload" commands only need an API key (DD_API_KEY). With Workload Identity Federation (WIF),
79237
+ * an intake mapping provides one.
79238
+ * - "Org action" commands act on behalf of a user or service account: they need an access token
79239
+ * (DD_ACCESS_TOKEN, sent as `Authorization: Bearer`) from a WIF identity mapping, or an API key and an
79240
+ * application key. An access token takes precedence over an application key.
79241
+ */
79242
+ exports.AUTHENTICATION_DOCS_URL = "https://github.com/DataDog/datadog-ci#authentication";
79243
+ /**
79244
+ * Read the access token from the environment, following the same `DATADOG_*` then `DD_*` order as the API and
79245
+ * application keys.
79246
+ */
79247
+ const getAccessTokenFromEnv = (env = process.env) => env.DATADOG_ACCESS_TOKEN || env.DD_ACCESS_TOKEN || void 0;
79248
+ exports.getAccessTokenFromEnv = getAccessTokenFromEnv;
79249
+ /**
79250
+ * Normalize org-action credentials: empty values are dropped, and an access token wins over an application key,
79251
+ * so the application key is dropped when a token is set. The API key is kept when provided.
79252
+ */
79253
+ const resolveOrgCredentials = ({ accessToken, apiKey, appKey }) => {
79254
+ if (accessToken) return {
79255
+ accessToken,
79256
+ apiKey: apiKey || void 0
79257
+ };
79258
+ return {
79259
+ apiKey: apiKey || void 0,
79260
+ appKey: appKey || void 0
79261
+ };
79262
+ };
79263
+ exports.resolveOrgCredentials = resolveOrgCredentials;
79264
+ const hasOrgCredentials = (credentials) => !!credentials.accessToken || !!credentials.apiKey && !!credentials.appKey;
79265
+ exports.hasOrgCredentials = hasOrgCredentials;
79266
+ /**
79267
+ * Explain which credentials an org-action command is missing, or return `undefined` when the credentials are enough:
79268
+ * an access token, or an API key and an application key.
79269
+ */
79270
+ const getMissingOrgCredentialsMessage = (commandName, credentials) => {
79271
+ if ((0, exports.hasOrgCredentials)(credentials)) return;
79272
+ const identityMappingHint = "With Workload Identity Federation, use an identity mapping to get an access token: an intake mapping only provides an API key.";
79273
+ if (credentials.apiKey) return `\`${commandName}\` needs an application key (DD_APP_KEY) or an access token (DD_ACCESS_TOKEN). An intake mapping only provides an API key: use a Workload Identity Federation identity mapping to get an access token. See ${exports.AUTHENTICATION_DOCS_URL}`;
79274
+ if (credentials.appKey) return `\`${commandName}\` needs an API key (DD_API_KEY) to go with the application key, or an access token (DD_ACCESS_TOKEN). ${identityMappingHint} See ${exports.AUTHENTICATION_DOCS_URL}`;
79275
+ return `\`${commandName}\` needs an access token (DD_ACCESS_TOKEN), or an API key (DD_API_KEY) and an application key (DD_APP_KEY). ${identityMappingHint} See ${exports.AUTHENTICATION_DOCS_URL}`;
79276
+ };
79277
+ exports.getMissingOrgCredentialsMessage = getMissingOrgCredentialsMessage;
79278
+ exports.WORKLOAD_IDENTITY_FEDERATION_DOCS_URL = "https://docs.datadoghq.com/account_management/workload_identity_federation/";
79279
+ /** "Workload Identity Federation" as a terminal link to its docs. */
79280
+ exports.wifLink = (0, terminal_link_1.makeTerminalLink)(exports.WORKLOAD_IDENTITY_FEDERATION_DOCS_URL)`Workload Identity Federation`;
79281
+ /** The last line of every authentication help text. */
79282
+ exports.seeReadme = `See ${exports.AUTHENTICATION_DOCS_URL}`;
79283
+ /**
79284
+ * Bodies of the "Authentication" section of `--help`. Paragraphs are separated by a blank line, and a single newline is
79285
+ * a hard line break. Each body ends with "See <README URL>" on its own short line, so the wrapper never splits it.
79286
+ */
79287
+ exports.AUTH_HELP = {
79288
+ apiKey: `This command sends telemetry to your org. As such, it requires an API key (DD_API_KEY), which a ${exports.wifLink} intake mapping can provide.\n\n${exports.seeReadme}`,
79289
+ orgAction: `This command calls Datadog API endpoints. As such, it requires either an API key (DD_API_KEY) and an application key (DD_APP_KEY), or an access token (DD_ACCESS_TOKEN) from a ${exports.wifLink} identity mapping.\n\n${exports.seeReadme}`,
79290
+ none: `This command does not need Datadog credentials.\n\n${exports.seeReadme}`
79291
+ };
79292
+ /**
79293
+ * Authentication help for Serverless `instrument` commands, which save the Datadog API key in the instrumented service.
79294
+ * @param cloudCredentials - the cloud provider credentials the command uses, for example "AWS credentials".
79295
+ * @param datadogCredentials - how the command reads the Datadog API key, for example "a Datadog API key (DD_API_KEY)".
79296
+ */
79297
+ const getServerlessInstrumentAuthHelp = (cloudCredentials, datadogCredentials) => `This command uses your ${cloudCredentials} and saves ${datadogCredentials} in the instrumented service, which uses it to send telemetry. As such, it requires a long-lived API key: a short-lived key from a ${exports.wifLink} intake mapping would expire.\n\n${exports.seeReadme}`;
79298
+ exports.getServerlessInstrumentAuthHelp = getServerlessInstrumentAuthHelp;
79299
+ /**
79300
+ * Authentication help for commands that only call the cloud provider, such as Serverless `uninstrument` commands.
79301
+ * @param cloudCredentials - the cloud provider credentials the command uses, for example "AWS credentials".
79302
+ */
79303
+ const getCloudCredentialsOnlyAuthHelp = (cloudCredentials) => `This command uses your ${cloudCredentials}. It does not need Datadog credentials.\n\n${exports.seeReadme}`;
79304
+ exports.getCloudCredentialsOnlyAuthHelp = getCloudCredentialsOnlyAuthHelp;
79305
+ /**
79306
+ * Authentication help for the Serverless `flare` commands, which read from the cloud provider and send a flare to Datadog.
79307
+ * @param cloudCredentials - the cloud provider credentials the command uses, for example "AWS credentials".
79308
+ */
79309
+ const getFlareAuthHelp = (cloudCredentials) => `This command uses your ${cloudCredentials} and sends a flare to Datadog support. As such, it requires an API key (DD_API_KEY), which a ${exports.wifLink} intake mapping can provide.\n\n${exports.seeReadme}`;
79310
+ exports.getFlareAuthHelp = getFlareAuthHelp;
79311
+ /** Calls Datadog API endpoints: an API key and an application key, or an access token. */
79312
+ exports.orgActionAuth = { kind: "orgAction" };
79313
+ /** Only sends telemetry: an API key. */
79314
+ exports.apiKeyAuth = { kind: "apiKey" };
79315
+ /** Does not need Datadog credentials. */
79316
+ exports.noAuth = { kind: "none" };
79317
+ /** A command-specific authentication help text. */
79318
+ const customAuth = (help) => ({
79319
+ kind: "custom",
79320
+ help
79321
+ });
79322
+ exports.customAuth = customAuth;
79323
+ const getAuthHelp = (requirement) => requirement.kind === "custom" ? requirement.help : exports.AUTH_HELP[requirement.kind];
79324
+ exports.getAuthHelp = getAuthHelp;
79325
+ /** The authentication requirement a command class declares, if any. */
79326
+ const getAuthRequirement = (commandClass) => commandClass.authRequirement;
79327
+ exports.getAuthRequirement = getAuthRequirement;
79328
+ /** The authentication help of a command, from the `authRequirement` its class declares. */
79329
+ const getAuthHelpForCommand = (commandClass) => {
79330
+ const requirement = (0, exports.getAuthRequirement)(commandClass);
79331
+ return requirement ? (0, exports.getAuthHelp)(requirement) : void 0;
79332
+ };
79333
+ exports.getAuthHelpForCommand = getAuthHelpForCommand;
79334
+ const HELP_WIDTH = 80;
79335
+ const WORD_REGEX = /\u001B\]8;;[^\u0007]*\u0007[^\u001B]*\u001B\]8;;\u0007\S*|\S+/g;
79336
+ /** Wrap a line at 80 visible characters, like Clipanion does for `Details`, without splitting terminal links. */
79337
+ const wrapLine = (line) => {
79338
+ var _a;
79339
+ const lines = [];
79340
+ let current = "";
79341
+ for (const word of (_a = line.match(WORD_REGEX)) !== null && _a !== void 0 ? _a : []) {
79342
+ const candidate = current ? `${current} ${word}` : word;
79343
+ if (current && (0, util_1.stripVTControlCharacters)(candidate).length > HELP_WIDTH) {
79344
+ lines.push(current);
79345
+ current = word;
79346
+ } else current = candidate;
79347
+ }
79348
+ lines.push(current);
79349
+ return lines.join("\n");
79350
+ };
79351
+ /** Format an authentication help text: paragraphs separated by a blank line, single newlines kept as line breaks. */
79352
+ const formatAuthHelp = (text) => `${text.split("\n\n").map((paragraph) => paragraph.split("\n").map(wrapLine).join("\n")).join("\n\n")}\n`;
79353
+ exports.formatAuthHelp = formatAuthHelp;
79354
+ /**
79355
+ * A Clipanion `Cli` whose detailed `--help` has an "Authentication" section, after "Details" and before "Examples",
79356
+ * for every command that declares an `authRequirement`. The section is rendered with Clipanion's own header style.
79357
+ *
79358
+ * Every help route goes through `Cli.usage()`: `<command> --help` and `-h` (through the builtin `HelpCommand`) and
79359
+ * `Cli.run` for a command with `help` set. The command's `usage.details` is left unchanged.
79360
+ */
79361
+ var CliWithAuthHelp = class extends clipanion_1.Cli {
79362
+ usage(command = null, opts = {}) {
79363
+ const result = super.usage(command, opts);
79364
+ const commandClass = command instanceof clipanion_1.Command ? command.constructor : command;
79365
+ const help = opts.detailed && commandClass ? (0, exports.getAuthHelpForCommand)(commandClass) : void 0;
79366
+ if (!help) return result;
79367
+ const format = this.format(opts.colored);
79368
+ const section = `\n${format.header("Authentication")}\n\n${(0, exports.formatAuthHelp)(help)}`;
79369
+ const examplesIndex = result.indexOf(`\n${format.header("Examples")}\n`);
79370
+ return examplesIndex === -1 ? `${result}${section}` : `${result.slice(0, examplesIndex)}${section}${result.slice(examplesIndex)}`;
79371
+ }
79372
+ };
79373
+ exports.CliWithAuthHelp = CliWithAuthHelp;
79374
+ }));
79375
+ //#endregion
79040
79376
  //#region ../base/dist/index.js
79041
79377
  var require_dist = /* @__PURE__ */ __commonJSMin(((exports) => {
79042
79378
  var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
@@ -79162,6 +79498,7 @@ var require_upload = /* @__PURE__ */ __commonJSMin(((exports) => {
79162
79498
  const clipanion_1 = require_advanced();
79163
79499
  const t = __importStar(require_lib$1());
79164
79500
  const plugin_1 = require_plugin();
79501
+ const auth_1 = require_auth();
79165
79502
  const __1 = require_dist();
79166
79503
  var TerraformUploadCommand = class extends __1.BaseCommand {
79167
79504
  constructor() {
@@ -79172,6 +79509,10 @@ var require_upload = /* @__PURE__ */ __commonJSMin(((exports) => {
79172
79509
  });
79173
79510
  this.filePaths = clipanion_1.Option.Rest({ required: 1 });
79174
79511
  this.repoId = clipanion_1.Option.String("--repo-id", { description: "Repository identifier override (e.g., github.com/datadog/my-repo)" });
79512
+ this.expectedPlans = clipanion_1.Option.String("--expected-plans", {
79513
+ description: "Total number of plans the pipeline will upload for this commit (all jobs combined). Defaults to the number of plan files provided. Only valid for plan uploads",
79514
+ validator: t.cascade(t.isNumber(), [t.isInteger(), t.isAtLeast(1)])
79515
+ });
79175
79516
  this.skipGitMetadataUpload = clipanion_1.Option.Boolean("--skip-git-metadata-upload", false, { description: "Skip the upload of git metadata" });
79176
79517
  this.verbose = clipanion_1.Option.Boolean("--verbose", false, { description: "Enable verbose logging" });
79177
79518
  this.fips = clipanion_1.Option.Boolean("--fips", false, { description: "Enable FIPS mode for the command" });
@@ -79198,10 +79539,12 @@ var require_upload = /* @__PURE__ */ __commonJSMin(((exports) => {
79198
79539
  ["Upload a Terraform plan file", "datadog-ci terraform upload plan terraform-plan.json"],
79199
79540
  ["Upload multiple Terraform plan files", "datadog-ci terraform upload plan plan1.json plan2.json plan3.json"],
79200
79541
  ["Upload a Terraform state file", "datadog-ci terraform upload state terraform.tfstate"],
79542
+ ["Upload plans from a pipeline that uploads 3 plans in total for this commit", "datadog-ci terraform upload plan terraform-plan.json --expected-plans 3"],
79201
79543
  ["Upload with verbose output", "datadog-ci terraform upload plan terraform-plan.json --verbose"],
79202
79544
  ["Dry run mode", "datadog-ci terraform upload plan terraform-plan.json --dry-run"]
79203
79545
  ]
79204
79546
  });
79547
+ TerraformUploadCommand.authRequirement = auth_1.apiKeyAuth;
79205
79548
  }));
79206
79549
  //#endregion
79207
79550
  //#region ../base/dist/helpers/fips.js
@@ -79341,6 +79684,7 @@ const uploadTerraformArtifact = (request) => async (payload) => {
79341
79684
  ...payload.spanTags
79342
79685
  };
79343
79686
  if (payload.repoId) event.repo_id = payload.repoId;
79687
+ if (payload.expectedPlanCount !== void 0) event.expected_plan_count = payload.expectedPlanCount;
79344
79688
  form.append("event", JSON.stringify(event), { filename: "event.json" });
79345
79689
  const gzippedContent = await gzipContent(payload.fileContent);
79346
79690
  form.append("iac_file", gzippedContent, {
@@ -79535,6 +79879,7 @@ var PluginCommand = class extends import_upload.TerraformUploadCommand {
79535
79879
  fipsIgnoreError: (0, import_env.toBoolean)(process.env[import_constants.FIPS_IGNORE_ERROR_ENV_VAR]) ?? false
79536
79880
  };
79537
79881
  this.git = void 0;
79882
+ this.expectedPlanCount = void 0;
79538
79883
  }
79539
79884
  async execute() {
79540
79885
  (0, import_fips.enableFips)(this.fips || this.config.fips, this.fipsIgnoreError || this.config.fipsIgnoreError);
@@ -79544,6 +79889,18 @@ var PluginCommand = class extends import_upload.TerraformUploadCommand {
79544
79889
  this.logger.error(`Neither ${import_source.default.red.bold("DATADOG_API_KEY")} nor ${import_source.default.red.bold("DD_API_KEY")} is in your environment.`);
79545
79890
  return 1;
79546
79891
  }
79892
+ if (this.expectedPlans !== void 0 && this.artifactType !== "plan") {
79893
+ this.logger.error("--expected-plans can only be used with plan uploads");
79894
+ return 1;
79895
+ }
79896
+ this.expectedPlanCount = this.expectedPlans;
79897
+ if (this.artifactType === "plan") {
79898
+ if (this.expectedPlanCount === void 0) this.expectedPlanCount = this.filePaths.length;
79899
+ else if (this.expectedPlanCount < this.filePaths.length) {
79900
+ this.logger.warn(`Expected plan count (${this.expectedPlanCount}) is lower than the number of plan files provided (${this.filePaths.length}), using ${this.filePaths.length} instead`);
79901
+ this.expectedPlanCount = this.filePaths.length;
79902
+ }
79903
+ }
79547
79904
  const isGitRepository = await (0, import_library.isGitRepo)();
79548
79905
  if (isGitRepository) this.git = await (0, import_git.newSimpleGit)();
79549
79906
  if (!this.skipGitMetadataUpload && isGitRepository) await this.syncGitMetadata();
@@ -79593,7 +79950,8 @@ var PluginCommand = class extends import_upload.TerraformUploadCommand {
79593
79950
  artifactSha256,
79594
79951
  artifactSizeBytes,
79595
79952
  spanTags,
79596
- repoId: resolveRepoId(this.repoId, spanTags)
79953
+ repoId: resolveRepoId(this.repoId, spanTags),
79954
+ expectedPlanCount: this.expectedPlanCount
79597
79955
  };
79598
79956
  try {
79599
79957
  if (this.dryRun) this.logger.info(renderDryRunUpload(payload));
@@ -108,6 +108,19 @@ Bundled license information:
108
108
  * SOFTWARE.
109
109
  */
110
110
 
111
+ ansi-escapes/license:
112
+ /*
113
+ * MIT License
114
+ *
115
+ * Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
116
+ *
117
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
118
+ *
119
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
120
+ *
121
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
122
+ */
123
+
111
124
  ansi-styles/license:
112
125
  /*
113
126
  * MIT License
@@ -1326,6 +1339,32 @@ supports-color/license:
1326
1339
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1327
1340
  */
1328
1341
 
1342
+ supports-hyperlinks/license:
1343
+ /*
1344
+ * MIT License
1345
+ *
1346
+ * Copyright (c) James Talmage <james@talmage.io> (github.com/jamestalmage)
1347
+ *
1348
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
1349
+ *
1350
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
1351
+ *
1352
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1353
+ */
1354
+
1355
+ terminal-link/license:
1356
+ /*
1357
+ * MIT License
1358
+ *
1359
+ * Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
1360
+ *
1361
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
1362
+ *
1363
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
1364
+ *
1365
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1366
+ */
1367
+
1329
1368
  tinyexec/LICENSE:
1330
1369
  /*
1331
1370
  * MIT License