Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
"command": "gitguardian.authenticate",
"title": "gitguardian: Authenticate"
},
{
"command": "gitguardian.logout",
"title": "gitguardian: logout"
},
{
"command": "gitguardian.showOutput",
"title": "Show Output"
Expand Down
11 changes: 11 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ignoreLastFound,
ignoreSecret,
loginGGShield,
logoutGGShield,
showAPIQuota,
} from "./lib/ggshield-api";
import {
Expand Down Expand Up @@ -255,6 +256,16 @@ export function activate(context: ExtensionContext) {
} else {
updateStatusBarItem(StatusBarStatus.unauthenticated, statusBar);
}
}),
commands.registerCommand("gitguardian.logout", async () => {
outputChannel.show();
logoutGGShield(ggshieldResolver.configuration);
updateStatusBarItem(StatusBarStatus.unauthenticated, statusBar);
commands.executeCommand('setContext', 'isAuthenticated', false);
setApiKey(configuration, undefined);
ggshieldViewProvider.refresh();
ggshieldRemediationMessageViewProvider.refresh();
ggshieldQuotaViewProvider.refresh();
})
);
})
Expand Down
6 changes: 6 additions & 0 deletions src/lib/ggshield-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ export async function loginGGShield(
});
}

export function logoutGGShield(
configuration: GGShieldConfiguration
): void {
const proc = runGGShieldCommand(configuration, ["auth", "logout"]);
}

export function ggshieldAuthStatus(
configuration: GGShieldConfiguration
): boolean {
Expand Down
6 changes: 1 addition & 5 deletions src/lib/ggshield-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ export function getConfiguration(

export function setApiKey(configuration: GGShieldConfiguration, apiKey: string | undefined): void {
const config = workspace.getConfiguration("gitguardian");
if (!apiKey) {
throw new Error("Missing API Key");
}

configuration.apiKey = apiKey;
configuration.apiKey = apiKey ? apiKey : "";
config.update("apiKey", apiKey, ConfigurationTarget.Global);
}