Skip to content

Commit 105cf4b

Browse files
committed
fix: migrated github to universal git, fixed stream errors
1 parent ed31582 commit 105cf4b

File tree

2 files changed

+43
-36
lines changed

2 files changed

+43
-36
lines changed

proxy.config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@
108108
"enabled": true,
109109
"port": 2222,
110110
"hostKey": {
111-
"privateKeyPath": "/Users/dcoric/.ssh/bb_rsa",
112-
"publicKeyPath": "/Users/dcoric/.ssh/bb_rsa.pub"
111+
"privateKeyPath": "/Users/dcoric/.ssh/id_rsa",
112+
"publicKeyPath": "/Users/dcoric/.ssh/id_rsa.pub"
113113
}
114114
}
115115
}

src/proxy/ssh/server.js

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,13 @@ class SSHServer {
158158
}
159159

160160
// Create SSH connection to GitHub
161-
const githubSsh = new ssh2.Client();
161+
const remoteGitSsh = new ssh2.Client();
162162

163163
console.log('[SSH] Creating SSH connection to GitHub');
164164

165165
// Add connection options
166166
const connectionOptions = {
167-
host: 'github.com',
167+
host: config.getProxyUrl().replace('https://', ''),
168168
port: 22,
169169
username: 'git',
170170
keepaliveInterval: 10000, // Send keepalive every 10 seconds
@@ -176,6 +176,8 @@ class SSHServer {
176176
},
177177
};
178178

179+
console.log('[SSH] Connection options', connectionOptions);
180+
179181
// Get the client's SSH key that was used for authentication
180182
const clientKey = session._channel._client.userPrivateKeyz;
181183
console.log('[SSH] Client key:', clientKey ? 'Available' : 'Not available');
@@ -191,49 +193,54 @@ class SSHServer {
191193
);
192194
}
193195

194-
githubSsh.on('ready', () => {
196+
remoteGitSsh.on('ready', () => {
195197
console.log('[SSH] Connected to GitHub');
196198

197199
// Execute the Git command on GitHub
198-
githubSsh.exec(command, { env: { GIT_PROTOCOL: 'version=2' } }, (err, githubStream) => {
199-
if (err) {
200-
console.error('[SSH] Failed to execute command on GitHub:', err);
201-
stream.write(err.toString());
202-
stream.end();
203-
return;
204-
}
205-
206-
// Handle stream errors
207-
githubStream.on('error', (err) => {
208-
console.error('[SSH] GitHub stream error:', err);
209-
stream.write(err.toString());
210-
stream.end();
211-
});
212-
213-
// Handle stream close
214-
githubStream.on('close', () => {
215-
console.log('[SSH] GitHub stream closed');
216-
githubSsh.end();
217-
});
218-
219-
// Pipe data between client and GitHub
220-
stream.pipe(githubStream).pipe(stream);
221-
222-
githubStream.on('exit', (code) => {
223-
console.log(`[SSH] GitHub command exited with code ${code}`);
224-
githubSsh.end();
225-
});
226-
});
200+
remoteGitSsh.exec(
201+
command,
202+
{ env: { GIT_PROTOCOL: 'version=2' } },
203+
(err, githubStream) => {
204+
if (err) {
205+
console.error('[SSH] Failed to execute command on GitHub:', err);
206+
stream.write(err.toString());
207+
stream.end();
208+
return;
209+
}
210+
211+
// Handle stream errors
212+
githubStream.on('error', (err) => {
213+
console.error('[SSH] GitHub stream error:', err);
214+
stream.write(err.toString());
215+
stream.end();
216+
});
217+
218+
// Handle stream close
219+
githubStream.on('close', () => {
220+
console.log('[SSH] GitHub stream closed');
221+
stream.pipe(githubStream).pipe(stream);
222+
remoteGitSsh.end();
223+
});
224+
225+
// Pipe data between client and GitHub
226+
stream.pipe(githubStream).pipe(stream);
227+
228+
githubStream.on('exit', (code) => {
229+
console.log(`[SSH] GitHub command exited with code ${code}`);
230+
remoteGitSsh.end();
231+
});
232+
},
233+
);
227234
});
228235

229-
githubSsh.on('error', (err) => {
236+
remoteGitSsh.on('error', (err) => {
230237
console.error('[SSH] GitHub SSH error:', err);
231238
stream.write(err.toString());
232239
stream.end();
233240
});
234241

235242
// Connect to GitHub
236-
githubSsh.connect(connectionOptions);
243+
remoteGitSsh.connect(connectionOptions);
237244
} catch (error) {
238245
console.error('[SSH] Error during SSH connection:', error);
239246
stream.write(error.toString());

0 commit comments

Comments
 (0)