cloudCredentialsList() public method

Gets cloud credentials for listed clouds
public cloudCredentialsList ( array $clouds = null, array $credentialsFilter = [], array $propertiesFilter = [], boolean $cacheResult = true ) : CloudCredentials[]
$clouds array optional Clouds list
$credentialsFilter array optional Criteria to filter by CloudCredentials properties
$propertiesFilter array optional Criteria to filter by CloudCredentialsProperties
$cacheResult boolean optional Cache result
return Scalr\Model\Entity\CloudCredentials[]
Example #1
0
 public function xSaveRackspaceAction()
 {
     $pars = array();
     $locations = array('rs-ORD1', 'rs-LONx');
     $enabled = false;
     /* @var $currentCloudCredentials Entity\CloudCredentials[] */
     $currentCloudCredentials = $this->env->cloudCredentialsList(array_map(function ($location) {
         return "{$location}." . SERVER_PLATFORMS::RACKSPACE;
     }, $locations));
     foreach ($currentCloudCredentials as $cloudCredential) {
         if ($cloudCredential->isEnabled()) {
             $enabled = true;
             break;
         }
     }
     if (!$enabled) {
         throw new Scalr_Exception_Core('Rackspace cloud has been deprecated. Please use Rackspace Open Cloud instead.');
     } else {
         $enabled = false;
     }
     foreach ($locations as $location) {
         if ($this->getParam("rackspace_is_enabled_{$location}")) {
             $enabled = true;
             $pars[$location][Entity\CloudCredentialsProperty::RACKSPACE_USERNAME] = $this->checkVar(Entity\CloudCredentialsProperty::RACKSPACE_USERNAME, 'string', "Username required", $location . SERVER_PLATFORMS::RACKSPACE);
             $pars[$location][Entity\CloudCredentialsProperty::RACKSPACE_API_KEY] = $this->checkVar(Entity\CloudCredentialsProperty::RACKSPACE_API_KEY, 'string', "API Key required", $location . SERVER_PLATFORMS::RACKSPACE);
             $pars[$location][Entity\CloudCredentialsProperty::RACKSPACE_IS_MANAGED] = $this->checkVar(Entity\CloudCredentialsProperty::RACKSPACE_IS_MANAGED, 'bool', "", $location . SERVER_PLATFORMS::RACKSPACE);
         } else {
             $pars[$location][Entity\CloudCredentialsProperty::RACKSPACE_USERNAME] = false;
             $pars[$location][Entity\CloudCredentialsProperty::RACKSPACE_API_KEY] = false;
             $pars[$location][Entity\CloudCredentialsProperty::RACKSPACE_IS_MANAGED] = false;
         }
     }
     if (count($this->checkVarError)) {
         $this->response->failure();
         $this->response->data(array('errors' => $this->checkVarError));
     } else {
         $this->db->BeginTrans();
         try {
             $this->env->enablePlatform(SERVER_PLATFORMS::RACKSPACE, $enabled);
             foreach ($pars as $cloud => $prs) {
                 $this->makeCloudCredentials("{$cloud}." . SERVER_PLATFORMS::RACKSPACE, $prs);
                 $this->env->setPlatformConfig([Entity\Account\EnvironmentProperty::RACKSPACE_LOCATIONS => 'enabled'], true, $cloud);
             }
             if (!$this->user->getAccount()->getSetting(Scalr_Account::SETTING_DATE_ENV_CONFIGURED)) {
                 $this->user->getAccount()->setSetting(Scalr_Account::SETTING_DATE_ENV_CONFIGURED, time());
             }
             $this->response->success('Cloud credentials have been ' . ($enabled ? 'saved' : 'removed from Scalr'));
             $this->response->data(array('enabled' => $enabled));
         } catch (Exception $e) {
             $this->db->RollbackTrans();
             throw new Exception(_('Failed to save Rackspace settings'));
         }
         $this->db->CommitTrans();
     }
 }