Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new appstore API #1940

Merged
merged 15 commits into from
Nov 2, 2016
Merged

Use new appstore API #1940

merged 15 commits into from
Nov 2, 2016

Conversation

LukasReschke
Copy link
Member

@LukasReschke LukasReschke commented Oct 27, 2016

This change introduces the new appstore API in Nextcloud.

Todo

  • App updates

Signed-off-by: Lukas Reschke lukas@statuscode.ch

@LukasReschke LukasReschke added the 2. developing Work in progress label Oct 27, 2016
@LukasReschke LukasReschke added this to the Nextcloud 11.0 milestone Oct 27, 2016
@mention-bot
Copy link

@LukasReschke, thanks for your PR! By analyzing the history of the files in this pull request, we identified @DeepDiver1975, @nickvergessen and @rullzer to be potential reviewers.

@LukasReschke
Copy link
Member Author

cc @BernhardPosselt @rullzer

@@ -674,20 +674,6 @@
'appstoreenabled' => true,

/**
* The URL of the appstore to use.
*/
'appstoreurl' => 'https://api.owncloud.com/v1',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this still be configurable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure on that. So the problem is there are a ton of people out there who actually have no idea what they are doing™️ and just copy the sample config file. I don't really look forward to have around 30 people asking why their appstore doesn't work anymore and because nobody fills out the issue template that's just a waste of time.

So we either have to rename that variable (suggestions welcome) or go with hard-coded for now. I'd be fine with hard-coded for the moment, especially since you also can't easily replace the certificate use for verification. (neither one could before)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point about renaming the value, that would relieve us from the need to migrate existing overrides. It's still probably better to keep it configurable for maintainability and flexibility purposes. As for certificate locations: should probably also be configurable but can be added later on.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to think about that a bit more. Especially since we also now have a proxy in place which would also be another config value.

$this->fileName = 'apps.json';
$this->endpointUrl = sprintf(
'https://apps.nextcloud.com/api/v1/platform/%s/apps.json',
substr(implode(\OC_Util::getVersion(), '.'), 0, 5)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why substr? looks dangerous

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, pretty much, also this needs at least a comment

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OC_Util::getVersion returns the version from config.php such as array(9, 2, 0, 4). But the appstore only takes 3 numbers and ignores the internal patch level.

That said, will add a comment. It's also tested at https://github.com/nextcloud/server/blob/ea32ef300c214c5af4a78f2650801bb856a03395/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, but substr(..., 0,5) will break with 11.0.0 which is 0,6 ...
and so on...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing just fyi: you need to pass Nextcloud versions, not ownCloud internal versions. Using 9.2.0 won't yield any compatible apps

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing just fyi: you need to pass Nextcloud versions, not ownCloud internal versions. Using 9.2.0 won't yield any compatible apps

Well… It does 🙈

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also we'll likely just bump that to 11 for 11 so that it then would request the right URL :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, but substr(..., 0,5) will break with 11.0.0 which is 0,6 ....

True. So let's just read the array elements on it's own.

return new Version(substr($matches[0][0], 2), substr($matches[0][1], 2));
break;
default:
throw new \Exception('Version cannot be parsed');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably include the version string that can not be parsed


// Count the amount of =, if it is one then it's either maximum or minimum
// version. If it is two then it is maximum and minimum.
if (preg_match_all('/(?:>|<)(?:=|)[0-9.]+/', $versionSpec, $matches)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a regex to parse a simple version string is maybe a bit overkill. explode() and strpos() may be faster and easier to read

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

$x509 = new X509();
$x509->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt'));
$x509->loadX509($app['certificate']);
if($x509->validateSignature() !== true) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose CRL support will be added later on :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually let's just add that here as well and add tests for this.

'app' => 'core',
]
);
return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for this? Should probably throw an exception with your logging string

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same applies to the following lines

new \OC\App\AppStore\Fetcher\AppFetcher(
\OC::$server->getAppDataDir('appstore'),
\OC::$server->getHTTPClientService(),
new \OC\AppFramework\Utility\TimeFactory(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just query the class from the server e.g. $server->query(\OC\AppFramework\Utility\TimeFactory::class)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naive question: Any advantage of doing so?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If things change your code won't break

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would go for the public interface however :D

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Querying the interface doesn't seem to work. But the other thing works. Replacing.

$params['category'] = $category;
$params['appstoreEnabled'] = $this->config->getSystemValue('appstoreenabled', true) === true;
$this->navigationManager->setActiveEntry('core_apps');

$templateResponse = new TemplateResponse($this->appName, 'apps', $params, 'user');
$policy = new ContentSecurityPolicy();
$policy->addAllowedImageDomain('https://apps.owncloud.com');
$policy->addAllowedImageDomain('*');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can actually use https instead of *

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will also use an image proxy. So we can limit even further. Just waiting for the domain :)

Ref #1939

$this->endpointUrl = sprintf(
'https://apps.nextcloud.com/api/v1/platform/%s/apps.json',
substr(implode(\OC_Util::getVersion(), '.'), 0, 5)
'https://apps.nextcloud.com/api/v1/platform/%s.%s.%s/apps.json',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%d since it's only numbers? 🙊

This change introduces the new appstore API in Nextcloud.

Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Otherwise this would break with 11.0.0

Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
These are only numbers. THX @nickvergessen

Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
The other function doesn't work if the appstore is disabled

Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
@LukasReschke LukasReschke added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Oct 31, 2016
@LukasReschke LukasReschke changed the title [WIP] Use new appstore API Use new appstore API Oct 31, 2016
@LukasReschke
Copy link
Member Author

Ready for review. Will also add some more tests.

cc @rullzer @nickvergessen

The static version is used nowhere in the code and just decreases coverage

Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
@rullzer
Copy link
Member

rullzer commented Nov 1, 2016

Ok so. I have been playing with this for a while now and haven't hit weird errors yet. I'd say lets merge 👍

* @param array $groups (optional) when set, only these groups will have access to the app
* @throws \Exception
* @return void
*
* This function set an app as enabled in appconfig.
*/
public static function enable($app, $groups = null) {
public function enable($appId,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this breaking change really required?
Can't you just make that change in the AppManager and leave the old static stuff as a wrapper?

Copy link
Member Author

@LukasReschke LukasReschke Nov 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well. This is private API and the usages in core have been adjusted. If someone relies on private API then they are to blame themselves. I'm not a fan of limiting myself just because some other people may do it majorly wrong. ;)

Copy link
Member Author

@LukasReschke LukasReschke Nov 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also \OC\App\AppManager does a ton of different stuff not related to the appstore at all… I don't really want to pull that into that class at the moment as well. (also since it's public API and thus the expectation is that it will work nearly forever)

@stp-ip
Copy link
Contributor

stp-ip commented Nov 2, 2016

lgtm

@stp-ip stp-ip merged commit e81d04c into master Nov 2, 2016
@ChristophWurst ChristophWurst deleted the new-appstore branch November 2, 2016 17:17
MorrisJobke added a commit that referenced this pull request Nov 17, 2016
* experimental apps where removed with 32cf661 (#1940)
* fixes #2183

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
MorrisJobke added a commit that referenced this pull request Apr 23, 2018
Left over from a refactoring

#1940

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
MorrisJobke added a commit that referenced this pull request May 29, 2018
Left over from a refactoring

#1940

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants