Skip to content

Commit

Permalink
v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
benvp committed Oct 24, 2024
1 parent 6593bd4 commit 7214320
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 27 deletions.
6 changes: 6 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"singleQuote": true,
"trailingComma": "all",
"printWidth": 100,
"arrowParens": "avoid"
}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changelog

## 0.2.0 (2024-10-24)

### Enhancements
* Support passing flags to op-cli via `flags` configuration key.
* Add an argument to specify an account when fetching a secret.
* Allow setting up a default account in config.
36 changes: 20 additions & 16 deletions dist/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
Expand Down Expand Up @@ -67,28 +67,29 @@ var op_js_1 = require("@1password/op-js");
var cache = __importStar(require("./cache"));
var path_1 = __importDefault(require("path"));
var fs_1 = __importDefault(require("fs"));
var OP_PLUGIN_CONFIG_KEY = '__op_plugin';
var OP_PLUGIN_CONFIG_KEY = "__op_plugin";
var fetchSecretTemplateTag = {
name: 'op',
displayName: '1Password => Fetch Secret',
name: "op",
displayName: "1Password => Fetch Secret",
liveDisplayName: function (args) {
var _a, _b, _c;
return "1Password => ".concat((_b = (_a = args[0]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '--', " {").concat(((_c = args[1]) === null || _c === void 0 ? void 0 : _c.value) ? (args[1].value) : '', "}");
console.log(args);
return "1Password => ".concat((_b = (_a = args[0]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : "--").concat(((_c = args[1]) === null || _c === void 0 ? void 0 : _c.value) ? " (".concat(args[1].value, ")") : "");
},
description: 'Fetch a secret from your 1Password vault',
description: "Fetch a secret from your 1Password vault",
args: [
{
displayName: 'Reference',
description: '1Password item reference (op://...)',
type: 'string',
defaultValue: '',
displayName: "Reference",
description: "1Password item reference (op://...)",
type: "string",
defaultValue: "",
placeholder: "e.g. 'op://vault-name/item-name/section/field'",
},
{
displayName: 'Account',
description: '1Password account name',
type: 'string',
defaultValue: '',
displayName: "Account",
description: "1Password account name",
type: "string",
defaultValue: "",
placeholder: "e.g. 'team-name.1password.com'",
},
],
Expand All @@ -99,6 +100,7 @@ var fetchSecretTemplateTag = {
switch (_a.label) {
case 0:
config = context.context[OP_PLUGIN_CONFIG_KEY];
console.log(context, reference, account);
if (config === null || config === void 0 ? void 0 : config.flags) {
(0, op_js_1.setGlobalFlags)(config.flags);
}
Expand Down Expand Up @@ -134,7 +136,9 @@ function checkCli(cliPath) {
pathToAdd = path_1.default.dirname(cliPath);
}
}
process.env.PATH = pathToAdd ? "".concat(pathToAdd, ":").concat(process.env.PATH) : process.env.PATH;
process.env.PATH = pathToAdd
? "".concat(pathToAdd, ":").concat(process.env.PATH)
: process.env.PATH;
return [4, (0, op_js_1.validateCli)()];
case 2:
_a.sent();
Expand Down
9 changes: 5 additions & 4 deletions dist/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.writeEntry = writeEntry;
exports.getEntry = getEntry;
exports.opCliInstalled = opCliInstalled;
exports.writeOpCliInstalled = writeOpCliInstalled;
exports.writeOpCliInstalled = exports.opCliInstalled = exports.getEntry = exports.writeEntry = void 0;
var node_cache_1 = __importDefault(require("node-cache"));
var cache = new node_cache_1.default({ stdTTL: 60 * 60 });
function writeEntry(ref, value) {
return cache.set(ref, value);
}
exports.writeEntry = writeEntry;
function getEntry(ref) {
return cache.get(ref);
}
exports.getEntry = getEntry;
function opCliInstalled() {
return cache.get('opCliInstalled');
}
exports.opCliInstalled = opCliInstalled;
function writeOpCliInstalled(installed) {
return cache.set('opCliInstalled', installed);
}
exports.writeOpCliInstalled = writeOpCliInstalled;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-react-hooks": "^5.0.0",
"prettier": "^3.2.4",
"typescript": "^5.3.3"
},
Expand Down
28 changes: 23 additions & 5 deletions pnpm-lock.yaml

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

7 changes: 5 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const fetchSecretTemplateTag = {
name: 'op',
displayName: '1Password => Fetch Secret',
liveDisplayName: (args: any[]) => {
return `1Password => ${args[0]?.value ?? '--'} {${args[1]?.value ? (args[1].value) : ''}}`;
console.log(args);
return `1Password => ${args[0]?.value ?? '--'}${args[1]?.value ? ` (${args[1].value})` : ''}`;
},
description: 'Fetch a secret from your 1Password vault',
args: [
Expand All @@ -37,6 +38,8 @@ const fetchSecretTemplateTag = {
async run(context: any, reference: string, account: string) {
const config = context.context[OP_PLUGIN_CONFIG_KEY] as PluginConfig | undefined;

console.log(context, reference, account);

if (config?.flags) {
setGlobalFlags(config.flags);
}
Expand Down Expand Up @@ -90,7 +93,7 @@ async function fetchEntry(ref: string, account: string) {

const args: Partial<GlobalFlags> = {};

if ( account ) {
if (account) {
args.account = account;
}

Expand Down

0 comments on commit 7214320

Please sign in to comment.