Skip to content

Commit

Permalink
init google compute scanner template
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbroks committed Aug 25, 2024
1 parent 804c544 commit 465e3a2
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 26 deletions.
4 changes: 2 additions & 2 deletions packages/logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./src/index.ts"
"types": "./src/index.ts",
"default": "./dist/index.js"
}
},
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions packages/node-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"dist/**"
],
"scripts": {
"build": "tsc",
"build:tsup": "tsup",
"build": "tsup",
"build:tsc": "tsc",
"dev": "tsc --watch",
"clean": "rm -rf .turbo node_modules",
"format": "prettier --check . --ignore-path ../../.gitignore",
Expand Down
29 changes: 22 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion providers/google-cloud/compute-scanner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,21 @@
"license": "MIT",
"scripts": {
"build": "tsc",
"dev": "tsc --watch",
"dev": "tsx watch --clear-screen=false src/index.ts",
"clean": "rm -rf .turbo node_modules",
"format": "prettier --check . --ignore-path ../../.gitignore",
"lint": "eslint",
"typecheck": "tsc --noEmit --emitDeclarationOnly false"
},
"dependencies": {
"@ctrlplane/logger": "workspace:*",
"@ctrlplane/node-sdk": "workspace:*",
"@google-cloud/container": "^5.16.0",
"@t3-oss/env-core": "^0.10.1",
"cron": "^3.1.7",
"dotenv": "^16.4.5",
"handlebars": "^4.7.8",
"p-retry": "^6.2.0",
"semver": "^7.6.2",
"zod": "catalog:"
},
Expand Down
13 changes: 0 additions & 13 deletions providers/google-cloud/compute-scanner/src/config-file.ts

This file was deleted.

32 changes: 32 additions & 0 deletions providers/google-cloud/compute-scanner/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { createEnv } from "@t3-oss/env-core";
import dotenv from "dotenv";
import { z } from "zod";

dotenv.config();

export const env = createEnv({
server: {
CTRLPLANE_API_URL: z.string().default("http://localhost:3000"),
CTRLPLANE_API_KEY: z.string(),
CTRLPLANE_WORKSPACE: z.string(),
CTRLPLANE_SCANNER_NAME: z.string().default("offical-google-scanner"),
CTRLPLANE_GKE_TARGET_NAME: z
.string()
.default("gke-{{ projectId }}-{{ cluster.name }}"),
CTRLPLANE_COMPUTE_TARGET_NAME: z
.string()
.default("gc-{{ projectId }}-{{ vm.name }}"),

CRON_ENABLED: z.boolean().default(true),
CRON_TIME: z.string().default("* * * * *"),

GOOGLE_PROJECT_ID: z.string().min(1),
GOOGLE_SCAN_GKE: z.boolean().default(true),
},
runtimeEnv: process.env,

skipValidation:
!!process.env.CI ||
!!process.env.SKIP_ENV_VALIDATION ||
process.env.npm_lifecycle_event === "lint",
});
23 changes: 22 additions & 1 deletion providers/google-cloud/compute-scanner/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
export * from "./config-file.js";
import { CronJob } from "cron";

import { logger } from "@ctrlplane/logger";

import { env } from "./config.js";

const scan = async () => {

Check failure on line 7 in providers/google-cloud/compute-scanner/src/index.ts

View workflow job for this annotation

GitHub Actions / Lint

Async arrow function 'scan' has no 'await' expression
logger.info("Running google compute scanner", {
date: new Date().toISOString(),
});
};

logger.info(
`Starting google compute scanner from project '${env.GOOGLE_PROJECT_ID}' into workspace '${env.CTRLPLANE_WORKSPACE}'`,
env,
);

scan().catch(console.error);
if (env.CRON_ENABLED) {
logger.info(`Enabling cron job, ${env.CRON_TIME}`, { time: env.CRON_TIME });
new CronJob(env.CRON_TIME, scan).start();
}
10 changes: 10 additions & 0 deletions providers/google-cloud/compute-scanner/src/sdk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Configuration, DefaultApi } from "@ctrlplane/node-sdk";

import { env } from "./config.js";

const config = new Configuration({
basePath: `${env.CTRLPLANE_API_URL}/api`,
apiKey: env.CTRLPLANE_API_KEY,
});

export const api = new DefaultApi(config);

0 comments on commit 465e3a2

Please sign in to comment.