public function get_service($opts, $useservercerts = false, $disablesslverify = null) { # 'tenant', 'user', 'password', 'authurl', 'path', (optional) 'region' extract($opts); if (null === $disablesslverify) { $disablesslverify = UpdraftPlus_Options::get_updraft_option('updraft_ssl_disableverify'); } if (empty($user) || empty($password) || empty($authurl)) { throw new Exception(__('Authorisation failed (check your credentials)', 'updraftplus')); } require_once UPDRAFTPLUS_DIR . '/oc/autoload.php'; global $updraftplus; $updraftplus->log("OpenStack authentication URL: " . $authurl); $client = new OpenStack($authurl, array('username' => $user, 'password' => $password, 'tenantName' => $tenant)); $this->client = $client; if ($disablesslverify) { $client->setSslVerification(false); } else { if ($useservercerts) { $client->setConfig(array($client::SSL_CERT_AUTHORITY => false)); } else { $client->setSslVerification(UPDRAFTPLUS_DIR . '/includes/cacert.pem', true, 2); } } $client->authenticate(); if (empty($region)) { $catalog = $client->getCatalog(); if (!empty($catalog)) { $items = $catalog->getItems(); if (is_array($items)) { foreach ($items as $item) { $name = $item->getName(); $type = $item->getType(); if ('swift' != $name || 'object-store' != $type) { continue; } $eps = $item->getEndpoints(); if (!is_array($eps)) { continue; } foreach ($eps as $ep) { if (is_object($ep) && !empty($ep->region)) { $region = $ep->region; } } } } } } $this->region = $region; return $client->objectStoreService('swift', $region); }