@pipeline-builder/pipeline-manager 6.5.3 → 6.5.4
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/dist/lambda/runner-handler.d.ts +10 -1
- package/dist/lambda/runner-handler.d.ts.map +1 -1
- package/dist/lambda/runner-handler.js +303 -114
- package/dist/lambda/runner-inspect.d.ts +27 -0
- package/dist/lambda/runner-inspect.d.ts.map +1 -0
- package/dist/lambda/runner-inspect.js +123 -0
- package/dist/lambda/runner-jws.d.ts.map +1 -1
- package/dist/lambda/runner-jws.js +42 -5
- package/dist/lambda/runner-sources.d.ts +3 -1
- package/dist/lambda/runner-sources.d.ts.map +1 -1
- package/dist/lambda/runner-sources.js +3 -3
- package/dist/templates/runner-stack.json +12 -0
- package/dist/utils/runner-template.d.ts +3 -2
- package/dist/utils/runner-template.d.ts.map +1 -1
- package/dist/utils/runner-template.js +5 -3
- package/package.json +4 -4
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { type DeployBuildState, type DeployJobResultCode, type DeployStage, type RunnerCapability, type RunnerOutcome, type RunnerReplyErrorCode } from '@pipeline-builder/api-core/pipeline-runners';
|
|
2
|
+
import type { RepositoryReadResult } from '@pipeline-builder/api-core/pipeline-source';
|
|
2
3
|
import { type Sender } from './pipeline-tag.js';
|
|
3
4
|
import { type DeployConfig } from './runner-deploy.js';
|
|
5
|
+
import { type GitHubGet } from './runner-inspect.js';
|
|
4
6
|
import { type FetchFn } from './runner-jws.js';
|
|
5
7
|
import { type SourcesDetails } from './runner-sources.js';
|
|
6
8
|
export type Outcome = RunnerOutcome;
|
|
@@ -27,6 +29,8 @@ export interface OutcomeDetails {
|
|
|
27
29
|
connections?: SourcesDetails['connections'];
|
|
28
30
|
githubToken?: SourcesDetails['githubToken'];
|
|
29
31
|
truncated?: SourcesDetails['truncated'];
|
|
32
|
+
/** inspect_repository: one `{ status, body? }` per read, in order (runner-inspect.ts). */
|
|
33
|
+
results?: RepositoryReadResult[];
|
|
30
34
|
}
|
|
31
35
|
export interface RunnerResult {
|
|
32
36
|
status: number;
|
|
@@ -63,8 +67,13 @@ export interface RunnerDeps {
|
|
|
63
67
|
kms: () => Sender;
|
|
64
68
|
/** A region's CodeConnections (list_sources / check_source). */
|
|
65
69
|
codeconnections: (region: string) => Sender;
|
|
66
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* A region's Secrets Manager — DescribeSecret (list_sources / check_source)
|
|
72
|
+
* and GetSecretValue of the chosen GitHub token secret (inspect_repository).
|
|
73
|
+
*/
|
|
67
74
|
secrets: (region: string) => Sender;
|
|
75
|
+
/** One authenticated GET to api.github.com (inspect_repository; runner-inspect.ts). */
|
|
76
|
+
github: GitHubGet;
|
|
68
77
|
log: (level: 'INFO' | 'WARN' | 'ERROR', msg: string, data?: Record<string, unknown>) => void;
|
|
69
78
|
}
|
|
70
79
|
/** The runner's own account, from the invoked function's ARN — used to build lookups, never logged. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner-handler.d.ts","sources":["../../src/lambda/runner-handler.ts"],"names":[],"mappings":"AAkEA,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,EAAqB,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAwC,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC7F,OAAO,EAEL,KAAK,OAAO,EACb,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAA4B,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAMpF,MAAM,MAAM,OAAO,GAAG,aAAa,CAAC;AACpC;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,CAAC,oBAAoB,EAAE,cAAc,CAAC,GAAG,oBAAoB,CAAC;AAEnG,oGA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AAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,GAC9C,OAAO,CAAC,MAAM,CAAC,CAejB;AAID,MAAM,WAAW,MAAM;IACrB,4CAA4C;IAC5C,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,cAAc,CAAA;KAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IACjF,oEAAoE;IACpE,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE;QAAE,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,kBAAkB,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC7G;AAkBD,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM,CAyN3E;AAoBD,mFAAmF;AACnF,eAAO,MAAM,OAAO,UAAiB,OAAO,YAAY;IAAE,YAAY,CAAC,EAAE,MAAM,CAAC;IAAC,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAAE,KAAG,OAAO,CAAC,OAAO,CAY/H,CAAC;AAEF,iDAAiD;AACjD,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C"}
|
|
@@ -28,10 +28,13 @@ var RUNNER_ACTIONS = [
|
|
|
28
28
|
"undeploy",
|
|
29
29
|
// The account's source connections (the create review's picker) and the pre-deploy source check.
|
|
30
30
|
"list_sources",
|
|
31
|
-
"check_source"
|
|
31
|
+
"check_source",
|
|
32
|
+
// Reading a private GitHub repository for Generate from Git with the stored token, inside the account.
|
|
33
|
+
"inspect_repository"
|
|
32
34
|
];
|
|
33
35
|
var DEPLOY_CAPABILITY = "deploy:1";
|
|
34
36
|
var SOURCES_CAPABILITY = "sources:1";
|
|
37
|
+
var INSPECT_CAPABILITY = "inspect:1";
|
|
35
38
|
var DEPLOY_ACTION_CAPABILITY = {
|
|
36
39
|
deploy: DEPLOY_CAPABILITY,
|
|
37
40
|
deploy_status: DEPLOY_CAPABILITY,
|
|
@@ -42,7 +45,10 @@ var SOURCE_ACTION_CAPABILITY = {
|
|
|
42
45
|
list_sources: SOURCES_CAPABILITY,
|
|
43
46
|
check_source: SOURCES_CAPABILITY
|
|
44
47
|
};
|
|
45
|
-
var
|
|
48
|
+
var INSPECT_ACTION_CAPABILITY = {
|
|
49
|
+
inspect_repository: INSPECT_CAPABILITY
|
|
50
|
+
};
|
|
51
|
+
var ACTION_CAPABILITY = { ...DEPLOY_ACTION_CAPABILITY, ...SOURCE_ACTION_CAPABILITY, ...INSPECT_ACTION_CAPABILITY };
|
|
46
52
|
var AWS_REGION_PATTERN = /^[a-z]{2}(-[a-z]+)+-\d{1,2}$/;
|
|
47
53
|
var RUNNER_ERRORS = {
|
|
48
54
|
// -- The pipeline service's answers --
|
|
@@ -178,6 +184,11 @@ var RUN_REQUEST_CLOCK_SKEW_SECONDS = 120;
|
|
|
178
184
|
var SOURCE_ORG_ID_PATTERN = /^[A-Za-z0-9_-]{1,64}$/;
|
|
179
185
|
var SOURCE_HOST_PATTERN = /^(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/;
|
|
180
186
|
var SOURCE_OWNER_PATTERN = /^[A-Za-z0-9._-]{1,100}$/;
|
|
187
|
+
var INSPECT_MAX_READS = 10;
|
|
188
|
+
var INSPECT_MAX_READ_BYTES = 128 * 1024;
|
|
189
|
+
var INSPECT_MAX_REPLY_BYTES = 1024 * 1024;
|
|
190
|
+
var INSPECT_MAX_LISTING_ENTRIES = 1e3;
|
|
191
|
+
var INSPECT_REPO_PATTERN = /^[A-Za-z0-9._-]{1,100}$/;
|
|
181
192
|
var RUNNER_KEY_ACTIVATION_DELAY_MS = 10 * 6e4;
|
|
182
193
|
var RUNNER_KEY_RETIRE_WINDOW_MS = 60 * 6e4;
|
|
183
194
|
var RUNNER_TUNABLE_DEFAULTS = {
|
|
@@ -468,8 +479,8 @@ async function runDeployAction(ctx, claims) {
|
|
|
468
479
|
}
|
|
469
480
|
}
|
|
470
481
|
|
|
471
|
-
// src/lambda/runner-
|
|
472
|
-
import {
|
|
482
|
+
// src/lambda/runner-inspect.ts
|
|
483
|
+
import { GetSecretValueCommand } from "@aws-sdk/client-secrets-manager";
|
|
473
484
|
|
|
474
485
|
// ../api-core/lib/types/pipeline-source.js
|
|
475
486
|
var CONNECTION_ARN_PATTERN = /^arn:aws(?:-[a-z]+)*:(?:codeconnections|codestar-connections):[a-z0-9-]+:\d{12}:connection\/[A-Za-z0-9-]+$/;
|
|
@@ -542,8 +553,260 @@ async function chooseGitHubTokenSecret(a, describe) {
|
|
|
542
553
|
return { secret: orgDefault, ...owner ? { owner } : {}, scope: "org", found: await describe(orgDefault) };
|
|
543
554
|
}
|
|
544
555
|
var MAX_SOURCE_CONNECTIONS = 100;
|
|
556
|
+
var isRecord = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
557
|
+
var MAX_READ_PATH = 500;
|
|
558
|
+
var READ_SEGMENT_PATTERN = /^[^\u0000-\u001f\u007f?#\\]{1,255}$/;
|
|
559
|
+
var READ_REF_PATTERN = /^[^\s\u0000-\u001f\u007f?#]{1,255}$/;
|
|
560
|
+
function repositoryReadProblem(raw) {
|
|
561
|
+
if (!isRecord(raw))
|
|
562
|
+
return "not a read";
|
|
563
|
+
if (raw.kind === "repo" || raw.kind === "languages")
|
|
564
|
+
return Object.keys(raw).length === 1 ? null : "unexpected fields";
|
|
565
|
+
if (raw.kind !== "contents")
|
|
566
|
+
return "unknown read";
|
|
567
|
+
const { path, ref } = raw;
|
|
568
|
+
if (typeof ref !== "string" || !READ_REF_PATTERN.test(ref) || ref.includes(".."))
|
|
569
|
+
return "malformed ref";
|
|
570
|
+
if (typeof path !== "string" || path.length > MAX_READ_PATH)
|
|
571
|
+
return "malformed path";
|
|
572
|
+
if (path === "")
|
|
573
|
+
return null;
|
|
574
|
+
const segments = path.split("/");
|
|
575
|
+
if (segments.some((seg) => seg === "." || seg === ".." || !READ_SEGMENT_PATTERN.test(seg)))
|
|
576
|
+
return "malformed path";
|
|
577
|
+
return null;
|
|
578
|
+
}
|
|
579
|
+
var MAX_TEXT = 2e3;
|
|
580
|
+
var MAX_TOPICS = 50;
|
|
581
|
+
var MAX_LANGUAGES = 100;
|
|
582
|
+
var MAX_BASE64_CHARS = 2e5;
|
|
583
|
+
var optionalString = (v, max) => v === void 0 || v === null || typeof v === "string" && v.length <= max;
|
|
584
|
+
function parseRepositoryReadBody(read, body) {
|
|
585
|
+
if (read.kind === "repo") {
|
|
586
|
+
if (!isRecord(body))
|
|
587
|
+
return null;
|
|
588
|
+
const { default_branch: branch, description, topics, private: isPrivate, visibility } = body;
|
|
589
|
+
if (!optionalString(branch, 255) || !optionalString(description, MAX_TEXT))
|
|
590
|
+
return null;
|
|
591
|
+
if (isPrivate !== void 0 && typeof isPrivate !== "boolean")
|
|
592
|
+
return null;
|
|
593
|
+
if (visibility !== void 0 && visibility !== "public" && visibility !== "private" && visibility !== "internal")
|
|
594
|
+
return null;
|
|
595
|
+
if (topics !== void 0 && (!Array.isArray(topics) || topics.length > MAX_TOPICS || topics.some((t) => typeof t !== "string" || t.length > 100)))
|
|
596
|
+
return null;
|
|
597
|
+
return {
|
|
598
|
+
...typeof branch === "string" ? { default_branch: branch } : {},
|
|
599
|
+
...typeof description === "string" ? { description } : {},
|
|
600
|
+
...Array.isArray(topics) ? { topics } : {},
|
|
601
|
+
...typeof isPrivate === "boolean" ? { private: isPrivate } : {},
|
|
602
|
+
...typeof visibility === "string" ? { visibility } : {}
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
if (read.kind === "languages") {
|
|
606
|
+
if (!isRecord(body))
|
|
607
|
+
return null;
|
|
608
|
+
const entries = Object.entries(body);
|
|
609
|
+
if (entries.length > MAX_LANGUAGES || entries.some(([k, v]) => k.length > 100 || typeof v !== "number" || !Number.isFinite(v)))
|
|
610
|
+
return null;
|
|
611
|
+
return Object.fromEntries(entries);
|
|
612
|
+
}
|
|
613
|
+
if (Array.isArray(body)) {
|
|
614
|
+
if (body.length > INSPECT_MAX_LISTING_ENTRIES)
|
|
615
|
+
return null;
|
|
616
|
+
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 }));
|
|
617
|
+
}
|
|
618
|
+
if (!isRecord(body))
|
|
619
|
+
return null;
|
|
620
|
+
const { name, type, encoding, content } = body;
|
|
621
|
+
if (typeof name !== "string" || name.length > 255 || type !== "file" || encoding !== "base64" || typeof content !== "string" || content.length > MAX_BASE64_CHARS)
|
|
622
|
+
return null;
|
|
623
|
+
return { name, type, encoding, content };
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// src/lambda/runner-sources.ts
|
|
627
|
+
import { GetConnectionCommand, GetHostCommand, ListConnectionsCommand, ListHostsCommand } from "@aws-sdk/client-codeconnections";
|
|
628
|
+
import { DescribeSecretCommand } from "@aws-sdk/client-secrets-manager";
|
|
629
|
+
var MAX_PAGES = 10;
|
|
630
|
+
var errName2 = (err) => String(err?.name ?? "");
|
|
631
|
+
var isNotFound = (err) => errName2(err) === "ResourceNotFoundException";
|
|
632
|
+
var isProviderType = (v) => SOURCE_CONNECTION_PROVIDER_TYPES.includes(v);
|
|
633
|
+
var isStatus = (v) => SOURCE_CONNECTION_STATUSES.includes(v);
|
|
634
|
+
function describeSecretLookup(deps, region) {
|
|
635
|
+
return async (name) => {
|
|
636
|
+
try {
|
|
637
|
+
const out = await deps.secrets(region).send(new DescribeSecretCommand({ SecretId: name }));
|
|
638
|
+
if (out.DeletedDate) return null;
|
|
639
|
+
return { lastChangedDate: out.LastChangedDate instanceof Date ? out.LastChangedDate.toISOString() : null };
|
|
640
|
+
} catch (err) {
|
|
641
|
+
if (isNotFound(err)) return null;
|
|
642
|
+
throw err;
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
async function githubTokenFor(claim, deps) {
|
|
647
|
+
const repository = claim.repository;
|
|
648
|
+
if (!repository || providerForHost(repository.host) !== "github") return null;
|
|
649
|
+
const choice = await chooseGitHubTokenSecret(
|
|
650
|
+
{ orgId: claim.orgId, owner: repository.owner, prefix: DEFAULT_SECRETS_PATH_PREFIX },
|
|
651
|
+
describeSecretLookup(deps, claim.region)
|
|
652
|
+
);
|
|
653
|
+
return choice.found ? { secretName: choice.secret, scope: choice.scope, lastChangedDate: choice.found.lastChangedDate } : null;
|
|
654
|
+
}
|
|
655
|
+
async function hostEndpoints(deps, region) {
|
|
656
|
+
const endpoints = /* @__PURE__ */ new Map();
|
|
657
|
+
let token;
|
|
658
|
+
let pages = 0;
|
|
659
|
+
do {
|
|
660
|
+
const out = await deps.codeconnections(region).send(new ListHostsCommand({ MaxResults: 100, ...token ? { NextToken: token } : {} }));
|
|
661
|
+
for (const h of out.Hosts ?? []) if (h.HostArn && h.ProviderEndpoint) endpoints.set(h.HostArn, h.ProviderEndpoint);
|
|
662
|
+
token = out.NextToken || void 0;
|
|
663
|
+
} while (token && ++pages < MAX_PAGES);
|
|
664
|
+
return endpoints;
|
|
665
|
+
}
|
|
666
|
+
function toDto(c, hostEndpoint) {
|
|
667
|
+
if (!c.ConnectionArn || !c.ConnectionName || !isProviderType(c.ProviderType) || !isStatus(c.ConnectionStatus)) return null;
|
|
668
|
+
return {
|
|
669
|
+
arn: c.ConnectionArn,
|
|
670
|
+
name: c.ConnectionName,
|
|
671
|
+
providerType: c.ProviderType,
|
|
672
|
+
status: c.ConnectionStatus,
|
|
673
|
+
...hostEndpoint ? { hostEndpoint } : {}
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
async function listSources(claim, accountId, deps) {
|
|
677
|
+
const repoHost = claim.repository.host;
|
|
678
|
+
const raw = [];
|
|
679
|
+
let token;
|
|
680
|
+
let pages = 0;
|
|
681
|
+
let more = false;
|
|
682
|
+
do {
|
|
683
|
+
const out = await deps.codeconnections(claim.region).send(new ListConnectionsCommand({ MaxResults: 100, ...token ? { NextToken: token } : {} }));
|
|
684
|
+
raw.push(...out.Connections ?? []);
|
|
685
|
+
token = out.NextToken || void 0;
|
|
686
|
+
more = !!token && ++pages >= MAX_PAGES;
|
|
687
|
+
} while (token && !more);
|
|
688
|
+
const hosts = raw.some((c) => c.HostArn) && providerForHost(repoHost) === "unknown" ? await hostEndpoints(deps, claim.region) : /* @__PURE__ */ new Map();
|
|
689
|
+
const matching = raw.map((c) => toDto(c, c.HostArn ? hosts.get(c.HostArn) : void 0)).filter((c) => !!c && connectionMatchesRepository(c, repoHost)).sort((a, b) => a.name.localeCompare(b.name) || a.arn.localeCompare(b.arn));
|
|
690
|
+
return {
|
|
691
|
+
accountId,
|
|
692
|
+
region: claim.region,
|
|
693
|
+
connections: matching.slice(0, MAX_SOURCE_CONNECTIONS),
|
|
694
|
+
githubToken: await githubTokenFor(claim, deps),
|
|
695
|
+
truncated: more || matching.length > MAX_SOURCE_CONNECTIONS
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
async function checkSource(claim, accountId, deps) {
|
|
699
|
+
const source = claim.source;
|
|
700
|
+
if (source.type === "github") {
|
|
701
|
+
if (!claim.repository || providerForHost(claim.repository.host) !== "github") return "SOURCE_CONNECTION_WRONG_PROVIDER";
|
|
702
|
+
return await githubTokenFor(claim, deps) ? null : "GITHUB_TOKEN_MISSING";
|
|
703
|
+
}
|
|
704
|
+
const parts = connectionArnParts(source.connectionArn);
|
|
705
|
+
if (!parts || parts.accountId !== accountId) return "SOURCE_CONNECTION_WRONG_ACCOUNT";
|
|
706
|
+
if (parts.region !== claim.region) return "SOURCE_CONNECTION_WRONG_REGION";
|
|
707
|
+
let connection;
|
|
708
|
+
try {
|
|
709
|
+
const out = await deps.codeconnections(claim.region).send(new GetConnectionCommand({ ConnectionArn: source.connectionArn }));
|
|
710
|
+
connection = out.Connection;
|
|
711
|
+
} catch (err) {
|
|
712
|
+
if (isNotFound(err)) return "SOURCE_CONNECTION_NOT_FOUND";
|
|
713
|
+
throw err;
|
|
714
|
+
}
|
|
715
|
+
if (!connection) return "SOURCE_CONNECTION_NOT_FOUND";
|
|
716
|
+
if (connection.ConnectionStatus !== "AVAILABLE") return "SOURCE_CONNECTION_NOT_AVAILABLE";
|
|
717
|
+
let hostEndpoint;
|
|
718
|
+
if (connection.HostArn) {
|
|
719
|
+
try {
|
|
720
|
+
const host = await deps.codeconnections(claim.region).send(new GetHostCommand({ HostArn: connection.HostArn }));
|
|
721
|
+
hostEndpoint = host.ProviderEndpoint;
|
|
722
|
+
} catch (err) {
|
|
723
|
+
if (!isNotFound(err)) throw err;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
const dto = toDto(connection, hostEndpoint);
|
|
727
|
+
if (!dto) return "SOURCE_CONNECTION_WRONG_PROVIDER";
|
|
728
|
+
return !claim.repository || connectionMatchesRepository(dto, claim.repository.host) ? null : "SOURCE_CONNECTION_WRONG_PROVIDER";
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
// src/lambda/runner-inspect.ts
|
|
732
|
+
var GITHUB_API = "https://api.github.com";
|
|
733
|
+
var GITHUB_TIMEOUT_MS = 6e3;
|
|
734
|
+
async function readCapped(res, cap) {
|
|
735
|
+
if (!res.body) return "";
|
|
736
|
+
const reader = res.body.getReader();
|
|
737
|
+
const chunks = [];
|
|
738
|
+
let size = 0;
|
|
739
|
+
for (; ; ) {
|
|
740
|
+
const { done, value } = await reader.read();
|
|
741
|
+
if (done) break;
|
|
742
|
+
size += value.byteLength;
|
|
743
|
+
if (size > cap) {
|
|
744
|
+
await reader.cancel();
|
|
745
|
+
return null;
|
|
746
|
+
}
|
|
747
|
+
chunks.push(value);
|
|
748
|
+
}
|
|
749
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
750
|
+
}
|
|
751
|
+
var githubGet = async (url, token) => {
|
|
752
|
+
const res = await fetch(url, {
|
|
753
|
+
headers: {
|
|
754
|
+
"Accept": "application/vnd.github+json",
|
|
755
|
+
"User-Agent": "pipeline-builder-runner",
|
|
756
|
+
"X-GitHub-Api-Version": "2022-11-28",
|
|
757
|
+
"Authorization": `Bearer ${token}`
|
|
758
|
+
},
|
|
759
|
+
redirect: "error",
|
|
760
|
+
signal: AbortSignal.timeout(GITHUB_TIMEOUT_MS)
|
|
761
|
+
});
|
|
762
|
+
return { status: res.status, text: await readCapped(res, INSPECT_MAX_READ_BYTES) };
|
|
763
|
+
};
|
|
764
|
+
function readUrl(repository, read) {
|
|
765
|
+
const base = `${GITHUB_API}/repos/${encodeURIComponent(repository.owner)}/${encodeURIComponent(repository.repo)}`;
|
|
766
|
+
if (read.kind === "repo") return base;
|
|
767
|
+
if (read.kind === "languages") return `${base}/languages`;
|
|
768
|
+
const path = read.path ? read.path.split("/").map(encodeURIComponent).join("/") : "";
|
|
769
|
+
return `${base}/contents/${path}?ref=${encodeURIComponent(read.ref)}`;
|
|
770
|
+
}
|
|
771
|
+
async function answer(deps, claim, read, token) {
|
|
772
|
+
let got;
|
|
773
|
+
try {
|
|
774
|
+
got = await deps.github(readUrl(claim.repository, read), token);
|
|
775
|
+
} catch {
|
|
776
|
+
return { status: 504 };
|
|
777
|
+
}
|
|
778
|
+
if (got.status < 200 || got.status >= 300) return { status: got.status };
|
|
779
|
+
if (got.text === null) return { status: 413 };
|
|
780
|
+
let json;
|
|
781
|
+
try {
|
|
782
|
+
json = JSON.parse(got.text);
|
|
783
|
+
} catch {
|
|
784
|
+
return { status: 502 };
|
|
785
|
+
}
|
|
786
|
+
const body = parseRepositoryReadBody(read, json);
|
|
787
|
+
return body === null ? { status: 502 } : { status: got.status, body };
|
|
788
|
+
}
|
|
789
|
+
async function inspectRepository(claim, deps) {
|
|
790
|
+
const choice = await chooseGitHubTokenSecret(
|
|
791
|
+
{ orgId: claim.orgId, owner: claim.repository.owner, prefix: DEFAULT_SECRETS_PATH_PREFIX },
|
|
792
|
+
describeSecretLookup(deps, claim.region)
|
|
793
|
+
);
|
|
794
|
+
if (!choice.found) return "GITHUB_TOKEN_MISSING";
|
|
795
|
+
const out = await deps.secrets(claim.region).send(new GetSecretValueCommand({ SecretId: choice.secret }));
|
|
796
|
+
const token = typeof out.SecretString === "string" ? out.SecretString.trim() : "";
|
|
797
|
+
if (!token) return "GITHUB_TOKEN_MISSING";
|
|
798
|
+
const answers = await Promise.all(claim.reads.map((read) => answer(deps, claim, read, token)));
|
|
799
|
+
let total = 0;
|
|
800
|
+
const results = answers.map((a) => {
|
|
801
|
+
if (a.body === void 0) return a;
|
|
802
|
+
total += JSON.stringify(a.body).length;
|
|
803
|
+
return total > INSPECT_MAX_REPLY_BYTES ? { status: 413 } : a;
|
|
804
|
+
});
|
|
805
|
+
return { results };
|
|
806
|
+
}
|
|
545
807
|
|
|
546
808
|
// src/lambda/runner-jws.ts
|
|
809
|
+
import { createPublicKey, verify as cryptoVerify } from "node:crypto";
|
|
547
810
|
var JWKS_TTL_MS = 10 * 60 * 1e3;
|
|
548
811
|
var JWKS_MIN_REFETCH_MS = 60 * 1e3;
|
|
549
812
|
var REPLAY_WINDOW_MS = 15 * 60 * 1e3;
|
|
@@ -671,7 +934,8 @@ async function verifyRunRequest(jws, opts) {
|
|
|
671
934
|
if (!opts.runnerId) throw new SignatureError("runner has no RUNNER_ID");
|
|
672
935
|
if (c.aud !== opts.runnerId) throw new SignatureError("wrong aud");
|
|
673
936
|
const isSourceAction = Object.hasOwn(SOURCE_ACTION_CAPABILITY, action);
|
|
674
|
-
|
|
937
|
+
const isInspect = action === "inspect_repository";
|
|
938
|
+
if (action !== "ping" && !isSourceAction && !isInspect && !isNonEmptyString(c.pipelineId)) throw new SignatureError("missing pipelineId");
|
|
675
939
|
if ((action === "stop" || action === "status") && !isNonEmptyString(c.executionId)) throw new SignatureError("missing executionId");
|
|
676
940
|
let hint;
|
|
677
941
|
if (c.hint !== void 0 && c.hint !== null) {
|
|
@@ -689,6 +953,8 @@ async function verifyRunRequest(jws, opts) {
|
|
|
689
953
|
const deploy = takesBlock ? parseDeployClaim(c.deploy, action) : void 0;
|
|
690
954
|
if (!isSourceAction && c.sources !== void 0) throw new SignatureError("unexpected sources claim");
|
|
691
955
|
const sources = isSourceAction ? parseSourcesClaim(c.sources, action === "check_source") : void 0;
|
|
956
|
+
if (!isInspect && c.inspect !== void 0) throw new SignatureError("unexpected inspect claim");
|
|
957
|
+
const inspect = isInspect ? parseInspectClaim(c.inspect) : void 0;
|
|
692
958
|
if (takesBuild) {
|
|
693
959
|
if (!isNonEmptyString(c.deployRequestId) || c.deployRequestId.length > 128) throw new SignatureError("missing deployRequestId");
|
|
694
960
|
if (typeof c.buildId !== "string" || !BUILD_ID_PATTERN.test(c.buildId)) throw new SignatureError("malformed buildId");
|
|
@@ -706,6 +972,7 @@ async function verifyRunRequest(jws, opts) {
|
|
|
706
972
|
...deploy ? { deploy } : {},
|
|
707
973
|
...takesBuild ? { deployRequestId: c.deployRequestId, buildId: c.buildId } : {},
|
|
708
974
|
...sources ? { sources } : {},
|
|
975
|
+
...inspect ? { inspect } : {},
|
|
709
976
|
requestedBy: c.requestedBy
|
|
710
977
|
};
|
|
711
978
|
}
|
|
@@ -767,6 +1034,25 @@ function parseSourcesClaim(raw, isCheck) {
|
|
|
767
1034
|
if (typeof src.connectionArn !== "string" || !CONNECTION_ARN_PATTERN.test(src.connectionArn)) throw new SignatureError("malformed source connectionArn");
|
|
768
1035
|
return { ...claim, source: { type: "codestar", connectionArn: src.connectionArn } };
|
|
769
1036
|
}
|
|
1037
|
+
function parseInspectClaim(raw) {
|
|
1038
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw new SignatureError("missing inspect claim");
|
|
1039
|
+
const b = raw;
|
|
1040
|
+
if (typeof b.orgId !== "string" || !SOURCE_ORG_ID_PATTERN.test(b.orgId)) throw new SignatureError("malformed inspect orgId");
|
|
1041
|
+
if (typeof b.region !== "string" || !AWS_REGION_PATTERN.test(b.region)) throw new SignatureError("malformed inspect region");
|
|
1042
|
+
const repo = b.repository;
|
|
1043
|
+
if (!repo || typeof repo !== "object" || Array.isArray(repo)) throw new SignatureError("missing inspect repository");
|
|
1044
|
+
if (typeof repo.owner !== "string" || !SOURCE_OWNER_PATTERN.test(repo.owner)) throw new SignatureError("malformed inspect repository owner");
|
|
1045
|
+
if (typeof repo.repo !== "string" || !INSPECT_REPO_PATTERN.test(repo.repo) || repo.repo === "." || repo.repo === "..") {
|
|
1046
|
+
throw new SignatureError("malformed inspect repository repo");
|
|
1047
|
+
}
|
|
1048
|
+
if (!Array.isArray(b.reads) || b.reads.length === 0 || b.reads.length > INSPECT_MAX_READS) throw new SignatureError("malformed inspect reads");
|
|
1049
|
+
const reads = b.reads.map((r) => {
|
|
1050
|
+
const problem = repositoryReadProblem(r);
|
|
1051
|
+
if (problem) throw new SignatureError(`malformed inspect read: ${problem}`);
|
|
1052
|
+
return { ...r };
|
|
1053
|
+
});
|
|
1054
|
+
return { orgId: b.orgId, region: b.region, repository: { owner: repo.owner, repo: repo.repo }, reads };
|
|
1055
|
+
}
|
|
770
1056
|
var ReplayCache = class {
|
|
771
1057
|
constructor(now) {
|
|
772
1058
|
this.now = now;
|
|
@@ -794,111 +1080,6 @@ var ReplayCache = class {
|
|
|
794
1080
|
}
|
|
795
1081
|
};
|
|
796
1082
|
|
|
797
|
-
// src/lambda/runner-sources.ts
|
|
798
|
-
import { GetConnectionCommand, GetHostCommand, ListConnectionsCommand, ListHostsCommand } from "@aws-sdk/client-codeconnections";
|
|
799
|
-
import { DescribeSecretCommand } from "@aws-sdk/client-secrets-manager";
|
|
800
|
-
var MAX_PAGES = 10;
|
|
801
|
-
var errName2 = (err) => String(err?.name ?? "");
|
|
802
|
-
var isNotFound = (err) => errName2(err) === "ResourceNotFoundException";
|
|
803
|
-
var isProviderType = (v) => SOURCE_CONNECTION_PROVIDER_TYPES.includes(v);
|
|
804
|
-
var isStatus = (v) => SOURCE_CONNECTION_STATUSES.includes(v);
|
|
805
|
-
function describeSecret(deps, region) {
|
|
806
|
-
return async (name) => {
|
|
807
|
-
try {
|
|
808
|
-
const out = await deps.secrets(region).send(new DescribeSecretCommand({ SecretId: name }));
|
|
809
|
-
if (out.DeletedDate) return null;
|
|
810
|
-
return { lastChangedDate: out.LastChangedDate instanceof Date ? out.LastChangedDate.toISOString() : null };
|
|
811
|
-
} catch (err) {
|
|
812
|
-
if (isNotFound(err)) return null;
|
|
813
|
-
throw err;
|
|
814
|
-
}
|
|
815
|
-
};
|
|
816
|
-
}
|
|
817
|
-
async function githubTokenFor(claim, deps) {
|
|
818
|
-
const repository = claim.repository;
|
|
819
|
-
if (!repository || providerForHost(repository.host) !== "github") return null;
|
|
820
|
-
const choice = await chooseGitHubTokenSecret(
|
|
821
|
-
{ orgId: claim.orgId, owner: repository.owner, prefix: DEFAULT_SECRETS_PATH_PREFIX },
|
|
822
|
-
describeSecret(deps, claim.region)
|
|
823
|
-
);
|
|
824
|
-
return choice.found ? { secretName: choice.secret, scope: choice.scope, lastChangedDate: choice.found.lastChangedDate } : null;
|
|
825
|
-
}
|
|
826
|
-
async function hostEndpoints(deps, region) {
|
|
827
|
-
const endpoints = /* @__PURE__ */ new Map();
|
|
828
|
-
let token;
|
|
829
|
-
let pages = 0;
|
|
830
|
-
do {
|
|
831
|
-
const out = await deps.codeconnections(region).send(new ListHostsCommand({ MaxResults: 100, ...token ? { NextToken: token } : {} }));
|
|
832
|
-
for (const h of out.Hosts ?? []) if (h.HostArn && h.ProviderEndpoint) endpoints.set(h.HostArn, h.ProviderEndpoint);
|
|
833
|
-
token = out.NextToken || void 0;
|
|
834
|
-
} while (token && ++pages < MAX_PAGES);
|
|
835
|
-
return endpoints;
|
|
836
|
-
}
|
|
837
|
-
function toDto(c, hostEndpoint) {
|
|
838
|
-
if (!c.ConnectionArn || !c.ConnectionName || !isProviderType(c.ProviderType) || !isStatus(c.ConnectionStatus)) return null;
|
|
839
|
-
return {
|
|
840
|
-
arn: c.ConnectionArn,
|
|
841
|
-
name: c.ConnectionName,
|
|
842
|
-
providerType: c.ProviderType,
|
|
843
|
-
status: c.ConnectionStatus,
|
|
844
|
-
...hostEndpoint ? { hostEndpoint } : {}
|
|
845
|
-
};
|
|
846
|
-
}
|
|
847
|
-
async function listSources(claim, accountId, deps) {
|
|
848
|
-
const repoHost = claim.repository.host;
|
|
849
|
-
const raw = [];
|
|
850
|
-
let token;
|
|
851
|
-
let pages = 0;
|
|
852
|
-
let more = false;
|
|
853
|
-
do {
|
|
854
|
-
const out = await deps.codeconnections(claim.region).send(new ListConnectionsCommand({ MaxResults: 100, ...token ? { NextToken: token } : {} }));
|
|
855
|
-
raw.push(...out.Connections ?? []);
|
|
856
|
-
token = out.NextToken || void 0;
|
|
857
|
-
more = !!token && ++pages >= MAX_PAGES;
|
|
858
|
-
} while (token && !more);
|
|
859
|
-
const hosts = raw.some((c) => c.HostArn) && providerForHost(repoHost) === "unknown" ? await hostEndpoints(deps, claim.region) : /* @__PURE__ */ new Map();
|
|
860
|
-
const matching = raw.map((c) => toDto(c, c.HostArn ? hosts.get(c.HostArn) : void 0)).filter((c) => !!c && connectionMatchesRepository(c, repoHost)).sort((a, b) => a.name.localeCompare(b.name) || a.arn.localeCompare(b.arn));
|
|
861
|
-
return {
|
|
862
|
-
accountId,
|
|
863
|
-
region: claim.region,
|
|
864
|
-
connections: matching.slice(0, MAX_SOURCE_CONNECTIONS),
|
|
865
|
-
githubToken: await githubTokenFor(claim, deps),
|
|
866
|
-
truncated: more || matching.length > MAX_SOURCE_CONNECTIONS
|
|
867
|
-
};
|
|
868
|
-
}
|
|
869
|
-
async function checkSource(claim, accountId, deps) {
|
|
870
|
-
const source = claim.source;
|
|
871
|
-
if (source.type === "github") {
|
|
872
|
-
if (!claim.repository || providerForHost(claim.repository.host) !== "github") return "SOURCE_CONNECTION_WRONG_PROVIDER";
|
|
873
|
-
return await githubTokenFor(claim, deps) ? null : "GITHUB_TOKEN_MISSING";
|
|
874
|
-
}
|
|
875
|
-
const parts = connectionArnParts(source.connectionArn);
|
|
876
|
-
if (!parts || parts.accountId !== accountId) return "SOURCE_CONNECTION_WRONG_ACCOUNT";
|
|
877
|
-
if (parts.region !== claim.region) return "SOURCE_CONNECTION_WRONG_REGION";
|
|
878
|
-
let connection;
|
|
879
|
-
try {
|
|
880
|
-
const out = await deps.codeconnections(claim.region).send(new GetConnectionCommand({ ConnectionArn: source.connectionArn }));
|
|
881
|
-
connection = out.Connection;
|
|
882
|
-
} catch (err) {
|
|
883
|
-
if (isNotFound(err)) return "SOURCE_CONNECTION_NOT_FOUND";
|
|
884
|
-
throw err;
|
|
885
|
-
}
|
|
886
|
-
if (!connection) return "SOURCE_CONNECTION_NOT_FOUND";
|
|
887
|
-
if (connection.ConnectionStatus !== "AVAILABLE") return "SOURCE_CONNECTION_NOT_AVAILABLE";
|
|
888
|
-
let hostEndpoint;
|
|
889
|
-
if (connection.HostArn) {
|
|
890
|
-
try {
|
|
891
|
-
const host = await deps.codeconnections(claim.region).send(new GetHostCommand({ HostArn: connection.HostArn }));
|
|
892
|
-
hostEndpoint = host.ProviderEndpoint;
|
|
893
|
-
} catch (err) {
|
|
894
|
-
if (!isNotFound(err)) throw err;
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
const dto = toDto(connection, hostEndpoint);
|
|
898
|
-
if (!dto) return "SOURCE_CONNECTION_WRONG_PROVIDER";
|
|
899
|
-
return !claim.repository || connectionMatchesRepository(dto, claim.repository.host) ? null : "SOURCE_CONNECTION_WRONG_PROVIDER";
|
|
900
|
-
}
|
|
901
|
-
|
|
902
1083
|
// src/lambda/runner-handler.ts
|
|
903
1084
|
var MAX_BODY_BYTES = 16 * 1024;
|
|
904
1085
|
var csv = (v) => (v ?? "").split(",").map((s) => s.trim()).filter(Boolean);
|
|
@@ -954,6 +1135,7 @@ function defaultDeps() {
|
|
|
954
1135
|
if (!sm.has(region)) sm.set(region, new SecretsManagerClient({ region }));
|
|
955
1136
|
return sm.get(region);
|
|
956
1137
|
},
|
|
1138
|
+
github: githubGet,
|
|
957
1139
|
log: defaultLog
|
|
958
1140
|
};
|
|
959
1141
|
}
|
|
@@ -1097,7 +1279,7 @@ function createRunner(config, deps) {
|
|
|
1097
1279
|
return ok("status", { executionId: claims.executionId, executionStatus: execution.executionStatus ?? "Unknown" });
|
|
1098
1280
|
}
|
|
1099
1281
|
async function deployAction(claims) {
|
|
1100
|
-
const
|
|
1282
|
+
const answer2 = await runDeployAction({
|
|
1101
1283
|
runnerId: config.runnerId,
|
|
1102
1284
|
config: config.deploy,
|
|
1103
1285
|
codebuild: deps.codebuild(),
|
|
@@ -1105,8 +1287,8 @@ function createRunner(config, deps) {
|
|
|
1105
1287
|
isAllowed: (region, name) => isAllowed(config, region, name),
|
|
1106
1288
|
alreadyDeployed: async (pipelineId) => (await arnsByTag(config, deps, pipelineId)).length > 0
|
|
1107
1289
|
}, claims);
|
|
1108
|
-
if ("refuse" in
|
|
1109
|
-
const { outcome, ...details } =
|
|
1290
|
+
if ("refuse" in answer2) return fail(answer2.refuse);
|
|
1291
|
+
const { outcome, ...details } = answer2;
|
|
1110
1292
|
return ok(outcome, details);
|
|
1111
1293
|
}
|
|
1112
1294
|
async function sourceAction(claims, account) {
|
|
@@ -1117,16 +1299,23 @@ function createRunner(config, deps) {
|
|
|
1117
1299
|
const refusal = await checkSource(sources, account.accountId, deps);
|
|
1118
1300
|
return refusal ? fail(refusal) : ok("source_ok");
|
|
1119
1301
|
}
|
|
1302
|
+
async function inspectAction(claims) {
|
|
1303
|
+
const inspect = claims.inspect;
|
|
1304
|
+
if (!config.allowedRegions.includes(inspect.region)) return fail("SOURCE_REGION_NOT_ALLOWED");
|
|
1305
|
+
const answer2 = await inspectRepository(inspect, deps);
|
|
1306
|
+
return answer2 === "GITHUB_TOKEN_MISSING" ? fail(answer2) : ok("repository_reads", { results: answer2.results });
|
|
1307
|
+
}
|
|
1120
1308
|
async function act(claims, account) {
|
|
1121
1309
|
if (claims.action === "ping") {
|
|
1122
1310
|
return ok("pong", {
|
|
1123
1311
|
regions: [...config.allowedRegions],
|
|
1124
|
-
capabilities: config.deploy.enabled ? [DEPLOY_CAPABILITY, SOURCES_CAPABILITY] : [SOURCES_CAPABILITY],
|
|
1312
|
+
capabilities: config.deploy.enabled ? [DEPLOY_CAPABILITY, SOURCES_CAPABILITY, INSPECT_CAPABILITY] : [SOURCES_CAPABILITY, INSPECT_CAPABILITY],
|
|
1125
1313
|
pipelinePrefixes: [...config.allowedPrefixes]
|
|
1126
1314
|
});
|
|
1127
1315
|
}
|
|
1128
1316
|
if (Object.hasOwn(DEPLOY_ACTION_CAPABILITY, claims.action)) return deployAction(claims);
|
|
1129
1317
|
if (Object.hasOwn(SOURCE_ACTION_CAPABILITY, claims.action)) return sourceAction(claims, account);
|
|
1318
|
+
if (claims.action === "inspect_repository") return inspectAction(claims);
|
|
1130
1319
|
const found = await findPipeline(config, deps, account, claims.pipelineId, claims.hint);
|
|
1131
1320
|
if (claims.action === "probe") {
|
|
1132
1321
|
if (found.kind === "ambiguous") return fail("AMBIGUOUS_PIPELINE");
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type RunInspectClaim } from '@pipeline-builder/api-core/pipeline-runners';
|
|
2
|
+
import { type RepositoryReadResult } from '@pipeline-builder/api-core/pipeline-source';
|
|
3
|
+
import type { Sender } from './pipeline-tag.js';
|
|
4
|
+
/**
|
|
5
|
+
* One authenticated GET to the GitHub API: the status, and the body text —
|
|
6
|
+
* null when it was larger than {@link INSPECT_MAX_READ_BYTES} (never buffered
|
|
7
|
+
* past it).
|
|
8
|
+
*/
|
|
9
|
+
export type GitHubGet = (url: string, token: string) => Promise<{
|
|
10
|
+
status: number;
|
|
11
|
+
text: string | null;
|
|
12
|
+
}>;
|
|
13
|
+
/** What inspect_repository uses. */
|
|
14
|
+
export interface InspectDeps {
|
|
15
|
+
secrets(region: string): Sender;
|
|
16
|
+
github: GitHubGet;
|
|
17
|
+
}
|
|
18
|
+
/** The real GitHub GET: redirects refused, a timeout, the body capped. */
|
|
19
|
+
export declare const githubGet: GitHubGet;
|
|
20
|
+
/**
|
|
21
|
+
* inspect_repository: the reads, in order, or GITHUB_TOKEN_MISSING when neither
|
|
22
|
+
* the owner's nor the org's token secret holds a token in the claim's region.
|
|
23
|
+
*/
|
|
24
|
+
export declare function inspectRepository(claim: RunInspectClaim, deps: InspectDeps): Promise<{
|
|
25
|
+
results: RepositoryReadResult[];
|
|
26
|
+
} | 'GITHUB_TOKEN_MISSING'>;
|
|
27
|
+
//# sourceMappingURL=runner-inspect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner-inspect.d.ts","sources":["../../src/lambda/runner-inspect.ts"],"names":[],"mappings":"AA2BA,OAAO,EAEgB,KAAK,eAAe,EAC1C,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAC0E,KAAK,oBAAoB,EACzG,MAAM,4CAA4C,CAAC;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAQhD;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC,CAAC;AAEzG,oCAAoC;AACpC,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IAChC,MAAM,EAAE,SAAS,CAAC;CACnB;AAqBD,0EAA0E;AAC1E,eAAO,MAAM,SAAS,EAAE,SAYvB,CAAC;AA+BF;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,oBAAoB,EAAE,CAAA;CAAE,GAAG,sBAAsB,CAAC,CAmBxJ"}
|