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

feat: support secure interactions with private repositories 🔒 #806

Merged
merged 8 commits into from
Nov 20, 2024
Prev Previous commit
Next Next commit
fix: use isomorphic-git to support secure clone of repositories (#552)
  • Loading branch information
JamieSlome committed Nov 20, 2024
commit 55ddf0cc02cfb880e899fe644bfdb4e2a80162a3
36 changes: 25 additions & 11 deletions src/proxy/processors/push-action/pullRemote.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const spawnSync = require('child_process').spawnSync;
const Step = require('../../actions').Step;
const fs = require('fs');
const dir = './.remote';
const git = require('isomorphic-git');
const http = require('isomorphic-git/http/node');

JamieSlome marked this conversation as resolved.
Show resolved Hide resolved
const exec = async (req, action) => {
const step = new Step('pullRemote');
Expand All @@ -19,20 +20,33 @@ const exec = async (req, action) => {
fs.mkdirSync(action.proxyGitPath, '0755', true);
}

const cmd = `git clone ${action.url} --bare`;

const cmd = `git clone ${action.url}`;
step.log(`Exectuting ${cmd}`);

const response = spawnSync('git', ['clone', action.url, '--bare', '--progress'], {
cwd: action.proxyGitPath,
encoding: 'utf-8',
});

const cloneOutput = response?.stderr;
step.log(cloneOutput);
const authHeader = req.headers?.authorization;
const [username, password] = Buffer.from(authHeader.split(' ')[1], 'base64')
.toString()
.split(':');

await git
.clone({
fs,
http,
url: action.url,
JamieSlome marked this conversation as resolved.
Show resolved Hide resolved
onAuth: () => {
return {
username: username,
password: password,
};
},
dir: `${action.proxyGitPath}/${action.repoName}`,
JamieSlome marked this conversation as resolved.
Show resolved Hide resolved
})
.then(() => {
console.log('Clone Success: ', action.url);
});

JamieSlome marked this conversation as resolved.
Show resolved Hide resolved
step.log(`Completed ${cmd}`);
step.setContent(cloneOutput);
step.setContent(`Completed ${cmd}`);
} catch (e) {
JamieSlome marked this conversation as resolved.
Show resolved Hide resolved
step.setError(e.toString('utf-8'));
throw e;
Expand Down
Loading