1
0
mirror of https://github.com/QRouland/UTPass.git synced 2025-06-24 22:42:28 +00:00

Some improvements

This commit is contained in:
2025-03-12 15:34:33 +01:00
parent 884488b9ed
commit bdb2d58ac4
14 changed files with 117 additions and 37 deletions

View File

@ -37,7 +37,7 @@ QDir CloneJob::cloneSetup()
QDir tmp_dir(QStandardPaths::writableLocation( QStandardPaths::CacheLocation).append("/clone"));
tmp_dir.removeRecursively();
qDebug() << "[CloneJob]Temp dir path is " << tmp_dir.absolutePath();
qDebug() << "[CloneJob] Temp dir path is " << tmp_dir.absolutePath();
return tmp_dir;
}
@ -64,9 +64,10 @@ bool CloneJob::clone(QString url, QString path, cred_type cred, git_cred_acquire
{
git_repository *repo = NULL;
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
PayloadCB payload = PayloadCB(false, cred);
opts.fetch_opts.callbacks.credentials = cb;
opts.fetch_opts.callbacks.payload = &cred;
opts.fetch_opts.callbacks.payload = &payload;
int ret = git_clone(&repo, url.toLocal8Bit().data(), path.toLocal8Bit().data(), &opts);
if (ret == GIT_EUSER ) {

View File

@ -24,26 +24,32 @@ int GitJob::credentialsCB(git_cred **out, const char *url, const char *username_
unsigned int allowed_types, void *payload)
{
UNUSED(url);
cred_type *cred = (cred_type *)payload;
PayloadCB *p = (PayloadCB *)payload;
if (!username_from_url) {
qWarning() << "[GitJob] credentials_cb : no username provided ";
if (!username_from_url) { // we required here that the username must be provided directly in url (maybe improve later on)
qWarning() << "[GitJob] credentials_cb : no username provided";
return (int) GIT_EUSER;
}
if (p->called) {
qWarning() << "[GitJob] credentials_cb : cb already called, probably invalid creds";
return (int) GIT_EUSER;
}
p->called = true;
auto v = overload {
[](const HTTP & x)
{
UNUSED(x);
qDebug() << "[GitJob] credentialsCB : None ";
qWarning() << "[GitJob] credentialsCB : callback should never be call for None ";
qDebug() << "[GitJob] credentialsCB : HTTP ";
qWarning() << "[GitJob] credentialsCB : callback should never be call for HTTP";
return (int) GIT_EUSER;
},
[allowed_types, &out, &username_from_url](const HTTPUserPass & x)
{
qDebug() << "[GitJob] credentialsCB : HTTPUserPass ";
if (!(allowed_types & GIT_CREDTYPE_USERPASS_PLAINTEXT)) {
qWarning() << "[GitJob] credentials_cb : allowed_types is invalid for HTTPUserPass ";
qWarning() << "[GitJob] credentials_cb : allowed_types is invalid for HTTPUserPass creds";
return (int) GIT_EUSER;
}
return git_cred_userpass_plaintext_new(out, username_from_url, x.pass.toLocal8Bit().constData());
@ -52,13 +58,17 @@ int GitJob::credentialsCB(git_cred **out, const char *url, const char *username_
{
qDebug() << "[GitJob] credentialsCB : SSHKey ";
if (!(allowed_types & GIT_CREDTYPE_SSH_KEY)) {
qWarning() << "[GitJob] credentials_cb : allowed_types is invalid for HTTPUserPass ";
qWarning() << "[GitJob] credentials_cb : allowed_types is invalid for SSHKey creds";
return (int) GIT_EUSER;
}
qDebug() << "[GitJob] username_from_url :" << username_from_url;
qDebug() << "[GitJob] pub_key :" << x.pub_key.toLocal8Bit().constData();
qDebug() << "[GitJob] priv_key :" << x.priv_key.toLocal8Bit().constData();
qDebug() << "[GitJob] passphrase :" << x.passphrase.toLocal8Bit().constData();
return git_cred_ssh_key_new(out, username_from_url, x.pub_key.toLocal8Bit().constData(),
x.priv_key.toLocal8Bit().constData(), x.passphrase.toLocal8Bit().constData());
}
};
auto error = std::visit(v, *cred);
return error;
auto ret = std::visit(v, p->creds);
return ret;
}

View File

@ -31,6 +31,14 @@ struct SSHKey {
*/
typedef std::variant<HTTP, HTTPUserPass, SSHKey> cred_type;
struct PayloadCB
{
bool called;
cred_type creds;
PayloadCB(bool ca, cred_type cr): called(ca), creds(cr) {}
};
/**
* @class GitJob
* @brief A class that manages Git-related tasks using libgit2.