Skip to content

Commit 9625776

Browse files
feat: remove the api key from the vscode extension settings
1 parent 89eeeb7 commit 9625776

9 files changed

+5
-57
lines changed

package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@
4141
"default": "https://dashboard.gitguardian.com",
4242
"markdownDescription": "You can override the value here for On Premise installations"
4343
},
44-
"gitguardian.apiKey": {
45-
"type": "string",
46-
"default": "",
47-
"markdownDescription": "Your API Key"
48-
},
4944
"gitguardian.allowSelfSigned": {
5045
"type": "boolean",
5146
"default": false,

src/extension.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ import {
1010
scanFile,
1111
showAPIQuota,
1212
} from "./lib/ggshield-api";
13-
import {
14-
getConfiguration,
15-
setApiKey,
16-
} from "./lib/ggshield-configuration-utils";
13+
import { getConfiguration } from "./lib/ggshield-configuration-utils";
1714
import {
1815
ExtensionContext,
1916
Uri,
@@ -138,7 +135,6 @@ export function activate(context: ExtensionContext) {
138135
ggshieldAuthStatus(configuration, context);
139136
if (context.globalState.get("isAuthenticated", false)) {
140137
updateStatusBarItem(StatusBarStatus.ready);
141-
setApiKey(configuration, ggshieldApiKey(configuration));
142138
ggshieldViewProvider.refresh();
143139
ggshieldRemediationMessageViewProvider.refresh();
144140
ggshieldQuotaViewProvider.refresh();
@@ -219,7 +215,6 @@ export function activate(context: ExtensionContext) {
219215
.then(() => {
220216
if (context.globalState.get("isAuthenticated", false)) {
221217
updateStatusBarItem(StatusBarStatus.ready);
222-
setApiKey(configuration, ggshieldApiKey(configuration));
223218
} else {
224219
updateStatusBarItem(StatusBarStatus.unauthenticated);
225220
}
@@ -234,7 +229,6 @@ export function activate(context: ExtensionContext) {
234229
commands.registerCommand("gitguardian.logout", async () => {
235230
logoutGGShield(ggshieldResolver.configuration, context);
236231
updateStatusBarItem(StatusBarStatus.unauthenticated);
237-
setApiKey(configuration, undefined);
238232
ggshieldViewProvider.refresh();
239233
ggshieldRemediationMessageViewProvider.refresh();
240234
ggshieldQuotaViewProvider.refresh();

src/ggshield-webview/gitguardian-remediation-message-view.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { getRemediationMessage } from "../lib/ggshield-api";
21
import { GGShieldConfiguration } from "../lib/ggshield-configuration";
32
import * as vscode from "vscode";
43

@@ -46,9 +45,8 @@ export class GitGuardianRemediationMessageWebviewProvider
4645

4746
private async updateRemediationMessage() {
4847
if (this.isAuthenticated) {
49-
this.remediationMessage = await getRemediationMessage(
50-
this.ggshieldConfiguration
51-
);
48+
//TODO: Get remediation message
49+
this.remediationMessage = "";
5250
}
5351
}
5452

src/lib/ggshield-api.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,6 @@ export async function getAPIquota(
5959
}
6060
}
6161

62-
export async function getRemediationMessage(
63-
configuration: GGShieldConfiguration
64-
): Promise<string> {
65-
const apiUrl = dasboardToApi(configuration.apiUrl);
66-
const path = require("node:path");
67-
try {
68-
const response = await axios.get(path.join(apiUrl, "v1/metadata"), {
69-
headers: {
70-
authorization: `Token ${configuration.apiKey}`,
71-
},
72-
});
73-
return response.data.remediation_messages.pre_commit;
74-
} catch (error) {
75-
return "An error occurred.";
76-
}
77-
}
78-
7962
/**
8063
* Ignore last found secrets
8164
*
@@ -214,7 +197,7 @@ export async function loginGGShield(
214197
webviewView: WebviewView,
215198
context: ExtensionContext
216199
): Promise<void> {
217-
const { ggshieldPath, apiUrl, apiKey } = configuration;
200+
const { ggshieldPath, apiUrl } = configuration;
218201

219202
let options: SpawnOptionsWithoutStdio = {
220203
cwd: os.tmpdir(),

src/lib/ggshield-configuration-utils.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,12 @@ export function getConfiguration(
1818

1919
const ggshieldPath: string | undefined = config.get("GGShieldPath");
2020
const apiUrl: string | undefined = config.get("apiUrl");
21-
const apiKey: string | undefined = config.get("apiKey");
2221
const allowSelfSigned: boolean = config.get("allowSelfSigned", false);
2322
return new GGShieldConfiguration(
2423
ggshieldPath
2524
? ggshieldPath
2625
: getBinaryAbsolutePath(os.platform(), os.arch(), context),
2726
apiUrl || apiUrlDefault,
28-
apiKey || "",
2927
allowSelfSigned || false
3028
);
3129
}
32-
33-
export function setApiKey(
34-
configuration: GGShieldConfiguration,
35-
apiKey: string | undefined
36-
): void {
37-
configuration.apiKey = apiKey ? apiKey : "";
38-
}

src/lib/ggshield-configuration.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
export class GGShieldConfiguration {
22
ggshieldPath: string;
33
apiUrl: string;
4-
apiKey: string;
54
allowSelfSigned: boolean;
65

76
constructor(
87
ggshieldPath: string = "",
98
apiUrl: string = "",
10-
apiKey: string = "",
119
allowSelfSigned: boolean = false
1210
) {
1311
this.ggshieldPath = ggshieldPath;
1412
this.apiUrl = apiUrl;
15-
this.apiKey = apiKey;
1613
this.allowSelfSigned = allowSelfSigned;
1714
}
1815
}

src/lib/run-ggshield.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,13 @@ export function runGGShieldCommand(
1919
configuration: GGShieldConfiguration,
2020
args: string[]
2121
): SpawnSyncReturns<string> {
22-
const { ggshieldPath, apiUrl, apiKey } = configuration;
22+
const { ggshieldPath, apiUrl } = configuration;
2323
let env: NodeJS.ProcessEnv = {
2424
...process.env,
2525
GITGUARDIAN_INSTANCE: apiUrl,
2626
GG_USER_AGENT: "gitguardian-vscode",
2727
};
2828

29-
if (apiKey) {
30-
env.GITGUARDIAN_API_KEY = apiKey;
31-
}
32-
3329
let options: SpawnSyncOptionsWithStringEncoding = {
3430
cwd: os.tmpdir(),
3531
env: env,

src/test/suite/lib/ggshield-configuration-utils.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ suite("getConfiguration", () => {
2424
if (key === "apiUrl") {
2525
return "https://custom-url.com";
2626
}
27-
if (key === "apiKey") {
28-
return "test-api-key";
29-
}
3027
if (key === "allowSelfSigned") {
3128
return true;
3229
}
@@ -43,7 +40,6 @@ suite("getConfiguration", () => {
4340
// Assert that the configuration has the expected values
4441
assert.strictEqual(configuration.ggshieldPath, "path/to/ggshield");
4542
assert.strictEqual(configuration.apiUrl, "https://custom-url.com");
46-
assert.strictEqual(configuration.apiKey, "test-api-key");
4743
assert.strictEqual(configuration.allowSelfSigned, true);
4844
});
4945
});

src/test/suite/lib/run-ggshield.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ suite("runGGShieldCommand", () => {
2121
{
2222
ggshieldPath: "path/to/ggshield",
2323
apiUrl: "",
24-
apiKey: "",
2524
} as GGShieldConfiguration,
2625
[]
2726
);
@@ -58,7 +57,6 @@ suite("runGGShieldCommand", () => {
5857
{
5958
ggshieldPath: "path/to/ggshield",
6059
apiUrl: "",
61-
apiKey: "",
6260
allowSelfSigned: allowSelfSigned,
6361
} as GGShieldConfiguration,
6462
["test"]

0 commit comments

Comments
 (0)