getScriptingData() public static method

public static getScriptingData ( $accountId, $envId )
Ejemplo n.º 1
0
 public function viewAction()
 {
     $this->request->restrictAccess(Acl::RESOURCE_ORCHESTRATION_ACCOUNT);
     $this->response->page('ui/account2/orchestration/view.js', array('orchestrationRules' => $this->getOrchestrationRules(), 'scriptData' => \Scalr\Model\Entity\Script::getScriptingData($this->user->getAccountId(), null)), array('ui/scripts/scriptfield.js', 'ui/services/chef/chefsettings.js'), array('ui/scripts/scriptfield.css'));
 }
Ejemplo n.º 2
0
 public function xGetScriptsAction()
 {
     $dbRole = DBRole::loadById($this->getParam('roleId'));
     if ($dbRole->origin == ROLE_TYPE::CUSTOM) {
         $this->user->getPermissions()->validate($dbRole);
     }
     $data = \Scalr\Model\Entity\Script::getScriptingData($this->user->getAccountId(), $this->getEnvironmentId());
     $data['roleScripts'] = $dbRole->getScripts();
     $this->response->data($data);
 }
Ejemplo n.º 3
0
 /**
  * @param   int   $roleId
  * @throws  Exception
  * @throws  Scalr_Exception_Core
  * @throws  Scalr_Exception_InsufficientPermissions
  * @throws  Scalr_UI_Exception_NotFound
  */
 public function editAction($roleId = 0)
 {
     $this->request->restrictAccess('ROLES', 'MANAGE');
     $params = array();
     $params['scriptData'] = \Scalr\Model\Entity\Script::getScriptingData($this->user->getAccountId(), $this->getEnvironmentId(true));
     $params['categories'] = array_values($this->listRoleCategories());
     $params['accountScripts'] = [];
     if (!$this->user->isScalrAdmin()) {
         foreach (Scalr_UI_Controller_Account2_Orchestration::controller()->getOrchestrationRules() as $script) {
             $script['system'] = 'account';
             $params['accountScripts'][] = $script;
         }
     }
     $envs = [];
     if ($this->request->getScope() == ScopeInterface::SCOPE_ACCOUNT) {
         foreach (Environment::find([['accountId' => $this->user->getAccountId()]], null, ['name' => true]) as $env) {
             /* @var $env Environment */
             $envs[] = ['id' => $env->id, 'name' => $env->name, 'enabled' => 1];
         }
     }
     $variables = new Scalr_Scripting_GlobalVariables($this->user->getAccountId(), $this->getEnvironmentId(true), ScopeInterface::SCOPE_ROLE);
     if ($roleId) {
         /* @var $role Role */
         $role = Role::findPk($roleId);
         if (!$role) {
             throw new Scalr_Exception_Core(sprintf(_("Role ID#%s not found in database"), $roleId));
         }
         $this->request->checkPermissions($role, true);
         $images = array();
         foreach (RoleImage::find([['roleId' => $role->id]]) as $image) {
             /* @var $image RoleImage */
             $im = $image->getImage();
             $a = get_object_vars($image);
             if ($im) {
                 $b = get_object_vars($im);
                 $b['scope'] = $im->getScope();
                 $b['dtAdded'] = Scalr_Util_DateTime::convertTz($b['dtAdded']);
                 $b['software'] = $im->getSoftwareAsString();
                 $a['name'] = $im->name;
                 $a['hash'] = $im->hash;
                 $a['extended'] = $b;
             }
             $images[] = $a;
         }
         $properties = [];
         foreach (RoleProperty::find([['roleId' => $role->id], ['name' => ['$like' => 'chef.%']]]) as $prop) {
             /* @var $prop RoleProperty */
             $properties[$prop->name] = $prop->value;
         }
         $params['role'] = array('roleId' => $role->id, 'name' => $role->name, 'catId' => $role->catId, 'os' => $role->getOs()->name, 'osId' => $role->osId, 'osFamily' => $role->getOs()->family, 'osGeneration' => $role->getOs()->generation, 'osVersion' => $role->getOs()->version, 'description' => $role->description, 'behaviors' => $role->getBehaviors(), 'images' => $images, 'scripts' => $role->getScripts(), 'dtadded' => Scalr_Util_DateTime::convertTz($role->added), 'addedByEmail' => $role->addedByEmail, 'chef' => $properties, 'isQuickStart' => $role->isQuickStart, 'isDeprecated' => $role->isDeprecated, 'isScalarized' => $role->isScalarized, 'environments' => []);
         if ($this->request->getScope() == ScopeInterface::SCOPE_ACCOUNT) {
             $allowedEnvs = $role->getAllowedEnvironments();
             if (!empty($allowedEnvs)) {
                 foreach ($envs as &$env) {
                     $env['enabled'] = in_array($env['id'], $allowedEnvs) ? 1 : 0;
                 }
             }
             $params['role']['environments'] = $envs;
         }
         $params['role']['variables'] = $variables->getValues($role->id);
         $params['roleUsage'] = ['farms' => $role->getFarmsCount($this->user->getAccountId(), $this->getEnvironmentId(true)), 'instances' => $role->getServersCount($this->user->getAccountId(), $this->getEnvironmentId(true))];
     } else {
         $params['role'] = array('roleId' => 0, 'name' => '', 'arch' => 'x86_64', 'agent' => 2, 'description' => '', 'behaviors' => array(), 'images' => array(), 'scripts' => array(), 'tags' => array(), 'environments' => [], 'variables' => $variables->getValues(), 'isScalarized' => 1);
         if ($this->request->getScope() == ScopeInterface::SCOPE_ACCOUNT) {
             $params['role']['environments'] = $envs;
         }
     }
     $this->response->page('ui/roles/edit.js', $params, ['ui/roles/edit/overview.js', 'ui/roles/edit/images.js', 'ui/roles/edit/scripting.js', 'ui/roles/edit/variables.js', 'ui/roles/edit/chef.js', 'ui/roles/edit/environments.js', 'ui/scripts/scriptfield.js', 'ui/core/variablefield.js', 'ui/services/chef/chefsettings.js'], ['ui/roles/edit.css', 'ui/scripts/scriptfield.css']);
 }
Ejemplo n.º 4
0
 public function editAction()
 {
     $this->request->restrictAccess(Acl::RESOURCE_FARMS_ROLES, Acl::PERM_FARMS_ROLES_MANAGE);
     $this->request->defineParams(array('roleId' => array('type' => 'int')));
     $params = array();
     $params['scriptData'] = \Scalr\Model\Entity\Script::getScriptingData($this->user->getAccountId(), $this->getEnvironment() ? $this->getEnvironmentId() : NULL);
     $params['categories'] = $this->db->GetAll("SELECT * FROM role_categories WHERE env_id IN (0, ?)", array($this->user->isScalrAdmin() ? 0 : $this->getEnvironmentId()));
     if ($this->getParam('roleId')) {
         $dbRole = DBRole::loadById($this->getParam('roleId'));
         if (!$this->user->isScalrAdmin()) {
             $this->user->getPermissions()->validate($dbRole);
         }
         $images = array();
         $imDetails = $dbRole->getImages(true);
         if (!empty($imDetails) && (is_array($imDetails) || $imDetails instanceof \Traversable)) {
             foreach ($imDetails as $platform => $locations) {
                 foreach ($locations as $location => $imageInfo) {
                     $images[] = array('image_id' => $imageInfo['image_id'], 'platform' => $platform, 'location' => $location, 'architecture' => $imageInfo['architecture']);
                 }
             }
         }
         $params['role'] = array('roleId' => $dbRole->id, 'name' => $dbRole->name, 'catId' => $dbRole->catId, 'os' => $dbRole->os, 'osFamily' => $dbRole->osFamily, 'osGeneration' => $dbRole->osGeneration, 'osVersion' => $dbRole->osVersion, 'description' => $dbRole->description, 'behaviors' => $dbRole->getBehaviors(), 'images' => $images, 'scripts' => $dbRole->getScripts(), 'dtadded' => Scalr_Util_DateTime::convertTz($dbRole->dateAdded), 'addedByEmail' => $dbRole->addedByEmail, 'software' => $dbRole->getSoftwareList(), 'tags' => array_fill_keys($dbRole->getTags(), 1), 'chef' => $dbRole->getProperties('chef.'));
         $variables = new Scalr_Scripting_GlobalVariables($this->user->getAccountId(), $this->user->isScalrAdmin() ? 0 : $this->getEnvironmentId(), Scalr_Scripting_GlobalVariables::SCOPE_ROLE);
         $params['role']['variables'] = $variables->getValues($dbRole->id);
         if ($this->user->isScalrAdmin()) {
             $params['roleUsage'] = array('farms' => $dbRole->getFarmRolesCount(), 'instances' => $this->db->GetOne("SELECT COUNT(*) FROM servers WHERE role_id=?", array($dbRole->id)));
         } else {
             $params['roleUsage'] = array('farms' => $dbRole->getFarmRolesCount($this->getEnvironmentId()), 'instances' => $this->db->GetOne("SELECT COUNT(*) FROM servers WHERE role_id=? AND env_id=?", array($dbRole->id, $this->getEnvironmentId())));
         }
     } else {
         $params['role'] = array('roleId' => 0, 'name' => '', 'arch' => 'x86_64', 'agent' => 2, 'description' => '', 'behaviors' => array(), 'images' => array(), 'scripts' => array(), 'tags' => array());
     }
     $this->response->page('ui/roles/edit.js', $params, array('ui/roles/edit/overview.js', 'ui/roles/edit/images.js', 'ui/roles/edit/scripting.js', 'ui/roles/edit/variables.js', 'ui/roles/edit/chef.js', 'ui/scripts/scriptfield.js', 'ui/core/variablefield.js', 'ux-boxselect.js', 'ui/services/chef/chefsettings.js'), array('ui/roles/edit.css', 'ui/scripts/scriptfield.css', 'ui/core/variablefield.css'));
 }
Ejemplo n.º 5
0
 /**
  * @param  int  $roleId
  */
 public function xGetScriptsAction($roleId)
 {
     $role = Role::findPk($roleId);
     if (!$role) {
         $this->response->failure('Role not found');
         return;
     }
     $this->checkPermissions($role);
     $data = \Scalr\Model\Entity\Script::getScriptingData($this->user->getAccountId(), $this->getEnvironmentId());
     $data['roleScripts'] = $role->getScripts();
     $this->response->data($data);
 }
Ejemplo n.º 6
0
 public function editAction()
 {
     $this->request->restrictAccess(Acl::RESOURCE_FARMS_ROLES, Acl::PERM_FARMS_ROLES_MANAGE);
     $this->request->defineParams(array('roleId' => array('type' => 'int')));
     $params = array();
     $params['scriptData'] = \Scalr\Model\Entity\Script::getScriptingData($this->user->getAccountId(), $this->getEnvironmentId(true));
     $params['categories'] = $this->db->GetAll("SELECT * FROM role_categories WHERE env_id IS NULL OR env_id = ?", [$this->user->isScalrAdmin() ? null : $this->getEnvironmentId()]);
     $params['accountScripts'] = [];
     if (!$this->user->isScalrAdmin()) {
         foreach (self::loadController('Orchestration', 'Scalr_UI_Controller_Account2')->getOrchestrationRules() as $script) {
             $script['system'] = 'account';
             $params['accountScripts'][] = $script;
         }
     }
     $variables = new Scalr_Scripting_GlobalVariables($this->user->getAccountId(), $this->user->isScalrAdmin() ? 0 : $this->getEnvironmentId(), Scalr_Scripting_GlobalVariables::SCOPE_ROLE);
     if ($this->getParam('roleId')) {
         $dbRole = DBRole::loadById($this->getParam('roleId'));
         if (!$this->user->isScalrAdmin()) {
             $this->user->getPermissions()->validate($dbRole);
         }
         $images = array();
         foreach (RoleImage::find([['roleId' => $dbRole->id]]) as $image) {
             /* @var $image RoleImage */
             $im = $image->getImage();
             $a = get_object_vars($image);
             if ($im) {
                 $b = get_object_vars($im);
                 $b['dtAdded'] = Scalr_Util_DateTime::convertTz($b['dtAdded']);
                 $b['software'] = $im->getSoftwareAsString();
                 $a['name'] = $im->name;
                 $a['hash'] = $im->hash;
                 $a['extended'] = $b;
             }
             $images[] = $a;
         }
         $params['role'] = array('roleId' => $dbRole->id, 'name' => $dbRole->name, 'catId' => $dbRole->catId, 'os' => $dbRole->getOs()->name, 'osId' => $dbRole->osId, 'osFamily' => $dbRole->getOs()->family, 'osGeneration' => $dbRole->getOs()->generation, 'osVersion' => $dbRole->getOs()->version, 'description' => $dbRole->description, 'behaviors' => $dbRole->getBehaviors(), 'images' => $images, 'scripts' => $dbRole->getScripts(), 'dtadded' => Scalr_Util_DateTime::convertTz($dbRole->dateAdded), 'addedByEmail' => $dbRole->addedByEmail, 'chef' => $dbRole->getProperties('chef.'));
         $params['role']['variables'] = $variables->getValues($dbRole->id);
         if ($this->user->isScalrAdmin()) {
             $params['roleUsage'] = array('farms' => $dbRole->getFarmRolesCount(), 'instances' => $this->db->GetOne("SELECT COUNT(*) FROM servers LEFT JOIN farm_roles ON servers.farm_roleid = farm_roles.id WHERE farm_roles.role_id=?", array($dbRole->id)));
         } else {
             $params['roleUsage'] = array('farms' => $dbRole->getFarmRolesCount($this->getEnvironmentId()), 'instances' => $this->db->GetOne("SELECT COUNT(*) FROM servers LEFT JOIN farm_roles ON servers.farm_roleid = farm_roles.id WHERE farm_roles.role_id=? AND env_id=?", array($dbRole->id, $this->getEnvironmentId())));
         }
     } else {
         $params['role'] = array('roleId' => 0, 'name' => '', 'arch' => 'x86_64', 'agent' => 2, 'description' => '', 'behaviors' => array(), 'images' => array(), 'scripts' => array(), 'tags' => array(), 'variables' => $variables->getValues());
     }
     $this->response->page('ui/roles/edit.js', $params, array('ui/roles/edit/overview.js', 'ui/roles/edit/images.js', 'ui/roles/edit/scripting.js', 'ui/roles/edit/variables.js', 'ui/roles/edit/chef.js', 'ui/scripts/scriptfield.js', 'ui/core/variablefield.js', 'ui/services/chef/chefsettings.js'), array('ui/roles/edit.css', 'ui/scripts/scriptfield.css'));
 }