mirror of
https://github.com/QRouland/UTPass.git
synced 2025-02-24 12:14:57 +00:00
Add initial ssh support in git cpp plugin
This commit is contained in:
parent
ec4ebca950
commit
6306af6dde
@ -30,10 +30,9 @@ bool Git::clone(QString url, QString path, cred_type mode)
|
||||
return false;
|
||||
}
|
||||
auto v = overload {
|
||||
[](const HTTP & x) { return "HTTP"; },
|
||||
[](const HTTPUserPass & x) { return "HTTPAuth"; },
|
||||
[](const SSHPass & x) { return "SSHAuth"; },
|
||||
[](const SSHKey & x) { return "SSHKey"; },
|
||||
[](const HTTP & x) { UNUSED(x); return "HTTP"; },
|
||||
[](const HTTPUserPass & x) { UNUSED(x); return "HTTPAuth"; },
|
||||
[](const SSHKey & x) { UNUSED(x); return "SSHKey"; },
|
||||
};
|
||||
qDebug() << "Creating clone Job " << url << " " << path << " " << std::visit(v, mode);
|
||||
CloneJob *clone_job = new CloneJob(url, path, mode);
|
||||
|
@ -18,36 +18,57 @@ GitJob::~GitJob()
|
||||
git_libgit2_shutdown();
|
||||
}
|
||||
|
||||
bool GitJob::getUsername(char **username, QString maybe_username, const char *username_from_url)
|
||||
{
|
||||
if (username_from_url) {
|
||||
*username = strdup(username_from_url);
|
||||
return true;
|
||||
} else if (!maybe_username.isNull()) {
|
||||
*username = maybe_username.toLocal8Bit().data();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int GitJob::credentialsCB(git_cred **out, const char *url, const char *username_from_url,
|
||||
unsigned int allowed_types, void *payload)
|
||||
{
|
||||
UNUSED(url);
|
||||
cred_type *cred = (cred_type *)payload;
|
||||
auto v = overload {
|
||||
[](const HTTP & x)
|
||||
{
|
||||
qDebug() << "[GitJob] credentialsCB : HTTP ";
|
||||
qWarning() << "[GitJob] credentialsCB : callback should never be call for HTTP ";
|
||||
return (int) GIT_EUSER;
|
||||
},
|
||||
[&out, &username_from_url](const HTTPUserPass & x)
|
||||
{
|
||||
qDebug() << "[GitJob] credentialsCB : HTTPUserPass ";
|
||||
|
||||
if (!username_from_url) {
|
||||
qWarning() << "[GitJob] credentials_cb : no username provided ";
|
||||
return (int) GIT_EUSER;
|
||||
}
|
||||
|
||||
auto v = overload {
|
||||
[](const HTTP & x)
|
||||
{
|
||||
UNUSED(x);
|
||||
qDebug() << "[GitJob] credentialsCB : None ";
|
||||
qWarning() << "[GitJob] credentialsCB : callback should never be call for None ";
|
||||
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 ";
|
||||
return (int) GIT_EUSER;
|
||||
}
|
||||
return git_cred_userpass_plaintext_new(out, username_from_url, x.pass.toLocal8Bit().constData());
|
||||
},
|
||||
[](const SSHPass & x)
|
||||
[allowed_types, &out, &username_from_url](const SSHKey & x)
|
||||
{
|
||||
qWarning() << "[GitJob] credentials_cb : SSHAuth to be implemented ";
|
||||
qDebug() << "[GitJob] credentialsCB : SSHKey ";
|
||||
if (!(allowed_types & GIT_CREDTYPE_SSH_KEY)) {
|
||||
qWarning() << "[GitJob] credentials_cb : allowed_types is invalid for HTTPUserPass ";
|
||||
return (int) GIT_EUSER;
|
||||
}, // TODO
|
||||
[](const SSHKey & x)
|
||||
{
|
||||
qWarning() << "[GitJob] credentials_cb : SSHKey to be implemented ";
|
||||
return (int) GIT_EUSER;
|
||||
} // TODO
|
||||
};
|
||||
return std::visit(v, *cred);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
@ -12,8 +12,13 @@ struct HTTP { };
|
||||
struct HTTPUserPass {
|
||||
QString pass; ///< Password for HTTP user authentication.
|
||||
};
|
||||
struct SSHPass { };
|
||||
struct SSHKey { };
|
||||
struct SSHKey {
|
||||
QString pub_key; ///< public key path.
|
||||
QString priv_key; ///< private key path.
|
||||
QString passphrase; ///< key passphrase.
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Variant type to represent various types of credentials.
|
||||
@ -21,10 +26,9 @@ struct SSHKey { };
|
||||
* This type is used to store one of the following credential types:
|
||||
* - HTTP
|
||||
* - HTTPUserPass
|
||||
* - SSHPass
|
||||
* - SSHKey
|
||||
*/
|
||||
typedef std::variant<HTTP, HTTPUserPass, SSHPass, SSHKey> cred_type;
|
||||
typedef std::variant<HTTP, HTTPUserPass, SSHKey> cred_type;
|
||||
|
||||
/**
|
||||
* @class GitJob
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
#define UNUSED(x) (void)(x)
|
||||
|
||||
/**
|
||||
* @brief A utility structure for enabling function overloading with template-based classes.
|
||||
* see : https://stackoverflow.com/a/64018031
|
||||
|
Loading…
x
Reference in New Issue
Block a user