/** * Function to handle index request on /policy * Fills out the policy-list view with policies, apis and auths * retrieved from E3. */ public function indexAction() { // //print_r("indexAction"); $this->view->messages = $this->getZendFlashMessenger()->getMessages(); $this->view->apis = $this->policyManager->getAllApis(true); $this->view->auths = $this->policyManager->getAllAuths(true); $this->view->policies = $this->policyManager->getAllPolicies(true); } /** * Handle the delete-Policy action */ public function deleteAction() { $this->policyManager->deletePolicy($this->_getParam("id")); $this->getZendFlashMessenger()->addMessage(PolicyController::translate("Deleted Policy")); $this->_redirect("/policy"); } /** * This is the on-enter callback for the "form" state * It will load the object needed to back the form. * @param $action * @param $flowScope */ public function loadFormBacker($action, &$flowScope) { // Default to using the id from the $flowScope $id = @$flowScope['policyId']; // If that is empty then we use the one from the request
/** * This function will guarantee that an api object exists in the * view object and in the flowscope. * * This function will set a null apiid in the view and flowscope if * this is a new api. * * @param $action * @param $flowScope */ function fill_form($action, &$flowScope) { $registry = Zend_Registry::getInstance(); $translate = $registry->get("Zend_Translate"); $apiid = $this->_getParam("id"); if (!isset($flowScope["api"])) { if ($apiid === "create") { $flowScope["apiid"] = null; $api = new Api(); $api->setStatus(Status::$ACTIVE); $provAuth = new ProvisionAuthentication(); $provAuth->setAuths(array(AuthType::$NOAUTH)); $api->setAuthentication($provAuth); $context = new ApiContext(); $context->setId("actx"); $context->setMaxRateLimitTPMThreshold(-1); $context->setMaxRateLimitTPMWarning(-1); $context->setMaxRateLimitTPSWarning(-1); $context->setMaxRateLimitTPSThreshold(-1); $api->setContexts(array($context)); $methods = array("GET", "POST", "PUT", "DELETE"); $api->setAllowedHttpMethods($methods); $flowScope["api"] = $api; } else { $flowScope["apiid"] = $apiid; try { $api = $this->getManager()->getApi($apiid); $flowScope["api"] = $api; $flowScope["relatedProperties"] = JsonPropertyPrinter::getRelatedFromApi($api); } catch (Exception $e) { $this->_helper->FlashMessenger($translate->translate("Error fetching api ") . $apiid . " : " . $e->getMessage()); $this->_helper->redirector("index", "api"); } } } if (!isset($flowScope["validationErrors"])) { $flowScope["validationErrors"] = array(); } }
/** * This is the on-enter callback for the "form" state * It will load the object needed to back the form. * @param $action * @param $flowScope */ public function loadFormBacker($action, &$flowScope) { $registry = Zend_Registry::getInstance(); $translate = $registry->get("Zend_Translate"); // Default to using the id from the $flowScope $id = @$flowScope['authid']; // If that is empty then we use the one from the request if (empty($id)) { $id = $this->_getParam("id"); } if (empty($id)) { throw new Zend_Controller_Action_Exception($translate->translate('Resource Not Found'), 404); } $howMany = !isset($flowScope['howMany']) ? "1" : $flowScope['howMany']; $flowScope['howMany'] = $howMany; // Set the id is the flowscope $flowScope['authid'] = $id; $auth = @$flowScope['auth']; /** * If the id is "create" and we haven't filled out the form before * then we need to create a new Auth and set some defaults */ if ($id === "create" && $auth === null) { $auth = new Auth(); $auth->id = $id; $auth->type = AuthType::$AUTHKEY; if (isset($flowScope['preSelectedAuthType'])) { $auth->type = $flowScope['preSelectedAuthType']; $flowScope['authTypeLocked'] = true; } $auth->apiContext = "actx"; $auth->policyContext = "pctx"; $flowScope['isNew'] = true; } else { if ($auth === null) { $authManager = new AuthManager(); $auth = $authManager->getAuth($id); $flowScope['isNew'] = false; $flowScope["relatedProperties"] = JsonPropertyPrinter::getRelatedFromAuth($auth); } } /** * Put the auth in the flow scope for reference by other states and the views */ $flowScope['auth'] = $auth; }