Skip to content

Commit 24cf143

Browse files
committed
refactor(auth): rename clearSecrets to clearKeyringSecrets
The function only deletes keyring entries; auth.json cleanup is the caller's responsibility (logout rimrafs the whole file). Renaming makes the scope honest and avoids misleading future callers.
1 parent b90fa2f commit 24cf143

3 files changed

Lines changed: 13 additions & 11 deletions

File tree

src/commands/auth/logout.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
22
import { AUTH_FILE_PATH } from '../../lib/consts.js';
3-
import { clearSecrets } from '../../lib/credentials.js';
3+
import { clearKeyringSecrets } from '../../lib/credentials.js';
44
import { rimrafPromised } from '../../lib/files.js';
55
import { updateUserId } from '../../lib/hooks/telemetry/useTelemetryState.js';
66
import { success } from '../../lib/outputs.js';
@@ -25,7 +25,7 @@ export class AuthLogoutCommand extends ApifyCommand<typeof AuthLogoutCommand> {
2525
static override docsUrl = 'https://docs.apify.com/cli/docs/reference#apify-logout';
2626

2727
async run() {
28-
await clearSecrets();
28+
await clearKeyringSecrets();
2929
await rimrafPromised(AUTH_FILE_PATH());
3030

3131
await updateUserId(null);

src/lib/credentials.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,13 @@ export async function setProxyPassword(password: string, opts: { skipIfUnchanged
195195
}
196196

197197
/**
198-
* Remove all stored secrets. Always attempts to clear the keyring even when the
199-
* current backend is `file`, so toggling `APIFY_DISABLE_KEYRING=1` between login
200-
* and logout does not orphan entries the user has no in-CLI way to discover.
198+
* Remove the token and proxy-password entries from the OS keyring. Always attempts the
199+
* keyring deletes even when the current backend is `file`, so toggling
200+
* `APIFY_DISABLE_KEYRING=1` between login and logout does not orphan entries the user
201+
* has no in-CLI way to discover. Plaintext secrets in `auth.json` are the caller's
202+
* responsibility (e.g. `logout` removes the whole file).
201203
*/
202-
export async function clearSecrets(): Promise<void> {
204+
export async function clearKeyringSecrets(): Promise<void> {
203205
await deleteKeyring(TOKEN_ACCOUNT);
204206
await deleteKeyring(PROXY_PASSWORD_ACCOUNT);
205207
}

test/local/lib/credentials.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { cryptoRandomObjectId } from '@apify/utilities';
66
import { AUTH_FILE_PATH, GLOBAL_CONFIGS_FOLDER } from '../../../src/lib/consts.js';
77
import {
88
__resetCredentialsForTests,
9-
clearSecrets,
9+
clearKeyringSecrets,
1010
ensureMigrated,
1111
getBackend,
1212
getProxyPassword,
@@ -134,16 +134,16 @@ describe('credentials', () => {
134134
expect(existsSync(AUTH_FILE_PATH())).toBe(false);
135135
});
136136

137-
it('clearSecrets() removes the token and proxy entries from the keyring', async () => {
137+
it('clearKeyringSecrets() removes the token and proxy entries from the keyring', async () => {
138138
await setToken('tok_123');
139139
await setProxyPassword('pw_abc');
140-
await clearSecrets();
140+
await clearKeyringSecrets();
141141
expect(await getToken()).toBeUndefined();
142142
expect(await getProxyPassword()).toBeUndefined();
143143
});
144144
});
145145

146-
describe('clearSecrets()', () => {
146+
describe('clearKeyringSecrets()', () => {
147147
it('clears the keyring token entry even when APIFY_DISABLE_KEYRING=1 is set at logout time', async () => {
148148
vitest.stubEnv('APIFY_DISABLE_KEYRING', '');
149149
await setToken('tok_123');
@@ -153,7 +153,7 @@ describe('credentials', () => {
153153
vitest.stubEnv('APIFY_DISABLE_KEYRING', '1');
154154
expect(await getBackend()).toBe('file');
155155

156-
await clearSecrets();
156+
await clearKeyringSecrets();
157157
expect(keyringStore.get('com.apify.cli:token')).toBeUndefined();
158158
});
159159
});

0 commit comments

Comments
 (0)