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

@ -41,7 +41,7 @@ bool Git::clone(QString url, QString path, cred_type mode)
[](const HTTPUserPass & x) { UNUSED(x); return "HTTPAuth"; },
[](const SSHKey & x) { UNUSED(x); return "SSHKey"; },
};
qDebug() << "Creating clone Job " << url << " " << path << " " << std::visit(v, mode);
qDebug() << "[Git] Creating clone Job " << url << " " << path << " " << std::visit(v, mode);
CloneJob *clone_job = new CloneJob(url, path, mode);
connect(clone_job, &CloneJob::resultReady, this, &Git::cloneResult);
connect(clone_job, &CloneJob::finished, clone_job, &QObject::deleteLater);
@ -65,7 +65,7 @@ bool Git::cloneHttpPass(QString url, QString path, QString pass)
bool Git::cloneSshKey(QString url, QString path, QString passphrase)
{
qInfo() << "[Git] Call clone command HttpPass " << url << " " << path;
qInfo() << "[Git] Call clone command SshKey " << url << " " << path;
SSHKey mode = { this->pubKeyPath(), this->privKeyPath(), passphrase };
return this->clone(url, path, mode);

View File

@ -56,7 +56,7 @@ private:
* @brief Clones a repository from a specified URL.
*
* This private method initiates the cloning job. It sets up the repository cloning process based on
* the specified URL, destination path, and cloning mode (HTTP or SSH).
* the specified URL, destination path, and cloning mode (HTTP, HTTP_AUTH or SSH).
*
* @param url The URL of the Git repository to clone.
* @param path The destination path for the cloned repository.
@ -90,14 +90,14 @@ public:
/**
* @brief Constructor for the Git class.
*
* Initializes the `Git` class, setting up necessary resources such as the semaphore for concurrent operation management.
* Initializes the `Git` class.
*/
Git();
/**
* @brief Destructor for the Git class.
*
* Cleans up any resources used by the `Git` class, ensuring that no ongoing operations or resources are left hanging.
* Cleans up any resources used by the `Git` class.
*/
~Git() override;
@ -108,11 +108,10 @@ public:
* @brief Clones a repository over HTTP.
*
* This method clones a Git repository from the specified HTTP URL and saves it to the given destination path.
* It is a wrapper around the private `clone()` method, specifying the HTTP cloning mode.
*
* @param url The HTTP URL of the Git repository to clone.
* @param path The destination path for the cloned repository.
* @return `true` if the clone operation was successful, `false` otherwise.
* @return `true` if the clone operation was successfully started, `false` otherwise.
*/
Q_INVOKABLE bool cloneHttp(QString url, QString path);

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.