@kustodian/plugin-1password 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/resolver.ts +31 -1
- package/src/types.ts +27 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kustodian/plugin-1password",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "1Password secret provider plugin for Kustodian",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
"registry": "https://npm.pkg.github.com"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@kustodian/core": "
|
|
41
|
-
"@kustodian/plugins": "
|
|
42
|
-
"@kustodian/schema": "
|
|
40
|
+
"@kustodian/core": "1.1.0",
|
|
41
|
+
"@kustodian/plugins": "1.0.1",
|
|
42
|
+
"@kustodian/schema": "1.3.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {}
|
|
45
45
|
}
|
package/src/resolver.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { OnePasswordPluginOptionsType } from './types.js';
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Resolves 1Password substitutions to actual secret values.
|
|
10
|
+
* Supports both full references and shorthand with cluster defaults.
|
|
10
11
|
* Returns a map from substitution name to resolved value.
|
|
11
12
|
*/
|
|
12
13
|
export async function resolve_onepassword_substitutions(
|
|
@@ -20,7 +21,36 @@ export async function resolve_onepassword_substitutions(
|
|
|
20
21
|
const results: Record<string, string> = {};
|
|
21
22
|
|
|
22
23
|
for (const sub of substitutions) {
|
|
23
|
-
|
|
24
|
+
// Build the reference string
|
|
25
|
+
let ref: string;
|
|
26
|
+
|
|
27
|
+
if (sub.ref) {
|
|
28
|
+
// Full reference provided
|
|
29
|
+
ref = sub.ref;
|
|
30
|
+
} else if (sub.item && sub.field) {
|
|
31
|
+
// Shorthand reference - need cluster vault
|
|
32
|
+
const vault = options.cluster_defaults?.vault;
|
|
33
|
+
if (!vault) {
|
|
34
|
+
return failure({
|
|
35
|
+
code: 'MISSING_1PASSWORD_VAULT',
|
|
36
|
+
message: `1Password substitution '${sub.name}' uses shorthand but no cluster vault configured`,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Build op:// reference
|
|
41
|
+
if (sub.section) {
|
|
42
|
+
ref = `op://${vault}/${sub.item}/${sub.section}/${sub.field}`;
|
|
43
|
+
} else {
|
|
44
|
+
ref = `op://${vault}/${sub.item}/${sub.field}`;
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
return failure({
|
|
48
|
+
code: 'INVALID_1PASSWORD_REFERENCE',
|
|
49
|
+
message: `1Password substitution '${sub.name}' must specify either 'ref' or 'item'+'field'`,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const result = await op_read(ref, options);
|
|
24
54
|
|
|
25
55
|
if (!result.success) {
|
|
26
56
|
// If we have a default and fail_on_missing is false, use the default
|
package/src/types.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cluster-level 1Password defaults.
|
|
3
|
+
*/
|
|
4
|
+
export interface OnePasswordClusterDefaultsType {
|
|
5
|
+
/** Default vault name or ID */
|
|
6
|
+
vault?: string | undefined;
|
|
7
|
+
}
|
|
8
|
+
|
|
1
9
|
/**
|
|
2
10
|
* Options for the 1Password plugin.
|
|
3
11
|
*/
|
|
@@ -8,6 +16,8 @@ export interface OnePasswordPluginOptionsType {
|
|
|
8
16
|
timeout?: number | undefined;
|
|
9
17
|
/** Whether to fail on missing secrets (default: true) */
|
|
10
18
|
fail_on_missing?: boolean | undefined;
|
|
19
|
+
/** Cluster-level defaults for vault */
|
|
20
|
+
cluster_defaults?: OnePasswordClusterDefaultsType | undefined;
|
|
11
21
|
}
|
|
12
22
|
|
|
13
23
|
/**
|
|
@@ -37,20 +47,31 @@ export function parse_onepassword_ref(ref: string): OnePasswordRefType | undefin
|
|
|
37
47
|
return undefined;
|
|
38
48
|
}
|
|
39
49
|
|
|
40
|
-
const
|
|
50
|
+
const vault = match[1];
|
|
51
|
+
const item = match[2];
|
|
52
|
+
const section = match[3];
|
|
53
|
+
const field = match[4];
|
|
41
54
|
|
|
42
55
|
// If section is undefined, the field is in position 3
|
|
43
56
|
if (field === undefined) {
|
|
57
|
+
// When there's no section, match[3] contains the field
|
|
58
|
+
if (!vault || !item || !section) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
44
61
|
return {
|
|
45
|
-
vault
|
|
46
|
-
item
|
|
47
|
-
field: section
|
|
62
|
+
vault,
|
|
63
|
+
item,
|
|
64
|
+
field: section,
|
|
48
65
|
};
|
|
49
66
|
}
|
|
50
67
|
|
|
68
|
+
if (!vault || !item || !field) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
51
72
|
return {
|
|
52
|
-
vault
|
|
53
|
-
item
|
|
73
|
+
vault,
|
|
74
|
+
item,
|
|
54
75
|
section,
|
|
55
76
|
field,
|
|
56
77
|
};
|