1
- import * as fs from "fs/promises"
2
- import * as jsonc from "jsonc-parser"
3
1
import * as vscode from "vscode"
4
- import { Storage } from "./storage"
5
2
6
3
export class SelfSignedCertificateError extends Error {
7
4
public static Notification =
@@ -17,24 +14,13 @@ export class SelfSignedCertificateError extends Error {
17
14
return vscode . env . openExternal ( vscode . Uri . parse ( "https://github.com/coder/vscode-coder/issues/105" ) )
18
15
}
19
16
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 )
35
21
}
36
22
37
- public async showInsecureNotification ( storage : Storage ) : Promise < void > {
23
+ public async showInsecureNotification ( ) : Promise < void > {
38
24
const value = await vscode . window . showErrorMessage (
39
25
SelfSignedCertificateError . Notification ,
40
26
SelfSignedCertificateError . ActionAllowInsecure ,
@@ -45,7 +31,7 @@ export class SelfSignedCertificateError extends Error {
45
31
return
46
32
}
47
33
if ( value === SelfSignedCertificateError . ActionAllowInsecure ) {
48
- return this . allowInsecure ( storage )
34
+ return this . allowInsecure ( )
49
35
}
50
36
}
51
37
}
0 commit comments