Skip to content

Commit

Permalink
Merge pull request #1085 from pantheon-systems/fix/site_set-https-cer…
Browse files Browse the repository at this point in the history
…tificate

Fixed bug in site set-https-certificate
  • Loading branch information
TeslaDethray committed May 26, 2016
2 parents c741b98 + 407e32a commit e53dfc3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 56 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
72 changes: 28 additions & 44 deletions php/Terminus/Commands/SiteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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=<site>]
* : name of the site
* : Name of the site to apply the HTTPS certificate to
*
* [--env=<env>]
* : site environment
* : Environment of the site to apply the HTTPS certificate to
*
* [--certificate=<value>]
* : Certificate
*
* [--private-key=<value>]
* : RSA Private Key
* : RSA private key
*
* [--intermediate-certificate=<value>]
* : (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;
}

Expand Down
27 changes: 15 additions & 12 deletions php/Terminus/Models/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
}

Expand Down

0 comments on commit e53dfc3

Please sign in to comment.