Skip to content

Commit

Permalink
return output file
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Dec 3, 2023
1 parent e6492b7 commit e89491c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/zenith.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Zenith Example
on:
push:
branches:
- zenith
- main

jobs:
tests:
Expand Down
4 changes: 3 additions & 1 deletion example/config.gql
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
trivy {
config(src: ".", exitCode: 0)
config(src: ".", exitCode: 0) {
id
}
}
}
4 changes: 3 additions & 1 deletion example/image.gql
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
trivy {
image(src: ".", exitCode: 0, image: "snyk/snyk:alpine")
image(src: ".", exitCode: 0, image: "snyk/snyk:alpine") {
id
}
}
}
57 changes: 29 additions & 28 deletions src/dagger/jobs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Client, { Directory } from "../../deps.ts";
import Client, { Directory, File } from "../../deps.ts";
import { connect } from "../../sdk/connect.ts";
import { getDirectory } from "./lib.ts";

Expand All @@ -19,14 +19,15 @@ export const exclude = [".fluentci"];
* @param {number} exitCode
* @param {string} format
* @param {string} output
* @returns {Promise<string>}
* @returns {Promise<File | string>}
*/
export async function config(
src: Directory | string,
exitCode?: number,
format?: string,
output?: string
): Promise<string> {
): Promise<File | string> {
let id = "";
await connect(async (client: Client) => {
const context = getDirectory(client, src);
const args = ["config", "."];
Expand All @@ -48,11 +49,10 @@ export async function config(
.withWorkdir("/app")
.withExec(args);

const result = await ctr.stdout();

console.log(result);
await ctr.stdout();
id = await ctr.file(`/app/${output}`).id();
});
return "Done";
return id;
}

/**
Expand All @@ -62,14 +62,15 @@ export async function config(
* @param {number} exitCode
* @param {string} format
* @param {string} output
* @returns {Promise<string>}
* @returns {Promise<File | string>}
*/
export async function fs(
src: Directory | string,
exitCode?: number,
format?: string,
output?: string
): Promise<string> {
let id = "";
await connect(async (client: Client) => {
const context = getDirectory(client, src);
const args = ["fs", "."];
Expand All @@ -91,11 +92,11 @@ export async function fs(
.withWorkdir("/app")
.withExec(args);

const result = await ctr.stdout();
await ctr.stdout();

console.log(result);
id = await ctr.file(`/app/${output}`).id();
});
return "Done";
return id;
}

/**
Expand All @@ -106,7 +107,7 @@ export async function fs(
* @param {string} repoUrl
* @param {string} format
* @param {string} output
* @returns {Promise<string>}
* @returns {Promise<File | string>}
*/
export async function repo(
src: Directory | string,
Expand All @@ -115,6 +116,7 @@ export async function repo(
format?: string,
output?: string
): Promise<string> {
let id = "";
await connect(async (client: Client) => {
const context = getDirectory(client, src);
const args = ["repo", Deno.env.get("TRIVY_REPO_URL") || repoUrl || "."];
Expand All @@ -135,12 +137,11 @@ export async function repo(
.withDirectory("/app", context, { exclude })
.withWorkdir("/app")
.withExec(args);
await ctr.stdout();

const result = await ctr.stdout();

console.log(result);
id = await ctr.file(`/app/${output}`).id();
});
return "Done";
return id;
}

/**
Expand All @@ -151,7 +152,7 @@ export async function repo(
* @param {string} image
* @param {string} format
* @param {string} output
* @returns {Promise<string>}
* @returns {Promise<File | string>}
*/
export async function image(
src: Directory | string,
Expand All @@ -160,6 +161,7 @@ export async function image(
format?: string,
output?: string
): Promise<string> {
let id = "";
await connect(async (client: Client) => {
const context = getDirectory(client, src);
if (!Deno.env.has("TRIVY_IMAGE") && !image) {
Expand Down Expand Up @@ -187,11 +189,10 @@ export async function image(
.withWorkdir("/app")
.withExec(args);

const result = await ctr.stdout();

console.log(result);
await ctr.stdout();
id = await ctr.file(`/app/${output}`).id();
});
return "Done";
return id;
}

/**
Expand All @@ -202,15 +203,16 @@ export async function image(
* @param {string} path
* @param {string} format
* @param {string} output
* @returns {Promise<string>}
* @returns {Promise<File | string>}
*/
export async function sbom(
src: Directory | string,
exitCode?: number,
path?: string,
format?: string,
output?: string
): Promise<string> {
): Promise<File | string> {
let id = "";
await connect(async (client: Client) => {
const context = getDirectory(client, src);
if (!Deno.env.has("TRIVY_SBOM_PATH") && !path) {
Expand All @@ -237,11 +239,10 @@ export async function sbom(
.withWorkdir("/app")
.withExec(args);

const result = await ctr.stdout();

console.log(result);
await ctr.stdout();
id = await ctr.file(`/app/${output}`).id();
});
return "Done";
return id;
}

export type JobExec = (
Expand All @@ -250,7 +251,7 @@ export type JobExec = (
path?: string,
format?: string,
output?: string
) => Promise<string>;
) => Promise<File | string>;

export const runnableJobs: Record<Job, JobExec> = {
[Job.config]: config,
Expand Down

0 comments on commit e89491c

Please sign in to comment.