@pipeline-builder/pipeline-manager 6.5.6 → 6.5.7

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.
@@ -203,7 +203,9 @@ var EVENTS_CONFIG_DEFAULTS = {
203
203
  redriveIntervalMs: 5 * 60 * 1e3,
204
204
  redriveMaxAgeSec: 6 * 60 * 60,
205
205
  tagCacheTtlMs: 15 * 60 * 1e3,
206
- tagMissCacheTtlMs: 5 * 60 * 1e3
206
+ tagMissCacheTtlMs: 5 * 60 * 1e3,
207
+ lastStampIntervalMs: 60 * 1e3,
208
+ scmCooldownMs: 2 * 60 * 1e3
207
209
  };
208
210
  function str(name) {
209
211
  return envStr(name, "").trim() || void 0;
@@ -230,6 +232,14 @@ function dlqArn() {
230
232
  }
231
233
  return raw;
232
234
  }
235
+ var SSM_PARAMETER_PATH_RE = /^\/[A-Za-z0-9_.\-/]{1,1010}$/;
236
+ function lastEventParameter() {
237
+ const raw = str("LAST_EVENT_PARAMETER");
238
+ if (raw !== void 0 && !SSM_PARAMETER_PATH_RE.test(raw)) {
239
+ throw new Error("LAST_EVENT_PARAMETER must be an SSM parameter path (/name, letters, digits, _.-/ only)");
240
+ }
241
+ return raw;
242
+ }
233
243
  function loadEventsConfig() {
234
244
  const d = EVENTS_CONFIG_DEFAULTS;
235
245
  const positive = (name, def) => envIntStrict(name, def, { min: 1 });
@@ -244,7 +254,10 @@ function loadEventsConfig() {
244
254
  redriveIntervalMs: positive("EVENT_DLQ_REDRIVE_INTERVAL_MS", d.redriveIntervalMs),
245
255
  redriveMaxAgeSec: positive("EVENT_DLQ_REDRIVE_MAX_AGE_SEC", d.redriveMaxAgeSec),
246
256
  tagCacheTtlMs: positive("EVENT_TAG_CACHE_TTL_MS", d.tagCacheTtlMs),
247
- tagMissCacheTtlMs: positive("EVENT_TAG_MISS_CACHE_TTL_MS", d.tagMissCacheTtlMs)
257
+ tagMissCacheTtlMs: positive("EVENT_TAG_MISS_CACHE_TTL_MS", d.tagMissCacheTtlMs),
258
+ lastEventParameter: lastEventParameter(),
259
+ lastStampIntervalMs: positive("EVENT_LAST_STAMP_INTERVAL_MS", d.lastStampIntervalMs),
260
+ scmCooldownMs: positive("SCM_COOLDOWN_MS", d.scmCooldownMs)
248
261
  };
249
262
  }
250
263
 
@@ -515,10 +528,9 @@ function recordForwarded(events) {
515
528
  var ssmMod;
516
529
  var ssm;
517
530
  var lastStampAt = 0;
518
- var STAMP_EVERY_MS = 6e4;
519
531
  async function stampLastEvent(now = Date.now()) {
520
- const name = process.env.LAST_EVENT_PARAMETER?.trim();
521
- if (!name || now - lastStampAt < STAMP_EVERY_MS) return;
532
+ const { lastEventParameter: name, lastStampIntervalMs } = loadEventsConfig();
533
+ if (!name || now - lastStampAt < lastStampIntervalMs) return;
522
534
  lastStampAt = now;
523
535
  try {
524
536
  if (!ssmMod) ssmMod = await loadSdk("@aws-sdk/client-ssm");
@@ -630,33 +642,52 @@ async function readSynthFailure(region, buildId) {
630
642
  import { GetSecretValueCommand as GetSecretValueCommand2, SecretsManagerClient as SecretsManagerClient2 } from "@aws-sdk/client-secrets-manager";
631
643
 
632
644
  // ../api-core/lib/types/pipeline-runners.js
645
+ var RUNNER_ACTIONS = [
646
+ "start",
647
+ "stop",
648
+ "probe",
649
+ "ping",
650
+ "status",
651
+ "deploy",
652
+ "deploy_status",
653
+ "deploy_cancel",
654
+ "undeploy",
655
+ // The account's source connections (the create review's picker) and the pre-deploy source check.
656
+ "list_sources",
657
+ "check_source",
658
+ // Reading a private GitHub repository for Generate from Git with the stored token, inside the account.
659
+ "inspect_repository",
660
+ // Reading any private repository for Generate from Git through a CodeConnections connection: a short
661
+ // CodeBuild job in the account clones it and leaves a bounded snapshot the platform reads back;
662
+ // _stop ends that job early when the platform gives up on it (deadline, cancel, failure).
663
+ "inspect_connection_start",
664
+ "inspect_connection_status",
665
+ "inspect_connection_stop"
666
+ ];
633
667
  var DEPLOY_CAPABILITY = "deploy:1";
634
- var SOURCES_CAPABILITY = "sources:1";
635
- var INSPECT_CAPABILITY = "inspect:1";
636
- var INSPECT_CONNECTION_CAPABILITY = "inspect_connection:1";
637
- var DEPLOY_ACTION_CAPABILITY = {
638
- deploy: DEPLOY_CAPABILITY,
639
- deploy_status: DEPLOY_CAPABILITY,
640
- deploy_cancel: DEPLOY_CAPABILITY,
641
- undeploy: DEPLOY_CAPABILITY
642
- };
643
- var SOURCE_ACTION_CAPABILITY = {
644
- list_sources: SOURCES_CAPABILITY,
645
- check_source: SOURCES_CAPABILITY
646
- };
647
- var INSPECT_ACTION_CAPABILITY = {
648
- inspect_repository: INSPECT_CAPABILITY
649
- };
650
- var INSPECT_CONNECTION_ACTION_CAPABILITY = {
651
- inspect_connection_start: INSPECT_CONNECTION_CAPABILITY,
652
- inspect_connection_status: INSPECT_CONNECTION_CAPABILITY
653
- };
654
- var ACTION_CAPABILITY = {
655
- ...DEPLOY_ACTION_CAPABILITY,
656
- ...SOURCE_ACTION_CAPABILITY,
657
- ...INSPECT_ACTION_CAPABILITY,
658
- ...INSPECT_CONNECTION_ACTION_CAPABILITY
668
+ var RUNNER_ACTION_SPECS = {
669
+ start: { outcomes: ["started"], runRequest: true },
670
+ stop: { outcomes: ["stopped"], runRequest: true },
671
+ probe: { outcomes: ["match", "no_match"], runRequest: true },
672
+ ping: { outcomes: ["pong"] },
673
+ status: { outcomes: ["status"] },
674
+ deploy: { outcomes: ["deploying"], capability: DEPLOY_CAPABILITY, runRequest: true },
675
+ deploy_status: { outcomes: ["deploy_status"], capability: DEPLOY_CAPABILITY },
676
+ deploy_cancel: { outcomes: ["deploy_cancelled"], capability: DEPLOY_CAPABILITY },
677
+ undeploy: { outcomes: ["undeploying"], capability: DEPLOY_CAPABILITY, runRequest: true },
678
+ list_sources: { outcomes: ["sources"] },
679
+ check_source: { outcomes: ["source_ok"] },
680
+ inspect_repository: { outcomes: ["repository_reads"] },
681
+ inspect_connection_start: { outcomes: ["inspection_started"] },
682
+ inspect_connection_status: { outcomes: ["inspection_status"] },
683
+ inspect_connection_stop: { outcomes: ["inspection_stopped"] }
659
684
  };
685
+ var RUN_REQUEST_ACTIONS = RUNNER_ACTIONS.filter((a) => RUNNER_ACTION_SPECS[a].runRequest === true);
686
+ var EXPECTED_OUTCOMES = Object.fromEntries(RUNNER_ACTIONS.map((a) => [a, RUNNER_ACTION_SPECS[a].outcomes]));
687
+ function actionsGatedBy(capability) {
688
+ return Object.freeze(Object.fromEntries(RUNNER_ACTIONS.filter((a) => RUNNER_ACTION_SPECS[a].capability === capability).map((a) => [a, capability])));
689
+ }
690
+ var DEPLOY_ACTION_CAPABILITY = actionsGatedBy(DEPLOY_CAPABILITY);
660
691
  var RUNNER_ERRORS = {
661
692
  // -- The pipeline service's answers --
662
693
  RUNNERS_UNAVAILABLE: { httpStatus: 409, retryable: false, category: "platform" },
@@ -677,7 +708,6 @@ var RUNNER_ERRORS = {
677
708
  RUNNER_ACCOUNT_CHANGED: { httpStatus: 409, retryable: false, category: "platform" },
678
709
  RUN_REQUEST_RATE_LIMITED: { httpStatus: 429, retryable: false, category: "platform" },
679
710
  TOO_MANY_PENDING: { httpStatus: 429, retryable: false, category: "platform" },
680
- RUNNER_UPDATE_REQUIRED: { httpStatus: 409, retryable: false, category: "platform" },
681
711
  RUNNER_PENDING: { httpStatus: 409, retryable: false, category: "platform" },
682
712
  /** The org's effective signing key exists but cannot be decrypted (wrong master, rotated KMS key). That org only. */
683
713
  RUNNER_KEY_UNREADABLE: { httpStatus: 409, retryable: false, category: "platform" },
@@ -777,7 +807,7 @@ var RUNNER_ERRORS = {
777
807
  INSPECT_BUSY: { httpStatus: 409, retryable: false, category: "runner" },
778
808
  // -- Recorded by the platform --
779
809
  /** Not delivered within the request's lifetime. */
780
- /** A reply whose echoed connector id or request id is not the request's (or an identity:1 reply without one). */
810
+ /** A reply whose echoed connector id, request id or region is not the request's, or a success without the echo. */
781
811
  RUNNER_IDENTITY_MISMATCH: { httpStatus: null, retryable: false, category: "recorded" },
782
812
  RUN_REQUEST_EXPIRED: { httpStatus: null, retryable: false, category: "recorded" },
783
813
  /** A discovery probe that found nothing (probe rows only). */
@@ -927,7 +957,6 @@ var NO_RECORDED_DEPLOY_MAX = 1e3;
927
957
  var noRecordedDeploy = new BoundedMap(NO_RECORDED_DEPLOY_MAX);
928
958
  var commitMetaCache = new BoundedMap(CACHE_MAX_ENTRIES);
929
959
  var scmCooldownUntil = 0;
930
- var SCM_COOLDOWN_MS = 2 * 60 * 1e3;
931
960
  var MAX_COMMIT_WALK = 50;
932
961
  var githubTokenByOrg = new BoundedMap(CACHE_MAX_ENTRIES);
933
962
  var githubTokenMissUntil = new BoundedMap(CACHE_MAX_ENTRIES);
@@ -1066,7 +1095,7 @@ async function resolveGitHub(owner, repo, sha, sinceSha, orgId) {
1066
1095
  if (sinceSha) {
1067
1096
  const r = await fetchWithTimeout(`${base}/compare/${encodeURIComponent(sinceSha)}...${encodeURIComponent(sha)}`, { headers }, loadEventsConfig().scmFetchTimeoutMs);
1068
1097
  if (rateLimited(r)) {
1069
- scmCooldownUntil = Date.now() + SCM_COOLDOWN_MS;
1098
+ scmCooldownUntil = Date.now() + loadEventsConfig().scmCooldownMs;
1070
1099
  return {};
1071
1100
  }
1072
1101
  if (r.ok) {
@@ -1081,7 +1110,7 @@ async function resolveGitHub(owner, repo, sha, sinceSha, orgId) {
1081
1110
  }
1082
1111
  const r2 = await fetchWithTimeout(`${base}/commits/${encodeURIComponent(sha)}`, { headers }, loadEventsConfig().scmFetchTimeoutMs);
1083
1112
  if (rateLimited(r2)) {
1084
- scmCooldownUntil = Date.now() + SCM_COOLDOWN_MS;
1113
+ scmCooldownUntil = Date.now() + loadEventsConfig().scmCooldownMs;
1085
1114
  return {};
1086
1115
  }
1087
1116
  if (r2.ok) {
@@ -1096,7 +1125,7 @@ async function resolveBitbucket(owner, repo, sha) {
1096
1125
  headers: { "User-Agent": "pipeline-builder-forwarder", "Accept": "application/json" }
1097
1126
  }, loadEventsConfig().scmFetchTimeoutMs);
1098
1127
  if (r.status === 429) {
1099
- scmCooldownUntil = Date.now() + SCM_COOLDOWN_MS;
1128
+ scmCooldownUntil = Date.now() + loadEventsConfig().scmCooldownMs;
1100
1129
  return {};
1101
1130
  }
1102
1131
  if (r.ok) {
@@ -40,6 +40,8 @@ export interface OutcomeDetails {
40
40
  snapshot?: Extract<InspectionStatus, {
41
41
  state: 'succeeded';
42
42
  }>['snapshot'];
43
+ /** inspect_connection_stop: false when the build had already finished. */
44
+ stopped?: boolean;
43
45
  }
44
46
  export interface RunnerResult {
45
47
  status: number;
@@ -63,8 +65,8 @@ export interface RunnerConfig {
63
65
  version: string;
64
66
  /** Deploys through this runner (EnableDeploy): the stack's deploy project, pull host, credential and grant key. */
65
67
  deploy: DeployConfig;
66
- /** The stack's inspect build and results bucket (inspect_connection_*); absent = the stack has none. */
67
- inspectConnection?: InspectConnectionConfig;
68
+ /** The stack's inspect build and results bucket (inspect_connection_*): every runner stack has them. */
69
+ inspectConnection: InspectConnectionConfig;
68
70
  /** The stack's EventBridge reporting (events:1): its dead-letter queue and last-event parameter; absent = no reporting. */
69
71
  reporting?: ReportingConfig;
70
72
  }
@@ -1 +1 @@
1
- {"version":3,"file":"runner-handler.d.ts","sources":["../../src/lambda/runner-handler.ts"],"names":[],"mappings":"AA0EA,OAAO,EAEL,KAAK,gBAAgB,EAAE,KAAK,mBAAmB,EAAE,KAAK,WAAW,EAAE,KAAK,gBAAgB,EAAE,KAAK,aAAa,EAAE,KAAK,oBAAoB,EACxI,MAAM,6CAA6C,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AACzG,OAAO,EAAqB,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAwC,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC7F,OAAO,EAAqC,KAAK,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACjH,OAAO,EAAgC,KAAK,SA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AAoB,IAAI,IAAI,CAE3C"}
@@ -35,39 +35,39 @@ var RUNNER_ACTIONS = [
35
35
  // Reading a private GitHub repository for Generate from Git with the stored token, inside the account.
36
36
  "inspect_repository",
37
37
  // Reading any private repository for Generate from Git through a CodeConnections connection: a short
38
- // CodeBuild job in the account clones it and leaves a bounded snapshot the platform reads back.
38
+ // CodeBuild job in the account clones it and leaves a bounded snapshot the platform reads back;
39
+ // _stop ends that job early when the platform gives up on it (deadline, cancel, failure).
39
40
  "inspect_connection_start",
40
- "inspect_connection_status"
41
+ "inspect_connection_status",
42
+ "inspect_connection_stop"
41
43
  ];
42
44
  var DEPLOY_CAPABILITY = "deploy:1";
43
- var SOURCES_CAPABILITY = "sources:1";
44
- var INSPECT_CAPABILITY = "inspect:1";
45
- var INSPECT_CONNECTION_CAPABILITY = "inspect_connection:1";
46
- var IDENTITY_CAPABILITY = "identity:1";
47
45
  var EVENTS_CAPABILITY = "events:1";
48
- var DEPLOY_ACTION_CAPABILITY = {
49
- deploy: DEPLOY_CAPABILITY,
50
- deploy_status: DEPLOY_CAPABILITY,
51
- deploy_cancel: DEPLOY_CAPABILITY,
52
- undeploy: DEPLOY_CAPABILITY
53
- };
54
- var SOURCE_ACTION_CAPABILITY = {
55
- list_sources: SOURCES_CAPABILITY,
56
- check_source: SOURCES_CAPABILITY
57
- };
58
- var INSPECT_ACTION_CAPABILITY = {
59
- inspect_repository: INSPECT_CAPABILITY
60
- };
61
- var INSPECT_CONNECTION_ACTION_CAPABILITY = {
62
- inspect_connection_start: INSPECT_CONNECTION_CAPABILITY,
63
- inspect_connection_status: INSPECT_CONNECTION_CAPABILITY
64
- };
65
- var ACTION_CAPABILITY = {
66
- ...DEPLOY_ACTION_CAPABILITY,
67
- ...SOURCE_ACTION_CAPABILITY,
68
- ...INSPECT_ACTION_CAPABILITY,
69
- ...INSPECT_CONNECTION_ACTION_CAPABILITY
46
+ var RUNNER_ACTION_SPECS = {
47
+ start: { outcomes: ["started"], runRequest: true },
48
+ stop: { outcomes: ["stopped"], runRequest: true },
49
+ probe: { outcomes: ["match", "no_match"], runRequest: true },
50
+ ping: { outcomes: ["pong"] },
51
+ status: { outcomes: ["status"] },
52
+ deploy: { outcomes: ["deploying"], capability: DEPLOY_CAPABILITY, runRequest: true },
53
+ deploy_status: { outcomes: ["deploy_status"], capability: DEPLOY_CAPABILITY },
54
+ deploy_cancel: { outcomes: ["deploy_cancelled"], capability: DEPLOY_CAPABILITY },
55
+ undeploy: { outcomes: ["undeploying"], capability: DEPLOY_CAPABILITY, runRequest: true },
56
+ list_sources: { outcomes: ["sources"] },
57
+ check_source: { outcomes: ["source_ok"] },
58
+ inspect_repository: { outcomes: ["repository_reads"] },
59
+ inspect_connection_start: { outcomes: ["inspection_started"] },
60
+ inspect_connection_status: { outcomes: ["inspection_status"] },
61
+ inspect_connection_stop: { outcomes: ["inspection_stopped"] }
70
62
  };
63
+ var RUN_REQUEST_ACTIONS = RUNNER_ACTIONS.filter((a) => RUNNER_ACTION_SPECS[a].runRequest === true);
64
+ var EXPECTED_OUTCOMES = Object.fromEntries(RUNNER_ACTIONS.map((a) => [a, RUNNER_ACTION_SPECS[a].outcomes]));
65
+ function actionsGatedBy(capability) {
66
+ return Object.freeze(Object.fromEntries(RUNNER_ACTIONS.filter((a) => RUNNER_ACTION_SPECS[a].capability === capability).map((a) => [a, capability])));
67
+ }
68
+ var DEPLOY_ACTION_CAPABILITY = actionsGatedBy(DEPLOY_CAPABILITY);
69
+ var SOURCE_ACTIONS = ["list_sources", "check_source"];
70
+ var INSPECT_CONNECTION_ACTIONS = ["inspect_connection_start", "inspect_connection_status", "inspect_connection_stop"];
71
71
  var AWS_REGION_PATTERN = /^[a-z]{2}(-[a-z]+)+-\d{1,2}$/;
72
72
  var RUNNER_LABEL_MAX_LENGTH = 64;
73
73
  var CONTROL_CHARS_G = /[\p{Cc}\p{Cf}\u2028\u2029]/gu;
@@ -100,7 +100,6 @@ var RUNNER_ERRORS = {
100
100
  RUNNER_ACCOUNT_CHANGED: { httpStatus: 409, retryable: false, category: "platform" },
101
101
  RUN_REQUEST_RATE_LIMITED: { httpStatus: 429, retryable: false, category: "platform" },
102
102
  TOO_MANY_PENDING: { httpStatus: 429, retryable: false, category: "platform" },
103
- RUNNER_UPDATE_REQUIRED: { httpStatus: 409, retryable: false, category: "platform" },
104
103
  RUNNER_PENDING: { httpStatus: 409, retryable: false, category: "platform" },
105
104
  /** The org's effective signing key exists but cannot be decrypted (wrong master, rotated KMS key). That org only. */
106
105
  RUNNER_KEY_UNREADABLE: { httpStatus: 409, retryable: false, category: "platform" },
@@ -200,7 +199,7 @@ var RUNNER_ERRORS = {
200
199
  INSPECT_BUSY: { httpStatus: 409, retryable: false, category: "runner" },
201
200
  // -- Recorded by the platform --
202
201
  /** Not delivered within the request's lifetime. */
203
- /** A reply whose echoed connector id or request id is not the request's (or an identity:1 reply without one). */
202
+ /** A reply whose echoed connector id, request id or region is not the request's, or a success without the echo. */
204
203
  RUNNER_IDENTITY_MISMATCH: { httpStatus: null, retryable: false, category: "recorded" },
205
204
  RUN_REQUEST_EXPIRED: { httpStatus: null, retryable: false, category: "recorded" },
206
205
  /** A discovery probe that found nothing (probe rows only). */
@@ -545,8 +544,8 @@ async function runDeployAction(ctx, claims) {
545
544
  }
546
545
 
547
546
  // src/lambda/runner-inspect-connection.ts
548
- import { BatchGetBuildsCommand as BatchGetBuildsCommand2, StartBuildCommand as StartBuildCommand2 } from "@aws-sdk/client-codebuild";
549
- import { DeleteObjectCommand, GetObjectCommand } from "@aws-sdk/client-s3";
547
+ import { BatchGetBuildsCommand as BatchGetBuildsCommand2, StartBuildCommand as StartBuildCommand2, StopBuildCommand as StopBuildCommand2 } from "@aws-sdk/client-codebuild";
548
+ import { GetObjectCommand } from "@aws-sdk/client-s3";
550
549
 
551
550
  // ../api-core/lib/types/pipeline-source.js
552
551
  var CONNECTION_ARN_PATTERN = /^arn:aws(?:-[a-z]+)*:(?:codeconnections|codestar-connections):[a-z0-9-]+:\d{12}:connection\/[A-Za-z0-9-]+$/;
@@ -600,17 +599,19 @@ var GIT_PROVIDERS = {
600
599
  unknown: { host: null, browse: "tree" }
601
600
  };
602
601
  function providerForHost(host) {
603
- const hit = Object.keys(GIT_PROVIDERS).find((id) => GIT_PROVIDERS[id].host === host);
602
+ const name = host.trim().toLowerCase().replace(/^www\./, "");
603
+ const hit = Object.keys(GIT_PROVIDERS).find((id) => GIT_PROVIDERS[id].host === name);
604
604
  return hit ?? "unknown";
605
605
  }
606
606
  var SOURCE_CONNECTION_PROVIDER_TYPES = ["GitHub", "GitHubEnterpriseServer", "GitLab", "GitLabSelfManaged", "Bitbucket"];
607
607
  var SOURCE_CONNECTION_STATUSES = ["PENDING", "AVAILABLE", "ERROR"];
608
- var PUBLIC_PROVIDER_TYPE = {
609
- github: "GitHub",
610
- gitlab: "GitLab",
611
- bitbucket: "Bitbucket"
608
+ var SOURCE_CONNECTION_PROVIDERS = {
609
+ GitHub: { label: "GitHub", codebuildSourceType: "GITHUB", publicProvider: "github" },
610
+ GitHubEnterpriseServer: { label: "GitHub Enterprise Server", codebuildSourceType: "GITHUB_ENTERPRISE", publicProvider: null },
611
+ GitLab: { label: "GitLab", codebuildSourceType: "GITLAB", publicProvider: "gitlab" },
612
+ GitLabSelfManaged: { label: "GitLab self-managed", codebuildSourceType: "GITLAB_SELF_MANAGED", publicProvider: null },
613
+ Bitbucket: { label: "Bitbucket", codebuildSourceType: "BITBUCKET", publicProvider: "bitbucket" }
612
614
  };
613
- var SELF_MANAGED_PROVIDER_TYPES = ["GitHubEnterpriseServer", "GitLabSelfManaged"];
614
615
  function connectionArnParts(arn) {
615
616
  const value = arn.trim();
616
617
  if (!CONNECTION_ARN_PATTERN.test(value))
@@ -621,9 +622,10 @@ function connectionArnParts(arn) {
621
622
  function connectionMatchesRepository(connection, repoHost) {
622
623
  const host = repoHost.trim().toLowerCase();
623
624
  const provider = providerForHost(host);
625
+ const served = SOURCE_CONNECTION_PROVIDERS[connection.providerType]?.publicProvider;
624
626
  if (provider !== "unknown")
625
- return connection.providerType === PUBLIC_PROVIDER_TYPE[provider];
626
- if (!SELF_MANAGED_PROVIDER_TYPES.includes(connection.providerType) || !connection.hostEndpoint)
627
+ return served === provider;
628
+ if (served !== null || !connection.hostEndpoint)
627
629
  return false;
628
630
  try {
629
631
  return new URL(connection.hostEndpoint).hostname.toLowerCase() === host;
@@ -677,6 +679,8 @@ var MAX_TOPICS = 50;
677
679
  var MAX_LANGUAGES = 100;
678
680
  var MAX_BASE64_CHARS = 2e5;
679
681
  var optionalString = (v, max) => v === void 0 || v === null || typeof v === "string" && v.length <= max;
682
+ var listingNameOk = (name) => name !== "." && name !== ".." && !name.includes("/") && READ_SEGMENT_PATTERN.test(name);
683
+ var languageEntryOk = (name, bytes) => name.length <= 100 && typeof bytes === "number" && Number.isFinite(bytes) && bytes >= 0;
680
684
  function parseRepositoryReadBody(read, body) {
681
685
  if (read.kind === "repo") {
682
686
  if (!isRecord(body))
@@ -702,14 +706,14 @@ function parseRepositoryReadBody(read, body) {
702
706
  if (!isRecord(body))
703
707
  return null;
704
708
  const entries = Object.entries(body);
705
- if (entries.length > MAX_LANGUAGES || entries.some(([k, v]) => k.length > 100 || typeof v !== "number" || !Number.isFinite(v)))
709
+ if (entries.length > MAX_LANGUAGES || entries.some(([k, v]) => !languageEntryOk(k, v)))
706
710
  return null;
707
711
  return Object.fromEntries(entries);
708
712
  }
709
713
  if (Array.isArray(body)) {
710
714
  if (body.length > INSPECT_MAX_LISTING_ENTRIES)
711
715
  return null;
712
- return body.filter((e) => isRecord(e) && typeof e.name === "string" && e.name.length <= 255 && (e.type === "file" || e.type === "dir")).map((e) => ({ name: e.name, type: e.type }));
716
+ return body.filter((e) => isRecord(e) && typeof e.name === "string" && listingNameOk(e.name) && (e.type === "file" || e.type === "dir")).map((e) => ({ name: e.name, type: e.type }));
713
717
  }
714
718
  if (!isRecord(body))
715
719
  return null;
@@ -747,7 +751,7 @@ function parseRepositorySnapshot(raw) {
747
751
  return null;
748
752
  const kept = [];
749
753
  for (const e of entries) {
750
- if (!isRecord(e) || typeof e.name !== "string" || !READ_SEGMENT_PATTERN.test(e.name) || e.type !== "file" && e.type !== "dir")
754
+ if (!isRecord(e) || typeof e.name !== "string" || !listingNameOk(e.name) || e.type !== "file" && e.type !== "dir")
751
755
  return null;
752
756
  kept.push({ name: e.name, type: e.type });
753
757
  }
@@ -761,7 +765,7 @@ function parseRepositorySnapshot(raw) {
761
765
  return null;
762
766
  }
763
767
  const langEntries = Object.entries(languages);
764
- if (langEntries.length > MAX_LANGUAGES || langEntries.some(([k, v]) => k.length > 100 || typeof v !== "number" || !Number.isFinite(v) || v < 0))
768
+ if (langEntries.length > MAX_LANGUAGES || langEntries.some(([k, v]) => !languageEntryOk(k, v)))
765
769
  return null;
766
770
  return { branch, listings: outListings, files: Object.fromEntries(fileEntries), languages: Object.fromEntries(langEntries) };
767
771
  }
@@ -874,13 +878,6 @@ async function checkSource(claim, accountId, deps) {
874
878
  }
875
879
 
876
880
  // src/lambda/runner-inspect-connection.ts
877
- var SOURCE_TYPE = {
878
- GitHub: "GITHUB",
879
- GitHubEnterpriseServer: "GITHUB_ENTERPRISE",
880
- GitLab: "GITLAB",
881
- GitLabSelfManaged: "GITLAB_SELF_MANAGED",
882
- Bitbucket: "BITBUCKET"
883
- };
884
881
  var errName3 = (err) => String(err?.name ?? "");
885
882
  function resultKey(buildId) {
886
883
  return `${buildId.slice(buildId.indexOf(":") + 1)}.json`;
@@ -893,7 +890,7 @@ async function startInspection(claim, accountId, config, deps) {
893
890
  try {
894
891
  const out = await deps.codebuild().send(new StartBuildCommand2({
895
892
  projectName: config.projectName,
896
- sourceTypeOverride: SOURCE_TYPE[connection.providerType],
893
+ sourceTypeOverride: SOURCE_CONNECTION_PROVIDERS[connection.providerType].codebuildSourceType,
897
894
  sourceLocationOverride: location,
898
895
  ...claim.branch ? { sourceVersion: claim.branch } : {},
899
896
  gitCloneDepthOverride: 1,
@@ -931,8 +928,6 @@ async function readSnapshot(buildId, config, deps) {
931
928
  } catch (err) {
932
929
  if (errName3(err) === "NoSuchKey" || errName3(err) === "NotFound") return null;
933
930
  throw err;
934
- } finally {
935
- await deps.s3().send(new DeleteObjectCommand({ Bucket: config.bucket, Key: key })).catch(() => void 0);
936
931
  }
937
932
  if (text === null) return null;
938
933
  let json;
@@ -960,6 +955,17 @@ async function inspectionStatus(claim, config, deps) {
960
955
  return { state: "failed", failedPhase: failedPhase(build) };
961
956
  }
962
957
  }
958
+ async function stopInspection(claim, config, deps) {
959
+ if (!claim.buildId.startsWith(`${config.projectName}:`)) return "INSPECT_BUILD_NOT_FOUND";
960
+ try {
961
+ await deps.codebuild().send(new StopBuildCommand2({ id: claim.buildId }));
962
+ return { stopped: true };
963
+ } catch (err) {
964
+ if (errName3(err) === "InvalidInputException") return { stopped: false };
965
+ if (errName3(err) === "ResourceNotFoundException") return "INSPECT_BUILD_NOT_FOUND";
966
+ throw err;
967
+ }
968
+ }
963
969
 
964
970
  // src/lambda/runner-inspect.ts
965
971
  import { GetSecretValueCommand } from "@aws-sdk/client-secrets-manager";
@@ -1171,9 +1177,9 @@ async function verifyRunRequest(jws, opts) {
1171
1177
  const action = c.action;
1172
1178
  if (!opts.runnerId) throw new SignatureError("runner has no RUNNER_ID");
1173
1179
  if (c.aud !== opts.runnerId) throw new SignatureError("wrong aud");
1174
- const isSourceAction = Object.hasOwn(SOURCE_ACTION_CAPABILITY, action);
1180
+ const isSourceAction = SOURCE_ACTIONS.includes(action);
1175
1181
  const isInspect = action === "inspect_repository";
1176
- const isInspectConnection = Object.hasOwn(INSPECT_CONNECTION_ACTION_CAPABILITY, action);
1182
+ const isInspectConnection = INSPECT_CONNECTION_ACTIONS.includes(action);
1177
1183
  if (action !== "ping" && !isSourceAction && !isInspect && !isInspectConnection && !isNonEmptyString(c.pipelineId)) throw new SignatureError("missing pipelineId");
1178
1184
  if ((action === "stop" || action === "status") && !isNonEmptyString(c.executionId)) throw new SignatureError("missing executionId");
1179
1185
  let hint;
@@ -1195,7 +1201,7 @@ async function verifyRunRequest(jws, opts) {
1195
1201
  if (!isInspect && c.inspect !== void 0) throw new SignatureError("unexpected inspect claim");
1196
1202
  const inspect = isInspect ? parseInspectClaim(c.inspect) : void 0;
1197
1203
  if (!isInspectConnection && c.inspectConnection !== void 0) throw new SignatureError("unexpected inspectConnection claim");
1198
- const inspectConnection = isInspectConnection ? parseInspectConnectionClaim(c.inspectConnection, action === "inspect_connection_start") : void 0;
1204
+ const inspectConnection = isInspectConnection ? parseInspectConnectionClaim(c.inspectConnection, INSPECT_CONNECTION_CLAIM_KIND[action]) : void 0;
1199
1205
  if (takesBuild) {
1200
1206
  if (!isNonEmptyString(c.deployRequestId) || c.deployRequestId.length > 128) throw new SignatureError("missing deployRequestId");
1201
1207
  if (typeof c.buildId !== "string" || !BUILD_ID_PATTERN.test(c.buildId)) throw new SignatureError("malformed buildId");
@@ -1297,15 +1303,20 @@ function parseInspectClaim(raw) {
1297
1303
  });
1298
1304
  return { orgId: b.orgId, region: b.region, repository: { owner: repo.owner, repo: repo.repo }, reads };
1299
1305
  }
1300
- function parseInspectConnectionClaim(raw, isStart) {
1306
+ var INSPECT_CONNECTION_CLAIM_KIND = {
1307
+ inspect_connection_start: "start",
1308
+ inspect_connection_status: "status",
1309
+ inspect_connection_stop: "stop"
1310
+ };
1311
+ function parseInspectConnectionClaim(raw, kind) {
1301
1312
  if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw new SignatureError("missing inspectConnection claim");
1302
1313
  const b = raw;
1303
- if (b.kind !== (isStart ? "start" : "status")) throw new SignatureError("inspectConnection kind is not the action");
1314
+ if (b.kind !== kind) throw new SignatureError("inspectConnection kind is not the action");
1304
1315
  if (typeof b.region !== "string" || !AWS_REGION_PATTERN.test(b.region)) throw new SignatureError("malformed inspectConnection region");
1305
- if (!isStart) {
1316
+ if (kind !== "start") {
1306
1317
  if (Object.keys(b).some((k) => !["kind", "region", "buildId"].includes(k))) throw new SignatureError("unexpected inspectConnection field");
1307
1318
  if (typeof b.buildId !== "string" || !INSPECT_BUILD_ID_PATTERN.test(b.buildId)) throw new SignatureError("malformed inspectConnection buildId");
1308
- return { kind: "status", region: b.region, buildId: b.buildId };
1319
+ return { kind, region: b.region, buildId: b.buildId };
1309
1320
  }
1310
1321
  if (Object.keys(b).some((k) => !["kind", "region", "connectionArn", "repository", "branch", "subdirectory"].includes(k))) {
1311
1322
  throw new SignatureError("unexpected inspectConnection field");
@@ -1374,7 +1385,7 @@ function configFromEnv(env = process.env) {
1374
1385
  allowedPrefixes,
1375
1386
  version: env.RUNNER_VERSION?.trim() || "0.0.0",
1376
1387
  deploy: deployConfigFromEnv(env),
1377
- ...inspectConnectionFromEnv(env),
1388
+ inspectConnection: inspectConnectionFromEnv(env),
1378
1389
  ...reportingFromEnv(env)
1379
1390
  };
1380
1391
  }
@@ -1387,7 +1398,8 @@ function inspectConnectionFromEnv(env) {
1387
1398
  const projectName = env.INSPECT_PROJECT_NAME?.trim();
1388
1399
  const bucket = env.INSPECT_RESULTS_BUCKET?.trim();
1389
1400
  const region = env.AWS_REGION?.trim();
1390
- return projectName && bucket && region ? { inspectConnection: { projectName, bucket, region } } : {};
1401
+ if (!projectName || !bucket || !region) throw new Error("INSPECT_PROJECT_NAME, INSPECT_RESULTS_BUCKET and AWS_REGION environment variables are required");
1402
+ return { projectName, bucket, region };
1391
1403
  }
1392
1404
  function defaultLog(level, msg, data) {
1393
1405
  const line = JSON.stringify({ level, msg, ...data });
@@ -1602,12 +1614,15 @@ function createRunner(config, deps) {
1602
1614
  const claim = claims.inspectConnection;
1603
1615
  if (!config.allowedRegions.includes(claim.region)) return fail("SOURCE_REGION_NOT_ALLOWED");
1604
1616
  const inspect = config.inspectConnection;
1605
- if (!inspect) return fail("INSPECT_REGION_UNSUPPORTED");
1606
1617
  if (claim.kind === "start") {
1607
1618
  if (!account) return internal();
1608
1619
  const started = await startInspection(claim, account.accountId, inspect, deps);
1609
1620
  return typeof started === "string" ? fail(started) : ok("inspection_started", { buildId: started.buildId });
1610
1621
  }
1622
+ if (claim.kind === "stop") {
1623
+ const stopped = await stopInspection(claim, inspect, deps);
1624
+ return typeof stopped === "string" ? fail(stopped) : ok("inspection_stopped", { stopped: stopped.stopped });
1625
+ }
1611
1626
  const status = await inspectionStatus(claim, inspect, deps);
1612
1627
  return typeof status === "string" ? fail(status) : ok("inspection_status", { ...status });
1613
1628
  }
@@ -1635,18 +1650,14 @@ function createRunner(config, deps) {
1635
1650
  if (claims.action === "ping") {
1636
1651
  const capabilities = [
1637
1652
  ...config.deploy.enabled ? [DEPLOY_CAPABILITY] : [],
1638
- SOURCES_CAPABILITY,
1639
- INSPECT_CAPABILITY,
1640
- ...config.inspectConnection ? [INSPECT_CONNECTION_CAPABILITY] : [],
1641
- IDENTITY_CAPABILITY,
1642
1653
  ...config.reporting ? [EVENTS_CAPABILITY] : []
1643
1654
  ];
1644
1655
  const reporting = await reportingHealth();
1645
1656
  return ok("pong", { regions: [...config.allowedRegions], capabilities, pipelinePrefixes: [...config.allowedPrefixes], ...reporting ? { reporting } : {} });
1646
1657
  }
1647
- if (Object.hasOwn(INSPECT_CONNECTION_ACTION_CAPABILITY, claims.action)) return inspectConnectionAction(claims, account);
1658
+ if (INSPECT_CONNECTION_ACTIONS.includes(claims.action)) return inspectConnectionAction(claims, account);
1648
1659
  if (Object.hasOwn(DEPLOY_ACTION_CAPABILITY, claims.action)) return deployAction(claims);
1649
- if (Object.hasOwn(SOURCE_ACTION_CAPABILITY, claims.action)) return sourceAction(claims, account);
1660
+ if (SOURCE_ACTIONS.includes(claims.action)) return sourceAction(claims, account);
1650
1661
  if (claims.action === "inspect_repository") return inspectAction(claims);
1651
1662
  const found = await findPipeline(config, deps, account, claims.pipelineId, claims.hint);
1652
1663
  if (claims.action === "probe") {
@@ -22,11 +22,24 @@ type StartClaim = Extract<RunInspectConnectionClaim, {
22
22
  type StatusClaim = Extract<RunInspectConnectionClaim, {
23
23
  kind: 'status';
24
24
  }>;
25
+ type StopClaim = Extract<RunInspectConnectionClaim, {
26
+ kind: 'stop';
27
+ }>;
25
28
  /** inspect_connection_start: the build it started, or the refusal. */
26
29
  export declare function startInspection(claim: StartClaim, accountId: string, config: InspectConnectionConfig, deps: InspectConnectionDeps): Promise<{
27
30
  buildId: string;
28
31
  } | 'INSPECT_REGION_UNSUPPORTED' | 'INSPECT_BUSY' | Exclude<Awaited<ReturnType<typeof checkConnection>>, object>>;
29
32
  /** inspect_connection_status: the build's state (with the snapshot once it succeeded), or INSPECT_BUILD_NOT_FOUND. */
30
33
  export declare function inspectionStatus(claim: StatusClaim, config: InspectConnectionConfig, deps: InspectConnectionDeps): Promise<InspectionStatus | 'INSPECT_BUILD_NOT_FOUND'>;
34
+ /**
35
+ * inspect_connection_stop: end one of this stack's own inspect builds early —
36
+ * the platform gave up on it (its deadline, a cancelled request, a failure after
37
+ * the start). `stopped: false` when the build had already finished (CodeBuild
38
+ * answers InvalidInputException); INSPECT_BUILD_NOT_FOUND for another project's
39
+ * build or an unknown one. The snapshot, if any, still expires with the bucket.
40
+ */
41
+ export declare function stopInspection(claim: StopClaim, config: InspectConnectionConfig, deps: InspectConnectionDeps): Promise<{
42
+ stopped: boolean;
43
+ } | 'INSPECT_BUILD_NOT_FOUND'>;
31
44
  export {};
32
45
  //# sourceMappingURL=runner-inspect-connection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"runner-inspect-connection.d.ts","sources":["../../src/lambda/runner-inspect-connection.ts"],"names":[],"mappings":"AA8BA,OAAO,EAA2B,KAAK,yBAAyB,EAAE,MAAM,6CAA6C,CAAC;AACtH,OAAO,EAA2B,KAAK,gBAAgB,EAAqC,MAAM,4CAA4C,CAAC;AAC/I,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,iGAAiG;AACjG,MAAM,WAAW,uBAAuB;IACtC,WAAW,EAAE,MAAM,CAAC;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