Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12242883
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
14 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/app/Http/Controllers/Gate/DockerHubGateController.php b/app/Http/Controllers/Gate/DockerHubGateController.php
index a876cef..24ebbde 100644
--- a/app/Http/Controllers/Gate/DockerHubGateController.php
+++ b/app/Http/Controllers/Gate/DockerHubGateController.php
@@ -1,88 +1,83 @@
<?php
namespace Nasqueron\Notifications\Http\Controllers\Gate;
use Nasqueron\Notifications\Events\DockerHubPayloadEvent;
use Symfony\Component\HttpFoundation\Response;
use Event;
use Request;
class DockerHubGateController extends GateController {
///
/// Private members
///
/**
* The request content, as a structured data
*
* @var \stdClass
*/
private $payload;
/**
* The request content
*
* @var string
*/
private $rawRequestContent;
- ///
- /// Constants
- ///
-
- /**
- * The name of the service this gate accepts payload from.
- */
- const SERVICE_NAME = 'DockerHub';
-
///
/// Request processing
///
/**
* Handles POST requests
*
* @param string $door The door, matching the project for this payload
* @return \Symfony\Component\HttpFoundation\Response
*/
public function onPost (string $door) : Response {
// Parses the request and check if it's legit
$this->door = $door;
$this->extractPayload();
// Process the request
$this->logRequest();
$this->onPayload();
// Output
return parent::renderReport();
}
/**
* Extracts payload from the request
*/
protected function extractPayload () : void {
$request = Request::instance();
$this->rawRequestContent = $request->getContent();
$this->payload = json_decode($this->rawRequestContent);
}
+ public function getServiceName () : string {
+ return "DockerHub";
+ }
+
///
/// Payload processing
///
protected function onPayload () : void {
$this->initializeReport();
Event::fire(new DockerHubPayloadEvent(
$this->door,
$this->payload
));
}
}
diff --git a/app/Http/Controllers/Gate/GateController.php b/app/Http/Controllers/Gate/GateController.php
index a25d29d..0077e19 100644
--- a/app/Http/Controllers/Gate/GateController.php
+++ b/app/Http/Controllers/Gate/GateController.php
@@ -1,120 +1,120 @@
<?php
namespace Nasqueron\Notifications\Http\Controllers\Gate;
use Nasqueron\Notifications\Config\Features;
use Nasqueron\Notifications\Config\Services\Service;
use Nasqueron\Notifications\Http\Controllers\Controller;
use Symfony\Component\HttpFoundation\Response as BaseResponse;
use Illuminate\View\View;
use App;
use Log;
use Report;
use Response;
use Services;
/**
* Represents a controller handling an entry-point for API payloads
*/
class GateController extends Controller {
///
/// Private members
///
/**
* @var string
*/
protected $door;
///
/// Requests
///
/**
* Handles GET requests
*/
public function onGet () : View {
// Virtually all the push APIs will send they payloads
// using a POST request, so we can provide a sensible
// default GET error message.
return view('gate/ispostonly');
}
/**
* Logs the request
*/
protected function logRequest (array $extraContextualData = []) : void {
Log::info('[Gate] New payload.', [
- 'service' => static::SERVICE_NAME,
+ 'service' => $this->getServiceName(),
'door' => $this->door,
] + $extraContextualData);
}
///
/// Reports
///
/**
* Initializes the report and registers it
*/
protected function initializeReport () : void {
if (Features::isEnabled('ActionsReport')) {
- Report::attachToGate(static::SERVICE_NAME, $this->door);
+ Report::attachToGate($this->getServiceName(), $this->door);
}
}
/**
* Renders the report
*
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function renderReport () : BaseResponse {
if (!Features::isEnabled('ActionsReport')) {
return response("");
}
$report = App::make('report');
$statusCode = $report->containsError() ? 503 : 200;
return Response::json($report)
->setStatusCode($statusCode);
}
///
/// Credentials
///
/**
* Gets service credentials for this gate and door
*
* @return \Nasqueron\Notifications\Config\Services\Service|null The service information is found; otherwise, null.
*/
public function getService () : ?Service {
- return Services::findServiceByDoor(static::SERVICE_NAME, $this->door);
+ return Services::findServiceByDoor($this->getServiceName(), $this->door);
}
/**
* Checks if a registered service exists for this service and door.
*/
protected function doesServiceExist () : bool {
return $this->getService() !== null;
}
/**
* Gets secret for this service and door.
*
* @return string the secret, or if unknown, an empty string
*/
protected function getSecret () : string {
$service= $this->getService();
if ($service !== null) {
return $service->secret;
}
return "";
}
}
diff --git a/app/Http/Controllers/Gate/GitHubGateController.php b/app/Http/Controllers/Gate/GitHubGateController.php
index acc559e..090fcc4 100644
--- a/app/Http/Controllers/Gate/GitHubGateController.php
+++ b/app/Http/Controllers/Gate/GitHubGateController.php
@@ -1,194 +1,189 @@
<?php
namespace Nasqueron\Notifications\Http\Controllers\Gate;
use Nasqueron\Notifications\Events\GitHubPayloadEvent;
use Keruald\GitHub\XHubSignature;
use Symfony\Component\HttpFoundation\Response;
use Event;
use Request;
class GitHubGateController extends GateController {
///
/// Private members
///
/**
* The request signature, allowing to determine if the payload is legit
*
* @var string
*/
private $signature;
/**
* The GitHub event triggering this request
*
* @var string
*/
private $event;
/**
* The request delivery GUID
*
* @var string
*/
private $delivery;
/**
* The request content, as a structured data
*
* @var \stdClass
*/
private $payload;
/**
* The request content
*
* @var string
*/
private $rawRequestContent;
- ///
- /// Constants
- ///
-
- /**
- * The name of the service this gate accepts payload from.
- */
- const SERVICE_NAME = 'GitHub';
-
///
/// Request processing
///
/**
* Handles POST requests
*
* @param string $door The door, matching the project for this payload
* @return \Symfony\Component\HttpFoundation\Response
*/
public function onPost (string $door) : Response {
// Parses the request and check if it's legit
$this->door = $door;
$this->extractHeaders();
$this->extractPayload();
if (!$this->isLegitRequest()) {
abort(403, 'Unauthorized action.');
}
if (!$this->isValidRequest()) {
abort(400, 'Bad request.');
}
// Process the request
$this->logGateRequest();
$this->onPayload();
// Output
return parent::renderReport();
}
/**
* Extracts headers from the request
*/
protected function extractHeaders () : void {
$this->signature = $this->getSignature();
$this->event = Request::header('X-Github-Event');
$this->delivery = Request::header('X-Github-Delivery');
}
/**
* Gets the signature from an X-Hub-Signature header
*
* @return string The signature part of the header
*/
private function getSignature () : string {
$headerSignature = Request::header('X-Hub-Signature');
return XHubSignature::parseSignature($headerSignature);
}
/**
* Extracts payload from the request
*/
protected function extractPayload () : void {
$request = Request::instance();
$this->rawRequestContent = $request->getContent();
$this->payload = json_decode($this->rawRequestContent);
}
/**
* Determines if the request is valid, ie contains the mandatory headers
* and a payload.
*
* @return bool true if the request looks valid; otherwise, false.
*/
protected function isValidRequest () : bool {
if (empty($this->event)) {
return false;
}
if (empty($this->delivery)) {
return false;
}
if (empty($this->payload) || !is_object($this->payload)) {
return false;
}
return true;
}
/**
* Determines if the request is legit.
*
* @return bool true if the request looks legit; otherwise, false.
*/
protected function isLegitRequest () : bool {
$secret = $this->getSecret();
// If the secret is not defined, request legitimation is bypassed
if (empty($secret)) {
return true;
}
// If the secret is defined, but signature is missing from the
// request, we don't need to perform any other validation.
if (empty($this->signature)) {
return false;
}
return XHubSignature::validatePayload(
$secret,
$this->rawRequestContent,
$this->signature
);
}
/**
* Logs the request
*/
protected function logGateRequest () {
$this->logRequest([
'delivery' => $this->delivery,
'event' => $this->event,
]);
}
+ public function getServiceName () : string {
+ return "GitHub";
+ }
+
///
/// Payload processing
///
protected function onPayload () {
$this->initializeReport();
Event::fire(new GitHubPayloadEvent(
$this->door,
$this->event,
$this->payload
));
}
}
diff --git a/app/Http/Controllers/Gate/JenkinsGateController.php b/app/Http/Controllers/Gate/JenkinsGateController.php
index c17205a..3364b92 100644
--- a/app/Http/Controllers/Gate/JenkinsGateController.php
+++ b/app/Http/Controllers/Gate/JenkinsGateController.php
@@ -1,88 +1,83 @@
<?php
namespace Nasqueron\Notifications\Http\Controllers\Gate;
use Nasqueron\Notifications\Events\JenkinsPayloadEvent;
use Symfony\Component\HttpFoundation\Response;
use Event;
use Request;
class JenkinsGateController extends GateController {
///
/// Private members
///
/**
* The request content, as a structured data
*
* @var \stdClass
*/
private $payload;
/**
* The request content
*
* @var string
*/
private $rawRequestContent;
- ///
- /// Constants
- ///
-
- /**
- * The name of the service this gate accepts payload from.
- */
- const SERVICE_NAME = 'Jenkins';
-
///
/// Request processing
///
/**
* Handles POST requests
*
* @param string $door The door, matching the project for this payload
* @return \Symfony\Component\HttpFoundation\Response
*/
public function onPost (string $door) : Response {
// Parses the request and check if it's legit
$this->door = $door;
$this->extractPayload();
// Process the request
$this->logRequest();
$this->onPayload();
// Output
return parent::renderReport();
}
/**
* Extracts payload from the request
*/
protected function extractPayload () {
$request = Request::instance();
$this->rawRequestContent = $request->getContent();
$this->payload = json_decode($this->rawRequestContent);
}
+ public function getServiceName () : string {
+ return "Jenkins";
+ }
+
///
/// Payload processing
///
protected function onPayload () {
$this->initializeReport();
Event::fire(new JenkinsPayloadEvent(
$this->door,
$this->payload
));
}
}
diff --git a/app/Http/Controllers/Gate/PhabricatorGateController.php b/app/Http/Controllers/Gate/PhabricatorGateController.php
index 76368dc..b4c94a3 100644
--- a/app/Http/Controllers/Gate/PhabricatorGateController.php
+++ b/app/Http/Controllers/Gate/PhabricatorGateController.php
@@ -1,78 +1,73 @@
<?php
namespace Nasqueron\Notifications\Http\Controllers\Gate;
use Nasqueron\Notifications\Events\PhabricatorPayloadEvent;
use Symfony\Component\HttpFoundation\Response;
use Event;
use Request;
class PhabricatorGateController extends GateController {
///
/// Private members
///
/**
* The request content, as a structured data
*
* @var array
*/
private $payload;
- ///
- /// Constants
- ///
-
- /**
- * The name of the service this gate accepts payload from.
- */
- const SERVICE_NAME = 'Phabricator';
-
///
/// Requests processing
///
/**
* Handles POST requests
*
* @param string $door The door, matching the project for this payload
* @return \Symfony\Component\HttpFoundation\Response
*/
public function onPost (string $door) : Response {
$this->door = $door;
if (!$this->doesServiceExist()) {
abort(404, 'Unknown Phabricator instance.');
}
$this->extractPayload();
$this->logRequest();
$this->onPayload();
return parent::renderReport();
}
/**
* Extracts payload from the request
*/
protected function extractPayload () : void {
$this->payload = Request::all();
}
+ public function getServiceName () : string {
+ return "Phabricator";
+ }
+
///
/// Payload processing
///
protected function onPayload () : void {
$this->initializeReport();
Event::fire(new PhabricatorPayloadEvent(
$this->door,
$this->payload
));
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Oct 12, 10:52 (4 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3065796
Default Alt Text
(14 KB)
Attached To
Mode
rNOTIF Notifications center
Attached
Detach File
Event Timeline
Log In to Comment