Skip to content

Commit 81a3dbc

Browse files
committed
feat(auth-logout): Add logout command
1 parent 02c1c2b commit 81a3dbc

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
"command": "gitguardian.authenticate",
5151
"title": "gitguardian: Authenticate"
5252
},
53+
{
54+
"command": "gitguardian.logout",
55+
"title": "gitguardian: logout"
56+
},
5357
{
5458
"command": "gitguardian.showOutput",
5559
"title": "Show Output"

src/extension.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
ignoreLastFound,
66
ignoreSecret,
77
loginGGShield,
8+
logoutGGShield,
89
showAPIQuota,
910
} from "./lib/ggshield-api";
1011
import {
@@ -255,6 +256,16 @@ export function activate(context: ExtensionContext) {
255256
} else {
256257
updateStatusBarItem(StatusBarStatus.unauthenticated, statusBar);
257258
}
259+
}),
260+
commands.registerCommand("gitguardian.logout", async () => {
261+
outputChannel.show();
262+
logoutGGShield(ggshieldResolver.configuration);
263+
updateStatusBarItem(StatusBarStatus.unauthenticated, statusBar);
264+
commands.executeCommand('setContext', 'isAuthenticated', false);
265+
setApiKey(configuration, undefined);
266+
ggshieldViewProvider.refresh();
267+
ggshieldRemediationMessageViewProvider.refresh();
268+
ggshieldQuotaViewProvider.refresh();
258269
})
259270
);
260271
})

src/lib/ggshield-api.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ export async function loginGGShield(
251251
});
252252
}
253253

254+
export function logoutGGShield(
255+
configuration: GGShieldConfiguration
256+
): void {
257+
const proc = runGGShieldCommand(configuration, ["auth", "logout"]);
258+
}
259+
254260
export function ggshieldAuthStatus(
255261
configuration: GGShieldConfiguration
256262
): boolean {

src/lib/ggshield-configuration.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ export function getConfiguration(
4040

4141
export function setApiKey(configuration: GGShieldConfiguration, apiKey: string | undefined): void {
4242
const config = workspace.getConfiguration("gitguardian");
43-
if (!apiKey) {
44-
throw new Error("Missing API Key");
45-
}
46-
47-
configuration.apiKey = apiKey;
43+
configuration.apiKey = apiKey ? apiKey : "";
4844
config.update("apiKey", apiKey, ConfigurationTarget.Global);
4945
}

0 commit comments

Comments
 (0)