summaryrefslogtreecommitdiff
path: root/worker
diff options
context:
space:
mode:
authorElizabeth <lizhunt@amazon.com>2025-05-28 15:05:38 -0700
committerElizabeth <lizhunt@amazon.com>2025-05-28 15:05:38 -0700
commit3005cc83e605fb89b079cf0e6fd0ec95cd27b30e (patch)
tree992c5933f2ec4a75e32469ddd772c61dbcb2e2fd /worker
parente3cf820b07e282221502cf2f116c9780b7375e0e (diff)
downloadci-3005cc83e605fb89b079cf0e6fd0ec95cd27b30e.tar.gz
ci-3005cc83e605fb89b079cf0e6fd0ec95cd27b30e.zip
Run prettier, add zed settings
Diffstat (limited to 'worker')
-rw-r--r--worker/deno.json4
-rw-r--r--worker/executor/job.ts26
-rw-r--r--worker/executor/pipeline.ts27
-rw-r--r--worker/secret/bitwarden.ts66
4 files changed, 71 insertions, 52 deletions
diff --git a/worker/deno.json b/worker/deno.json
index 77c65de..90f50c9 100644
--- a/worker/deno.json
+++ b/worker/deno.json
@@ -1,4 +1,4 @@
{
- "name": "@emprespresso/ci-worker",
- "exports": "./mod.ts"
+ "name": "@emprespresso/ci-worker",
+ "exports": "./mod.ts"
}
diff --git a/worker/executor/job.ts b/worker/executor/job.ts
index 76f0e0c..ca7feed 100644
--- a/worker/executor/job.ts
+++ b/worker/executor/job.ts
@@ -12,31 +12,31 @@ import type { Job } from "@emprespresso/ci-model";
const jobTypeMetric = memoize((type: string) => Metric.fromName(`run.${type}`));
export const executeJob = (tJob: ITraceable<Job, LogMetricTraceSupplier>) =>
- tJob.bimap(TraceUtil.withMetricTrace(jobTypeMetric(tJob.get().type)))
+ tJob
+ .bimap(TraceUtil.withMetricTrace(jobTypeMetric(tJob.get().type)))
.peek((tJob) =>
- tJob.trace.trace(
- `let's do this little job ok!! ${tJob.get()}`,
- )
+ tJob.trace.trace(`let's do this little job ok!! ${tJob.get()}`),
)
.map((tJob) =>
validateExecutionEntries(tJob.get().arguments)
.mapLeft((badEntries) => {
- tJob.trace.addTrace(LogLevel.ERROR).trace(
- badEntries.toString(),
- );
+ tJob.trace.addTrace(LogLevel.ERROR).trace(badEntries.toString());
return new Error("invalid job arguments");
})
.flatMapAsync((args) =>
- getStdout(tJob.move(tJob.get().type), { env: args })
- )
+ getStdout(tJob.move(tJob.get().type), { env: args }),
+ ),
)
.peek(
TraceUtil.promiseify((q) =>
q.trace.trace(
- q.get().fold((err, _val) =>
- jobTypeMetric(tJob.get().type)[err ? "failure" : "success"]
- ),
- )
+ q
+ .get()
+ .fold(
+ (err, _val) =>
+ jobTypeMetric(tJob.get().type)[err ? "failure" : "success"],
+ ),
+ ),
),
)
.get();
diff --git a/worker/executor/pipeline.ts b/worker/executor/pipeline.ts
index a1aa7c3..c8423b1 100644
--- a/worker/executor/pipeline.ts
+++ b/worker/executor/pipeline.ts
@@ -14,7 +14,8 @@ export const executePipeline = (
tPipeline: ITraceable<Pipeline, LogMetricTraceSupplier>,
baseEnv?: JobArgT,
): Promise<IEither<Error, void>> =>
- tPipeline.bimap(TraceUtil.withFunctionTrace(executePipeline))
+ tPipeline
+ .bimap(TraceUtil.withFunctionTrace(executePipeline))
.bimap(TraceUtil.withMetricTrace(pipelinesMetric))
.map(async (tJobs): Promise<IEither<Error, void>> => {
for (const [i, serialStage] of tJobs.get().serialJobs.entries()) {
@@ -23,22 +24,26 @@ export const executePipeline = (
);
const jobResults = await Promise.all(
serialStage.parallelJobs.map((job) =>
- tJobs.bimap((_) => [job, `stage ${i}`])
- .map((tJob) =>
- <Job> ({
- ...tJob.get(),
- arguments: { ...baseEnv, ...tJob.get().arguments },
- })
+ tJobs
+ .bimap((_) => [job, `stage ${i}`])
+ .map(
+ (tJob) =>
+ <Job>{
+ ...tJob.get(),
+ arguments: { ...baseEnv, ...tJob.get().arguments },
+ },
)
.map(executeJob)
.peek(
TraceUtil.promiseify((tEitherJobOutput) =>
- tEitherJobOutput.get().mapRight((stdout) =>
- tEitherJobOutput.trace.addTrace("STDOUT").trace(stdout)
- )
+ tEitherJobOutput
+ .get()
+ .mapRight((stdout) =>
+ tEitherJobOutput.trace.addTrace("STDOUT").trace(stdout),
+ ),
),
)
- .get()
+ .get(),
),
);
const failures = jobResults.filter((e) => e.fold((err) => !!err));
diff --git a/worker/secret/bitwarden.ts b/worker/secret/bitwarden.ts
index 0172a1b..7145f49 100644
--- a/worker/secret/bitwarden.ts
+++ b/worker/secret/bitwarden.ts
@@ -17,24 +17,27 @@ export class Bitwarden implements IVault<TClient, TKey, TItemId> {
constructor(private readonly config: BitwardenConfig) {}
public unlock(client: TClient) {
- return client.move(this.config)
+ return client
+ .move(this.config)
.bimap(TraceUtil.withMetricTrace(Bitwarden.loginMetric))
.flatMap((tConfig) =>
- tConfig.move(`bw config server ${tConfig.get().server}`).map(getStdout)
+ tConfig.move(`bw config server ${tConfig.get().server}`).map(getStdout),
)
.map(async (tEitherWithConfig) => {
const eitherWithConfig = await tEitherWithConfig.get();
tEitherWithConfig.trace.trace("logging in~ ^.^");
return eitherWithConfig.flatMapAsync((_) =>
- tEitherWithConfig.move("bw login --apikey --quiet").map(getStdout)
- .get()
+ tEitherWithConfig
+ .move("bw login --apikey --quiet")
+ .map(getStdout)
+ .get(),
);
})
.peek(async (tEitherWithAuthd) => {
const eitherWithAuthd = await tEitherWithAuthd.get();
return tEitherWithAuthd.trace.trace(
- eitherWithAuthd.fold((err, _val) =>
- Bitwarden.loginMetric[err ? "failure" : "success"]
+ eitherWithAuthd.fold(
+ (err, _val) => Bitwarden.loginMetric[err ? "failure" : "success"],
),
);
})
@@ -42,16 +45,18 @@ export class Bitwarden implements IVault<TClient, TKey, TItemId> {
const eitherWithAuthd = await tEitherWithAuthd.get();
tEitherWithAuthd.trace.trace("unlocking the secret vault~ (◕ᴗ◕✿)");
return eitherWithAuthd.flatMapAsync((_) =>
- tEitherWithAuthd.move("bw unlock --passwordenv BW_PASSWORD --raw")
+ tEitherWithAuthd
+ .move("bw unlock --passwordenv BW_PASSWORD --raw")
.map(getStdout)
- .get()
+ .get(),
);
})
.peek(async (tEitherWithSession) => {
const eitherWithAuthd = await tEitherWithSession.get();
return tEitherWithSession.trace.trace(
- eitherWithAuthd.fold((err, _val) =>
- Bitwarden.unlockVaultMetric[err ? "failure" : "success"]
+ eitherWithAuthd.fold(
+ (err, _val) =>
+ Bitwarden.unlockVaultMetric[err ? "failure" : "success"],
),
);
})
@@ -63,21 +68,26 @@ export class Bitwarden implements IVault<TClient, TKey, TItemId> {
key: string,
item: string,
): Promise<IEither<Error, T>> {
- return client.move(key)
+ return client
+ .move(key)
.bimap(TraceUtil.withMetricTrace(Bitwarden.fetchSecretMetric))
.peek((tSession) =>
- tSession.trace.trace(`looking for your secret ${item} (⑅˘꒳˘)`)
+ tSession.trace.trace(`looking for your secret ${item} (⑅˘꒳˘)`),
)
.flatMap((tSession) =>
- tSession.move("bw list items").map((listCmd) =>
- getStdout(listCmd, { env: { BW_SESSION: tSession.get() } })
- )
+ tSession
+ .move("bw list items")
+ .map((listCmd) =>
+ getStdout(listCmd, { env: { BW_SESSION: tSession.get() } }),
+ ),
)
.map(
TraceUtil.promiseify((tEitherItemsJson) =>
- tEitherItemsJson.get()
- .flatMap((itemsJson): IEither<Error, Array<T & { name: string }>> =>
- Either.fromFailable(() => JSON.parse(itemsJson))
+ tEitherItemsJson
+ .get()
+ .flatMap(
+ (itemsJson): IEither<Error, Array<T & { name: string }>> =>
+ Either.fromFailable(() => JSON.parse(itemsJson)),
)
.flatMap((itemsList): IEither<Error, T> => {
const secret = itemsList.find(({ name }) => name === item);
@@ -87,14 +97,15 @@ export class Bitwarden implements IVault<TClient, TKey, TItemId> {
);
}
return Either.right(secret);
- })
+ }),
),
)
.peek(async (tEitherWithSecret) => {
const eitherWithSecret = await tEitherWithSecret.get();
return tEitherWithSecret.trace.trace(
- eitherWithSecret.fold((err, _val) =>
- Bitwarden.fetchSecretMetric[err ? "failure" : "success"]
+ eitherWithSecret.fold(
+ (err, _val) =>
+ Bitwarden.fetchSecretMetric[err ? "failure" : "success"],
),
);
})
@@ -102,15 +113,18 @@ export class Bitwarden implements IVault<TClient, TKey, TItemId> {
}
public lock(client: TClient, key: TKey) {
- return client.move(key)
+ return client
+ .move(key)
.bimap(TraceUtil.withMetricTrace(Bitwarden.lockVaultMetric))
.peek((tSession) =>
- tSession.trace.trace(`taking care of locking the vault :3`)
+ tSession.trace.trace(`taking care of locking the vault :3`),
)
.flatMap((tSession) =>
- tSession.move("bw lock").map((lockCmd) =>
- getStdout(lockCmd, { env: { BW_SESSION: tSession.get() } })
- )
+ tSession
+ .move("bw lock")
+ .map((lockCmd) =>
+ getStdout(lockCmd, { env: { BW_SESSION: tSession.get() } }),
+ ),
)
.peek(async (tEitherWithLocked) => {
const eitherWithLocked = await tEitherWithLocked.get();