Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target Metadata for get-job-inputs #88

Merged
merged 8 commits into from
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion apps/webservice/src/app/api/v1/jobs/[jobId]/route.ts
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ import {
runbook,
runbookJobTrigger,
target,
targetMetadata,
updateJob,
} from "@ctrlplane/db/schema";
import { onJobCompletion } from "@ctrlplane/job-dispatch";
@@ -58,7 +59,26 @@ export const GET = async (
jobVariableRows.map((v) => [v.key, v.value]),
);

return NextResponse.json({ ...je.job, ...je, variables });
const jobTargetMetadataRows = await db
.select()
.from(targetMetadata)
.where(eq(targetMetadata.targetId, je.target?.id ?? ""));

const metadata = Object.fromEntries(
jobTargetMetadataRows.map((m) => [m.key, m.value]),
);

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

return NextResponse.json({
...je.job,
...je,
variables,
target: targetWithMetadata,
});
};

const bodySchema = updateJob;
10 changes: 7 additions & 3 deletions github/get-job-inputs/index.js

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

3 changes: 2 additions & 1 deletion integrations/get-job-inputs/src/index.ts
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ const setOutputAndLog = (key: string, value: any) => {
const setOutputsRecursively = (prefix: string, obj: any) => {
if (typeof obj === "object" && obj !== null) {
for (const [key, value] of Object.entries(obj)) {
const sanitizedKey = key.split(".").join("_");
const sanitizedKey = key.replace(/[.\-/\s\t]+/g, "_");
const newPrefix = prefix ? `${prefix}_${sanitizedKey}` : sanitizedKey;
if (typeof value === "object" && value !== null)
setOutputsRecursively(newPrefix, value);
@@ -59,6 +59,7 @@ async function run() {
setOutputAndLog("target_version", target?.version);
setOutputAndLog("target_identifier", target?.identifier);
setOutputsRecursively("target_config", target?.config);
setOutputsRecursively("target_metadata", target?.metadata);

setOutputAndLog("workspace_id", target?.workspaceId);

11 changes: 10 additions & 1 deletion packages/node-sdk/openapi.yaml
Original file line number Diff line number Diff line change
@@ -337,8 +337,17 @@ paths:
type: string
config:
type: object
metadata:
type: object
required:
[id, name, version, kind, identifier, workspaceId, config]
- id
- name
- version
- kind
- identifier
- workspaceId
- config
- metadata

environment:
type: object
9 changes: 9 additions & 0 deletions packages/node-sdk/src/models/GetJob200ResponseTarget.ts
Original file line number Diff line number Diff line change
@@ -62,6 +62,12 @@ export interface GetJob200ResponseTarget {
* @memberof GetJob200ResponseTarget
*/
config: object;
/**
*
* @type {object}
* @memberof GetJob200ResponseTarget
*/
metadata: object;
}

/**
@@ -79,6 +85,7 @@ export function instanceOfGetJob200ResponseTarget(
if (!("workspaceId" in value) || value["workspaceId"] === undefined)
return false;
if (!("config" in value) || value["config"] === undefined) return false;
if (!("metadata" in value) || value["metadata"] === undefined) return false;
return true;
}

@@ -103,6 +110,7 @@ export function GetJob200ResponseTargetFromJSONTyped(
identifier: json["identifier"],
workspaceId: json["workspaceId"],
config: json["config"],
metadata: json["metadata"],
};
}

@@ -120,5 +128,6 @@ export function GetJob200ResponseTargetToJSON(
identifier: value["identifier"],
workspaceId: value["workspaceId"],
config: value["config"],
metadata: value["metadata"],
};
}

Unchanged files with check annotations Beta

EXPOSE 3000
ENV PORT=3000
ENV AUTH_TRUST_HOST=true

Check warning on line 59 in apps/webservice/Dockerfile

GitHub Actions / build

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ENV "AUTH_TRUST_HOST") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/
ENV NODE_ENV=production
ENV HOSTNAME=0.0.0.0