@enactprotocol/secrets 2.0.0 → 2.0.2
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/dist/dagger/index.d.ts +8 -0
- package/dist/dagger/index.d.ts.map +1 -0
- package/dist/dagger/index.js +8 -0
- package/dist/dagger/index.js.map +1 -0
- package/dist/dagger/secret-object.d.ts +49 -0
- package/dist/dagger/secret-object.d.ts.map +1 -0
- package/dist/dagger/secret-object.js +100 -0
- package/dist/dagger/secret-object.js.map +1 -0
- package/dist/dagger/uri-parser.d.ts +36 -0
- package/dist/dagger/uri-parser.d.ts.map +1 -0
- package/dist/dagger/uri-parser.js +179 -0
- package/dist/dagger/uri-parser.js.map +1 -0
- package/dist/env/index.d.ts +10 -0
- package/dist/env/index.d.ts.map +1 -0
- package/dist/env/index.js +14 -0
- package/dist/env/index.js.map +1 -0
- package/dist/env/manager.d.ts +87 -0
- package/dist/env/manager.d.ts.map +1 -0
- package/dist/env/manager.js +204 -0
- package/dist/env/manager.js.map +1 -0
- package/dist/env/parser.d.ts +58 -0
- package/dist/env/parser.d.ts.map +1 -0
- package/dist/env/parser.js +211 -0
- package/dist/env/parser.js.map +1 -0
- package/dist/env/reader.d.ts +61 -0
- package/dist/env/reader.d.ts.map +1 -0
- package/dist/env/reader.js +92 -0
- package/dist/env/reader.js.map +1 -0
- package/dist/env/writer.d.ts +68 -0
- package/dist/env/writer.d.ts.map +1 -0
- package/dist/env/writer.js +108 -0
- package/dist/env/writer.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/keyring.d.ts +77 -0
- package/dist/keyring.d.ts.map +1 -0
- package/dist/keyring.js +123 -0
- package/dist/keyring.js.map +1 -0
- package/dist/resolver.d.ts +65 -0
- package/dist/resolver.d.ts.map +1 -0
- package/dist/resolver.js +144 -0
- package/dist/resolver.js.map +1 -0
- package/dist/types.d.ts +162 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .env file writer
|
|
3
|
+
*
|
|
4
|
+
* Writes .env files while preserving comments and formatting
|
|
5
|
+
*/
|
|
6
|
+
import type { ParsedEnvFile } from "../types";
|
|
7
|
+
/**
|
|
8
|
+
* Write a parsed env file to disk
|
|
9
|
+
*
|
|
10
|
+
* @param path - Path to write to
|
|
11
|
+
* @param parsed - Parsed env file to write
|
|
12
|
+
*/
|
|
13
|
+
export declare function writeEnvFile(path: string, parsed: ParsedEnvFile): void;
|
|
14
|
+
/**
|
|
15
|
+
* Write a vars object to an .env file
|
|
16
|
+
*
|
|
17
|
+
* @param path - Path to write to
|
|
18
|
+
* @param vars - Key-value pairs to write
|
|
19
|
+
*/
|
|
20
|
+
export declare function writeEnvVars(path: string, vars: Record<string, string>): void;
|
|
21
|
+
/**
|
|
22
|
+
* Set an environment variable in a file
|
|
23
|
+
* Creates file if it doesn't exist, preserves existing content
|
|
24
|
+
*
|
|
25
|
+
* @param path - Path to the .env file
|
|
26
|
+
* @param key - Variable key
|
|
27
|
+
* @param value - Variable value
|
|
28
|
+
*/
|
|
29
|
+
export declare function setEnvVar(path: string, key: string, value: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* Delete an environment variable from a file
|
|
32
|
+
*
|
|
33
|
+
* @param path - Path to the .env file
|
|
34
|
+
* @param key - Variable key to delete
|
|
35
|
+
* @returns true if variable existed and was deleted
|
|
36
|
+
*/
|
|
37
|
+
export declare function deleteEnvVar(path: string, key: string): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Set a global environment variable (~/.enact/.env)
|
|
40
|
+
*
|
|
41
|
+
* @param key - Variable key
|
|
42
|
+
* @param value - Variable value
|
|
43
|
+
*/
|
|
44
|
+
export declare function setGlobalEnvVar(key: string, value: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* Set a local environment variable (.enact/.env)
|
|
47
|
+
*
|
|
48
|
+
* @param key - Variable key
|
|
49
|
+
* @param value - Variable value
|
|
50
|
+
* @param cwd - Current working directory (defaults to process.cwd())
|
|
51
|
+
*/
|
|
52
|
+
export declare function setLocalEnvVar(key: string, value: string, cwd?: string): void;
|
|
53
|
+
/**
|
|
54
|
+
* Delete a global environment variable
|
|
55
|
+
*
|
|
56
|
+
* @param key - Variable key to delete
|
|
57
|
+
* @returns true if variable existed and was deleted
|
|
58
|
+
*/
|
|
59
|
+
export declare function deleteGlobalEnvVar(key: string): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Delete a local environment variable
|
|
62
|
+
*
|
|
63
|
+
* @param key - Variable key to delete
|
|
64
|
+
* @param cwd - Current working directory (defaults to process.cwd())
|
|
65
|
+
* @returns true if variable existed and was deleted
|
|
66
|
+
*/
|
|
67
|
+
export declare function deleteLocalEnvVar(key: string, cwd?: string): boolean;
|
|
68
|
+
//# sourceMappingURL=writer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writer.d.ts","sourceRoot":"","sources":["../../src/env/writer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAc9C;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,GAAG,IAAI,CAItE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAI7E;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAIxE;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAQ/D;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAEhE;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAE7E;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAEpE"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .env file writer
|
|
3
|
+
*
|
|
4
|
+
* Writes .env files while preserving comments and formatting
|
|
5
|
+
*/
|
|
6
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { dirname } from "node:path";
|
|
8
|
+
import { createEnvContent, removeEnvVar, serializeEnvFile, updateEnvVar } from "./parser";
|
|
9
|
+
import { getGlobalEnvPath, getLocalEnvPath, readEnvFile } from "./reader";
|
|
10
|
+
/**
|
|
11
|
+
* Ensure directory exists for a file path
|
|
12
|
+
*/
|
|
13
|
+
function ensureDirectory(filePath) {
|
|
14
|
+
const dir = dirname(filePath);
|
|
15
|
+
if (!existsSync(dir)) {
|
|
16
|
+
mkdirSync(dir, { recursive: true });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Write a parsed env file to disk
|
|
21
|
+
*
|
|
22
|
+
* @param path - Path to write to
|
|
23
|
+
* @param parsed - Parsed env file to write
|
|
24
|
+
*/
|
|
25
|
+
export function writeEnvFile(path, parsed) {
|
|
26
|
+
ensureDirectory(path);
|
|
27
|
+
const content = serializeEnvFile(parsed);
|
|
28
|
+
writeFileSync(path, content, "utf-8");
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Write a vars object to an .env file
|
|
32
|
+
*
|
|
33
|
+
* @param path - Path to write to
|
|
34
|
+
* @param vars - Key-value pairs to write
|
|
35
|
+
*/
|
|
36
|
+
export function writeEnvVars(path, vars) {
|
|
37
|
+
ensureDirectory(path);
|
|
38
|
+
const content = createEnvContent(vars);
|
|
39
|
+
writeFileSync(path, content, "utf-8");
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Set an environment variable in a file
|
|
43
|
+
* Creates file if it doesn't exist, preserves existing content
|
|
44
|
+
*
|
|
45
|
+
* @param path - Path to the .env file
|
|
46
|
+
* @param key - Variable key
|
|
47
|
+
* @param value - Variable value
|
|
48
|
+
*/
|
|
49
|
+
export function setEnvVar(path, key, value) {
|
|
50
|
+
const parsed = readEnvFile(path);
|
|
51
|
+
const updated = updateEnvVar(parsed, key, value);
|
|
52
|
+
writeEnvFile(path, updated);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Delete an environment variable from a file
|
|
56
|
+
*
|
|
57
|
+
* @param path - Path to the .env file
|
|
58
|
+
* @param key - Variable key to delete
|
|
59
|
+
* @returns true if variable existed and was deleted
|
|
60
|
+
*/
|
|
61
|
+
export function deleteEnvVar(path, key) {
|
|
62
|
+
const parsed = readEnvFile(path);
|
|
63
|
+
if (!(key in parsed.vars)) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
const updated = removeEnvVar(parsed, key);
|
|
67
|
+
writeEnvFile(path, updated);
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Set a global environment variable (~/.enact/.env)
|
|
72
|
+
*
|
|
73
|
+
* @param key - Variable key
|
|
74
|
+
* @param value - Variable value
|
|
75
|
+
*/
|
|
76
|
+
export function setGlobalEnvVar(key, value) {
|
|
77
|
+
setEnvVar(getGlobalEnvPath(), key, value);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Set a local environment variable (.enact/.env)
|
|
81
|
+
*
|
|
82
|
+
* @param key - Variable key
|
|
83
|
+
* @param value - Variable value
|
|
84
|
+
* @param cwd - Current working directory (defaults to process.cwd())
|
|
85
|
+
*/
|
|
86
|
+
export function setLocalEnvVar(key, value, cwd) {
|
|
87
|
+
setEnvVar(getLocalEnvPath(cwd), key, value);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Delete a global environment variable
|
|
91
|
+
*
|
|
92
|
+
* @param key - Variable key to delete
|
|
93
|
+
* @returns true if variable existed and was deleted
|
|
94
|
+
*/
|
|
95
|
+
export function deleteGlobalEnvVar(key) {
|
|
96
|
+
return deleteEnvVar(getGlobalEnvPath(), key);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Delete a local environment variable
|
|
100
|
+
*
|
|
101
|
+
* @param key - Variable key to delete
|
|
102
|
+
* @param cwd - Current working directory (defaults to process.cwd())
|
|
103
|
+
* @returns true if variable existed and was deleted
|
|
104
|
+
*/
|
|
105
|
+
export function deleteLocalEnvVar(key, cwd) {
|
|
106
|
+
return deleteEnvVar(getLocalEnvPath(cwd), key);
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=writer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writer.js","sourceRoot":"","sources":["../../src/env/writer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC1F,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE1E;;GAEG;AACH,SAAS,eAAe,CAAC,QAAgB;IAC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AAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC5B,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,GAAW,EAAE,KAAa;IACxD,SAAS,CAAC,gBAAgB,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAC5C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,KAAa,EAAE,GAAY;IACrE,SAAS,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAC9C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAW;IAC5C,OAAO,YAAY,CAAC,gBAAgB,EAAE,EAAE,GAAG,CAAC,CAAC;AAC/C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,GAAW,EAAE,GAAY;IACzD,OAAO,YAAY,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;AACjD,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @enactprotocol/secrets
|
|
3
|
+
*
|
|
4
|
+
* OS keyring integration and environment variable management for Enact.
|
|
5
|
+
* Provides secure secret storage using platform-native keychains.
|
|
6
|
+
*/
|
|
7
|
+
export declare const version = "0.1.0";
|
|
8
|
+
export type { SecretResolution, SecretNotFound, SecretResolutionResult, SecretMetadata, SecretTrace, SecretTraceEntry, EnvScope, EnvFileLocation, EnvironmentVariable, EnvResolution, ParsedEnvFile, EnvFileLine, DaggerSecretScheme, DaggerSecretUri, GetSecretOptions, SecretObject, } from "./types";
|
|
9
|
+
export { KEYRING_SERVICE } from "./types";
|
|
10
|
+
export { buildAccount, parseAccount, setSecret, getSecret, deleteSecret, listSecrets, listAllSecrets, secretExists, isKeyringAvailable, } from "./keyring";
|
|
11
|
+
export { getNamespaceChain, resolveSecret, traceSecretResolution, resolveSecrets, checkRequiredSecrets, } from "./resolver";
|
|
12
|
+
export { parseEnvFile, parseEnvContent, serializeEnvFile, createEnvContent, updateEnvVar, removeEnvVar, getGlobalEnvPath, getLocalEnvPath, readEnvFile, readEnvVars, loadGlobalEnv, loadLocalEnv, loadGlobalEnvFile, loadLocalEnvFile, globalEnvExists, localEnvExists, writeEnvFile, writeEnvVars, setEnvVar, deleteEnvVar, setGlobalEnvVar, setLocalEnvVar, deleteGlobalEnvVar, deleteLocalEnvVar, setEnv, getEnv, getEnvValue, deleteEnv, listEnv, resolveAllEnv, resolveToolEnv, hasLocalEnv, hasGlobalEnv, } from "./env";
|
|
13
|
+
export { parseSecretUri, resolveSecretUri, isSecretUri, getSupportedSchemes, getSecretObject, getSecretObjects, parseSecretOverride, parseSecretOverrides, } from "./dagger";
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,UAAU,CAAC;AAM/B,YAAY,EACV,gBAAgB,EAChB,cAAc,EACd,sBAAsB,EACtB,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,QAAQ,EACR,eAAe,EACf,mBAAmB,EACnB,aAAa,EACb,aAAa,EACb,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,YAAY,GACb,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAM1C,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,SAAS,EACT,YAAY,EACZ,WAAW,EACX,cAAc,EACd,YAAY,EACZ,kBAAkB,GACnB,MAAM,WAAW,CAAC;AAMnB,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,qBAAqB,EACrB,cAAc,EACd,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAMpB,OAAO,EAEL,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,YAAY,EAEZ,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,WAAW,EACX,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,cAAc,EAEd,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,iBAAiB,EAEjB,MAAM,EACN,MAAM,EACN,WAAW,EACX,SAAS,EACT,OAAO,EACP,aAAa,EACb,cAAc,EACd,WAAW,EACX,YAAY,GACb,MAAM,OAAO,CAAC;AAMf,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @enactprotocol/secrets
|
|
3
|
+
*
|
|
4
|
+
* OS keyring integration and environment variable management for Enact.
|
|
5
|
+
* Provides secure secret storage using platform-native keychains.
|
|
6
|
+
*/
|
|
7
|
+
export const version = "0.1.0";
|
|
8
|
+
export { KEYRING_SERVICE } from "./types";
|
|
9
|
+
// ============================================================================
|
|
10
|
+
// Keyring Functions
|
|
11
|
+
// ============================================================================
|
|
12
|
+
export { buildAccount, parseAccount, setSecret, getSecret, deleteSecret, listSecrets, listAllSecrets, secretExists, isKeyringAvailable, } from "./keyring";
|
|
13
|
+
// ============================================================================
|
|
14
|
+
// Secret Resolution
|
|
15
|
+
// ============================================================================
|
|
16
|
+
export { getNamespaceChain, resolveSecret, traceSecretResolution, resolveSecrets, checkRequiredSecrets, } from "./resolver";
|
|
17
|
+
// ============================================================================
|
|
18
|
+
// Environment Variables
|
|
19
|
+
// ============================================================================
|
|
20
|
+
export {
|
|
21
|
+
// Parser
|
|
22
|
+
parseEnvFile, parseEnvContent, serializeEnvFile, createEnvContent, updateEnvVar, removeEnvVar,
|
|
23
|
+
// Reader
|
|
24
|
+
getGlobalEnvPath, getLocalEnvPath, readEnvFile, readEnvVars, loadGlobalEnv, loadLocalEnv, loadGlobalEnvFile, loadLocalEnvFile, globalEnvExists, localEnvExists,
|
|
25
|
+
// Writer
|
|
26
|
+
writeEnvFile, writeEnvVars, setEnvVar, deleteEnvVar, setGlobalEnvVar, setLocalEnvVar, deleteGlobalEnvVar, deleteLocalEnvVar,
|
|
27
|
+
// Manager (high-level API)
|
|
28
|
+
setEnv, getEnv, getEnvValue, deleteEnv, listEnv, resolveAllEnv, resolveToolEnv, hasLocalEnv, hasGlobalEnv, } from "./env";
|
|
29
|
+
// ============================================================================
|
|
30
|
+
// Dagger Secret Integration
|
|
31
|
+
// ============================================================================
|
|
32
|
+
export { parseSecretUri, resolveSecretUri, isSecretUri, getSupportedSchemes, getSecretObject, getSecretObjects, parseSecretOverride, parseSecretOverrides, } from "./dagger";
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC;AAyB/B,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,+EAA+E;AAC/E,oBAAoB;AACpB,+EAA+E;AAE/E,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,SAAS,EACT,YAAY,EACZ,WAAW,EACX,cAAc,EACd,YAAY,EACZ,kBAAkB,GACnB,MAAM,WAAW,CAAC;AAEnB,+EAA+E;AAC/E,oBAAoB;AACpB,+EAA+E;AAE/E,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,qBAAqB,EACrB,cAAc,EACd,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAEpB,+EAA+E;AAC/E,wBAAwB;AACxB,+EAA+E;AAE/E,OAAO;AACL,SAAS;AACT,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,YAAY;AACZ,SAAS;AACT,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,WAAW,EACX,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,cAAc;AACd,SAAS;AACT,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,iBAAiB;AACjB,2BAA2B;AAC3B,MAAM,EACN,MAAM,EACN,WAAW,EACX,SAAS,EACT,OAAO,EACP,aAAa,EACb,cAAc,EACd,WAAW,EACX,YAAY,GACb,MAAM,OAAO,CAAC;AAEf,+EAA+E;AAC/E,4BAA4B;AAC5B,+EAA+E;AAE/E,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OS Keyring integration for secure secret storage
|
|
3
|
+
*
|
|
4
|
+
* Uses the system keychain:
|
|
5
|
+
* - macOS: Keychain
|
|
6
|
+
* - Windows: Credential Manager
|
|
7
|
+
* - Linux: Secret Service (libsecret)
|
|
8
|
+
*
|
|
9
|
+
* All secrets are stored with:
|
|
10
|
+
* - Service: "enact-cli"
|
|
11
|
+
* - Account: "{namespace}:{SECRET_NAME}"
|
|
12
|
+
*/
|
|
13
|
+
import { type SecretMetadata } from "./types";
|
|
14
|
+
/**
|
|
15
|
+
* Build the account string for keyring storage
|
|
16
|
+
* Format: "namespace:SECRET_NAME"
|
|
17
|
+
*/
|
|
18
|
+
export declare function buildAccount(namespace: string, secretName: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Parse an account string back to namespace and secret name
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseAccount(account: string): {
|
|
23
|
+
namespace: string;
|
|
24
|
+
secretName: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Store a secret in the OS keyring
|
|
28
|
+
*
|
|
29
|
+
* @param namespace - The namespace for the secret (e.g., "alice/api")
|
|
30
|
+
* @param name - The secret name (e.g., "API_TOKEN")
|
|
31
|
+
* @param value - The secret value to store
|
|
32
|
+
*/
|
|
33
|
+
export declare function setSecret(namespace: string, name: string, value: string): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Retrieve a secret from the OS keyring
|
|
36
|
+
*
|
|
37
|
+
* @param namespace - The namespace for the secret
|
|
38
|
+
* @param name - The secret name
|
|
39
|
+
* @returns The secret value, or null if not found
|
|
40
|
+
*/
|
|
41
|
+
export declare function getSecret(namespace: string, name: string): Promise<string | null>;
|
|
42
|
+
/**
|
|
43
|
+
* Delete a secret from the OS keyring
|
|
44
|
+
*
|
|
45
|
+
* @param namespace - The namespace for the secret
|
|
46
|
+
* @param name - The secret name
|
|
47
|
+
* @returns true if deleted, false if not found
|
|
48
|
+
*/
|
|
49
|
+
export declare function deleteSecret(namespace: string, name: string): Promise<boolean>;
|
|
50
|
+
/**
|
|
51
|
+
* List all secrets for a namespace
|
|
52
|
+
*
|
|
53
|
+
* @param namespace - The namespace to list secrets for
|
|
54
|
+
* @returns Array of secret names in the namespace
|
|
55
|
+
*/
|
|
56
|
+
export declare function listSecrets(namespace: string): Promise<string[]>;
|
|
57
|
+
/**
|
|
58
|
+
* List all secrets across all namespaces
|
|
59
|
+
*
|
|
60
|
+
* @returns Array of secret metadata
|
|
61
|
+
*/
|
|
62
|
+
export declare function listAllSecrets(): Promise<SecretMetadata[]>;
|
|
63
|
+
/**
|
|
64
|
+
* Check if a secret exists in the keyring
|
|
65
|
+
*
|
|
66
|
+
* @param namespace - The namespace for the secret
|
|
67
|
+
* @param name - The secret name
|
|
68
|
+
* @returns true if the secret exists
|
|
69
|
+
*/
|
|
70
|
+
export declare function secretExists(namespace: string, name: string): Promise<boolean>;
|
|
71
|
+
/**
|
|
72
|
+
* Check if the keyring is available on this system
|
|
73
|
+
*
|
|
74
|
+
* @returns true if keyring operations are available
|
|
75
|
+
*/
|
|
76
|
+
export declare function isKeyringAvailable(): Promise<boolean>;
|
|
77
|
+
//# sourceMappingURL=keyring.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyring.d.ts","sourceRoot":"","sources":["../src/keyring.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAmB,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAE/D;;;GAGG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAE1E;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG;IAC7C,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,CASA;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG7F;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAIvF;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAGpF;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAOtE;AAED;;;;GAIG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC,CAUhE;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAGpF;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC,CAQ3D"}
|
package/dist/keyring.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OS Keyring integration for secure secret storage
|
|
3
|
+
*
|
|
4
|
+
* Uses the system keychain:
|
|
5
|
+
* - macOS: Keychain
|
|
6
|
+
* - Windows: Credential Manager
|
|
7
|
+
* - Linux: Secret Service (libsecret)
|
|
8
|
+
*
|
|
9
|
+
* All secrets are stored with:
|
|
10
|
+
* - Service: "enact-cli"
|
|
11
|
+
* - Account: "{namespace}:{SECRET_NAME}"
|
|
12
|
+
*/
|
|
13
|
+
import { keyring } from "@zowe/secrets-for-zowe-sdk";
|
|
14
|
+
import { KEYRING_SERVICE } from "./types";
|
|
15
|
+
/**
|
|
16
|
+
* Build the account string for keyring storage
|
|
17
|
+
* Format: "namespace:SECRET_NAME"
|
|
18
|
+
*/
|
|
19
|
+
export function buildAccount(namespace, secretName) {
|
|
20
|
+
return `${namespace}:${secretName}`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Parse an account string back to namespace and secret name
|
|
24
|
+
*/
|
|
25
|
+
export function parseAccount(account) {
|
|
26
|
+
const colonIndex = account.lastIndexOf(":");
|
|
27
|
+
if (colonIndex === -1) {
|
|
28
|
+
throw new Error(`Invalid account format: ${account}`);
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
namespace: account.slice(0, colonIndex),
|
|
32
|
+
secretName: account.slice(colonIndex + 1),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Store a secret in the OS keyring
|
|
37
|
+
*
|
|
38
|
+
* @param namespace - The namespace for the secret (e.g., "alice/api")
|
|
39
|
+
* @param name - The secret name (e.g., "API_TOKEN")
|
|
40
|
+
* @param value - The secret value to store
|
|
41
|
+
*/
|
|
42
|
+
export async function setSecret(namespace, name, value) {
|
|
43
|
+
const account = buildAccount(namespace, name);
|
|
44
|
+
await keyring.setPassword(KEYRING_SERVICE, account, value);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Retrieve a secret from the OS keyring
|
|
48
|
+
*
|
|
49
|
+
* @param namespace - The namespace for the secret
|
|
50
|
+
* @param name - The secret name
|
|
51
|
+
* @returns The secret value, or null if not found
|
|
52
|
+
*/
|
|
53
|
+
export async function getSecret(namespace, name) {
|
|
54
|
+
const account = buildAccount(namespace, name);
|
|
55
|
+
const value = await keyring.getPassword(KEYRING_SERVICE, account);
|
|
56
|
+
return value ?? null;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Delete a secret from the OS keyring
|
|
60
|
+
*
|
|
61
|
+
* @param namespace - The namespace for the secret
|
|
62
|
+
* @param name - The secret name
|
|
63
|
+
* @returns true if deleted, false if not found
|
|
64
|
+
*/
|
|
65
|
+
export async function deleteSecret(namespace, name) {
|
|
66
|
+
const account = buildAccount(namespace, name);
|
|
67
|
+
return await keyring.deletePassword(KEYRING_SERVICE, account);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* List all secrets for a namespace
|
|
71
|
+
*
|
|
72
|
+
* @param namespace - The namespace to list secrets for
|
|
73
|
+
* @returns Array of secret names in the namespace
|
|
74
|
+
*/
|
|
75
|
+
export async function listSecrets(namespace) {
|
|
76
|
+
const credentials = await keyring.findCredentials(KEYRING_SERVICE);
|
|
77
|
+
const prefix = `${namespace}:`;
|
|
78
|
+
return credentials
|
|
79
|
+
.filter((cred) => cred.account.startsWith(prefix))
|
|
80
|
+
.map((cred) => cred.account.slice(prefix.length));
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* List all secrets across all namespaces
|
|
84
|
+
*
|
|
85
|
+
* @returns Array of secret metadata
|
|
86
|
+
*/
|
|
87
|
+
export async function listAllSecrets() {
|
|
88
|
+
const credentials = await keyring.findCredentials(KEYRING_SERVICE);
|
|
89
|
+
return credentials.map((cred) => {
|
|
90
|
+
const { namespace, secretName } = parseAccount(cred.account);
|
|
91
|
+
return {
|
|
92
|
+
key: secretName,
|
|
93
|
+
namespace,
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Check if a secret exists in the keyring
|
|
99
|
+
*
|
|
100
|
+
* @param namespace - The namespace for the secret
|
|
101
|
+
* @param name - The secret name
|
|
102
|
+
* @returns true if the secret exists
|
|
103
|
+
*/
|
|
104
|
+
export async function secretExists(namespace, name) {
|
|
105
|
+
const value = await getSecret(namespace, name);
|
|
106
|
+
return value !== null;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Check if the keyring is available on this system
|
|
110
|
+
*
|
|
111
|
+
* @returns true if keyring operations are available
|
|
112
|
+
*/
|
|
113
|
+
export async function isKeyringAvailable() {
|
|
114
|
+
try {
|
|
115
|
+
// Try to list credentials - this will fail if keyring is not available
|
|
116
|
+
await keyring.findCredentials(KEYRING_SERVICE);
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=keyring.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyring.js","sourceRoot":"","sources":["../src/keyring.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,eAAe,EAAuB,MAAM,SAAS,CAAC;AAE/D;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,SAAiB,EAAE,UAAkB;IAChE,OAAO,GAAG,SAAS,IAAI,UAAU,EAAE,CAAC;AACtC,CAAC;AAED;;G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ritance
|
|
3
|
+
*
|
|
4
|
+
* When a tool requests a secret, we walk up the namespace path:
|
|
5
|
+
* Tool: alice/api/slack/notifier
|
|
6
|
+
* Needs: API_TOKEN
|
|
7
|
+
*
|
|
8
|
+
* Lookup:
|
|
9
|
+
* 1. alice/api/slack:API_TOKEN
|
|
10
|
+
* 2. alice/api:API_TOKEN ✓ found
|
|
11
|
+
* 3. alice:API_TOKEN
|
|
12
|
+
*
|
|
13
|
+
* First match wins.
|
|
14
|
+
*/
|
|
15
|
+
import type { SecretResolution, SecretResolutionResult, SecretTrace } from "./types";
|
|
16
|
+
/**
|
|
17
|
+
* Get the namespace chain for a tool path
|
|
18
|
+
* Walks up the path segments from most specific to least specific
|
|
19
|
+
*
|
|
20
|
+
* @param toolPath - The full tool path (e.g., "alice/api/slack")
|
|
21
|
+
* @returns Array of namespaces to check in order
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* getNamespaceChain("alice/api/slack")
|
|
25
|
+
* // Returns: ["alice/api/slack", "alice/api", "alice"]
|
|
26
|
+
*/
|
|
27
|
+
export declare function getNamespaceChain(toolPath: string): string[];
|
|
28
|
+
/**
|
|
29
|
+
* Resolve a secret using namespace inheritance
|
|
30
|
+
*
|
|
31
|
+
* @param toolPath - The tool path to resolve secrets for
|
|
32
|
+
* @param secretName - The secret name to find
|
|
33
|
+
* @returns Resolution result with namespace info, or not-found result
|
|
34
|
+
*/
|
|
35
|
+
export declare function resolveSecret(toolPath: string, secretName: string): Promise<SecretResolutionResult>;
|
|
36
|
+
/**
|
|
37
|
+
* Trace secret resolution for debugging
|
|
38
|
+
* Shows which namespaces were checked and where the secret was found
|
|
39
|
+
*
|
|
40
|
+
* @param toolPath - The tool path to resolve secrets for
|
|
41
|
+
* @param secretName - The secret name to find
|
|
42
|
+
* @returns Full trace with all namespaces checked
|
|
43
|
+
*/
|
|
44
|
+
export declare function traceSecretResolution(toolPath: string, secretName: string): Promise<SecretTrace>;
|
|
45
|
+
/**
|
|
46
|
+
* Resolve multiple secrets for a tool
|
|
47
|
+
*
|
|
48
|
+
* @param toolPath - The tool path to resolve secrets for
|
|
49
|
+
* @param secretNames - Array of secret names to resolve
|
|
50
|
+
* @returns Map of secret name to resolution result
|
|
51
|
+
*/
|
|
52
|
+
export declare function resolveSecrets(toolPath: string, secretNames: string[]): Promise<Map<string, SecretResolutionResult>>;
|
|
53
|
+
/**
|
|
54
|
+
* Check if all required secrets are available for a tool
|
|
55
|
+
*
|
|
56
|
+
* @param toolPath - The tool path to check
|
|
57
|
+
* @param requiredSecrets - Array of required secret names
|
|
58
|
+
* @returns Object with available and missing secrets
|
|
59
|
+
*/
|
|
60
|
+
export declare function checkRequiredSecrets(toolPath: string, requiredSecrets: string[]): Promise<{
|
|
61
|
+
allFound: boolean;
|
|
62
|
+
found: SecretResolution[];
|
|
63
|
+
missing: string[];
|
|
64
|
+
}>;
|
|
65
|
+
//# sourceMappingURL=resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../src/resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,KAAK,EACV,gBAAgB,EAChB,sBAAsB,EACtB,WAAW,EAEZ,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAS5D;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,sBAAsB,CAAC,CAuBjC;AAED;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CACzC,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,WAAW,CAAC,CAqCtB;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAClC,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EAAE,GACpB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC,CAS9C;AAED;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,MAAM,EAChB,eAAe,EAAE,MAAM,EAAE,GACxB,OAAO,CAAC;IACT,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC1B,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB,CAAC,CAkBD"}
|
package/dist/resolver.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Secret resolution with namespace inheritance
|
|
3
|
+
*
|
|
4
|
+
* When a tool requests a secret, we walk up the namespace path:
|
|
5
|
+
* Tool: alice/api/slack/notifier
|
|
6
|
+
* Needs: API_TOKEN
|
|
7
|
+
*
|
|
8
|
+
* Lookup:
|
|
9
|
+
* 1. alice/api/slack:API_TOKEN
|
|
10
|
+
* 2. alice/api:API_TOKEN ✓ found
|
|
11
|
+
* 3. alice:API_TOKEN
|
|
12
|
+
*
|
|
13
|
+
* First match wins.
|
|
14
|
+
*/
|
|
15
|
+
import { getSecret } from "./keyring";
|
|
16
|
+
/**
|
|
17
|
+
* Get the namespace chain for a tool path
|
|
18
|
+
* Walks up the path segments from most specific to least specific
|
|
19
|
+
*
|
|
20
|
+
* @param toolPath - The full tool path (e.g., "alice/api/slack")
|
|
21
|
+
* @returns Array of namespaces to check in order
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* getNamespaceChain("alice/api/slack")
|
|
25
|
+
* // Returns: ["alice/api/slack", "alice/api", "alice"]
|
|
26
|
+
*/
|
|
27
|
+
export function getNamespaceChain(toolPath) {
|
|
28
|
+
const segments = toolPath.split("/").filter(Boolean);
|
|
29
|
+
const chain = [];
|
|
30
|
+
for (let i = segments.length; i > 0; i--) {
|
|
31
|
+
chain.push(segments.slice(0, i).join("/"));
|
|
32
|
+
}
|
|
33
|
+
return chain;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Resolve a secret using namespace inheritance
|
|
37
|
+
*
|
|
38
|
+
* @param toolPath - The tool path to resolve secrets for
|
|
39
|
+
* @param secretName - The secret name to find
|
|
40
|
+
* @returns Resolution result with namespace info, or not-found result
|
|
41
|
+
*/
|
|
42
|
+
export async function resolveSecret(toolPath, secretName) {
|
|
43
|
+
const namespaces = getNamespaceChain(toolPath);
|
|
44
|
+
const searchedNamespaces = [];
|
|
45
|
+
for (const namespace of namespaces) {
|
|
46
|
+
searchedNamespaces.push(namespace);
|
|
47
|
+
const value = await getSecret(namespace, secretName);
|
|
48
|
+
if (value !== null) {
|
|
49
|
+
return {
|
|
50
|
+
namespace,
|
|
51
|
+
value,
|
|
52
|
+
key: secretName,
|
|
53
|
+
found: true,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
key: secretName,
|
|
59
|
+
found: false,
|
|
60
|
+
searchedNamespaces,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Trace secret resolution for debugging
|
|
65
|
+
* Shows which namespaces were checked and where the secret was found
|
|
66
|
+
*
|
|
67
|
+
* @param toolPath - The tool path to resolve secrets for
|
|
68
|
+
* @param secretName - The secret name to find
|
|
69
|
+
* @returns Full trace with all namespaces checked
|
|
70
|
+
*/
|
|
71
|
+
export async function traceSecretResolution(toolPath, secretName) {
|
|
72
|
+
const namespaces = getNamespaceChain(toolPath);
|
|
73
|
+
const entries = [];
|
|
74
|
+
let result = null;
|
|
75
|
+
for (const namespace of namespaces) {
|
|
76
|
+
const account = `${namespace}:${secretName}`;
|
|
77
|
+
const value = await getSecret(namespace, secretName);
|
|
78
|
+
const found = value !== null;
|
|
79
|
+
entries.push({ namespace, account, found });
|
|
80
|
+
if (found && !result) {
|
|
81
|
+
result = {
|
|
82
|
+
namespace,
|
|
83
|
+
value,
|
|
84
|
+
key: secretName,
|
|
85
|
+
found: true,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// If not found anywhere
|
|
90
|
+
if (!result) {
|
|
91
|
+
result = {
|
|
92
|
+
key: secretName,
|
|
93
|
+
found: false,
|
|
94
|
+
searchedNamespaces: namespaces,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
key: secretName,
|
|
99
|
+
toolPath,
|
|
100
|
+
entries,
|
|
101
|
+
result,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Resolve multiple secrets for a tool
|
|
106
|
+
*
|
|
107
|
+
* @param toolPath - The tool path to resolve secrets for
|
|
108
|
+
* @param secretNames - Array of secret names to resolve
|
|
109
|
+
* @returns Map of secret name to resolution result
|
|
110
|
+
*/
|
|
111
|
+
export async function resolveSecrets(toolPath, secretNames) {
|
|
112
|
+
const results = new Map();
|
|
113
|
+
for (const name of secretNames) {
|
|
114
|
+
const result = await resolveSecret(toolPath, name);
|
|
115
|
+
results.set(name, result);
|
|
116
|
+
}
|
|
117
|
+
return results;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Check if all required secrets are available for a tool
|
|
121
|
+
*
|
|
122
|
+
* @param toolPath - The tool path to check
|
|
123
|
+
* @param requiredSecrets - Array of required secret names
|
|
124
|
+
* @returns Object with available and missing secrets
|
|
125
|
+
*/
|
|
126
|
+
export async function checkRequiredSecrets(toolPath, requiredSecrets) {
|
|
127
|
+
const found = [];
|
|
128
|
+
const missing = [];
|
|
129
|
+
for (const name of requiredSecrets) {
|
|
130
|
+
const result = await resolveSecret(toolPath, name);
|
|
131
|
+
if (result.found) {
|
|
132
|
+
found.push(result);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
missing.push(name);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
allFound: missing.length === 0,
|
|
140
|
+
found,
|
|
141
|
+
missing,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=resolver.js.map
|