Skip to content

Commit de50527

Browse files
committed
Add support for custom root certificate in GitHub Copilot for Xcode
Fixes #95 Add support for specifying extra CA certificates in GitHub Copilot for Xcode. * Add a new `@AppStorage` property for `nodeExtraCaCerts` in `Core/Sources/HostApp/AdvancedSettings/EnterpriseSection.swift`. * Add a new `SettingsTextField` for "Node extra CA certs" in `Core/Sources/HostApp/AdvancedSettings/EnterpriseSection.swift`. * Add a new function `nodeExtraCaCertsChanged` to handle changes in `Core/Sources/HostApp/AdvancedSettings/EnterpriseSection.swift`. * Add a new environment variable `NODE_EXTRA_CA_CERTS` in `Tool/Sources/GitHubCopilotService/LanguageServer/GitHubCopilotService.swift`. * Update the `environment` dictionary to include `nodeExtraCaCerts` in `Tool/Sources/GitHubCopilotService/LanguageServer/GitHubCopilotService.swift`. * Add a new preference key `nodeExtraCaCerts` in `Tool/Sources/Preferences/Keys.swift`. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/github/CopilotForXcode/issues/95?shareId=XXXX-XXXX-XXXX-XXXX).
1 parent dfe1195 commit de50527

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

Core/Sources/HostApp/AdvancedSettings/EnterpriseSection.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,25 @@ import Toast
44

55
struct EnterpriseSection: View {
66
@AppStorage(\.gitHubCopilotEnterpriseURI) var gitHubCopilotEnterpriseURI
7+
@AppStorage(\.nodeExtraCaCerts) var nodeExtraCaCerts
78
@Environment(\.toast) var toast
89

910
var body: some View {
1011
SettingsSection(title: "Enterprise") {
1112
SettingsTextField(
1213
title: "Auth provider URL",
1314
prompt: "https://your-enterprise.ghe.com",
14-
text: DebouncedBinding($gitHubCopilotEnterpriseURI, handler: urlChanged).binding
15+
text: DebouncedBinding($gitHubCopilotEnterpriseURI, handler: enterpriseUrlChanged).binding
16+
)
17+
SettingsTextField(
18+
title: "Node extra CA certs",
19+
prompt: "Path to extra CA certs (requires restart)",
20+
text: DebouncedBinding($nodeExtraCaCerts, handler: nodeExtraCaCertsChanged).binding
1521
)
1622
}
1723
}
1824

19-
func urlChanged(_ url: String) {
25+
func enterpriseUrlChanged(_ url: String) {
2026
if !url.isEmpty {
2127
validateAuthURL(url)
2228
}
@@ -26,6 +32,13 @@ struct EnterpriseSection: View {
2632
)
2733
}
2834

35+
func nodeExtraCaCertsChanged(_ path: String) {
36+
NotificationCenter.default.post(
37+
name: .gitHubCopilotShouldRefreshEditorInformation,
38+
object: nil
39+
)
40+
}
41+
2942
func validateAuthURL(_ url: String) {
3043
let maybeURL = URL(string: url)
3144
guard let parsedURl = maybeURL else {

Tool/Sources/GitHubCopilotService/LanguageServer/GitHubCopilotService.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ public class GitHubCopilotBaseService {
130130
let home = ProcessInfo.processInfo.homePath
131131
let versionNumber = JSONValue(stringLiteral: Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "")
132132
let xcodeVersion = JSONValue(stringLiteral: SystemInfo().xcodeVersion() ?? "")
133+
let nodeExtraCaCerts: String = UserDefaults.shared.value(for: \.nodeExtraCaCerts)
134+
let nodeExtraCaCertMap: [String: String] = nodeExtraCaCerts.isEmpty ? [:] : ["NODE_EXTRA_CA_CERTS": nodeExtraCaCerts]
133135

134136
#if DEBUG
135137
// Use local language server if set and available
@@ -145,13 +147,13 @@ public class GitHubCopilotBaseService {
145147
}
146148
}
147149
// Set debug port and verbose when running in debug
148-
let environment: [String: String] = ["HOME": home, "GH_COPILOT_DEBUG_UI_PORT": "8080", "GH_COPILOT_VERBOSE": "true"]
150+
let environment: [String: String] = ["HOME": home, "GH_COPILOT_DEBUG_UI_PORT": "8080", "GH_COPILOT_VERBOSE": "true"].merging(nodeExtraCaCertMap) { _, new in new }
149151
#else
150-
let environment: [String: String] = if UserDefaults.shared.value(for: \.verboseLoggingEnabled) {
152+
let environment: [String: String] = (if UserDefaults.shared.value(for: \.verboseLoggingEnabled) {
151153
["HOME": home, "GH_COPILOT_VERBOSE": "true"]
152154
} else {
153155
["HOME": home]
154-
}
156+
}).merging(nodeExtraCaCertMap) { _, new in new }
155157
#endif
156158

157159
let executionParams = Process.ExecutionParameters(
@@ -276,7 +278,7 @@ public class GitHubCopilotBaseService {
276278
}
277279

278280
public final class GitHubCopilotService: GitHubCopilotBaseService,
279-
GitHubCopilotSuggestionServiceType, GitHubCopilotConversationServiceType, GitHubCopilotAuthServiceType
281+
GitHubCopilotSuggestionServiceType, GitHubCopilotConversationServiceType, GitHubCopilotAuthServiceType
280282
{
281283

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

Tool/Sources/Preferences/Keys.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,10 @@ public extension UserDefaultPreferenceKeys {
551551
.init(defaultValue: "", key: "GitHubCopilotEnterpriseURI")
552552
}
553553

554+
var nodeExtraCaCerts: PreferenceKey<String> {
555+
.init(defaultValue: "", key: "NodeExtraCaCerts")
556+
}
557+
554558
var verboseLoggingEnabled: PreferenceKey<Bool> {
555559
.init(defaultValue: false, key: "VerboseLoggingEnabled")
556560
}

0 commit comments

Comments
 (0)