-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Micke Nordin <[email protected]>
- Loading branch information
1 parent
a849f4d
commit 7d0751d
Showing
6 changed files
with
68 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
<description> | ||
<![CDATA[Integrate Jupyther Hub into Nextcloud]]> | ||
</description> | ||
<version>0.1.1</version> | ||
<version>0.1.2</version> | ||
<licence>agpl</licence> | ||
<author mail="[email protected]" homepage="https://github.com/SUNET/nextcloud-jupyter">Mikael Nordin</author> | ||
<namespace>Jupyter</namespace> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
// SPDX-FileCopyrightText: Mikael Nordin <[email protected]> | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
namespace OCA\Jupyter\AppInfo; | ||
|
||
use OCA\Jupyter\Listener\CSPListener; | ||
|
||
use OCP\AppFramework\App; | ||
use OCP\AppFramework\Bootstrap\IBootContext; | ||
use OCP\AppFramework\Bootstrap\IBootstrap; | ||
use OCP\AppFramework\Bootstrap\IRegistrationContext; | ||
use OCP\Security\CSP\AddContentSecurityPolicyEvent; | ||
|
||
class Application extends App { | ||
public const APP_ID = 'integration_jupyterhub'; | ||
class Application extends App implements IBootstrap | ||
{ | ||
public const APP_ID = 'integration_jupyterhub'; | ||
|
||
public function __construct() { | ||
parent::__construct(self::APP_ID); | ||
} | ||
public function __construct() | ||
{ | ||
parent::__construct(self::APP_ID); | ||
} | ||
public function register(IRegistrationContext $context): void | ||
{ | ||
$context->registerEventListener(AddContentSecurityPolicyEvent::class, CSPListener::class); | ||
} | ||
public function boot(IBootContext $context): void {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Jupyter\Listener; | ||
|
||
use OCP\AppFramework\Http\ContentSecurityPolicy; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
use OCP\Security\CSP\AddContentSecurityPolicyEvent; | ||
use Psr\Log\LoggerInterface; | ||
use OCP\IConfig; | ||
|
||
class CSPListener implements IEventListener | ||
{ | ||
protected string $appName; | ||
private string $jupyter_url; | ||
public function __construct( | ||
private IConfig $config, | ||
private LoggerInterface $logger | ||
) { | ||
$this->jupyter_url = $config->getAppValue($this->appName, 'jupyter_url') . '/hub/home'; | ||
$this->appName = "integration_jupyterhub"; | ||
} | ||
|
||
public function handle(Event $event): void | ||
{ | ||
$this->logger->debug('Adding CSP for Jupyter', ['app' => 'integration_jupyterhub']); | ||
if (!($event instanceof AddContentSecurityPolicyEvent)) { | ||
return; | ||
} | ||
$csp = new ContentSecurityPolicy(); | ||
$url = parse_url($this->jupyter_url); | ||
$http = $url["scheme"] . "://" . $url["host"]; | ||
$csp->addAllowedConnectDomain($http); | ||
$csp->addAllowedScriptDomain($http); | ||
$csp->addAllowedFrameDomain($http); | ||
|
||
$event->addPolicy($csp); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "integration_jupyterhub", | ||
"description": "Integrate Jupyther Hub into Nextcloud", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"author": "Micke Nordin <[email protected]>", | ||
"contributors": [], | ||
"bugs": { | ||
|