setProxy() public méthode

Set proxy configuration to connect to AWS services
public setProxy ( string $host, integer $port = 3128, string $user = null, string $pass = null, integer $type, integer $authType = 1 )
$host string
$port integer
$user string
$pass string
$type integer Allowed values 4 - SOCKS4, 5 - SOCKS5, 0 - HTTP
$authType integer Allowed authtypes: 1 - Basic, Digest - 2, GSSNeg - 4, NTLM - 8, any - -1
Exemple #1
0
 private function saveCloudstack()
 {
     $pars = array();
     $enabled = false;
     $platform = $this->getParam('platform');
     $currentCloudCredentials = $this->env->keychain($platform);
     $ccProps = $currentCloudCredentials->properties;
     $bNew = !$currentCloudCredentials->isEnabled();
     if (!$bNew) {
         $oldUrl = $ccProps[Entity\CloudCredentialsProperty::CLOUDSTACK_API_URL];
     }
     if ($this->getParam("{$platform}_is_enabled")) {
         $enabled = true;
         $pars[Entity\CloudCredentialsProperty::CLOUDSTACK_API_URL] = $this->checkVar(Entity\CloudCredentialsProperty::CLOUDSTACK_API_URL, 'string', 'API URL required', $platform);
         $pars[Entity\CloudCredentialsProperty::CLOUDSTACK_API_KEY] = $this->checkVar(Entity\CloudCredentialsProperty::CLOUDSTACK_API_KEY, 'string', 'API key required', $platform);
         $pars[Entity\CloudCredentialsProperty::CLOUDSTACK_SECRET_KEY] = $this->checkVar(Entity\CloudCredentialsProperty::CLOUDSTACK_SECRET_KEY, 'password', 'Secret key required', $platform);
     }
     if (count($this->checkVarError)) {
         $this->response->failure();
         $this->response->data(array('errors' => $this->checkVarError));
     } else {
         if ($this->getParam("{$platform}_is_enabled")) {
             $cs = new CloudStack($pars[Entity\CloudCredentialsProperty::CLOUDSTACK_API_URL], $pars[Entity\CloudCredentialsProperty::CLOUDSTACK_API_KEY], $pars[Entity\CloudCredentialsProperty::CLOUDSTACK_SECRET_KEY], $platform);
             $listAccountsData = new ListAccountsData();
             $listAccountsData->listall = true;
             //$listAccountsData->accounttype = 0;
             /* @var $config Yaml */
             $config = $this->env->getContainer()->config;
             if ($config->defined("scalr.{$platform}.use_proxy") && $config("scalr.{$platform}.use_proxy") && in_array($config('scalr.connections.proxy.use_on'), ['both', 'scalr'])) {
                 $proxySettings = $config('scalr.connections.proxy');
                 $cs->setProxy($proxySettings['host'], $proxySettings['port'], $proxySettings['user'], $proxySettings['pass'], $proxySettings['type'], $proxySettings['authtype']);
             }
             if (!$this->searchCloudstackUser($cs->listAccounts($listAccountsData), $pars)) {
                 throw new Exception("Cannot determine account name for provided keys");
             }
         }
         $this->db->BeginTrans();
         try {
             $this->env->enablePlatform($platform, $enabled);
             if ($enabled) {
                 $this->makeCloudCredentials($platform, $pars);
                 if ($this->getContainer()->analytics->enabled && ($bNew || $oldUrl !== $pars[Entity\CloudCredentialsProperty::CLOUDSTACK_API_URL])) {
                     $this->getContainer()->analytics->notifications->onCloudAdd($platform, $this->env, $this->user);
                 }
             } else {
                 $currentCloudCredentials->environments[$this->env->id]->delete();
             }
             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 ' . ucfirst($platform) . ' settings'));
         }
         $this->db->CommitTrans();
     }
 }
 /**
  * @param   Entity\CloudCredentials $entity
  * @param   Entity\CloudCredentials $prevConfig
  *
  * @throws  ApiErrorException
  */
 public function validateEntity($entity, $prevConfig = null)
 {
     parent::validateEntity($entity, $prevConfig);
     $ccProps = $entity->properties;
     $prevCcProps = isset($prevConfig) ? $prevConfig->properties : null;
     if ($this->needValidation($ccProps, $prevCcProps)) {
         try {
             $cs = new CloudStack($ccProps[Entity\CloudCredentialsProperty::CLOUDSTACK_API_URL], $ccProps[Entity\CloudCredentialsProperty::CLOUDSTACK_API_KEY], $ccProps[Entity\CloudCredentialsProperty::CLOUDSTACK_SECRET_KEY], $entity->cloud);
             $listAccountsData = new ListAccountsData();
             $listAccountsData->listall = true;
         } catch (Exception $e) {
             throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Failed to verify your Cloudstack credentials: {$e->getMessage()}");
         }
         /* @var $config Yaml */
         $config = $this->controller->getContainer()->config;
         if ($config->defined("scalr.{$entity->cloud}.use_proxy") && $config("scalr.{$entity->cloud}.use_proxy") && in_array($config('scalr.connections.proxy.use_on'), ['both', 'scalr'])) {
             $proxySettings = $config('scalr.connections.proxy');
             $cs->setProxy($proxySettings['host'], $proxySettings['port'], $proxySettings['user'], $proxySettings['pass'], $proxySettings['type'], $proxySettings['authtype']);
         }
         if (!$this->searchCloudstackUser($cs->listAccounts($listAccountsData), $ccProps)) {
             throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Cannot determine account name for provided keys");
         }
         $entity->status = Entity\CloudCredentials::STATUS_ENABLED;
     }
 }