Skip to content

feat: add handling for insecure requests #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat: add handling for insecure requests
  • Loading branch information
kylecarbs committed Jun 9, 2023
commit dd2b9060618af154f142c2720a969688fd9086f4
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
},
"scope": "machine",
"default": []
},
"coder.insecure": {
"markdownDescription": "If true, the extension will not verify the authenticity of the remote host. This is useful for self-signed certificates.",
"type": "boolean",
"default": false
}
}
},
Expand Down Expand Up @@ -241,4 +246,4 @@
"yaml": "^1.10.0",
"zod": "^3.21.4"
}
}
}
23 changes: 23 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use strict"
import axios from "axios"
import { getAuthenticatedUser } from "coder/site/src/api/api"
import * as https from "https"
import * as module from "module"
import * as vscode from "vscode"
import { Commands } from "./commands"
Expand Down Expand Up @@ -83,6 +85,27 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {

const commands = new Commands(vscodeProposed, storage)

// updateInsecure is called on extension activation and when the insecure
// setting is changed. It updates the https agent to allow self-signed
// certificates if the insecure setting is true.
const updateInsecure = () => {
const insecure = Boolean(vscode.workspace.getConfiguration().get("coder.insecure"))
axios.defaults.httpsAgent = new https.Agent({
// rejectUnauthorized defaults to true, so we need to explicitly set it to false
// if we want to allow self-signed certificates.
rejectUnauthorized: !insecure,
})
}

axios.interceptors.response.use(undefined, (error) => {
// if (error)
return error
})

vscode.workspace.onDidChangeConfiguration((e) => {
e.affectsConfiguration("coder.insecure") && updateInsecure()
})

vscode.commands.registerCommand("coder.login", commands.login.bind(commands))
vscode.commands.registerCommand("coder.logout", commands.logout.bind(commands))
vscode.commands.registerCommand("coder.open", commands.open.bind(commands))
Expand Down