Skip to content

Commit

Permalink
fix: Target variables (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
adityachoudhari26 authored Oct 25, 2024
1 parent d82ff20 commit a75640e
Show file tree
Hide file tree
Showing 11 changed files with 3,942 additions and 6 deletions.
1 change: 1 addition & 0 deletions apps/webservice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@ctrlplane/db": "workspace:*",
"@ctrlplane/job-dispatch": "workspace:*",
"@ctrlplane/logger": "workspace:*",
"@ctrlplane/secrets": "workspace:*",
"@ctrlplane/ui": "workspace:*",
"@ctrlplane/validators": "workspace:*",
"@hookform/resolvers": "^3.3.4",
Expand Down
12 changes: 7 additions & 5 deletions apps/webservice/src/app/api/v1/jobs/[jobId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
updateJob,
} from "@ctrlplane/db/schema";
import { onJobCompletion } from "@ctrlplane/job-dispatch";
import { variablesAES256 } from "@ctrlplane/secrets";
import { JobStatus } from "@ctrlplane/validators/jobs";

import { getUser } from "~/app/api/v1/auth";
Expand Down Expand Up @@ -56,7 +57,11 @@ export const GET = async (
.where(eq(jobVariable.jobId, params.jobId));

const variables = Object.fromEntries(
jobVariableRows.map((v) => [v.key, v.value]),
jobVariableRows.map((v) => {
const strval = String(v.value);
const value = v.sensitive ? variablesAES256().decrypt(strval) : strval;
return [v.key, value];
}),
);

const jobTargetMetadataRows = await db
Expand All @@ -68,10 +73,7 @@ export const GET = async (
jobTargetMetadataRows.map((m) => [m.key, m.value]),
);

const targetWithMetadata = {
...je.target,
metadata,
};
const targetWithMetadata = { ...je.target, metadata };

return NextResponse.json({
...je.job,
Expand Down
1 change: 1 addition & 0 deletions packages/db/drizzle/0023_melted_nightshade.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "job_variable" ADD COLUMN "sensitive" boolean DEFAULT false NOT NULL;
Loading

0 comments on commit a75640e

Please sign in to comment.