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

fix 1pass service account, add timing debug #170

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
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
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.