Scalr\Service\CloudStack\CloudStack::setProxy PHP Метод

setProxy() публичный Метод

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
    public function setProxy($host, $port = 3128, $user = null, $pass = null, $type = 0, $authType = 1)
    {
        $this->proxyHost = $host;
        $this->proxyPort = $port;
        $this->proxyUser = $user;
        $this->proxyPass = $pass;
        $this->proxyType = $type;
        $this->authType = $authType;
    }

Usage Example

Пример #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();
     }
 }
All Usage Examples Of Scalr\Service\CloudStack\CloudStack::setProxy