private function _setKey(SSLKey &$key, $insertMode = FALSE) { $method = "PUT"; $url = E3_PROV_URL_KEY . "/" . rawurlencode($key->getId()); if ($insertMode) { $method = "POST"; $url = E3_PROV_URL_KEY; } /** * Send the XML payload the the Provisioning Backend */ $xmlKey = $key->toXML(); LoggerInterface::log(($insertMode ? "Creating" : "Updating") . " SSLKey: {$xml}\nEndpoint: ({$method}) {$url}", LoggerInterface::INFO); $reply = $this->restClient->makeCall($url, $method, $xmlKey); $xml = simplexml_load_string($reply->getPayload()); // TODO: figure out why successful adds sometime return code 100 if ($reply->getHTTPCode() === "200" || $reply->getHTTPCode() === "100") { if ($insertMode) { if ($key->getId() == NULL) { $key->setId((string) $xml->id); } } return $key; } else { throw new Exception(!empty($xml->error) ? $xml->error->errorText : UNDEFINED_ERROR_TEXT); } }
private function validateFormAndGetKey(&$validationErrors) { $registry = Zend_Registry::getInstance(); $translate = $registry->get("Zend_Translate"); $validationErrors = array(); $key = new SSLKey(); $validate_alnum_wspace = new Zend_Validate_Alnum(array('allowWhiteSpace' => true)); $name = $_POST['key_name']; if (!$validate_alnum_wspace->isValid($name)) { $validationErrors['key_name'] = $translate->translate("The key name must be only alpha-numeric characters"); } $key->setDisplayName($_POST['key_name']); // TODO: validate id value? $id = $_POST['key_id']; $key->setId($id); // Get key file contents if (isset($_FILES['key_file']) && !empty($_FILES['key_file']['name'])) { if (!$_FILES['key_file']['error']) { $contents = file_get_contents($_FILES['key_file']['tmp_name']); if ($contents !== false) { $key->setContent($contents); } else { $validationErrors['key_file'] = $translate->translate("There was an error getting contents of Key file."); } } else { $validationErrors['key_file'] = $translate->translate("There was an error uploading file: ") . $_FILES['key_file']['error']; } } else { if (empty($id)) { // A create operation (new SSLKey) must provide a content file $validationErrors['key_file'] = $translate->translate("Please upload a key file."); } } return $key; }