protected function init() { if ($this->container) { return; } // the OpenCloud client library will default to 'cloudFiles' if $serviceName is null $serviceName = null; if (isset($this->params['serviceName'])) { $serviceName = $this->params['serviceName']; } // the OpenCloud client library will default to 'publicURL' if $urlType is null $urlType = null; if (isset($this->params['urlType'])) { $urlType = $this->params['urlType']; } $this->objectStoreService = $this->client->objectStoreService($serviceName, $this->params['region'], $urlType); try { $this->container = $this->objectStoreService->getContainer($this->params['container']); } catch (ClientErrorResponseException $ex) { // if the container does not exist and autocreate is true try to create the container on the fly if (isset($this->params['autocreate']) && $this->params['autocreate'] === true) { $this->container = $this->objectStoreService->createContainer($this->params['container']); } else { throw $ex; } } }
/** * Returns the connection * * @return OpenCloud\ObjectStore\Service connected client * @throws \Exception if connection could not be made */ public function getConnection() { if (!is_null($this->connection)) { return $this->connection; } $settings = array('username' => $this->params['user']); if (!empty($this->params['password'])) { $settings['password'] = $this->params['password']; } else { if (!empty($this->params['key'])) { $settings['apiKey'] = $this->params['key']; } } if (!empty($this->params['tenant'])) { $settings['tenantName'] = $this->params['tenant']; } if (!empty($this->params['timeout'])) { $settings['timeout'] = $this->params['timeout']; } if (isset($settings['apiKey'])) { $this->anchor = new Rackspace($this->params['url'], $settings); } else { $this->anchor = new OpenStack($this->params['url'], $settings); } $connection = $this->anchor->objectStoreService($this->params['service_name'], $this->params['region']); if (!empty($this->params['endpoint_url'])) { $endpoint = $connection->getEndpoint(); $endpoint->setPublicUrl($this->params['endpoint_url']); $endpoint->setPrivateUrl($this->params['endpoint_url']); $connection->setEndpoint($endpoint); } $this->connection = $connection; return $this->connection; }
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); }
/** * Returns the file system provider * * @return \League\Flysystem\FilesystemInterface File system provider */ protected function getProvider() { if (!isset($this->fs)) { $config = $this->getConfig(); if (!isset($config['container'])) { throw new Exception(sprintf('Configuration option "%1$s" missing', 'container')); } $client = new OpenStack(Rackspace::UK_IDENTITY_ENDPOINT, $config); $container = $client->objectStoreService('cloudFiles', 'LON')->getContainer($config['container']); $this->fs = new Filesystem(new RackspaceAdapter($container)); } return $this->fs; }
/** * Returns the connection * * @return OpenCloud\ObjectStore\Service connected client * @throws \Exception if connection could not be made */ public function getConnection() { if (!is_null($this->connection)) { return $this->connection; } $this->anchor = new OpenStack(hubicAuth::HUBIC_URI_BASE, array()); if (!isset($this->credentials)) { $this->retrieveCredentials(); } $this->importCredentials(); $this->connection = $this->anchor->objectStoreService('cloudFiles', 'NCE'); return $this->connection; }
/** * Returns the connection * * @return OpenCloud\ObjectStore\Service connected client * @throws \Exception if connection could not be made */ public function getConnection() { if (!is_null($this->connection)) { return $this->connection; } $this->anchor = new OpenStack('https://api.hubic.com/'); if ($this->params['swift_token'] == 'false') { $this->retreiveCredentials(); } $this->importCredentials(); $this->connection = $this->anchor->objectStoreService('cloudFiles', 'NCE'); return $this->connection; }
/** * @inheritdoc */ public function doCreateService(ServiceLocatorInterface $serviceLocator) { if (!class_exists('League\\Flysystem\\Rackspace\\RackspaceAdapter') || !class_exists('ProxyManager\\Factory\\LazyLoadingValueHolderFactory')) { throw new RequirementsException(['league/flysystem-rackspace', 'ocramius/proxy-manager'], 'Rackspace'); } $proxy = $this->getLazyFactory($serviceLocator)->createProxy('League\\Flysystem\\Rackspace\\RackspaceAdapter', function (&$wrappedObject, $proxy, $method, $parameters, &$initializer) { $client = new OpenStack($this->options['url'], $this->options['secret'], $this->options['options']); $store = $client->objectStoreService($this->options['objectstore']['name'], $this->options['objectstore']['region'], $this->options['objectstore']['url_type']); $container = $store->getContainer($this->options['objectstore']['container']); $wrappedObject = new Adapter($container, $this->options['prefix']); return true; }); return $proxy; }
/** * @param array $credentials * @param string $endPoint * @param string $region * @param string $urlType * @throws \Tvision\RackspaceCloudFilesStreamWrapper\Exception\InvalidArgumentException * @return \OpenCloud\ObjectStore\Service */ public static function newObjectStore(array $credentials, $endPoint = Rackspace::UK_IDENTITY_ENDPOINT, $region = 'LON', $urlType = 'publicURL') { if (isset($credentials['apiKey']) && isset($credentials['username'])) { $openCloudConnection = new Rackspace($endPoint, $credentials); } elseif (isset($credentials['password']) && isset($credentials['username'])) { $openCloudConnection = new OpenStack($endPoint, $credentials); } else { throw new InvalidArgumentException(<<<MSG The credentials must always contain an 'username' and a 'password' or an 'apiKey' if you are using rackspace. MSG ); } return $openCloudConnection->objectStoreService('cloudFiles', $region, $urlType); }
public function __construct($params) { if (empty($params['key']) and empty($params['password']) or empty($params['user']) or empty($params['bucket']) or empty($params['region'])) { throw new \Exception("API Key or password, Username, Bucket and Region have to be configured."); } $this->id = 'swift::' . $params['user'] . md5($params['bucket']); $this->bucket = $params['bucket']; if (empty($params['url'])) { $params['url'] = 'https://identity.api.rackspacecloud.com/v2.0/'; } if (empty($params['service_name'])) { $params['service_name'] = 'cloudFiles'; } $settings = array('username' => $params['user']); if (!empty($params['password'])) { $settings['password'] = $params['password']; } else { if (!empty($params['key'])) { $settings['apiKey'] = $params['key']; } } if (!empty($params['tenant'])) { $settings['tenantName'] = $params['tenant']; } if (!empty($params['timeout'])) { $settings['timeout'] = $params['timeout']; } if (isset($settings['apiKey'])) { $this->anchor = new Rackspace($params['url'], $settings); } else { $this->anchor = new OpenStack($params['url'], $settings); } $this->connection = $this->anchor->objectStoreService($params['service_name'], $params['region']); try { $this->container = $this->connection->getContainer($this->bucket); } catch (ClientErrorResponseException $e) { $this->container = $this->connection->createContainer($this->bucket); } if (!$this->file_exists('.')) { $this->mkdir('.'); } }
/** * Returns the connection * * @return OpenCloud\ObjectStore\Service connected client * @throws \Exception if connection could not be made */ public function getConnection() { if (!is_null($this->connection)) { return $this->connection; } $settings = array('username' => $this->params['user']); if (!empty($this->params['password'])) { $settings['password'] = $this->params['password']; } else { if (!empty($this->params['key'])) { $settings['apiKey'] = $this->params['key']; } } if (!empty($this->params['tenant'])) { $settings['tenantName'] = $this->params['tenant']; } if (!empty($this->params['timeout'])) { $settings['timeout'] = $this->params['timeout']; } $this->anchor = new OpenStack($this->params['url'], $settings); $this->connection = $this->anchor->objectStoreService($this->params['service_name'], $this->params['region']); return $this->connection; }
/** * @param array $config * @return Flysystem */ public function get(array $config) { $client = new OpenStack($config['endpoint'], ['username' => $config['username'], 'password' => $config['key']]); $container = $client->objectStoreService('cloudFiles', $config['zone'])->getContainer($config['container']); return new Flysystem(new RackspaceAdapter($container, $config['root'])); }
/** * {@inheritdoc} */ public function getObjectStore() { return $this->connection->objectStoreService('cloudFiles', $this->region, $this->urlType); }
/** * {@inheritdoc} */ public function getObjectStore() { return $this->connection->objectStoreService($this->objectStoreType, $this->region, $this->urlType); }
public function testLoggerServiceInjection() { // Create a new client, pass stub via constructor options argument $stubLogger = $this->getMock('Psr\\Log\\NullLogger'); $client = new OpenStack(Rackspace::US_IDENTITY_ENDPOINT, $this->credentials, array('logger' => $stubLogger)); $client->addSubscriber(new MockSubscriber()); // Test all OpenStack factory methods on proper Logger service injection $service = $client->objectStoreService('cloudFiles', 'DFW'); $this->assertContains("Mock_NullLogger", get_class($service->getLogger())); $service = $service->getCdnService(); $this->assertContains("Mock_NullLogger", get_class($service->getLogger())); $service = $client->computeService('cloudServersOpenStack', 'DFW'); $this->assertContains("Mock_NullLogger", get_class($service->getLogger())); $service = $client->orchestrationService(null, 'DFW'); $this->assertContains("Mock_NullLogger", get_class($service->getLogger())); $service = $client->volumeService('cloudBlockStorage', 'DFW'); $this->assertContains("Mock_NullLogger", get_class($service->getLogger())); $service = $client->identityService(); $this->assertContains("Mock_NullLogger", get_class($service->getLogger())); $service = $client->imageService('cloudImages', 'IAD'); $this->assertContains("Mock_NullLogger", get_class($service->getLogger())); $service = $client->networkingService(null, 'IAD'); $this->assertContains("Mock_NullLogger", get_class($service->getLogger())); }
echo "The configuration file '{$configFile}' does not exist.\n\n"; exit(2); } $ocParameters = json_decode(file_get_contents($configFile)); if (!$ocParameters) { echo "The configuration file '{$configFile}' content is not valid JSON.\n\n"; exit(3); } // Initialization $client = new OpenStack($ocParameters->authUrl, array("username" => $ocParameters->username, "password" => $ocParameters->password, "tenantName" => $ocParameters->tenant)); $swiftUrl = $ocParameters->swiftUrl; $serviceName = $ocParameters->serviceName; $region = $ocParameters->region; try { $client->authenticate(); $service = $client->objectStoreService($serviceName, $region); $container = $service->createContainer($containerName); if ($container === false) { echo "The container '{$containerName}' already exists.\n"; } else { echo "The container '{$containerName}' has been successfully created.\n"; } $container = $service->getContainer($containerName); foreach (glob($files) as $filename) { echo "Sending {$filename} (" . number_format(filesize($filename) / 1024 / 1024, 2) . " MB)...\n"; $fileData = fopen($filename, "r+"); $container->uploadObject(basename($filename), $fileData); echo "-> File sent.\n"; } } catch (Exception $e) { echo "Problem while dealing with OpenCloud:\n";