Skip to content

Commit 19d6bbe

Browse files
committed
Set coder.insecure through the VS Code API
1 parent 011c1cf commit 19d6bbe

File tree

2 files changed

+8
-22
lines changed

2 files changed

+8
-22
lines changed

src/commands.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class Commands {
6363
message = err.response.data.detail
6464
}
6565
if (err instanceof SelfSignedCertificateError) {
66-
err.showInsecureNotification(this.storage)
66+
err.showInsecureNotification()
6767

6868
return {
6969
message: err.message,
@@ -200,7 +200,7 @@ export class Commands {
200200
})
201201
.catch((ex) => {
202202
if (ex instanceof SelfSignedCertificateError) {
203-
ex.showInsecureNotification(this.storage)
203+
ex.showInsecureNotification()
204204
}
205205
return
206206
})

src/error.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import * as fs from "fs/promises"
2-
import * as jsonc from "jsonc-parser"
31
import * as vscode from "vscode"
4-
import { Storage } from "./storage"
52

63
export class SelfSignedCertificateError extends Error {
74
public static Notification =
@@ -17,24 +14,13 @@ export class SelfSignedCertificateError extends Error {
1714
return vscode.env.openExternal(vscode.Uri.parse("https://github.com/coder/vscode-coder/issues/105"))
1815
}
1916

20-
// allowInsecure manually reads the settings file and updates the value of the
21-
// "coder.insecure" property.
22-
public async allowInsecure(storage: Storage): Promise<void> {
23-
let settingsContent = "{}"
24-
try {
25-
settingsContent = await fs.readFile(storage.getUserSettingsPath(), "utf8")
26-
} catch (ex) {
27-
// Ignore! It's probably because the file doesn't exist.
28-
}
29-
const edits = jsonc.modify(settingsContent, ["coder.insecure"], true, {})
30-
await fs.writeFile(storage.getUserSettingsPath(), jsonc.applyEdits(settingsContent, edits))
31-
32-
vscode.window.showInformationMessage(
33-
'The Coder extension will no longer verify TLS on HTTPS requests. You can change this at any time with the "coder.insecure" property in your VS Code settings.',
34-
)
17+
// allowInsecure updates the value of the "coder.insecure" property.
18+
async allowInsecure(): Promise<void> {
19+
vscode.workspace.getConfiguration().update("coder.insecure", true, vscode.ConfigurationTarget.Global)
20+
vscode.window.showInformationMessage(CertificateError.InsecureMessage)
3521
}
3622

37-
public async showInsecureNotification(storage: Storage): Promise<void> {
23+
public async showInsecureNotification(): Promise<void> {
3824
const value = await vscode.window.showErrorMessage(
3925
SelfSignedCertificateError.Notification,
4026
SelfSignedCertificateError.ActionAllowInsecure,
@@ -45,7 +31,7 @@ export class SelfSignedCertificateError extends Error {
4531
return
4632
}
4733
if (value === SelfSignedCertificateError.ActionAllowInsecure) {
48-
return this.allowInsecure(storage)
34+
return this.allowInsecure()
4935
}
5036
}
5137
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy