Commit 8499335d authored by Pekka Lundstrom's avatar Pekka Lundstrom

Implemented domain and domain-specific blocks in respos.ini

Signed-off-by: default avatarPekka Lundstrom <pekka.lundstrom@jollamobile.com>
parent 881a7833
...@@ -256,6 +256,13 @@ QString Ssu::flavour(){ ...@@ -256,6 +256,13 @@ QString Ssu::flavour(){
return "release"; return "release";
} }
QString Ssu::domain(){
if (settings->contains("domain"))
return settings->value("domain").toString();
else
return "";
}
bool Ssu::isRegistered(){ bool Ssu::isRegistered(){
if (!settings->contains("privateKey")) if (!settings->contains("privateKey"))
return false; return false;
...@@ -352,6 +359,19 @@ QString Ssu::repoUrl(QString repoName, bool rndRepo, QHash<QString, QString> rep ...@@ -352,6 +359,19 @@ QString Ssu::repoUrl(QString repoName, bool rndRepo, QHash<QString, QString> rep
repoParameters.insert("deviceFamily", deviceFamily()); repoParameters.insert("deviceFamily", deviceFamily());
repoParameters.insert("deviceModel", deviceModel()); repoParameters.insert("deviceModel", deviceModel());
// Domain variables
QString domainSection = domain() + "-domain";
QStringList sections = repoSettings->childGroups();
if (sections.contains(domainSection))
repoSettings->beginGroup(domainSection);
else
repoSettings->beginGroup("default-domain");
QStringList domainKeys = repoSettings->allKeys();
foreach (const QString &key, domainKeys){
repoParameters.insert(key, repoSettings->value(key).toString());
}
repoSettings->endGroup();
if (settings->contains("repository-urls/" + repoName)) if (settings->contains("repository-urls/" + repoName))
r = settings->value("repository-urls/" + repoName).toString(); r = settings->value("repository-urls/" + repoName).toString();
else { else {
...@@ -451,8 +471,11 @@ void Ssu::sendRegistration(QString username, QString password){ ...@@ -451,8 +471,11 @@ void Ssu::sendRegistration(QString username, QString password){
ssuCaCertificate = settings->value("ca-certificate").toString(); ssuCaCertificate = settings->value("ca-certificate").toString();
if (!settings->contains("register-url")){ if (!settings->contains("register-url")){
setError("URL for SSU registration not set (config key 'register-url')"); ssuRegisterUrl = repoUrl("register-url");
return; if (ssuRegisterUrl.isEmpty()){
setError("URL for SSU registration not set (config key 'register-url')");
return;
}
} else } else
ssuRegisterUrl = settings->value("register-url").toString(); ssuRegisterUrl = settings->value("register-url").toString();
...@@ -565,6 +588,11 @@ void Ssu::setRelease(QString release, bool rnd){ ...@@ -565,6 +588,11 @@ void Ssu::setRelease(QString release, bool rnd){
settings->setValue("release", release); settings->setValue("release", release);
} }
void Ssu::setDomain(QString domain){
settings->setValue("domain", domain);
settings->sync();
}
void Ssu::storeAuthorizedKeys(QByteArray data){ void Ssu::storeAuthorizedKeys(QByteArray data){
QDir dir; QDir dir;
...@@ -605,8 +633,11 @@ void Ssu::updateCredentials(bool force){ ...@@ -605,8 +633,11 @@ void Ssu::updateCredentials(bool force){
ssuCaCertificate = settings->value("ca-certificate").toString(); ssuCaCertificate = settings->value("ca-certificate").toString();
if (!settings->contains("credentials-url")){ if (!settings->contains("credentials-url")){
setError("URL for credentials update not set (config key 'credentials-url')"); ssuCredentialsUrl = repoUrl("credentials-url");
return; if (ssuCredentialsUrl.isEmpty()){
setError("URL for credentials update not set (config key 'credentials-url')");
return;
}
} else } else
ssuCredentialsUrl = settings->value("credentials-url").toString(); ssuCredentialsUrl = settings->value("credentials-url").toString();
......
...@@ -64,6 +64,11 @@ class Ssu: public QObject { ...@@ -64,6 +64,11 @@ class Ssu: public QObject {
* @return current flavour (usually something like testing, release, ..) * @return current flavour (usually something like testing, release, ..)
*/ */
Q_INVOKABLE QString flavour(); Q_INVOKABLE QString flavour();
/**
* Get the current domain used in registration
* @return domain, or "" if not set
*/
Q_INVOKABLE QString domain();
/** /**
* Return devices RND registration status * Return devices RND registration status
* @retval true device is registered * @retval true device is registered
...@@ -98,6 +103,10 @@ class Ssu: public QObject { ...@@ -98,6 +103,10 @@ class Ssu: public QObject {
* Set the release version string for either a release, or a RnD snapshot * Set the release version string for either a release, or a RnD snapshot
*/ */
Q_INVOKABLE void setRelease(QString release, bool rnd=false); Q_INVOKABLE void setRelease(QString release, bool rnd=false);
/**
* Set the domain string (usually something like nemo, jolla, ..)
*/
Q_INVOKABLE void setDomain(QString domain);
/** /**
* Unregister a device. This will clean all registration data from a device, * Unregister a device. This will clean all registration data from a device,
* though will not touch the information on SSU server; the information there * though will not touch the information on SSU server; the information there
......
...@@ -34,26 +34,26 @@ ...@@ -34,26 +34,26 @@
[all] [all]
credentials=jolla credentials=jolla
credentials-url=https://%(ssuRegDomain)/%(ssuRegPath)/%1/credentials.xml
register-url=https://%(ssuRegDomain)/%(ssuRegPath)/%1/register.xml
[release] [release]
jolla=https://packages.example.com/releases/%(release)/jolla/%(arch)/ jolla=https://%(packagesDomain)/releases/%(release)/jolla/%(arch)/
jolla-bad=https://packages.example.com/notused-bad/%(release)/bad/%(arch)/ jolla-bad=https://%(packagesDomain)/notused-bad/%(release)/bad/%(arch)/
mer-core=https://packages.example.com/%(release)/mer/%(arch)/%(debugSplit)/ mer-core=https://%(packagesDomain)/%(release)/mer/%(arch)/%(debugSplit)/
adaptation-common-main=https://packages.example.com/releases/%(release)/nemo/adaptation-%(deviceFamily)-common/%(arch)/ adaptation-common-main=https://%(packagesDomain)/releases/%(release)/nemo/adaptation-%(deviceFamily)-common/%(arch)/
adaptation=https://packages.example.com/releases/%(release)/nemo/adaptation-%(adaptation)/%(arch)/ adaptation=https://%(packagesDomain)/releases/%(release)/nemo/adaptation-%(adaptation)/%(arch)/
nemo=https://packages.example.com/releases/%(release)/nemo/platform/%(arch)/ nemo=https://%(packagesDomain)/releases/%(release)/nemo/platform/%(arch)/
[rnd] [rnd]
mer-core=https://packages.example.com/mer/%(release)/builds/%(arch)/%(debugSplit)/ mer-core=https://%(packagesDomain)/mer/%(release)/builds/%(arch)/%(debugSplit)/
adaptation-common-main=https://packages.example.com/nemo/%(release)/adaptation-%(adaptation)-common/%(arch)/ adaptation-common-main=https://%(packagesDomain)/nemo/%(release)/adaptation-%(adaptation)-common/%(arch)/
adaptation=https://packages.example.com/nemo/%(release)/adaptation-%(deviceFamily)/%(arch)/ adaptation=https://%(packagesDomain)/nemo/%(release)/adaptation-%(deviceFamily)/%(arch)/
nemo=https://packages.example.com/nemo/%(release)/platform/%(arch)/ nemo=https://%(packagesDomain)/nemo/%(release)/platform/%(arch)/
non-oss-bad=https://dump.example.com/pj:/non-oss-bad%(flavour)/%(release)_%(arch)/ non-oss-bad=https://%(dumpDomain)/pj:/non-oss-bad%(flavour)/%(release)_%(arch)/
non-oss=https://dump.example.com/pj:/non-oss%(flavour)/%(release)_%(arch)/ non-oss=https://%(dumpDomain)/pj:/non-oss%(flavour)/%(release)_%(arch)/
oss-bad=https://dump.example.com/pj:/oss-bad%(flavour)/%(release)_%(arch)/ oss-bad=https://%(dumpDomain)/pj:/oss-bad%(flavour)/%(release)_%(arch)/
oss=https://dump.example.com/pj:/oss%(flavour)/%(release)_%(arch)/ oss=https://%(dumpDomain)/pj:/oss%(flavour)/%(release)_%(arch)/
[devel-flavour] [devel-flavour]
flavour-pattern= flavour-pattern=
...@@ -63,3 +63,16 @@ flavour-pattern=:/release ...@@ -63,3 +63,16 @@ flavour-pattern=:/release
[testing-flavour] [testing-flavour]
flavour-pattern=:/testing flavour-pattern=:/testing
[example-domain]
dumpDomain=dump.example.com
packagesDomain=packages.example.com
ssuRegDomain=ssu.example.com
ssuRegPath=ssu/device
# fallback if domain is not matched or not set
[default-domain]
dumpDomain=dump.testing.com
packagesDomain=packages.testing.com
ssuRegDomain=ssu.testing.com
ssuRegPath=ssu/device
...@@ -8,10 +8,8 @@ rndRelease=latest ...@@ -8,10 +8,8 @@ rndRelease=latest
release= release=
adaptation= adaptation=
ca-certificate= ca-certificate=
credentials-url=https://example.com/ssu/device/%1/credentials.xml
register-url=https://example.com/ssu/device/%1/register.xml
credentials-scope=example credentials-scope=example
[2] [2]
release=latest release=latest
credentials-url-example=https://example.com
...@@ -6,8 +6,6 @@ rndRelease=latest ...@@ -6,8 +6,6 @@ rndRelease=latest
release= release=
adaptation= adaptation=
ca-certificate= ca-certificate=
credentials-url=https://example.com/ssu/device/%1/credentials.xml
register-url=https://example.com/ssu/device/%1/register.xml
credentials-scope=example credentials-scope=example
[repository-urls] [repository-urls]
......
...@@ -60,6 +60,28 @@ void UrlResolverTest::checkRelease(){ ...@@ -60,6 +60,28 @@ void UrlResolverTest::checkRelease(){
ssu.setRelease("latest", true); ssu.setRelease("latest", true);
} }
void UrlResolverTest::checkDomain(){
QString credentialsUrl;
QString registerUrl;
// domain not defined -> default
ssu.setDomain("");
credentialsUrl = ssu.repoUrl("credentials-url");
QCOMPARE(credentialsUrl, QString("https://ssu.testing.com/ssu/device/%1/credentials.xml"));
// domain defined but not matching block -> default
ssu.setDomain("nevermind");
credentialsUrl = ssu.repoUrl("credentials-url");
QCOMPARE(credentialsUrl, QString("https://ssu.testing.com/ssu/device/%1/credentials.xml"));
ssu.setDomain("example");
QCOMPARE(ssu.domain(), QString("example"));
credentialsUrl = ssu.repoUrl("credentials-url");
QCOMPARE(credentialsUrl, QString("https://ssu.example.com/ssu/device/%1/credentials.xml"));
registerUrl = ssu.repoUrl("register-url");
QCOMPARE(registerUrl, QString("https://ssu.example.com/ssu/device/%1/register.xml"));
}
void UrlResolverTest::checkCleanUrl(){ void UrlResolverTest::checkCleanUrl(){
QHashIterator<QString, QString> i(rndRepos); QHashIterator<QString, QString> i(rndRepos);
while (i.hasNext()){ while (i.hasNext()){
...@@ -101,3 +123,5 @@ void UrlResolverTest::checkReleaseRepoUrls(){ ...@@ -101,3 +123,5 @@ void UrlResolverTest::checkReleaseRepoUrls(){
QCOMPARE(url, i.value()); QCOMPARE(url, i.value());
} }
} }
...@@ -22,6 +22,7 @@ class UrlResolverTest: public QObject { ...@@ -22,6 +22,7 @@ class UrlResolverTest: public QObject {
void cleanupTestCase(); void cleanupTestCase();
void checkFlavour(); void checkFlavour();
void checkRelease(); void checkRelease();
void checkDomain();
void checkCleanUrl(); void checkCleanUrl();
void simpleRepoUrlLookup(); void simpleRepoUrlLookup();
void checkReleaseRepoUrls(); void checkReleaseRepoUrls();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment