summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Pugh2017-10-25 20:01:51 (GMT)
committerJon Pugh2017-10-25 20:01:51 (GMT)
commit37bd7d70753f50a8fd2904b5b67772e012e8c107 (patch)
tree42c684b002eb3fb2dceb31c00bc9417a58cae1ea
parent06280e10ef5538f5f8447f728fadf713a607a0ff (diff)
Add "services" to non-servers as "service_subscriptions". Separate method options_documentation() to server_options, platform_options, and site_options.
-rw-r--r--src/Command/ServicesCommand.php48
-rw-r--r--src/Context.php39
-rw-r--r--src/Service.php33
-rw-r--r--src/Service/DbService.php21
-rw-r--r--src/Service/HttpService.php15
5 files changed, 108 insertions, 48 deletions
diff --git a/src/Command/ServicesCommand.php b/src/Command/ServicesCommand.php
index 89baac1..2e343cd 100644
--- a/src/Command/ServicesCommand.php
+++ b/src/Command/ServicesCommand.php
@@ -81,9 +81,9 @@ class ServicesCommand extends Command
$input,
$output
);
- if (isset($this->context->type) && $this->context->type != 'server') {
- throw new \Exception('Context must be a server.');
- }
+// if (isset($this->context->type) && $this->context->type != 'server') {
+// throw new \Exception('Context must be a server.');
+// }
$this->sub_command = $input->getArgument('sub_command');
}
@@ -120,19 +120,42 @@ class ServicesCommand extends Command
$this->io->comment("Add Services");
$service = $this->io->choice('Which service?', $this->context->getServiceOptions());
- // Then ask which service type
- $service_type = $this->io->choice('Which service type?', $this->context->getServiceTypeOptions($service));
- // Then ask for all options.
- $properties = $this->askForServiceProperties($service);
+ // If server, ask which service type.
+ if ($this->context->type == 'server') {
+ $service_type = $this->io->choice('Which service type?', $this->context->getServiceTypeOptions($service));
- $this->io->info("Adding $service service $service_type...");
+ // Then ask for all options.
+ $properties = $this->askForServiceProperties($service);
- try {
- $this->context->config['services'][$service] = [
+ $this->io->info("Adding $service service $service_type...");
+
+ $services_key = 'services';
+ $service_info = [
'type' => $service_type,
- 'properties' => $properties,
];
+ }
+ // All other context types are associating with servers that provide the service.
+ else {
+ $server = $this->io->choice('Which server?', $this->getApplication()->getServerOptions($service));
+
+ // Then ask for all options.
+ $server_context = $this->getApplication()->getContext($server);
+ $properties = $this->askForServiceProperties($service);
+
+ $this->io->info("Using $service service from server $server...");
+
+ $services_key = 'service_subscriptions';
+ $service_info = [
+ 'server' => $server,
+ ];
+ }
+
+ try {
+ $this->context->config[$services_key][$service] = $service_info;
+ if (!empty($properties)) {
+ $this->context->config[$services_key][$service]['properties'] = $properties;
+ }
$this->context->save();
$this->io->success('Service saved to Context!');
}
@@ -149,8 +172,9 @@ class ServicesCommand extends Command
private function askForServiceProperties($service) {
$class = $this->context->getAvailableServices($service);
+ $method = "{$this->context->type}_options";
- $options = $class::option_documentation();
+ $options = $class::{$method}();
$properties = [];
foreach ($options as $name => $description) {
// If option does not exist, ask for it.
diff --git a/src/Context.php b/src/Context.php
index 2257312..ea9b954 100644
--- a/src/Context.php
+++ b/src/Context.php
@@ -143,7 +143,7 @@ class Context
*
* @return array
*/
- public function getAvailableServices($service = NULL) {
+ public function getAvailableServices($service = '') {
// Load all service classes
$classes = [];
@@ -246,7 +246,7 @@ class Context
public function getConfigTreeBuilder()
{
$tree_builder = new TreeBuilder();
- $root_node = $tree_builder->root('server');
+ $root_node = $tree_builder->root($this->type);
$root_node
->children()
->scalarNode('name')
@@ -255,15 +255,24 @@ class Context
->end();
// Load Services
+ if ($this->type == 'server') {
+ $services_key = 'services';
+ $services_property = 'type';
+ }
+ else {
+ $services_key = 'service_subscriptions';
+ $services_property = 'server';
+ }
+
$root_node
->children()
- ->arrayNode('services')
+ ->arrayNode($services_key)
->prototype('array')
->children()
- ->scalarNode('type')
+ ->scalarNode($services_property)
->isRequired(true)
->end()
- ->append($this->addServiceProperties())
+ ->append($this->addServiceProperties($services_key))
->end()
->end();
@@ -287,18 +296,28 @@ class Context
/**
* Append Service class options_documentation to config tree.
*/
- public function addServiceProperties()
+ public function addServiceProperties($property_name = 'services')
{
$builder = new TreeBuilder();
$node = $builder->root('properties');
// Load config tree from Service type classes
- if (!empty($this->getProperty('services')) && !empty($this->getProperty('services'))) {
- foreach ($this->getProperty('services') as $service => $info) {
+ if (!empty($this->getProperty($property_name)) && !empty($this->getProperty($property_name))) {
+ foreach ($this->getProperty($property_name) as $service => $info) {
+
+ // If type is empty, it's because it's in the ServerContext
+ if (empty($info['type'])) {
+ $server = $this->application->getContext($info['server']);
+ $service_type = ucfirst($server->getService($service)->type);
+ }
+ else {
+ $service_type = ucfirst($info['type']);
+ }
$service = ucfirst($service);
- $service_type = ucfirst($info['type']);
$class = "\Aegir\Provision\Service\\{$service}\\{$service}{$service_type}Service";
- foreach ($class::option_documentation() as $name => $description) {
+ $method = "{$this->type}_options";
+
+ foreach ($class::{$method}() as $name => $description) {
$node
->children()
->scalarNode($name)->end()
diff --git a/src/Service.php b/src/Service.php
index 46aba4d..4ca3296 100644
--- a/src/Service.php
+++ b/src/Service.php
@@ -69,28 +69,31 @@ class Service {
* Return a list of user configurable options that this service provides to Server Context objects.
*/
static function server_options() {
- return [
- 'http_port' => 'The port which the web service is running on.',
- 'web_group' => 'server with http: OS group for permissions; working default will be attempted',
- ];
+ return [];
+// return [
+// 'http_port' => 'The port which the web service is running on.',
+// 'web_group' => 'server with http: OS group for permissions; working default will be attempted',
+// ];
}
/**
* Return a list of user configurable options that this service provides to Platform Context objects.
*/
static function platform_options() {
- return [
- 'platform_extra_config' => 'Extra lines of configuration to add to this platform.',
- ];
+ return [];
+// return [
+// 'platform_extra_config' => 'Extra lines of configuration to add to this platform.',
+// ];
}
/**
* Return a list of user configurable options that this service provides to Site Context objects.
*/
static function site_options() {
- return [
- 'site_mail' => 'The email address to use for the ServerAdmin configuration.',
- ];
+ return [];
+// return [
+// 'site_mail' => 'The email address to use for the ServerAdmin configuration.',
+// ];
}
/**
@@ -430,16 +433,6 @@ class Service {
// }
/**
- * Return service-specific configuration options for help.
- *
- * @return
- * array('option' => 'description')
- */
- static function option_documentation() {
- return array();
- }
-
- /**
* Save symlink for this server from /var/aegir/config/APPLICATION_NAME.conf -> /var/aegir/config/SERVER/APPLICATION_NAME.conf
*
* If service requires a fixed path config file, implement this function in the init_server() method.
diff --git a/src/Service/DbService.php b/src/Service/DbService.php
index 517ac87..7042a68 100644
--- a/src/Service/DbService.php
+++ b/src/Service/DbService.php
@@ -24,7 +24,12 @@ class DbService extends Service
const SERVICE_NAME = 'Database Server';
- static function option_documentation()
+ /**
+ * Implements Service::server_options()
+ *
+ * @return array
+ */
+ static function server_options()
{
return [
'master_db' => 'server with db: Master database connection info, {type}://{user}:{password}@{host}',
@@ -33,6 +38,20 @@ class DbService extends Service
}
/**
+ * Implements Service::server_options()
+ *
+ * @return array
+ */
+ static function site_options()
+ {
+ return [
+ 'db_name' => 'The name of the database. Default: Automatically generated.',
+ 'db_user' => 'The username used to access the database. Default: Automatically generated.',
+ 'db_password' => 'The password used to access the database. Default: Automatically generated.',
+ ];
+ }
+
+ /**
* Register the db handler for sites, based on the db_server option.
*/
static function subscribe_site($context)
diff --git a/src/Service/HttpService.php b/src/Service/HttpService.php
index 79c00ce..0fbdc7a 100644
--- a/src/Service/HttpService.php
+++ b/src/Service/HttpService.php
@@ -24,16 +24,21 @@ class HttpService extends Service {
protected $ssl_enabled = FALSE;
- static function option_documentation() {
- return array(
+
+ /**
+ * Implements Service::server_options()
+ *
+ * @return array
+ */
+ static function server_options()
+ {
+ return [
'http_port' => 'The port which the web service is running on.',
-// 'http_platformd_path' => 'The path to store platforms.',
-// 'http_postd_path' => 'The path to store post configuration.',
'web_group' => 'server with http: OS group for permissions; working default will be attempted',
'web_disable_url' => 'server with http: URL disabled sites are redirected to; default {master_url}/hosting/disabled',
'web_maintenance_url' => 'server with http: URL maintenance sites are redirected to; default {master_url}/hosting/maintenance',
'restart_command' => 'The command to reload the web server configuration;'
- );
+ ];
}
/**