Page MenuHomeDevCentral

D651.diff
No OneTemporary

D651.diff

diff --git a/app/Facades/DockerHub.php b/app/Facades/DockerHub.php
new file mode 100644
--- /dev/null
+++ b/app/Facades/DockerHub.php
@@ -0,0 +1,21 @@
+<?php
+
+namespace Nasqueron\Notifications\Facades;
+
+use Illuminate\Support\Facades\Facade;
+
+/**
+ * @see \Keruald\DockerHub\Build\TriggerBuildFactory
+ */
+class DockerHub extends Facade {
+
+ /**
+ * Gets the registered name of the component.
+ *
+ * @return string
+ */
+ protected static function getFacadeAccessor() {
+ return 'dockerhub';
+ }
+
+}
diff --git a/app/Providers/DockerHubServiceProvider.php b/app/Providers/DockerHubServiceProvider.php
new file mode 100644
--- /dev/null
+++ b/app/Providers/DockerHubServiceProvider.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace Nasqueron\Notifications\Providers;
+
+use Illuminate\Config\Repository;
+use Illuminate\Contracts\Foundation\Application;
+use Illuminate\Support\ServiceProvider;
+
+use GuzzleHttp\Client;
+use Keruald\DockerHub\Build\TriggerBuildFactory;
+
+class DockerHubServiceProvider extends ServiceProvider {
+ /**
+ * Bootstraps the application services.
+ *
+ * @return void
+ */
+ public function boot() {
+ }
+
+ /**
+ * Gets the tokens to trigger build for the Docker Hub images.
+ *
+ * @param \Illuminate\Contracts\Foundation\Application $app
+ * @return array
+ */
+ public static function getTokens (Application $app) {
+ $file = $app->make('config')->get('services.dockerhub.tokens');
+ $fs = $app->make('filesystem')->disk('local');
+
+ if ($fs->exists($file)) {
+ $content = $fs->get($file);
+ return json_decode($content, true);
+ }
+
+ return [];
+ }
+
+ /**
+ * Registers the application services.
+ *
+ * @return void
+ */
+ public function register() {
+ $this->app->singleton('dockerhub', function (Application $app) {
+ $tokens = DockerHubServiceProvider::getTokens($app);
+ return new TriggerBuildFactory(new Client, $tokens);
+ });
+ }
+}
diff --git a/composer.json b/composer.json
--- a/composer.json
+++ b/composer.json
@@ -13,6 +13,7 @@
"php": ">=5.6.0",
"laravel/framework": "5.2.*",
"guzzlehttp/guzzle": "^6.2",
+ "keruald/dockerhub": "^0.0.2",
"keruald/github": "^0.2.0",
"keruald/broker": "^0.4.1",
"keruald/mailgun": "^0.0.1",
diff --git a/config/app.php b/config/app.php
--- a/config/app.php
+++ b/config/app.php
@@ -171,6 +171,7 @@
*/
Nasqueron\Notifications\Providers\AppServiceProvider::class,
Nasqueron\Notifications\Providers\BrokerServiceProvider::class,
+ Nasqueron\Notifications\Providers\DockerHubServiceProvider::class,
Nasqueron\Notifications\Providers\EventServiceProvider::class,
Nasqueron\Notifications\Providers\MailgunServiceProvider::class,
Nasqueron\Notifications\Providers\PhabricatorAPIServiceProvider::class,
@@ -252,6 +253,7 @@
* App aliases...
*/
'Broker' => Nasqueron\Notifications\Facades\Broker::class,
+ 'DockerHub' => Nasqueron\Notifications\Facades\DockerHub::class,
'Mailgun' => Nasqueron\Notifications\Facades\Mailgun::class,
'PhabricatorAPI' => Nasqueron\Notifications\Facades\PhabricatorAPI::class,
'ProjectsMap' => Nasqueron\Notifications\Facades\ProjectsMap::class,
diff --git a/config/services.php b/config/services.php
--- a/config/services.php
+++ b/config/services.php
@@ -39,6 +39,10 @@
'dsn' => env('SENTRY_DSN'),
],
+ 'dockerhub' => [
+ 'tokens' => env('DOCKERHUB_TOKENS', 'DockerHubTokens.json')
+ ],
+
'github' => [
'analyzer' => [
'configDir' => env('GITHUB_ANALYZER_CONFIG_DIR', 'GitHubPayloadAnalyzer')
diff --git a/storage/app/.gitignore b/storage/app/.gitignore
--- a/storage/app/.gitignore
+++ b/storage/app/.gitignore
@@ -1 +1,2 @@
credentials.json
+DockerHubTokens.json
diff --git a/tests/Facades/DockerHubTest.php b/tests/Facades/DockerHubTest.php
new file mode 100644
--- /dev/null
+++ b/tests/Facades/DockerHubTest.php
@@ -0,0 +1,21 @@
+<?php
+
+namespace Nasqueron\Notifications\Tests\Facades;
+
+use Nasqueron\Notifications\Tests\TestCase;
+
+use Config;
+use DockerHub;
+
+use Keruald\DockerHub\Build\TriggerBuildFactory;
+
+class DockerHubTest extends TestCase {
+
+ public function testIfFacadeAccessorCouldBeResolvedInAppContainer () {
+ $this->assertInstanceOf(
+ TriggerBuildFactory::class,
+ DockerHub::getFacadeRoot()
+ );
+ }
+
+}
diff --git a/tests/Providers/DockerHubServiceProviderTest.php b/tests/Providers/DockerHubServiceProviderTest.php
new file mode 100644
--- /dev/null
+++ b/tests/Providers/DockerHubServiceProviderTest.php
@@ -0,0 +1,36 @@
+<?php
+
+namespace Nasqueron\Notifications\Tests\Providers;
+
+use Nasqueron\Notifications\Providers\DockerHubServiceProvider;
+
+use Config;
+
+class DockerHubServiceProviderTest extends TestCase {
+
+ public function testType () {
+ $this->assertServiceInstanceOf(
+ 'Keruald\DockerHub\Build\TriggerBuildFactory',
+ 'dockerhub'
+ );
+ }
+
+ public function testGetTokens () {
+ $this->assertSame(
+ ['acme/foo' => '0000'],
+ DockerHubServiceProvider::getTokens($this->app),
+ "The service provider should deserialize DockerHubTokens.json."
+ );
+ }
+
+ public function testGetTokensWhenFileDoesNotExist () {
+ Config::set('services.dockerhub.tokens', 'notexisting.json');
+
+ $this->assertSame(
+ [],
+ DockerHubServiceProvider::getTokens($this->app),
+ "When no tokens file exists, an empty array is used instead."
+ );
+ }
+
+}
diff --git a/tests/data/DockerHubTokens.json b/tests/data/DockerHubTokens.json
new file mode 100644
--- /dev/null
+++ b/tests/data/DockerHubTokens.json
@@ -0,0 +1,3 @@
+{
+ "acme/foo": "0000"
+}

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 27, 12:08 (16 h, 15 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2266611
Default Alt Text
D651.diff (5 KB)

Event Timeline