Skip to content
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

Fix certificate issue for internal company setup #1088

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 15 additions & 4 deletions crates/goose/src/providers/openai.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use anyhow::Result;
use async_trait::async_trait;
use reqwest::Client;
use reqwest::{Client, Certificate};
use serde_json::Value;
use std::fs;
use std::time::Duration;

use super::base::{ConfigKey, Provider, ProviderMetadata, ProviderUsage, Usage};
Expand Down Expand Up @@ -46,9 +47,18 @@ impl OpenAiProvider {
let host: String = config
.get("OPENAI_HOST")
.unwrap_or_else(|_| "https://api.openai.com".to_string());
let client = Client::builder()
.timeout(Duration::from_secs(600))
.build()?;

// Load custom certificate if specified
let cert_path: Option<String> = config.get("OPENAI_CERT_PATH").ok();
let mut client_builder = Client::builder().timeout(Duration::from_secs(600));

if let Some(cert_path) = cert_path {
let cert = fs::read(cert_path)?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better naming? like cert_data

let cert = Certificate::from_pem(&cert)?;
client_builder = client_builder.add_root_certificate(cert);
}

let client = client_builder.build()?;

Ok(Self {
client,
Expand Down Expand Up @@ -93,6 +103,7 @@ impl Provider for OpenAiProvider {
vec![
ConfigKey::new("OPENAI_API_KEY", true, true, None),
ConfigKey::new("OPENAI_HOST", false, false, Some("https://api.openai.com")),
ConfigKey::new("OPENAI_CERT_PATH", false, false, None),
],
)
}
Expand Down
14 changes: 14 additions & 0 deletions ui/desktop/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { Certificate } from 'electron';
import fs from 'fs';

// Helper to construct API endpoints
export const getApiUrl = (endpoint: string): string => {
const baseUrl = window.appConfig.get('GOOSE_API_HOST') + ':' + window.appConfig.get('GOOSE_PORT');
Expand All @@ -8,3 +11,14 @@ export const getApiUrl = (endpoint: string): string => {
export const getSecretKey = (): string => {
return window.appConfig.get('secretKey');
};

// Function to load custom certificate
export const loadCustomCertificate = (certPath: string): Certificate | null => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we use it somewhere?

try {
const cert = fs.readFileSync(certPath);
return Certificate.fromPEM(cert);
} catch (error) {
console.error('Failed to load custom certificate:', error);
return null;
}
};