- Notifications
You must be signed in to change notification settings - Fork34
Pass the header command output to WebSocket creation#619
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -67,7 +67,7 @@ export class CoderApi extends Api { | ||
return client; | ||
} | ||
watchInboxNotifications =async( | ||
watchTemplates: string[], | ||
watchTargets: string[], | ||
options?: ClientOptions, | ||
@@ -83,14 +83,14 @@ export class CoderApi extends Api { | ||
}); | ||
}; | ||
watchWorkspace =async(workspace: Workspace, options?: ClientOptions) => { | ||
return this.createWebSocket<ServerSentEvent>({ | ||
apiRoute: `/api/v2/workspaces/${workspace.id}/watch-ws`, | ||
options, | ||
}); | ||
}; | ||
watchAgentMetadata =async( | ||
agentId: WorkspaceAgent["id"], | ||
options?: ClientOptions, | ||
) => { | ||
@@ -100,21 +100,22 @@ export class CoderApi extends Api { | ||
}); | ||
}; | ||
watchBuildLogsByBuildId = async ( | ||
buildId: string, | ||
logs: ProvisionerJobLog[], | ||
) => { | ||
const searchParams = new URLSearchParams({ follow: "true" }); | ||
if (logs.length) { | ||
searchParams.append("after", logs[logs.length - 1].id.toString()); | ||
} | ||
return this.createWebSocket<ProvisionerJobLog>({ | ||
apiRoute: `/api/v2/workspacebuilds/${buildId}/logs`, | ||
searchParams, | ||
}); | ||
}; | ||
privateasynccreateWebSocket<TData = unknown>( | ||
configs: Omit<OneWayWebSocketInit, "location">, | ||
) { | ||
const baseUrlRaw = this.getAxiosInstance().defaults.baseURL; | ||
@@ -127,14 +128,23 @@ export class CoderApi extends Api { | ||
coderSessionTokenHeader | ||
] as string | undefined; | ||
const headers = await getHeaders( | ||
baseUrlRaw, | ||
getHeaderCommand(vscode.workspace.getConfiguration()), | ||
this.output, | ||
); | ||
EhabY marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
const httpAgent = await createHttpAgent( | ||
vscode.workspace.getConfiguration(), | ||
); | ||
const webSocket = new OneWayWebSocket<TData>({ | ||
location: baseUrl, | ||
...configs, | ||
options: { | ||
agent: httpAgent, | ||
followRedirects: true, | ||
headers: { | ||
...headers, | ||
...(token ? { [coderSessionTokenHeader]: token } : {}), | ||
...configs.options?.headers, | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Does this order make sense? (From lowest to highest)
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I think this makes sense. CollaboratorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. After re-reading the original issue:
Would this mean we want the headers to have a higher priority over the token from the axios instance 🤔 ? From highest to lowest:
| ||
@@ -191,7 +201,7 @@ function setupInterceptors( | ||
// Configure proxy and TLS. | ||
// Note that by default VS Code overrides the agent. To prevent this, set | ||
// `http.proxySupport` to `on` or `off`. | ||
const agent =awaitcreateHttpAgent(vscode.workspace.getConfiguration()); | ||
config.httpsAgent = agent; | ||
config.httpAgent = agent; | ||
config.proxy = false; | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import fs from "fs/promises"; | ||
import { ProxyAgent } from "proxy-agent"; | ||
import { type WorkspaceConfiguration } from "vscode"; | ||
@@ -23,7 +23,9 @@ export function needToken(cfg: WorkspaceConfiguration): boolean { | ||
* Create a new HTTP agent based on the current VS Code settings. | ||
* Configures proxy, TLS certificates, and security options. | ||
*/ | ||
export async function createHttpAgent( | ||
cfg: WorkspaceConfiguration, | ||
): Promise<ProxyAgent> { | ||
const insecure = Boolean(cfg.get("coder.insecure")); | ||
const certFile = expandPath( | ||
String(cfg.get("coder.tlsCertFile") ?? "").trim(), | ||
@@ -32,6 +34,12 @@ export function createHttpAgent(cfg: WorkspaceConfiguration): ProxyAgent { | ||
const caFile = expandPath(String(cfg.get("coder.tlsCaFile") ?? "").trim()); | ||
const altHost = expandPath(String(cfg.get("coder.tlsAltHost") ?? "").trim()); | ||
const [cert, key, ca] = await Promise.all([ | ||
EhabY marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
certFile === "" ? Promise.resolve(undefined) : fs.readFile(certFile), | ||
keyFile === "" ? Promise.resolve(undefined) : fs.readFile(keyFile), | ||
caFile === "" ? Promise.resolve(undefined) : fs.readFile(caFile), | ||
]); | ||
return new ProxyAgent({ | ||
// Called each time a request is made. | ||
getProxyForUrl: (url: string) => { | ||
@@ -41,9 +49,9 @@ export function createHttpAgent(cfg: WorkspaceConfiguration): ProxyAgent { | ||
cfg.get("coder.proxyBypass"), | ||
); | ||
}, | ||
cert, | ||
key, | ||
ca, | ||
servername: altHost === "" ? undefined : altHost, | ||
// rejectUnauthorized defaults to true, so we need to explicitly set it to | ||
// false if we want to allow self-signed certificates. | ||
Uh oh!
There was an error while loading.Please reload this page.