Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refresh credentials on any repo on registered devices; add logging
  • Loading branch information
Bernd Wachter committed Mar 11, 2013
1 parent 5136cc3 commit 0e18dbd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
44 changes: 31 additions & 13 deletions ssuurlresolver/ssuurlresolver.cpp
Expand Up @@ -31,6 +31,29 @@ void SsuUrlResolver::printJournal(int priority, QString message){
}
}

bool SsuUrlResolver::writeCredentials(QString filePath, QString credentialsScope){
QFile credentialsFile(filePath);
QPair<QString, QString> credentials = ssu.credentials(credentialsScope);

if (credentials.first == "" || credentials.second == ""){
printJournal(LOG_WARNING, "Returned credentials are empty, skip writing");
return false;
}

if (!credentialsFile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)){
printJournal(LOG_WARNING, "Unable to open credentials file for writing");
return false;
}

QTextStream out(&credentialsFile);
out << "[" << ssu.credentialsUrl(credentialsScope) << "]\n";
out << "username=" << credentials.first << "\n";
out << "password=" << credentials.second << "\n";
out.flush();
credentialsFile.close();
return true;
}

void SsuUrlResolver::run(){
QHash<QString, QString> repoParameters;
QString resolvedUrl, repo;
Expand Down Expand Up @@ -77,12 +100,13 @@ void SsuUrlResolver::run(){
if (!ssu.useSslVerify())
headerList.append("ssl_verify=no");

if (isRnd){
if (isRnd || ssu.isRegistered()){
SignalWait w;
connect(&ssu, SIGNAL(done()), &w, SLOT(finished()));
ssu.updateCredentials();
w.sleep();
}
} else
printJournal(LOG_DEBUG, "No RnD repository, and device not registered -- skipping credential update");

// TODO: check for credentials scope required for repository; check if the file exists;
// compare with configuration, and dump credentials to file if necessary
Expand All @@ -94,17 +118,11 @@ void SsuUrlResolver::run(){
QFileInfo credentialsFileInfo("/etc/zypp/credentials.d/" + credentialsScope);
if (!credentialsFileInfo.exists() ||
credentialsFileInfo.lastModified() <= ssu.lastCredentialsUpdate()){
QFile credentialsFile(credentialsFileInfo.filePath());
credentialsFile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate);
QTextStream out(&credentialsFile);
QPair<QString, QString> credentials = ssu.credentials(credentialsScope);
out << "[" << ssu.credentialsUrl(credentialsScope) << "]\n";
out << "username=" << credentials.first << "\n";
out << "password=" << credentials.second << "\n";
out.flush();
credentialsFile.close();
}
}
writeCredentials(credentialsFileInfo.filePath(), credentialsScope);
} else
printJournal(LOG_DEBUG, "Skipping credential update -- file exists and was modified after last update");
} else
printJournal(LOG_DEBUG, "Skipping credential update due to missing credentials scope");

if (headerList.isEmpty()){
resolvedUrl = ssu.repoUrl(repo, isRnd, repoParameters);
Expand Down
1 change: 1 addition & 0 deletions ssuurlresolver/ssuurlresolver.h
Expand Up @@ -53,6 +53,7 @@ class SsuUrlResolver: public QObject {
private:
Ssu ssu;
void printJournal(int priority, QString message);
bool writeCredentials(QString filePath, QString credentialsScope);

public slots:
void run();
Expand Down

0 comments on commit 0e18dbd

Please sign in to comment.