feat: release 2.5.1
This commit is contained in:
+31
-4
@@ -19,6 +19,15 @@ export type KuberSession = {
|
||||
};
|
||||
};
|
||||
|
||||
let cachedSession:
|
||||
| {
|
||||
runtimePath: string;
|
||||
persistentPath: string;
|
||||
value: KuberSession | undefined;
|
||||
expiresAt: number;
|
||||
}
|
||||
| undefined;
|
||||
|
||||
function runtimeSessionPath(): string {
|
||||
const directory =
|
||||
process.env.XDG_RUNTIME_DIR ??
|
||||
@@ -76,10 +85,26 @@ async function readSessionFile(
|
||||
}
|
||||
|
||||
export async function readSession(): Promise<KuberSession | undefined> {
|
||||
return (
|
||||
(await readSessionFile(runtimeSessionPath())) ??
|
||||
(await readSessionFile(persistentSessionPath()))
|
||||
);
|
||||
const runtimePath = runtimeSessionPath();
|
||||
const persistentPath = persistentSessionPath();
|
||||
if (
|
||||
cachedSession?.runtimePath === runtimePath &&
|
||||
cachedSession.persistentPath === persistentPath &&
|
||||
(cachedSession.expiresAt === 0 || cachedSession.expiresAt > Date.now())
|
||||
)
|
||||
return cachedSession.value;
|
||||
|
||||
const value =
|
||||
(await readSessionFile(runtimePath)) ??
|
||||
(await readSessionFile(persistentPath));
|
||||
cachedSession = {
|
||||
runtimePath,
|
||||
persistentPath,
|
||||
value,
|
||||
// Expiration is checked on every lookup, even while the file is memoized.
|
||||
expiresAt: value ? Date.parse(value.expiresAt) : 0,
|
||||
};
|
||||
return value;
|
||||
}
|
||||
|
||||
export async function writeSession(
|
||||
@@ -97,6 +122,7 @@ export async function writeSession(
|
||||
await rename(temporaryPath, path);
|
||||
await chmod(path, 0o600);
|
||||
await rm(getSessionPath(!persistent), { force: true });
|
||||
cachedSession = undefined;
|
||||
return path;
|
||||
}
|
||||
|
||||
@@ -106,4 +132,5 @@ export async function removeSessions(): Promise<void> {
|
||||
rm(path, { force: true }),
|
||||
),
|
||||
);
|
||||
cachedSession = undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user