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

Allow requesting a specific channel #557

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,25 @@ Example call: updater_server/?version=9x0x0x12x1448709225.0768x1448709281xstable
</nextcloud>
```

Deployed URL: https://updates.nextcloud.com/updater_server/
Example call: updater_server/?channel=stable
```xml
<?xml version="1.0" encoding="UTF-8"?>
<nextcloud>
<version>9.0.51</version>
<versionstring>Nextcloud 9.0.51</versionstring>
<url>https://download.nextcloud.com/server/releases/nextcloud-9.0.51.zip</url>
<web>https://docs.nextcloud.com/server/9/admin_manual/maintenance/upgrade.html</web>
</nextcloud>
```

## Webhook deployment

If you wish to receive webhooks and then automatically deploy the lastest version of the updater server there is one special API endpoint available.
If you wish to receive webhooks and then automatically deploy the latest version of the updater server there is one special API endpoint available.

For this the [Github Webhook](https://developer.github.com/webhooks/) needs to be configured to send `push` events to the endpoint `/hook` of the updater server. There only the ending part is crucial. That means that any URL ending in `/hook` which is served by the `index.php` of the updater server will trigger this behaviour.
For this the [GitHub Webhook](https://developer.github.com/webhooks/) needs to be configured to send `push` events to the endpoint `/hook` of the updater server. There only the ending part is crucial. That means that any URL ending in `/hook` which is served by the `index.php` of the updater server will trigger this behaviour.

Configure a webhook on Github in the repository of choice with `application/json` as content type, a random secret and the `push` event to be sent.
Configure a webhook on GitHub in the repository of choice with `application/json` as content type, a random secret and the `push` event to be sent.

![](docs/webhook.png)

Expand Down
30 changes: 17 additions & 13 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,28 @@
exit();
}

// Return empty response if no version is supplied
if(!isset($_GET['version']) || !is_string($_GET['version'])) {
exit();
}

// Parse the request
// Read config
try {
$request = new \UpdateServer\Request($_GET['version'], $_SERVER);
} catch (\UpdateServer\Exceptions\UnsupportedReleaseException $e) {
$config = new \UpdateServer\Config(__DIR__ . '/config/config.php');
} catch (\RuntimeException $e) {
exit();
}

try {
$config = new \UpdateServer\Config(__DIR__ . '/config/config.php');
} catch (\RuntimeException $e) {
// Check the request parameters
if(isset($_GET['version']) && is_string($_GET['version'])) {
try {
$request = new \UpdateServer\Requests\VersionRequest($_GET['version'], $_SERVER);
} catch (\UpdateServer\Exceptions\UnsupportedReleaseException $e) {
exit();
}
$response = new \UpdateServer\Responses\VersionResponse($request, $config);
} else if (isset($_GET['channel']) && is_string($_GET['channel'])) {
$request = new \UpdateServer\Requests\ChannelRequest($_GET['channel']);
$response = new \UpdateServer\Responses\ChannelResponse($request, $config);
} else {
// Return empty response if no version or channel is supplied
exit();
}

// Return a response
$response = new \UpdateServer\Response($request, $config);
// Return the response
echo $response->buildResponse();
26 changes: 26 additions & 0 deletions src/Requests/ChannelRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* @license MIT <http://opensource.org/licenses/MIT>
*/

namespace UpdateServer\Requests;

class ChannelRequest {
/** @var string */
private $channel;

/**
* ChannelRequest constructor.
* @param string $channel
*/
public function __construct(string $channel) {
$this->channel = $channel;
}

/**
* @return string
*/
public function getChannel(): string {
return $this->channel;
}
}
7 changes: 3 additions & 4 deletions src/Request.php → src/Requests/VersionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* @license MIT <http://opensource.org/licenses/MIT>
*/

namespace UpdateServer;
namespace UpdateServer\Requests;

use UpdateServer\Exceptions\UnsupportedReleaseException;

class Request {
class VersionRequest {
/** @var int|null */
private $majorVersion = null;
/** @var int|null */
Expand Down Expand Up @@ -41,8 +41,7 @@ class Request {
* @param array $server
* @throws UnsupportedReleaseException If the release is not supported by this update script.
*/
public function __construct($versionString,
array $server) {
public function __construct(string $versionString, array $server) {
$this->readVersion($versionString, $server);
}

Expand Down
210 changes: 0 additions & 210 deletions src/Response.php

This file was deleted.

Loading