diff --git a/CHANGELOG.md b/CHANGELOG.md index aa6d5fe12..43e7c0d47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ All notable changes to this project starting with the 0.6.0 release will be docu - Undefined method error while running `sites mass-update` has been fixed. (#1064) - Eliminated superfluous exception catching in `TerminusRequest` so that Github API rate limit overages will not disrupt scripts. (#1082) - Fixed bug in `delete-env` which prevented the `--remove-branch` option from working. (#1084) +- Fixed bug in `site set-https-certificate`. (#1085) - Updated dependencies to fix blank-menus-in-Windows bug. (#1086) ## [0.11.1] - 2016-03-30 diff --git a/php/Terminus/Commands/SiteCommand.php b/php/Terminus/Commands/SiteCommand.php index 2c8ecf82b..bf123740c 100755 --- a/php/Terminus/Commands/SiteCommand.php +++ b/php/Terminus/Commands/SiteCommand.php @@ -1605,77 +1605,61 @@ public function setDrushVersion($args, $assoc_args) { } /** - * Add/replace an HTTPS Certificate for an environment + * Add/replace an HTTPS certificate for an environment * * ## OPTIONS * * [--site=] - * : name of the site + * : Name of the site to apply the HTTPS certificate to * * [--env=] - * : site environment + * : Environment of the site to apply the HTTPS certificate to * * [--certificate=] * : Certificate * * [--private-key=] - * : RSA Private Key + * : RSA private key * * [--intermediate-certificate=] - * : (optional) CA Intermediate Certificate(s) + * : (optional) CA intermediate certificate(s) * * @subcommand set-https-certificate */ public function setHttpsCertificate($args, $assoc_args) { $site = $this->sites->get( - $this->input()->sitename(['args' => $assoc_args]) + $this->input()->sitename(['args' => $assoc_args,]) ); $environment = $site->environments->get( - $this->input()->env(['args' => $assoc_args, 'site' => $site]) - ); - - $certificate = $this->input()->string( - [ - 'args' => $assoc_args, - 'key' => 'certificate', - 'message' => 'Certificate', - ] - ); - $private_key = $this->input()->string( - [ - 'args' => $assoc_args, - 'key' => 'private-key', - 'message' => 'RSA Private Key', - ] + $this->input()->env(['args' => $assoc_args, 'site' => $site,]) ); - $is_interactive = !isset($assoc_args['certificate']); - if ($is_interactive) { - $intermediate_certificate = $this->input()->string( - [ - 'args' => $assoc_args, - 'key' => 'intermediate-certificate', - 'message' => 'CA Intermediate Certificate(s) (optional)', - ] - ); - } else { - $intermediate_certificate = ''; - } - - $options = [ - 'certificate' => trim($certificate), - 'private_key' => trim($private_key) + $https = [ + 'cert' => $this->input()->optional( + ['choices' => $assoc_args, 'key' => 'certificate',] + ), + 'key' => $this->input()->optional( + ['choices' => $assoc_args, 'key' => 'private-key',] + ), + 'intermediary' => $this->input()->optional( + ['choices' => $assoc_args, 'key' => 'intermediate-certificate',] + ), ]; - - $intermediate_certificate = trim($intermediate_certificate); - if ($intermediate_certificate != '') { - $options['intermediate_certificate'] = $intermediate_certificate; + if (is_null($https['cert']) + && is_null($https['intermediary']) + && ($this->log()->getOptions('logFormat') == 'normal') + ) { + $message = 'No certificate was provided.'; + $message .= ' Please provide a CA intemediate certificate.'; + $https['intermediary'] = $this->input()->string( + ['message' => $message, 'required' => true,] + ); } - $workflow = $environment->setHttpsCertificate($options); + $workflow = $environment->setHttpsCertificate($https); + $this->log()->info('SSL certificate updated. Converging loadbalancer.'); $workflow->wait(); $this->workflowOutput($workflow); - return true; } diff --git a/php/Terminus/Models/Environment.php b/php/Terminus/Models/Environment.php index dc468bd3e..15abb20d2 100755 --- a/php/Terminus/Models/Environment.php +++ b/php/Terminus/Models/Environment.php @@ -674,21 +674,24 @@ public function setDrushVersion($version_number) { } /** - * Add/Replace an HTTPS Certificate on the Environment + * Add/replace an HTTPS certificate on the environment * - * @param array $options Certificate data` + * @param array $certificate Certificate data elements as follow + * string cert Certificate + * string key RSA private key + * string intermediary CA intermediate certificate(s) * * @return $workflow */ - public function setHttpsCertificate($options = []) { - $params = [ - 'cert' => $options['certificate'], - 'key' => $options['private_key'], - ]; - - if (isset($options['intermediate_certificate'])) { - $params['intermediary'] = $options['intermediate_certificate']; - } + public function setHttpsCertificate($certificate = []) { + // Weed out nulls + $params = array_filter( + $certificate, + function ($param) { + $is_not_null = !is_null($param); + return $is_not_null; + } + ); $response = $this->request->request( sprintf( @@ -701,7 +704,7 @@ public function setHttpsCertificate($options = []) { // The response to the PUT is actually a workflow $workflow_data = $response['data']; - $workflow = new Workflow($workflow_data); + $workflow = new Workflow($workflow_data, ['owner' => $this->site,]); return $workflow; }