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;
|
return false;
|
||||||
}
|
}
|
||||||
auto v = overload {
|
auto v = overload {
|
||||||
[](const HTTP & x) { return "HTTP"; },
|
[](const HTTP & x) { UNUSED(x); return "HTTP"; },
|
||||||
[](const HTTPUserPass & x) { return "HTTPAuth"; },
|
[](const HTTPUserPass & x) { UNUSED(x); return "HTTPAuth"; },
|
||||||
[](const SSHPass & x) { return "SSHAuth"; },
|
[](const SSHKey & x) { UNUSED(x); return "SSHKey"; },
|
||||||
[](const SSHKey & x) { return "SSHKey"; },
|
|
||||||
};
|
};
|
||||||
qDebug() << "Creating clone Job " << url << " " << path << " " << std::visit(v, mode);
|
qDebug() << "Creating clone Job " << url << " " << path << " " << std::visit(v, mode);
|
||||||
CloneJob *clone_job = new CloneJob(url, path, mode);
|
CloneJob *clone_job = new CloneJob(url, path, mode);
|
||||||
|
@ -18,36 +18,57 @@ GitJob::~GitJob()
|
|||||||
git_libgit2_shutdown();
|
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,
|
int GitJob::credentialsCB(git_cred **out, const char *url, const char *username_from_url,
|
||||||
unsigned int allowed_types, void *payload)
|
unsigned int allowed_types, void *payload)
|
||||||
{
|
{
|
||||||
|
UNUSED(url);
|
||||||
cred_type *cred = (cred_type *)payload;
|
cred_type *cred = (cred_type *)payload;
|
||||||
|
|
||||||
|
if (!username_from_url) {
|
||||||
|
qWarning() << "[GitJob] credentials_cb : no username provided ";
|
||||||
|
return (int) GIT_EUSER;
|
||||||
|
}
|
||||||
|
|
||||||
auto v = overload {
|
auto v = overload {
|
||||||
[](const HTTP & x)
|
[](const HTTP & x)
|
||||||
{
|
{
|
||||||
qDebug() << "[GitJob] credentialsCB : HTTP ";
|
UNUSED(x);
|
||||||
qWarning() << "[GitJob] credentialsCB : callback should never be call for HTTP ";
|
qDebug() << "[GitJob] credentialsCB : None ";
|
||||||
|
qWarning() << "[GitJob] credentialsCB : callback should never be call for None ";
|
||||||
return (int) GIT_EUSER;
|
return (int) GIT_EUSER;
|
||||||
},
|
},
|
||||||
[&out, &username_from_url](const HTTPUserPass & x)
|
[allowed_types, &out, &username_from_url](const HTTPUserPass & x)
|
||||||
{
|
{
|
||||||
qDebug() << "[GitJob] credentialsCB : HTTPUserPass ";
|
qDebug() << "[GitJob] credentialsCB : HTTPUserPass ";
|
||||||
if (!username_from_url) {
|
if (!(allowed_types & GIT_CREDTYPE_USERPASS_PLAINTEXT)) {
|
||||||
qWarning() << "[GitJob] credentials_cb : no username provided ";
|
qWarning() << "[GitJob] credentials_cb : allowed_types is invalid for HTTPUserPass ";
|
||||||
return (int) GIT_EUSER;
|
return (int) GIT_EUSER;
|
||||||
}
|
}
|
||||||
return git_cred_userpass_plaintext_new(out, username_from_url, x.pass.toLocal8Bit().constData());
|
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 ";
|
||||||
return (int) GIT_EUSER;
|
if (!(allowed_types & GIT_CREDTYPE_SSH_KEY)) {
|
||||||
}, // TODO
|
qWarning() << "[GitJob] credentials_cb : allowed_types is invalid for HTTPUserPass ";
|
||||||
[](const SSHKey & x)
|
return (int) GIT_EUSER;
|
||||||
{
|
}
|
||||||
qWarning() << "[GitJob] credentials_cb : SSHKey to be implemented ";
|
return git_cred_ssh_key_new(out, username_from_url, x.pub_key.toLocal8Bit().constData(),
|
||||||
return (int) GIT_EUSER;
|
x.priv_key.toLocal8Bit().constData(), x.passphrase.toLocal8Bit().constData());
|
||||||
} // TODO
|
}
|
||||||
};
|
};
|
||||||
return std::visit(v, *cred);
|
auto error = std::visit(v, *cred);
|
||||||
|
return error;
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,17 @@ extern "C" {
|
|||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
// Forward declarations for the different credential types.
|
// Forward declarations for the different credential types.
|
||||||
struct HTTP { };
|
struct HTTP {};
|
||||||
struct HTTPUserPass {
|
struct HTTPUserPass {
|
||||||
QString pass; ///< Password for HTTP user authentication.
|
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.
|
* @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:
|
* This type is used to store one of the following credential types:
|
||||||
* - HTTP
|
* - HTTP
|
||||||
* - HTTPUserPass
|
* - HTTPUserPass
|
||||||
* - SSHPass
|
|
||||||
* - SSHKey
|
* - SSHKey
|
||||||
*/
|
*/
|
||||||
typedef std::variant<HTTP, HTTPUserPass, SSHPass, SSHKey> cred_type;
|
typedef std::variant<HTTP, HTTPUserPass, SSHKey> cred_type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class GitJob
|
* @class GitJob
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef UTILS_H
|
#ifndef UTILS_H
|
||||||
#define UTILS_H
|
#define UTILS_H
|
||||||
|
|
||||||
|
#define UNUSED(x) (void)(x)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A utility structure for enabling function overloading with template-based classes.
|
* @brief A utility structure for enabling function overloading with template-based classes.
|
||||||
* see : https://stackoverflow.com/a/64018031
|
* see : https://stackoverflow.com/a/64018031
|
||||||
|
Loading…
x
Reference in New Issue
Block a user