From 71edd8bbf38fad5b0be45ca2846164d44d271023 Mon Sep 17 00:00:00 2001 From: Sebastian Frank Date: Wed, 6 Mar 2019 12:26:09 +0100 Subject: [PATCH] config now in settings --- Controller/Settings.php | 42 +++++++++++++++ README.md | 23 ++++---- admin.php | 19 ++++++- bootstrap.php | 8 +-- views/partials/settings.php | 18 +++++++ views/settings/index.php | 105 ++++++++++++++++++++++++++++++++++++ 6 files changed, 197 insertions(+), 18 deletions(-) create mode 100644 Controller/Settings.php create mode 100644 views/partials/settings.php create mode 100644 views/settings/index.php diff --git a/Controller/Settings.php b/Controller/Settings.php new file mode 100644 index 0000000..d4fad75 --- /dev/null +++ b/Controller/Settings.php @@ -0,0 +1,42 @@ +app->module('cockpit')->hasaccess('drone', 'manage.settings')) { + return FALSE; + } + + $drone = $this->app->storage->findOne('drone/settings'); + + return $this->render('drone:views/settings/index.php', compact('drone')); + } + + public function save() { + if ($data = $this->param('drone', false)) { + + $data['_modified'] = time(); + + if (!isset($data['_id'])) { + $data['_created'] = $data['_modified']; + } + + $this->app->storage->save('drone/settings', $data); + + return json_encode($data); + } + + return false; + } +} diff --git a/README.md b/README.md index 9d7f77a..12a0d27 100644 --- a/README.md +++ b/README.md @@ -13,20 +13,17 @@ It provides an integration with Drone CI promote feature to trigger a pipeline r ## Configuration 1. Ensure that from your Drone account you have an access token and permissions to promote a build for the project and branch, you want to use. -2. Edit Cockpit config/config.yaml and add a new entry for drone like below: - -```yaml -drone: - url: https://YOUR.DRONE.SERVER - token: - owner: - project: - branch: - target: - build: # leave empty and the addon will use the latest successfull build based on a push event - -``` +2. Go to "Settings - Drone Deploys" and add a your drone configuration like below as following +| | +| --- | --- +| URL: | your drone server url, pe. https://YOUR.DRONE.SERVER +| Token: | your drone access token +| Owner: | the owner of the git repository +| Project: | the git project +| Branch: | the branch in your git repository for the deployment +| Target: | the target condition used in your drone pipeline +| Build: | the build number used as base for deployment, leave empty and the addon will use the latest successfull build based on a push event ### Permissions diff --git a/admin.php b/admin.php index df479ce..5665d4a 100644 --- a/admin.php +++ b/admin.php @@ -9,10 +9,22 @@ $this("acl")->addResource('drone', [ 'manage.view', 'manage.deploy', + 'manage.settings' ]); +/* + * add menu entry to settings + */ +$this->on('cockpit.view.settings.item', function () { + if ($this->module('cockpit')->hasaccess('drone', 'manage.settings')) { + $this->renderView("drone:views/partials/settings.php"); + } +}); + + $app->on('admin.init', function () use ($app) { - if ($app->config['drone']) { + $settings = $app->storage->findOne('drone/settings'); + if ($settings && $settings['active']) { // Bind admin routes. $this->bindClass('Drone\\Controller\\Admin', 'drone/deploys'); @@ -26,4 +38,9 @@ $app->on('admin.init', function () use ($app) { ]); } } + + if ($app->module('cockpit')->hasaccess('drone', 'manage.settings')) { + // Add settings + $this->bindClass('Drone\\Controller\\Settings', 'drone/settings'); + } }); diff --git a/bootstrap.php b/bootstrap.php index 664d275..9fc98f4 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -10,13 +10,13 @@ if (COCKPIT_ADMIN && !COCKPIT_API_REQUEST) { // Extend addon functions. $this->module('drone')->extend([ 'fetchDeploys' => function ($limit = 50) { - $settings = $this->app->config['drone'] ?? FALSE; + $settings = $this->app->storage->findOne('drone/settings') ?? FALSE; if (!$settings || !isset($settings['url'], $settings['owner'], $settings['project'], $settings['target'], - $settings['token'])) { + $settings['token']) || !$settings['active']) { return []; } @@ -85,13 +85,13 @@ if (COCKPIT_ADMIN && !COCKPIT_API_REQUEST) { }, 'createDeploy' => function ($fromBuild) { - $settings = $this->app->config['drone']; + $settings = $this->app->storage->findOne('drone/settings'); if (!$fromBuild || !$settings || !isset($settings['url'], $settings['owner'], $settings['project'], $settings['target'], - $settings['token'])) { + $settings['token']) || !$settings['active']) { return array( "error" => "missing settings" diff --git a/views/partials/settings.php b/views/partials/settings.php new file mode 100644 index 0000000..5bdf8c0 --- /dev/null +++ b/views/partials/settings.php @@ -0,0 +1,18 @@ + + +
+
+ + @lang('Drone Deploys') + +
+ @lang('Drone Deploys') +
+ +
+
diff --git a/views/settings/index.php b/views/settings/index.php new file mode 100644 index 0000000..c2069a3 --- /dev/null +++ b/views/settings/index.php @@ -0,0 +1,105 @@ +
+ +
+ +
+ +
+ +
+ +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + +
+ + @lang('Cancel') +
+
+
+ +
+ +
+ +
+ +
+ +
+
+ +
+ +
{ App.Utils.dateformat( new Date( 1000 * drone._modified )) }
+
+ +
+ +
+ +
+ +
+ + + + +