Skip to content

Commit 01bb328

Browse files
authored
Vendor cfn-guard instead of downloading (#302)
1 parent e1ce895 commit 01bb328

19 files changed

+2014
-9
lines changed

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export default tseslint.config([
2626
'**/*.md',
2727
'src/services/guard/assets/**',
2828
'sbom/',
29+
'vendor/',
2930
]),
3031
eslint.configs.recommended,
3132
...tseslint.configs.recommendedTypeChecked,

package-lock.json

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"bundle:beta": "rm -rf out && webpack --env mode=production --env env=beta",
3838
"bundle:prod": "rm -rf out && webpack --env mode=production --env env=prod",
3939
"download-wheels": "tsx tools/download-wheels.ts",
40+
"build-cfn-guard": "tsx tools/build-cfn-guard.ts",
4041
"benchmark": "cross-env NODE_ENV=test AWS_ENV=alpha node --max-old-space-size=16384 --expose-gc -r ts-node/register tools/benchmark.ts",
4142
"generate-metrics": "cross-env NODE_ENV=development AWS_ENV=alpha node --max-old-space-size=16384 -r ts-node/register tools/telemetry-generator.ts",
4243
"debug-tree": "node -r ts-node/register tools/debug_tree.ts",
@@ -74,7 +75,7 @@
7475
"archiver": "7.0.1",
7576
"async-mutex": "0.5.0",
7677
"axios": "1.11.0",
77-
"cfn-guard": "https://gitpkg.now.sh/aws-cloudformation/cloudformation-guard/guard/ts-lib?33d9931",
78+
"cfn-guard": "file:./vendor/cfn-guard",
7879
"deep-object-diff": "1.1.9",
7980
"fast-deep-equal": "3.1.3",
8081
"fuse.js": "7.1.0",
@@ -151,7 +152,6 @@
151152
"@opentelemetry/sdk-trace-base",
152153
"@opentelemetry/sdk-trace-node",
153154
"@tree-sitter-grammars/tree-sitter-yaml",
154-
"cfn-guard",
155155
"lmdb",
156156
"pino",
157157
"pino-pretty",

tools/build-cfn-guard.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env node
2+
3+
import { execSync } from 'child_process';
4+
import { existsSync, rmSync, mkdirSync, cpSync } from 'fs';
5+
import { join, resolve } from 'path';
6+
7+
const COMMIT_HASH = '33d9931';
8+
const TEMP_DIR = 'temp-cfn-guard';
9+
const OUTPUT_DIR = 'vendor/cfn-guard';
10+
11+
function buildCfnGuard(): void {
12+
const projectRoot = resolve(__dirname, '..');
13+
const tempPath = join(projectRoot, TEMP_DIR);
14+
const outputPath = join(projectRoot, OUTPUT_DIR);
15+
16+
console.log('Building cfn-guard from commit', COMMIT_HASH);
17+
18+
// Clean up previous builds
19+
if (existsSync(tempPath)) {
20+
rmSync(tempPath, { recursive: true, force: true });
21+
}
22+
if (existsSync(outputPath)) {
23+
rmSync(outputPath, { recursive: true, force: true });
24+
}
25+
26+
try {
27+
// Clone and checkout specific commit
28+
console.log('Cloning cloudformation-guard repository...');
29+
execSync(`git clone https://github.com/aws-cloudformation/cloudformation-guard.git ${TEMP_DIR}`, {
30+
stdio: 'inherit',
31+
cwd: projectRoot,
32+
});
33+
34+
console.log(`Checking out commit ${COMMIT_HASH}...`);
35+
execSync(`git checkout ${COMMIT_HASH}`, {
36+
stdio: 'inherit',
37+
cwd: tempPath,
38+
});
39+
40+
// Copy ts-lib files to vendor directory (files are pre-built)
41+
const tsLibPath = join(tempPath, 'guard', 'ts-lib');
42+
console.log(`Copying ts-lib files to ${OUTPUT_DIR}...`);
43+
mkdirSync(outputPath, { recursive: true });
44+
45+
cpSync(tsLibPath, outputPath, { recursive: true });
46+
47+
console.log(`cfn-guard copied to ${OUTPUT_DIR}`);
48+
} catch (error) {
49+
console.error('Error building cfn-guard:', error);
50+
process.exit(1);
51+
} finally {
52+
// Clean up temp directory
53+
if (existsSync(tempPath)) {
54+
rmSync(tempPath, { recursive: true, force: true });
55+
}
56+
}
57+
}
58+
59+
if (require.main === module) {
60+
buildCfnGuard();
61+
}

vendor/cfn-guard/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# AWS CloudFormation Guard Typescript / Javascript Module
2+
3+
Currently the module supports only the validate functionality of cfn-guard and only outputs to SARIF format.
4+
5+
## Install
6+
7+
```shell
8+
npm install 'https://gitpkg.now.sh/aws-cloudformation/cloudformation-guard/guard/ts-lib?ccfcd82'
9+
```
10+
11+
## How to use
12+
13+
```typescript
14+
import { validate } from "cfn-guard"
15+
16+
(async () => {
17+
const result = await validate({
18+
rulesPath: "path/to/rules",
19+
dataPath: "path/to/data",
20+
})
21+
22+
console.log(result)
23+
})()
24+
```
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
NotAwsAccessKey: AKIAIOSFODNN7EXAMPLE
2+
NotSecretAccessKey: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
NotAwsAccessKey != /(?<![A-Z0-9])[A-Z0-9]{20}(?![A-Z0-9])/
2+
NotSecretAccessKey != /(?<![A-Za-z0-9\\/+=])[A-Za-z0-9\\/+=]{40}(?![A-Za-z0-9\\/+=])/

0 commit comments

Comments
 (0)