Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[ssu] Expose new dbus API for updating the store credentials.
  • Loading branch information
kananoja committed Nov 8, 2013
1 parent 4b4afe9 commit 38a3052
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
4 changes: 4 additions & 0 deletions dbus/org.nemo.ssu.xml
Expand Up @@ -88,6 +88,10 @@
</method>
<method name="updateRepos">
</method>
<method name="updateStoreCredentials">
<arg direction="in" type="s" name="userName" />
<arg direction="in" type="s" name="accessToken" />
</method>

<method name="error">
<arg direction="out" type="b" name="status"/>
Expand Down
24 changes: 7 additions & 17 deletions libssu/ssu.cpp
Expand Up @@ -609,23 +609,13 @@ void Ssu::updateCredentials(bool force){
manager->get(request);
}

void Ssu::updateStoreCredentials(){
QDBusMessage message = QDBusMessage::createMethodCall("com.jolla.jollastore",
"/StoreClient",
"com.jolla.jollastore",
"storeCredentials");
QDBusPendingReply<QString, QString> reply = QDBusConnection::sessionBus().asyncCall(message);
reply.waitForFinished();
if (reply.isError()) {
setError(QString("Store credentials not received. %1").arg(reply.error().message()));
} else {
SsuCoreConfig *settings = SsuCoreConfig::instance();
settings->beginGroup("credentials-store");
settings->setValue("username", reply.argumentAt<0>());
settings->setValue("password", reply.argumentAt<1>());
settings->endGroup();
settings->sync();
}
void Ssu::updateStoreCredentials(const QString &userName, const QString &accessToken){
SsuCoreConfig *settings = SsuCoreConfig::instance();
settings->beginGroup("credentials-store");
settings->setValue("username", userName);
settings->setValue("password", accessToken);
settings->endGroup();
settings->sync();
}

void Ssu::unregister(){
Expand Down
2 changes: 1 addition & 1 deletion libssu/ssu.h
Expand Up @@ -180,7 +180,7 @@ class Ssu: public QObject {
/**
* Try to update credentials for (Jolla) store
*/
void updateStoreCredentials();
void updateStoreCredentials(const QString &userName, const QString &accessToken);

signals:
/**
Expand Down
5 changes: 5 additions & 0 deletions ssud/ssud.cpp
Expand Up @@ -194,3 +194,8 @@ void Ssud::updateRepos(){
repoManager.update();
autoclose.start();
}

void Ssud::updateStoreCredentials(const QString &userName, const QString &accessToken){
ssu.updateStoreCredentials(userName, accessToken);
autoclose.start();
}
1 change: 1 addition & 0 deletions ssud/ssud.h
Expand Up @@ -42,6 +42,7 @@ class Ssud: public QObject {
void modifyRepo(int action, const QString &repo);
void addRepo(const QString &repo, const QString &url);
void updateRepos();
void updateStoreCredentials(const QString &userName, const QString &accessToken);

bool error();
QString lastError();
Expand Down
11 changes: 6 additions & 5 deletions ssuurlresolver/ssuurlresolver.cpp
Expand Up @@ -139,11 +139,12 @@ void SsuUrlResolver::run(){
// store-auth-repos domain setting use store credentials. Refresh
// here, as we only know after checking scope if we need to have
// store credentials at all
if (credentialsScope == "store"){
ssu.updateStoreCredentials();
if (ssu.error())
error (ssu.lastError());
}

// store-client updates the store credentials via dbus call on
// every startup (or sign in to be precise).
// TODO: Is there need to check that the credentials were really
// set by store-client?

headerList.append(QString("credentials=%1").arg(credentialsScope));
writeZyppCredentialsIfNeeded(credentialsScope);
} else
Expand Down

0 comments on commit 38a3052

Please sign in to comment.