Skip to content

Commit

Permalink
fix 1pass service account, add timing debug (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
theoephraim authored Nov 25, 2024
1 parent c5a695e commit 48677e2
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 76 deletions.
5 changes: 5 additions & 0 deletions .changeset/old-adults-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@dmno/1password-plugin": patch
---

fix 1pass service account integration
2 changes: 2 additions & 0 deletions packages/plugins/1password/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@
"@dmno/eslint-config": "workspace:*",
"@dmno/tsconfig": "workspace:*",
"@types/lodash-es": "catalog:",
"@types/debug": "catalog:",
"@types/node": "catalog:",
"dmno": "workspace:*",
"tsup": "catalog:",
"typescript": "catalog:"
},
"dependencies": {
"@1password/sdk": "^0.1.1",
"debug": "catalog:",
"kleur": "^4.1.5",
"lodash-es": "catalog:"
},
Expand Down
11 changes: 9 additions & 2 deletions packages/plugins/1password/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ import {
PluginInputValue,
inject,
} from 'dmno';
import Debug from 'debug';

import { Client, createClient } from '@1password/sdk';

import packageJson from '../package.json';
import { OnePasswordTypes } from './data-types';

const debug = Debug('dmno:1pass-plugin');

type FieldId = string;
type ItemId = string;
type VaultId = string;
Expand All @@ -23,8 +26,11 @@ type ReferenceUrl = string;
type ServiceAccountToken = string;

async function execOpCliCommand(cmdArgs: Array<string>) {
const startAt = new Date();
// using system-installed copy of `op`
const cmd = spawnSync('op', cmdArgs);
debug(`op cli command - "${cmdArgs}"`);
debug(`> took ${+new Date() - +startAt}ms`);
if (cmd.status === 0) {
return cmd.stdout.toString();
} else if (cmd.error) {
Expand Down Expand Up @@ -160,7 +166,7 @@ export class OnePasswordDmnoPlugin extends DmnoPlugin {
const opClient = await this.getSdkClient();
// TODO: better error handling to tell you what went wrong? no access, non existant, etc
try {
const opItem = opClient.items.get(vaultId, itemId);
const opItem = await opClient.items.get(vaultId, itemId);
return JSON.parse(JSON.stringify(opItem)); // convert to plain object
} catch (err) {
// 1pass sdk throws strings as errors...
Expand Down Expand Up @@ -193,7 +199,8 @@ export class OnePasswordDmnoPlugin extends DmnoPlugin {
return await ctx.getOrSetCacheItem(`1pass-sdk:R|${referenceUrl}`, async () => {
const opClient = await this.getSdkClient();
// TODO: better error handling to tell you what went wrong? no access, non existant, etc
return opClient.secrets.resolve(referenceUrl);
const value = await opClient.secrets.resolve(referenceUrl);
return value;
});
} catch (err) {
// 1pass sdk throws strings as errors...
Expand Down
119 changes: 45 additions & 74 deletions pnpm-lock.yaml

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

0 comments on commit 48677e2

Please sign in to comment.