From a1f4baa8008c98552ee3546cb15bd735d91ed2e9 Mon Sep 17 00:00:00 2001 From: Jakob Schrettenbrunner Date: Fri, 10 Apr 2020 17:38:20 +0200 Subject: [PATCH] re-enable auto-deploy daemon endpoint --- .../Controllers/Daemon/ActionController.php | 2 +- app/Models/Node.php | 24 +++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/Daemon/ActionController.php b/app/Http/Controllers/Daemon/ActionController.php index c50c9a3d..eb77b4b9 100644 --- a/app/Http/Controllers/Daemon/ActionController.php +++ b/app/Http/Controllers/Daemon/ActionController.php @@ -102,6 +102,6 @@ class ActionController extends Controller $node = Node::findOrFail($nodeId); // Manually as getConfigurationAsJson() returns it in correct format already - return []; + return $node->getJsonConfiguration(); } } diff --git a/app/Models/Node.php b/app/Models/Node.php index 9518084c..950186fd 100644 --- a/app/Models/Node.php +++ b/app/Models/Node.php @@ -151,13 +151,13 @@ class Node extends Model } /** - * Returns the configuration in JSON format. + * Returns the configuration as an array. * * @return string */ - public function getYamlConfiguration() + private function getConfiguration() { - $config = [ + return [ 'debug' => false, 'api' => [ 'host' => '0.0.0.0', @@ -204,8 +204,24 @@ class Node extends Model 'remote' => route('index'), 'token' => $this->daemonSecret, ]; + } - return Yaml::dump($config, 4, 2); + /** + * Returns the configuration in Yaml format. + * + * @return string + */ + public function getYamlConfiguration() { + return Yaml::dump($this->getConfiguration(), 4, 2); + } + + /** + * Returns the configuration in JSON format. + * + * @return string + */ + public function getJsonConfiguration(bool $pretty = false) { + return json_encode($this->getConfiguration(), $pretty ? JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT : JSON_UNESCAPED_SLASHES); } /**