Page MenuHomeDevCentral

No OneTemporary

diff --git a/app/Facades/DockerHub.php b/app/Facades/DockerHub.php
new file mode 100644
index 0000000..6b409dd
--- /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
index 0000000..c590007
--- /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
index e2b2f73..54c4da5 100644
--- a/composer.json
+++ b/composer.json
@@ -1,55 +1,56 @@
{
"name": "nasqueron/notifications",
"description": "Nasqueron notifications center",
"keywords": [
"nasqueron",
"activemq",
"AMQP",
"notifications"
],
"license": "BSD-2-Clause",
"type": "project",
"require": {
"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",
"netresearch/jsonmapper": "~0.1.0",
"sentry/sentry": "^0.13.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpmd/phpmd" : "@stable",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1",
"squizlabs/php_codesniffer": "2.*",
"symfony/css-selector": "~3.0",
"symfony/dom-crawler": "~3.0"
},
"autoload": {
"psr-4": {
"Nasqueron\\Notifications\\": "app/",
"Nasqueron\\Notifications\\Tests\\": "tests/"
}
},
"scripts": {
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"phpmd": [
"vendor/bin/phpmd app/ xml ruleset.xml"
],
"test": [
"phpunit --no-coverage"
]
},
"config": {
"preferred-install": "dist"
}
}
diff --git a/config/app.php b/config/app.php
index 660abb4..240b539 100644
--- a/config/app.php
+++ b/config/app.php
@@ -1,264 +1,266 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Application Environment
|--------------------------------------------------------------------------
|
| This value determines the "environment" your application is currently
| running in. This may determine how you prefer to configure various
| services your application utilizes. Set this in your ".env" file.
|
*/
'env' => env('APP_ENV', 'production'),
/*
|--------------------------------------------------------------------------
| Application Debug Mode
|--------------------------------------------------------------------------
|
| When your application is in debug mode, detailed error messages with
| stack traces will be shown on every error that occurs within your
| application. If disabled, a simple generic error page is shown.
|
*/
'debug' => env('APP_DEBUG', false),
/*
|--------------------------------------------------------------------------
| Application URL
|--------------------------------------------------------------------------
|
| This URL is used by the console to properly generate URLs when using
| the Artisan command line tool. You should set this to the root of
| your application so that it is used when running Artisan tasks.
|
*/
'url' => 'http://localhost',
/*
|--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. We have gone
| ahead and set this to a sensible default for you out of the box.
|
*/
'timezone' => 'UTC',
/*
|--------------------------------------------------------------------------
| Application Locale Configuration
|--------------------------------------------------------------------------
|
| The application locale determines the default locale that will be used
| by the translation service provider. You are free to set this value
| to any of the locales which will be supported by the application.
|
*/
'locale' => 'en',
/*
|--------------------------------------------------------------------------
| Application Fallback Locale
|--------------------------------------------------------------------------
|
| The fallback locale determines the locale to use when the current one
| is not available. You may change the value to correspond to any of
| the language folders that are provided through your application.
|
*/
'fallback_locale' => 'en',
/*
|--------------------------------------------------------------------------
| Encryption Key
|--------------------------------------------------------------------------
|
| This key is used by the Illuminate encrypter service and should be set
| to a random, 32 character string, otherwise these encrypted strings
| will not be safe. Please do this before deploying an application!
|
*/
'key' => env('APP_KEY'),
'cipher' => 'AES-256-CBC',
/*
|--------------------------------------------------------------------------
| Logging Configuration
|--------------------------------------------------------------------------
|
| Here you may configure the log settings for your application. Out of
| the box, Laravel uses the Monolog PHP logging library. This gives
| you a variety of powerful log handlers / formatters to utilize.
|
| Available Settings: "single", "daily", "syslog", "errorlog"
|
*/
'log' => env('APP_LOG', 'single'),
/*
|--------------------------------------------------------------------------
| Features
|--------------------------------------------------------------------------
|
| This array contains the features provided by the notifications center.
|
| It allows to toggle a feature on the fly, with a boolean to enable it.
|
*/
'features' => [
// Enable the API entry point at the /gate URL
'Gate' => true,
// Send a response to inform the caller of the different actions done.
// If disabled, send an empty 200 response instead.
'ActionsReport' => true,
],
/*
|--------------------------------------------------------------------------
| Autoloaded Service Providers
|--------------------------------------------------------------------------
|
| The service providers listed here will be automatically loaded on the
| request to your application. Feel free to add your own services to
| this array to grant expanded functionality to your applications.
|
*/
'providers' => [
/*
* Laravel Framework Service Providers...
*/
Illuminate\Broadcasting\BroadcastServiceProvider::class,
Illuminate\Bus\BusServiceProvider::class,
Illuminate\Cache\CacheServiceProvider::class,
Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
Illuminate\Cookie\CookieServiceProvider::class,
Illuminate\Database\DatabaseServiceProvider::class,
Illuminate\Encryption\EncryptionServiceProvider::class,
Illuminate\Filesystem\FilesystemServiceProvider::class,
Illuminate\Foundation\Providers\FoundationServiceProvider::class,
Illuminate\Hashing\HashServiceProvider::class,
Illuminate\Mail\MailServiceProvider::class,
Illuminate\Pagination\PaginationServiceProvider::class,
Illuminate\Pipeline\PipelineServiceProvider::class,
Illuminate\Queue\QueueServiceProvider::class,
Illuminate\Redis\RedisServiceProvider::class,
Illuminate\Session\SessionServiceProvider::class,
Illuminate\Translation\TranslationServiceProvider::class,
Illuminate\Validation\ValidationServiceProvider::class,
Illuminate\View\ViewServiceProvider::class,
/*
* Application Service Providers...
*/
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,
Nasqueron\Notifications\Providers\PhabricatorProjectsMapServiceProvider::class,
Nasqueron\Notifications\Providers\ReportServiceProvider::class,
Nasqueron\Notifications\Providers\RouteServiceProvider::class,
Nasqueron\Notifications\Providers\SentryServiceProvider::class,
Nasqueron\Notifications\Providers\ServicesServiceProvider::class
],
/*
|--------------------------------------------------------------------------
| Events listeners
|--------------------------------------------------------------------------
|
| The events listeners listed here will be automatically loaded on the
| request to your application.
|
*/
'listeners' => [
Nasqueron\Notifications\Listeners\AMQPEventListener::class,
Nasqueron\Notifications\Listeners\LastPayloadSaver::class,
Nasqueron\Notifications\Listeners\NotificationListener::class,
Nasqueron\Notifications\Listeners\PhabricatorListener::class,
],
/*
|--------------------------------------------------------------------------
| Class Aliases
|--------------------------------------------------------------------------
|
| This array of class aliases will be registered when this application
| is started. However, feel free to register as many as you wish as
| the aliases are "lazy" loaded so they don't hinder performance.
|
*/
'aliases' => [
/*
* Laravel Framework aliases...
*/
'App' => Illuminate\Support\Facades\App::class,
'Artisan' => Illuminate\Support\Facades\Artisan::class,
'Auth' => Illuminate\Support\Facades\Auth::class,
'Blade' => Illuminate\Support\Facades\Blade::class,
'Bus' => Illuminate\Support\Facades\Bus::class,
'Cache' => Illuminate\Support\Facades\Cache::class,
'Config' => Illuminate\Support\Facades\Config::class,
'Cookie' => Illuminate\Support\Facades\Cookie::class,
'Crypt' => Illuminate\Support\Facades\Crypt::class,
'DB' => Illuminate\Support\Facades\DB::class,
'Eloquent' => Illuminate\Database\Eloquent\Model::class,
'Event' => Illuminate\Support\Facades\Event::class,
'File' => Illuminate\Support\Facades\File::class,
'Gate' => Illuminate\Support\Facades\Gate::class,
'Hash' => Illuminate\Support\Facades\Hash::class,
'Input' => Illuminate\Support\Facades\Input::class,
'Inspiring' => Illuminate\Foundation\Inspiring::class,
'Lang' => Illuminate\Support\Facades\Lang::class,
'Log' => Illuminate\Support\Facades\Log::class,
'Mail' => Illuminate\Support\Facades\Mail::class,
'Password' => Illuminate\Support\Facades\Password::class,
'Queue' => Illuminate\Support\Facades\Queue::class,
'Redirect' => Illuminate\Support\Facades\Redirect::class,
'Redis' => Illuminate\Support\Facades\Redis::class,
'Request' => Illuminate\Support\Facades\Request::class,
'Response' => Illuminate\Support\Facades\Response::class,
'Route' => Illuminate\Support\Facades\Route::class,
'Schema' => Illuminate\Support\Facades\Schema::class,
'Session' => Illuminate\Support\Facades\Session::class,
'Storage' => Illuminate\Support\Facades\Storage::class,
'URL' => Illuminate\Support\Facades\URL::class,
'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facades\View::class,
/*
* 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,
'Raven' => Nasqueron\Notifications\Facades\Raven::class,
'Report' => Nasqueron\Notifications\Facades\Report::class,
'Services' => Nasqueron\Notifications\Facades\Services::class,
],
];
diff --git a/config/services.php b/config/services.php
index 6aa43a7..e3ffb00 100644
--- a/config/services.php
+++ b/config/services.php
@@ -1,64 +1,68 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Third Party Services
|--------------------------------------------------------------------------
|
| This file is for storing the credentials for third party services such
| as Stripe, Mailgun, Mandrill, and others. This file provides a sane
| default location for this type of information, allowing packages
| to have a conventional place to find your various credentials.
|
*/
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
],
'mandrill' => [
'secret' => env('MANDRILL_SECRET'),
],
'ses' => [
'key' => env('SES_KEY'),
'secret' => env('SES_SECRET'),
'region' => 'us-east-1',
],
'stripe' => [
'model' => Nasqueron\Notifications\User::class,
'key' => env('STRIPE_KEY'),
'secret' => env('STRIPE_SECRET'),
],
'sentry' => [
'dsn' => env('SENTRY_DSN'),
],
+ 'dockerhub' => [
+ 'tokens' => env('DOCKERHUB_TOKENS', 'DockerHubTokens.json')
+ ],
+
'github' => [
'analyzer' => [
'configDir' => env('GITHUB_ANALYZER_CONFIG_DIR', 'GitHubPayloadAnalyzer')
]
],
'jenkins' => [
'analyzer' => [
'configDir' => env('JENKINS_ANALYZER_CONFIG_DIR', 'JenkinsPayloadAnalyzer')
]
],
'phabricator' => [
'analyzer' => [
'configDir' => env('PHABRICATOR_ANALYZER_CONFIG_DIR', 'PhabricatorPayloadAnalyzer')
]
],
'gate' => [
'credentials' => env('CREDENTIALS', 'credentials.json'),
]
];
diff --git a/storage/app/.gitignore b/storage/app/.gitignore
index 83f6e39..2657146 100644
--- 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
index 0000000..1bff186
--- /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
index 0000000..1da526c
--- /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
index 0000000..f56e331
--- /dev/null
+++ b/tests/data/DockerHubTokens.json
@@ -0,0 +1,3 @@
+{
+ "acme/foo": "0000"
+}

File Metadata

Mime Type
text/x-diff
Expires
Thu, Sep 18, 13:54 (16 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2990931
Default Alt Text
(18 KB)

Event Timeline