function api_validate_form1($action, &$flowScope) { $registry = Zend_Registry::getInstance(); $translate = $registry->get("Zend_Translate"); /** * @var Api $api */ $api = $flowScope["api"]; $validationErrors = array(); if (isset($_POST["apiName"]) && !empty($_POST["apiName"])) { $api->displayName = $_POST["apiName"]; } else { $validationErrors["name"] = $translate->translate("Apis must have a name."); } if (isset($_POST["apiEndpoint"]) && !empty($_POST["apiEndpoint"])) { $api->endpoint = $_POST["apiEndpoint"]; } else { $validationErrors["endpoint"] = $translate->translate("Apis must have an endpoint."); } $targetHosts = array(); foreach ($_POST as $k => $v) { if (preg_match('/^targethost[0-9]+$/', $k) && !empty($v)) { $th = new TargetHost(); $th->url = $v; $targetHosts[] = $th; } } if (empty($targetHosts)) { $validationErrors["targethost0"] = $translate->translate("Apis must have at least one targethost."); } else { $contexts = $api->getContexts(); if (empty($contexts)) { $contexts = array(new ApiContext()); } $context = $contexts[0]; $context->setStatus(Status::$ACTIVE); $context->targetHosts = array(); $i = 0; foreach ($targetHosts as $th) { $isbad = $this->target_host_is_bad($th); if ($isbad) { $validationErrors["targethost" . $i] = $isbad; } $context->targetHosts[] = $th; } $api->setContexts($contexts); } if ($_POST["apienabled"]) { $api->setStatus(Status::$ACTIVE); } else { $api->setStatus(Status::$INACTIVE); } $authTypes = array(); $authkeykey = null; foreach ($_POST as $k => $v) { $matches = array(); if (preg_match('/^auth-(\\w*)$/', $k, $matches) && $v == 1) { $authType = isset($matches[1]) ? AuthType::fromString($matches[1]) : null; if (!empty($authType)) { $authTypes[] = $authType; if ($authType === AuthType::$AUTHKEY) { $authkeykey = $_POST["authkey-key"]; $isbad = $this->auth_key_key_is_bad($authkeykey); if ($isbad) { $validationErrors["authkey-key"] = $isbad; } } } } } if (!empty($authTypes)) { $provAuth = new ProvisionAuthentication(); $provAuth->setAuths($authTypes); $provAuth->setAuthKey($authkeykey); $api->setAuthentication($provAuth); } else { $validationErrors["auth"] = $translate->translate("Apis must have at least one auth type."); } if ($_POST["https"]) { $https = new HTTPSType(); $https->setEnabled("true"); $https_mode = $_POST["https-mode"]; if (empty($https_mode) || TLSMode::fromString($https_mode) === null) { $validationErrors["https-mode"] = $translate->translate("With https on, TLS Mode must be 1way or 2way"); } else { $https->setTlsMode(TLSMode::fromString($https_mode)); } $api->setHttps($https); } else { $https = new HTTPSType(); $https->setEnabled(false); $api->setHttps($https); } foreach (array("tps-warn", "tps-threshold", "tpm-warn", "tpm-threshold") as $tpx) { if (isset($_POST[$tpx])) { if (is_numeric($_POST[$tpx])) { $contexts = $api->getContexts(); /** * @var ApiContext $context */ $context = $contexts[0]; switch ($tpx) { case "tps-warn": $context->setMaxRateLimitTPSWarning($_POST[$tpx]); break; case "tps-threshold": $context->setMaxRateLimitTPSThreshold($_POST[$tpx]); break; case "tpm-warn": $context->setMaxRateLimitTPMWarning($_POST[$tpx]); break; case "tpm-threshold": $context->setMaxRateLimitTPMThreshold($_POST[$tpx]); break; } } else { switch ($tpx) { case "tps-warn": $validationErrors[$tpx] = $translate->translate("Transactions-per-second warning trigger must be a number"); break; case "tps-threshold": $validationErrors[$tpx] = $translate->translate("Transactions-per-second cutoff threshold must be a number"); break; case "tpm-warn": $validationErrors[$tpx] = $translate->translate("Transactions-per-minute warning trigger must be a number"); break; case "tpm-threshold": $validationErrors[$tpx] = $translate->translate("Transactions-per-minute cutoff threshold must be a number"); break; } } } } $methods = $api->getAllowedHttpMethods(); $methods = array_diff($methods, array("GET")); if ($_POST["method-get"]) { $methods[] = "GET"; } $methods = array_diff($methods, array("POST")); if ($_POST["method-post"]) { $methods[] = "POST"; } $methods = array_diff($methods, array("PUT")); if ($_POST["method-put"]) { $methods[] = "PUT"; } $methods = array_diff($methods, array("DELETE")); if ($_POST["method-delete"]) { $methods[] = "DELETE"; } $api->setAllowedHttpMethods($methods); $headerTransformations = SharedViewUtility::deserializeHeaderTransformations($this->getRequest()); $api->setHeaderTransformations($headerTransformations); $api->setHeaderTransformationEnabled(count($headerTransformations) > 0); SharedViewUtility::validateHeaderTransformations($api->getHeaderTransformations(), $validationErrors); $properties = SharedViewUtility::deserializeProperties($this->getRequest()); $api->setProperties($properties); SharedViewUtility::validateProperties($properties, $validationErrors); $tdrsenabled = (bool) $_POST["tdrsenabled"]; $api->setTdrEnabled($tdrsenabled); $tdrRules = SharedViewUtility::deserializeTdrRules($this->getRequest()); $api->setTdrData($tdrRules); SharedViewUtility::validateTdrRules($tdrRules, $validationErrors); // If I don't have access to the view, set error messages in the flow scope $flowScope["validationErrors"] = $validationErrors; $flowScope['gotoAuthsubflow'] = $action === "submitAndAuth"; return count($validationErrors) === 0 ? "valid" : "invalid"; }
public static function fromXML(SimpleXMLElement $xml) { return TLSMode::fromString((string) $xml); }