From 136bf9e0f0ce0193f64fe291922431808c32406e Mon Sep 17 00:00:00 2001 From: Ten <32621403+TenDRILLL@users.noreply.github.com> Date: Thu, 4 Jul 2024 09:44:06 +0300 Subject: [PATCH] feat: Client Certificate Options Support (#1658) * feat: support client certificate authentication options * docs: support client certificate authentication options * chore: update package.json * docs: move clientCertificate to it's own example --- core/index.d.ts | 7 +++++ core/util/fetchWithOptions.ts | 11 +++++++- docs/docs/setup/configuration.md | 43 +++++++++++++++++++++-------- extensions/vscode/package-lock.json | 4 +-- extensions/vscode/package.json | 2 +- 5 files changed, 52 insertions(+), 15 deletions(-) diff --git a/core/index.d.ts b/core/index.d.ts index 21fadeb1e..a3dbbd72c 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -664,6 +664,13 @@ export interface RequestOptions { headers?: { [key: string]: string }; extraBodyProperties?: { [key: string]: any }; noProxy?: string[]; + clientCertificate?: ClientCertificateOptions; +} + +export interface ClientCertificateOptions { + cert: string; + key: string; + passphrase?: string; } export interface StepWithParams { diff --git a/core/util/fetchWithOptions.ts b/core/util/fetchWithOptions.ts index a2efe48af..f2e782266 100644 --- a/core/util/fetchWithOptions.ts +++ b/core/util/fetchWithOptions.ts @@ -42,7 +42,7 @@ export function fetchwithRequestOptions( const timeout = (requestOptions?.timeout ?? TIMEOUT) * 1000; // measured in ms - const agentOptions = { + const agentOptions: {[key: string]: any} = { ca, rejectUnauthorized: requestOptions?.verifySsl, timeout, @@ -51,6 +51,15 @@ export function fetchwithRequestOptions( keepAliveMsecs: timeout, }; + // Handle ClientCertificateOptions + if (requestOptions?.clientCertificate){ + agentOptions.cert = fs.readFileSync(requestOptions.clientCertificate.cert,"utf8"); + agentOptions.key = fs.readFileSync(requestOptions.clientCertificate.key,"utf8"); + if(requestOptions.clientCertificate.passphrase){ + agentOptions.passphrase = requestOptions.clientCertificate.passphrase; + } + } + const proxy = requestOptions?.proxy; // Create agent diff --git a/docs/docs/setup/configuration.md b/docs/docs/setup/configuration.md index 5b314c178..aa955de46 100644 --- a/docs/docs/setup/configuration.md +++ b/docs/docs/setup/configuration.md @@ -135,18 +135,39 @@ If you need to send custom headers for authentication, you may use the `requestO ```json title="~/.continue/config.json" { - "models": [ - { - "title": "Ollama", - "provider": "ollama", - "model": "llama2-7b", - "requestOptions": { - "headers": { - "X-Auth-Token": "xxx" - } + "models": [ + { + "title": "Ollama", + "provider": "ollama", + "model": "llama2-7b", + "requestOptions": { + "headers": { + "X-Auth-Token": "xxx" + } + } } - } - ] + ] +} +``` + +Similarly if your model requires a Certificate for authentication, you may use the `requestOptions.clientCertificate` property like in the example below: + +```json title="~/.continue/config.json" +{ + "models": [ + { + "title": "Ollama", + "provider": "ollama", + "model": "llama2-7b", + "requestOptions": { + "clientCertificate": { + "cert": "C:\temp\ollama.pem", + "key": "C:\temp\ollama.key", + "passphrase": "c0nt!nu3" + } + } + } + ] } ``` diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 56ed88234..47a3d36cb 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "0.9.170", + "version": "0.9.171", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "0.9.170", + "version": "0.9.171", "license": "Apache-2.0", "dependencies": { "@electron/rebuild": "^3.2.10", diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index 874ef6b2d..a31f45c59 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -1,7 +1,7 @@ { "name": "continue", "icon": "media/icon.png", - "version": "0.9.170", + "version": "0.9.171", "repository": { "type": "git", "url": "https://github.com/continuedev/continue"