summaryrefslogtreecommitdiff
path: root/worker/secret/bitwarden.ts
diff options
context:
space:
mode:
Diffstat (limited to 'worker/secret/bitwarden.ts')
-rw-r--r--worker/secret/bitwarden.ts66
1 files changed, 40 insertions, 26 deletions
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();