setBehaviors() public method

public setBehaviors ( $behaviors )
Exemplo n.º 1
0
 public function xSave2Action()
 {
     $this->request->restrictAccess(Acl::RESOURCE_FARMS_ROLES, Acl::PERM_FARMS_ROLES_MANAGE);
     $this->request->defineParams(array('roleId' => array('type' => 'int'), 'behaviors' => array('type' => 'array'), 'tags' => array('type' => 'array'), 'description', 'name', 'os', 'parameters' => array('type' => 'json'), 'removedImages' => array('type' => 'json'), 'images' => array('type' => 'json'), 'properties' => array('type' => 'json'), 'scripts' => array('type' => 'json'), 'chef' => array('type' => 'json')));
     $id = $this->getParam('roleId');
     if ($id == 0) {
         if ($this->user->isScalrAdmin()) {
             $origin = ROLE_TYPE::SHARED;
             $envId = 0;
             $clientId = 0;
         } else {
             $origin = ROLE_TYPE::CUSTOM;
             $envId = $this->environment->id;
             $clientId = $this->user->getAccountId();
         }
         $dbRole = new DBRole(0);
         $dbRole->generation = 2;
         $dbRole->origin = $origin;
         $dbRole->envId = $envId;
         $dbRole->clientId = $clientId;
         $dbRole->catId = $this->getParam('catId');
         $dbRole->name = $this->getParam('name');
         $dbRole->os = $this->getParam('os');
         $dbRole->osGeneration = $this->getParam('osGeneration');
         $dbRole->osFamily = $this->getParam('osFamily');
         $dbRole->osVersion = $this->getParam('osVersion');
         $dbRole->addedByEmail = $this->user->getEmail();
         $dbRole->addedByUserId = $this->user->getId();
         $dbRole->save();
         $dbRole->setBehaviors(array_values($this->getParam('behaviors')));
     } else {
         $dbRole = DBRole::loadById($id);
         if (!$this->user->isScalrAdmin()) {
             $this->user->getPermissions()->validate($dbRole);
         }
     }
     if ($dbRole->origin == ROLE_TYPE::CUSTOM) {
         $variables = new Scalr_Scripting_GlobalVariables($this->getEnvironmentId(), Scalr_Scripting_GlobalVariables::SCOPE_ROLE);
         $variables->setValues(json_decode($this->getParam('variables'), true), $dbRole->id);
     }
     $dbRole->description = $this->getParam('description');
     foreach ($this->getParam('removedImages') as $imageId) {
         $dbRole->removeImage($imageId);
     }
     foreach ($this->getParam('images') as $image) {
         $image = (array) $image;
         $dbRole->setImage($image['image_id'], $image['platform'], $image['location'], $image['szr_version'], $image['architecture']);
     }
     $dbRole->setScripts($this->getParam('scripts'));
     //todo
     //$dbRole->setChefSettings($this->getParam('chef'));
     if ($this->user->isScalrAdmin()) {
         $dbRole->setTags($this->getParam('tags'));
     }
     $dbRole->save();
     $this->response->success('Role saved');
 }
Exemplo n.º 2
0
     $dbRole->origin = ROLE_TYPE::SHARED;
     $dbRole->envId = 0;
     $dbRole->clientId = 0;
     $dbRole->catId = $info['catId'];
     $dbRole->name = $info['name'];
     $dbRole->os = $info['os'];
     $dbRole->osFamily = $info['osFamily'];
     $dbRole->osGeneration = $info['osGeneration'];
     $dbRole->osVersion = $info['osVersion'];
     foreach ($info['behaviors'] as $behavior) {
         foreach (Scalr_Role_Behavior::loadByName($behavior)->getSecurityRules() as $rr) {
             $rules[] = array('rule' => $rr);
         }
     }
 }
 $dbRole->setBehaviors(array_values($info['behaviors']));
 $dbRole->description = $info['description'];
 $dbRole = $dbRole->save();
 $db->Execute("DELETE FROM role_security_rules WHERE role_id = ?", array($dbRole->id));
 foreach ($rules as $rule) {
     $db->Execute("INSERT INTO role_security_rules SET `role_id`=?, `rule`=?", array($dbRole->id, $rule['rule']));
     if ($rule['comment']) {
         $db->Execute("REPLACE INTO `comments` SET `env_id` = ?, `comment` = ?, `sg_name` = ?, `rule` = ?", array(0, $rule['comment'], "role:{$dbRole->id}", $rule['rule']));
     }
 }
 foreach ($info['images'] as $image) {
     $image = (array) $image;
     $dbRole->setImage($image['image_id'], SERVER_PLATFORMS::OPENSTACK, $image['location'], $image['szr_version'], $image['architecture']);
     $dbRole->setImage($image['image_id'], SERVER_PLATFORMS::ECS, $image['location'], $image['szr_version'], $image['architecture']);
 }
 $dbRole->save();
Exemplo n.º 3
0
 public function xSaveAction()
 {
     $this->request->restrictAccess(Acl::RESOURCE_FARMS_ROLES, Acl::PERM_FARMS_ROLES_MANAGE);
     $this->request->defineParams(array('roleId' => array('type' => 'int'), 'behaviors' => array('type' => 'json'), 'tags' => array('type' => 'json'), 'description', 'name', 'parameters' => array('type' => 'json'), 'removedImages' => array('type' => 'json'), 'images' => array('type' => 'json'), 'properties' => array('type' => 'json'), 'scripts' => array('type' => 'json'), 'variables' => array('type' => 'json'), 'chef' => array('type' => 'json')));
     $id = $this->getParam('roleId');
     if ($id == 0) {
         if ($this->user->isScalrAdmin()) {
             $origin = ROLE_TYPE::SHARED;
             $envId = null;
             $clientId = null;
         } else {
             $origin = ROLE_TYPE::CUSTOM;
             $envId = $this->environment->id;
             $clientId = $this->user->getAccountId();
         }
         // TODO: validate role name via Scalr\Model\Entity\Role::validateName(), validate other fields
         $dbRole = new DBRole(0);
         $dbRole->generation = 2;
         $dbRole->origin = $origin;
         $dbRole->envId = $envId;
         $dbRole->clientId = $clientId;
         $dbRole->catId = $this->getParam('catId');
         $dbRole->name = $this->getParam('name');
         //TODO: VALIDATE osId
         $dbRole->osId = $this->getParam('osId');
         $dbRole->addedByEmail = $this->user->getEmail();
         $dbRole->addedByUserId = $this->user->getId();
         $dbRole->save();
         $dbRole->setBehaviors(array_values($this->getParam('behaviors')));
     } else {
         $dbRole = DBRole::loadById($id);
         if (!$this->user->isScalrAdmin()) {
             $this->user->getPermissions()->validate($dbRole);
         }
     }
     if ($dbRole->origin == ROLE_TYPE::CUSTOM && $this->user->getAccountId()) {
         $variables = new Scalr_Scripting_GlobalVariables($this->user->getAccountId(), $this->getEnvironmentId(), Scalr_Scripting_GlobalVariables::SCOPE_ROLE);
         $variables->setValues(is_array($this->getParam('variables')) ? $this->getParam('variables') : [], $dbRole->id);
     } else {
         if ($this->user->isScalrAdmin()) {
             $variables = new Scalr_Scripting_GlobalVariables(0, 0, Scalr_Scripting_GlobalVariables::SCOPE_ROLE);
             $variables->setValues(is_array($this->getParam('variables')) ? $this->getParam('variables') : [], $dbRole->id);
         }
     }
     $dbRole->clearProperties('chef.');
     if (!is_null($this->getParam('chef'))) {
         $dbRole->setProperties($this->getParam('chef'));
     }
     $dbRole->description = $this->getParam('description');
     $images = $this->getParam('images');
     if (!empty($images)) {
         foreach ($images as $i) {
             $dbRole->__getNewRoleObject()->setImage($i['platform'], $i['cloudLocation'], $i['imageId'], $this->user->getId(), $this->user->getEmail());
         }
     }
     $scripts = $this->getParam('scripts');
     if (is_null($scripts)) {
         $scripts = [];
     }
     $dbRole->setScripts($scripts);
     $dbRole->save();
     $this->response->data(['role' => $this->getInfo($dbRole->id, true)]);
     $this->response->success('Role saved');
 }