perf(http,auth): persist EASO, Unity, and Piper tokens across CLI invocations via token-store
This commit is contained in:
1 parent
76f7832522
commit
2d744d283b
5 files changed
+248
-32
No files matched your search
@@ -12,7 +12,11 @@ export const PRIMARY_TOKEN_CACHE_PATH = join(
|
||||
|
||||
export const TOKEN_CACHE_PATH = PRIMARY_TOKEN_CACHE_PATH;
|
||||
|
||||
function resolveTokenCachePath(): string {
|
||||
export function resolveTokenCachePath(): string {
|
||||
const envFile = process.env.HOSE_TOKENS_FILE?.trim();
|
||||
if (envFile) return envFile;
|
||||
const stateDir = process.env.HOSE_STATE_DIR?.trim();
|
||||
if (stateDir) return join(stateDir, "tokens.json");
|
||||
return PRIMARY_TOKEN_CACHE_PATH;
|
||||
}
|
||||
|
||||
@@ -28,9 +32,15 @@ function ensureDir(path: string): void {
|
||||
|
||||
let memoryTokenCache: TokenStore | null = null;
|
||||
let lastMtimeMs = 0;
|
||||
let lastResolvedPath = "";
|
||||
|
||||
export function loadTokenStore(): TokenStore {
|
||||
const filePath = resolveTokenCachePath();
|
||||
if (filePath !== lastResolvedPath) {
|
||||
memoryTokenCache = null;
|
||||
lastMtimeMs = 0;
|
||||
lastResolvedPath = filePath;
|
||||
}
|
||||
|
||||
if (existsSync(filePath)) {
|
||||
try {
|
||||
@@ -53,8 +63,9 @@ export function loadTokenStore(): TokenStore {
|
||||
}
|
||||
|
||||
export function saveTokenStore(store: TokenStore): void {
|
||||
const targetPath = resolveTokenCachePath();
|
||||
memoryTokenCache = store;
|
||||
const targetPath = PRIMARY_TOKEN_CACHE_PATH;
|
||||
lastResolvedPath = targetPath;
|
||||
ensureDir(targetPath);
|
||||
|
||||
// MAJ-03: 强制写入 0o600 保护敏感凭证
|
||||
|
||||
@@ -11,11 +11,18 @@ export const CorpTokensSchema = z.object({
|
||||
unityJwt: z.string(),
|
||||
easToken: z.string(),
|
||||
expiresAt: z.number(),
|
||||
sourceAccessToken: z.string().optional(),
|
||||
}).optional(),
|
||||
unity: z.object({
|
||||
unityJwt: z.string(),
|
||||
expiresAt: z.number(),
|
||||
sourceAccessToken: z.string().optional(),
|
||||
}).optional(),
|
||||
piper: z.object({
|
||||
hoseToken: z.string(),
|
||||
easJwt: z.string(),
|
||||
expiresAt: z.number(),
|
||||
sourceAccessToken: z.string().optional(),
|
||||
}).optional(),
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user