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

Add support for custom root certificate in GitHub Copilot for Xcode #111

Closed
wants to merge 1 commit into from
Closed
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
17 changes: 15 additions & 2 deletions Core/Sources/HostApp/AdvancedSettings/EnterpriseSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@ import Toast

struct EnterpriseSection: View {
@AppStorage(\.gitHubCopilotEnterpriseURI) var gitHubCopilotEnterpriseURI
@AppStorage(\.nodeExtraCaCerts) var nodeExtraCaCerts
@Environment(\.toast) var toast

var body: some View {
SettingsSection(title: "Enterprise") {
SettingsTextField(
title: "Auth provider URL",
prompt: "https://your-enterprise.ghe.com",
text: DebouncedBinding($gitHubCopilotEnterpriseURI, handler: urlChanged).binding
text: DebouncedBinding($gitHubCopilotEnterpriseURI, handler: enterpriseUrlChanged).binding
)
SettingsTextField(
title: "Node extra CA certs",
prompt: "Path to extra CA certs (requires restart)",
text: DebouncedBinding($nodeExtraCaCerts, handler: nodeExtraCaCertsChanged).binding
)
}
}

func urlChanged(_ url: String) {
func enterpriseUrlChanged(_ url: String) {
if !url.isEmpty {
validateAuthURL(url)
}
Expand All @@ -26,6 +32,13 @@ struct EnterpriseSection: View {
)
}

func nodeExtraCaCertsChanged(_ path: String) {
NotificationCenter.default.post(
name: .gitHubCopilotShouldRefreshEditorInformation,
object: nil
)
}

func validateAuthURL(_ url: String) {
let maybeURL = URL(string: url)
guard let parsedURl = maybeURL else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ public class GitHubCopilotBaseService {
let home = ProcessInfo.processInfo.homePath
let versionNumber = JSONValue(stringLiteral: Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "")
let xcodeVersion = JSONValue(stringLiteral: SystemInfo().xcodeVersion() ?? "")
let nodeExtraCaCerts: String = UserDefaults.shared.value(for: \.nodeExtraCaCerts)
let nodeExtraCaCertMap: [String: String] = nodeExtraCaCerts.isEmpty ? [:] : ["NODE_EXTRA_CA_CERTS": nodeExtraCaCerts]

#if DEBUG
// Use local language server if set and available
Expand All @@ -145,13 +147,13 @@ public class GitHubCopilotBaseService {
}
}
// Set debug port and verbose when running in debug
let environment: [String: String] = ["HOME": home, "GH_COPILOT_DEBUG_UI_PORT": "8080", "GH_COPILOT_VERBOSE": "true"]
let environment: [String: String] = ["HOME": home, "GH_COPILOT_DEBUG_UI_PORT": "8080", "GH_COPILOT_VERBOSE": "true"].merging(nodeExtraCaCertMap) { _, new in new }
#else
let environment: [String: String] = if UserDefaults.shared.value(for: \.verboseLoggingEnabled) {
let environment: [String: String] = (if UserDefaults.shared.value(for: \.verboseLoggingEnabled) {
["HOME": home, "GH_COPILOT_VERBOSE": "true"]
} else {
["HOME": home]
}
}).merging(nodeExtraCaCertMap) { _, new in new }
#endif

let executionParams = Process.ExecutionParameters(
Expand Down Expand Up @@ -276,7 +278,7 @@ public class GitHubCopilotBaseService {
}

public final class GitHubCopilotService: GitHubCopilotBaseService,
GitHubCopilotSuggestionServiceType, GitHubCopilotConversationServiceType, GitHubCopilotAuthServiceType
GitHubCopilotSuggestionServiceType, GitHubCopilotConversationServiceType, GitHubCopilotAuthServiceType
{

private var ongoingTasks = Set<Task<[CodeSuggestion], Error>>()
Expand Down Expand Up @@ -695,4 +697,3 @@ extension InitializingServer: GitHubCopilotLSP {
try await sendRequest(endpoint.request)
}
}

4 changes: 4 additions & 0 deletions Tool/Sources/Preferences/Keys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,10 @@ public extension UserDefaultPreferenceKeys {
.init(defaultValue: "", key: "GitHubCopilotEnterpriseURI")
}

var nodeExtraCaCerts: PreferenceKey<String> {
.init(defaultValue: "", key: "NodeExtraCaCerts")
}

var verboseLoggingEnabled: PreferenceKey<Bool> {
.init(defaultValue: false, key: "VerboseLoggingEnabled")
}
Expand Down