public function do_activity($task) { parent::do_activity($task); // Use workflowID to generate a unique TMP folder localy. $this->tmpPathInput = self::TMP_FOLDER . $task["workflowExecution"]["workflowId"] . "/" . "input"; $inputFileInfo = null; // Create TMP storage to store input file to transcode if (isset($this->input->{'input_asset'}->{'file'})) { $inputFileInfo = pathinfo($this->input->{'input_asset'}->{'file'}); } // Create the tmp folder if doesn't exist if (!file_exists($this->tmpPathInput)) { if ($this->debug) { $this->cpeLogger->log_out("INFO", basename(__FILE__), "Creating TMP input folder '" . $this->tmpPathInput . "'", $this->activityLogKey); } if (!mkdir($this->tmpPathInput, 0750, true)) { throw new CpeSdk\CpeException("Unable to create temporary folder '{$this->tmpPathInput}' !", self::TMP_FOLDER_FAIL); } } $this->pathToInputFile = null; if (isset($this->input->{'input_asset'}->{'bucket'}) && isset($this->input->{'input_asset'}->{'file'})) { // Make pre-signed URL so ffmpeg has access to file $this->pathToInputFile = 'cache:' . S3Client::factory()->getCommand('GetObject', ['Bucket' => $this->input->{'input_asset'}->{'bucket'}, 'Key' => $this->input->{'input_asset'}->{'file'}])->createPresignedUrl('+1 day'); } else { if ($this->input->{'input_asset'}->{'http'}) { // Pad HTTP input so it is cached in case of full encodes $this->pathToInputFile = 'cache:' . $this->input->{'input_asset'}->{'http'}; } } }
/** * @param string $name * @return \League\Flysystem\AdapterInterface * @throws \RuntimeException */ public static function make($name) { $connections = Config::get('storage.connections'); if (!isset($connections[$name])) { throw new \RuntimeException(sprintf('The storage connection %d does not exist.', $name)); } $connection = $connections[$name]; $connection['adapter'] = strtoupper($connection['adapter']); switch ($connection['adapter']) { case 'LOCAL': return new Local($connection['root_path'], $connection['public_url_base']); case 'RACKSPACE': $service = isset($connection['service']) ? Config::get($connection['service']) : Config::get('services.rackspace'); $client = new Rackspace($service['api_endpoint'], array('username' => $service['username'], 'tenantName' => $service['tenant_name'], 'apiKey' => $service['api_key'])); $store = $client->objectStoreService($connection['store'], $connection['region']); $container = $store->getContainer($connection['container']); return new RackspaceAdapter($container); case 'AWS': $service = isset($connection['service']) ? Config::get($connection['service']) : Config::get('services.aws'); $client = S3Client::factory(array('credentials' => array('key' => $service['access_key'], 'secret' => $service['secret_key']), 'region' => $service['region'], 'version' => 'latest')); return new AwsS3Adapter($client, $connection['bucket']); case 'GCLOUD': $service = isset($connection['service']) ? Config::get($connection['service']) : Config::get('services.google_cloud'); $credentials = new \Google_Auth_AssertionCredentials($service['service_account'], [\Google_Service_Storage::DEVSTORAGE_FULL_CONTROL], file_get_contents($service['key_file']), $service['secret']); $config = new \Google_Config(); $config->setAuthClass(GoogleAuthOAuth2::class); $client = new \Google_Client($config); $client->setAssertionCredentials($credentials); $client->setDeveloperKey($service['developer_key']); $service = new \Google_Service_Storage($client); return new GoogleStorageAdapter($service, $connection['bucket']); } throw new \RuntimeException(sprintf('The storage adapter %s is invalid.', $connection['adapter'])); }
protected function __construct($attrs = null) { if (!$this->no_backend) { if (!$this->table) { $this->table = strtolower(Inflector::get()->pluralize(get_class($this))); } $this->db = DB::instance(); } if (!$this->no_cache) { $this->cache = Cache::instance(); } if (class_exists('\\Notifier')) { $this->notifier = \Notifier::instance(); } if (defined('AWS_CONSUMER_KEY') && defined('AWS_CONSUMER_SECRET') && defined('AWS_BUCKET')) { if (!class_exists('\\Aws\\S3\\S3Client')) { throw new Exception("AWS S3 packaged is required"); } $this->s3 = \Aws\S3\S3Client::factory(array('key' => AWS_CONSUMER_KEY, 'secret' => AWS_CONSUMER_SECRET)); } $this->validator = ValidatorBase::instance(); if ($attrs && is_numeric($attrs)) { // assume $attrs is id $this->findOne(array($this->primary_key => $attrs)); } else { if ($attrs && is_array($attrs)) { if (!array_key_exists($this->primary_key, $attrs)) { $this->validate($attrs); } // set the attrs $this->attrs = $attrs; $this->protectAttrs(); } } }
private function getS3Client() { if (!$this->s3Client) { $this->s3Client = S3Client::factory(array('key' => $this->awsAccessKey, 'secret' => $this->awsAccessSecret)); } return $this->s3Client; }
public function __construct($key, $secret) { $this->key = $key; $this->secret = $secret; $arr = array('key' => $key, 'secret' => $secret, 'region' => AWS_REGION); $this->s3 = S3Client::factory($arr); }
/** * @inheritdoc * @param array $values */ public function __construct(array $values = []) { $values['amazon_s3_client'] = $this->share(function (Application $app) { return S3Client::factory(array_merge($this->getCredentials(), ['version' => '2006-03-01', 'ssl.certificate_authority' => false])); }); $values['amazon_s3_credentials_cookie_name'] = 'credentials'; $values['controller.amazon_s3_client'] = $this->share(function (Application $app) { return new AmazonS3Controller($app['twig'], $app['amazon_s3_client']); }); $values['controller.authentication'] = $this->share(function (Application $app) { return new AuthenticationController($app['twig'], $app['amazon_s3_credentials_cookie_name']); }); parent::__construct($values); $this->register(new TwigServiceProvider(), ['twig.path' => __DIR__ . '/../views', 'twig.options' => ['cache' => is_writable(__DIR__ . '/..') ? __DIR__ . '/../cache/twig' : false]]); $this->register(new UrlGeneratorServiceProvider()); $this->register(new ServiceControllerServiceProvider()); $this->get('/login', 'controller.authentication:loginAction')->bind('login')->before(function (Request $request, Application $app) { $credentials = $this->getCredentials(); if (!empty($credentials)) { return new RedirectResponse($app['url_generator']->generate('list')); } }); $this->post('/login', 'controller.authentication:authenticateAction'); $this->post('/logout', 'controller.authentication:logoutAction')->bind('logout'); $this->get('/{bucket}', 'controller.amazon_s3_client:listAction')->value('bucket', null)->bind('list')->before(function (Request $request, Application $app) { $credentials = $this->getCredentials(); if (empty($credentials)) { return $app->handle(Request::create($app['url_generator']->generate('login')), HttpKernelInterface::SUB_REQUEST, false); } }); }
public function __construct($params) { if (!isset($params['key']) || !isset($params['secret']) || !isset($params['bucket'])) { throw new \Exception("Access Key, Secret and Bucket have to be configured."); } $this->id = 'amazon::' . $params['key'] . md5($params['secret']); $this->bucket = $params['bucket']; $scheme = $params['use_ssl'] === 'false' ? 'http' : 'https'; $this->test = isset($params['test']); $this->timeout = !isset($params['timeout']) ? 15 : $params['timeout']; $params['region'] = !isset($params['region']) || $params['region'] === '' ? 'eu-west-1' : $params['region']; $params['hostname'] = !isset($params['hostname']) || $params['hostname'] === '' ? 's3.amazonaws.com' : $params['hostname']; if (!isset($params['port']) || $params['port'] === '') { $params['port'] = $params['use_ssl'] === 'false' ? 80 : 443; } $base_url = $scheme . '://' . $params['hostname'] . ':' . $params['port'] . '/'; $this->connection = S3Client::factory(array('key' => $params['key'], 'secret' => $params['secret'], 'base_url' => $base_url, 'region' => $params['region'])); if (!$this->connection->isValidBucketName($this->bucket)) { throw new \Exception("The configured bucket name is invalid."); } if (!$this->connection->doesBucketExist($this->bucket)) { try { $result = $this->connection->createBucket(array('Bucket' => $this->bucket)); $this->connection->waitUntilBucketExists(array('Bucket' => $this->bucket, 'waiter.interval' => 1, 'waiter.max_attempts' => 15)); $this->testTimeout(); } catch (S3Exception $e) { \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR); throw new \Exception("Creation of bucket failed."); } } if (!$this->file_exists('.')) { $result = $this->connection->putObject(array('Bucket' => $this->bucket, 'Key' => '.', 'Body' => '', 'ContentType' => 'httpd/unix-directory', 'ContentLength' => 0)); $this->testTimeout(); } }
public function __construct() { parent::__construct(); $this->Order = ClassRegistry::init('Order'); $this->client = S3Client::factory(["key" => "AKIAJVCBLQ3VQQS3DJHA", "secret" => "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"]); $this->bucket = "younique-reports"; }
/** * Register the service provider. * * @return void */ public function register() { /** @var \Illuminate\Config\Repository $config */ $config = $this->app->make('config'); $this->app->singleton('Intervention\\Image\\ImageManager', function (Application $app) { return new ImageManager(array('driver' => $app->config->get('imager::driver', 'gd'))); }); $this->app->bind('TippingCanoe\\Imager\\Repository\\Image', 'TippingCanoe\\Imager\\Repository\\DbImage'); $this->app->singleton('TippingCanoe\\Imager\\Service', function (Application $app) use($config) { // // Amazon S3 // if ($s3Config = $config->get('imager::s3')) { $this->app->bind('Aws\\S3\\S3Client', function (Application $app) use($s3Config) { return \Aws\S3\S3Client::factory($s3Config); }); } // Run through and call each config option as a setter on the storage method. $storageDrivers = []; foreach ($config->get('imager::storage', []) as $abstract => $driverConfig) { /** @var \TippingCanoe\Imager\Storage\Driver $driver */ $driver = $app->make($abstract); foreach ($driverConfig as $property => $value) { $setter = studly_case('set_' . $property); $driver->{$setter}($value); } $storageDrivers[$abstract] = $driver; } $service = new Service($app->make('TippingCanoe\\Imager\\Repository\\Image'), $app->make('Intervention\\Image\\ImageManager'), $app, $storageDrivers); return $service; }); }
public static function uploadNewScreenshot($sid, $name, $tempFile, $tempThumb) { $keyData = AWSFileManager::getCredentials(); $client = S3Client::factory(array("credentials" => array("key" => $keyData->aws_access_key_id, "secret" => $keyData->aws_secret_access_key))); $result = $client->putObject(array("Bucket" => $keyData->aws_bucket, "Key" => "screenshots/" . $sid, "SourceFile" => $tempFile, "ACL" => 'public-read', "ContentDisposition" => "attachment; filename=\"" . $name . "\"")); $result = $client->putObject(array("Bucket" => $keyData->aws_bucket, "Key" => "screenshots/thumb/" . $sid, "SourceFile" => $tempThumb, "ACL" => 'public-read', "ContentDisposition" => "attachment; filename=\"" . $name . "\"")); }
public static function getInstance($adapter = null, $localRoot = JPATH_SITE) { $params = JComponentHelper::getParams('com_k2'); if (is_null($adapter)) { $adapter = $params->get('filesystem', 'Local'); } $key = $adapter . '|' . $localRoot; if (empty(self::$instances[$key])) { if ($adapter == 'Local') { $filesystem = new Gaufrette\Filesystem(new Gaufrette\Adapter\Local($localRoot)); self::$instances[$key] = $filesystem; } elseif ($adapter == 'AmazonS3') { $AmazonS3AccessKey = $params->get('AmazonS3AccessKey'); $AmazonS3SecretAccessKey = $params->get('AmazonS3SecretAccessKey'); $AmazonS3Bucket = $params->get('AmazonS3Bucket'); $service = S3Client::factory(array('key' => $AmazonS3AccessKey, 'secret' => $AmazonS3SecretAccessKey)); $filesystem = new Gaufrette\Filesystem(new Gaufrette\Adapter\AwsS3($service, $AmazonS3Bucket)); self::$instances[$key] = $filesystem; } elseif ($adapter == 'MicrosoftAzure') { $MicrosoftAzureEndpoint = $params->get('MicrosoftAzureEndpoint'); $MicrosoftAzureAccountName = $params->get('MicrosoftAzureAccountName'); $MicrosoftAzureAccountKey = $params->get('MicrosoftAzureAccountKey'); $MicrosoftAzureContainer = $params->get('MicrosoftAzureContainer'); $connectionString = 'BlobEndpoint=' . $MicrosoftAzureEndpoint . '/;AccountName=' . $MicrosoftAzureAccountName . ';AccountKey=' . $MicrosoftAzureAccountKey; $factory = new Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactory($connectionString); $filesystem = new Gaufrette\Filesystem(new Gaufrette\Adapter\AzureBlobStorage($factory, $MicrosoftAzureContainer)); self::$instances[$key] = $filesystem; } } return self::$instances[$key]; }
public function __construct($config = array(), $autoConnect = true) { parent::__construct($config); $config['region'] = $this->region; $this->S3 = S3Client::factory($config); $this->bucketName = $config['bucket_name']; }
public function __construct($bucket, $con = 'default') { global $keys; $array = array('credentials' => array('key' => 'AcessKey', 'secret' => 'SecretKey'), 'region' => 'Region', 'version' => 'latest'); $this->client = S3Client::factory($array); $this->bucket = $bucket; }
public function __construct($config, $baseFolder, $options = array()) { $this->filesystem = new Filesystem(); // Create an Amazon S3 client object $this->client = S3Client::factory(array('key' => $config['key'], 'secret' => $config['secret'])); $this->bucketname = $config['bucketname']; $this->baseFolder = $baseFolder; // Register the stream wrapper from a client object $this->client->registerStreamWrapper(); $this->scheme = 's3://' . $this->bucketname; if (isset($config['region'])) { $this->client->setRegion($config['region']); } if (file_exists($this->scheme)) { $this->scheme .= '/' . $baseFolder; if (!file_exists($this->scheme)) { $this->filesystem->mkdir($this->scheme); } } else { throw new \Exception('Bucket ' . $this->bucketname . ' missing.'); } if (isset($config['url'])) { $this->baseUrl = trim($config['url'], '/') . '/' . $this->baseFolder; } if (isset($config['imagesize'])) { $this->imagesize = (bool) $config['imagesize']; } }
private function getS3Client() { if (!$this->S3Client) { $this->S3Client = S3Client::factory(array('credentials' => array('key' => br()->config()->get('AWS/S3AccessKey'), 'secret' => br()->config()->get('AWS/S3AccessSecret')), 'region' => br()->config()->get('AWS/S3Region'), 'version' => 'latest')); } return $this->S3Client; }
private function setupAdapter($invalid = false) { $bucket = constant('TESTS_DOTSUNITED_CABINET_ADAPTER_AMAZONS3_ONLINE_BUCKET_NAME'); if ($invalid) { $s3Client = S3Client::factory(array('credentials' => array('key' => 'foo', 'secret' => 'bar'), 'region' => 'us-east-1', 'version' => '2006-03-01')); } else { $key = constant('TESTS_DOTSUNITED_CABINET_ADAPTER_AMAZONS3_ONLINE_AWS_KEY'); $secret = constant('TESTS_DOTSUNITED_CABINET_ADAPTER_AMAZONS3_ONLINE_AWS_SECRET_KEY'); $region = constant('TESTS_DOTSUNITED_CABINET_ADAPTER_AMAZONS3_ONLINE_BUCKET_REGION'); $this->s3Client = $s3Client = S3Client::factory(array('credentials' => array('key' => $key, 'secret' => $secret), 'region' => $region, 'version' => '2006-03-01')); if (!$s3Client->doesBucketExist($bucket)) { $s3Client->createBucket(array('Bucket' => $bucket, 'LocationConstraint' => $region)); // Wait until the bucket is created $s3Client->waitUntil('BucketExists', array('Bucket' => $bucket)); } else { $s3Client->clearBucket($bucket); } } $mimeTypeDetector = $this->getMockBuilder('DotsUnited\\Cabinet\\MimeType\\Detector\\DetectorInterface')->getMock(); $mimeTypeDetector->expects($this->any())->method('detectFromFile')->will($this->returnValue('text/plain')); $mimeTypeDetector->expects($this->any())->method('detectFromString')->will($this->returnValue('text/plain')); $mimeTypeDetector->expects($this->any())->method('detectFromResource')->will($this->returnValue('text/plain')); $config = array('s3_client' => $s3Client, 'bucket' => $bucket, 'mime_type_detector' => $mimeTypeDetector, 'throw_exceptions' => !$invalid); $adapter = new AmazonS3Adapter($config); return $adapter; }
public function fire() { $environment = $this->argument('environment'); if (!($environment == "production" || $environment == "dev")) { return $this->error("Specify whether this should be deployed to production or development."); } $s3 = \Aws\S3\S3Client::factory(array('key' => 'AKIAIL4QPNABCUH3PXVA', 'secret' => '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', 'region' => 'us-west-1')); // Make sure no blockfile exists. If it does, someone else might be trying to deploy a new agent and we need to abort. if ($s3->doesObjectExist('agent.nosprawl.software', $environment == "production" ? 'block' : 'dev/block')) { return $this->error("A deployment is already in process for " . $environment . ". Talk to your fellow devs before deploying an agent."); } // Create blockfile $s3->putObject(array('Bucket' => 'agent.nosprawl.software', 'Key' => $environment == "production" ? 'block' : 'dev/block', 'ContentType' => 'text/plain', 'Body' => '', 'ACL' => 'public-read')); // Make sure the latest file exists. If not, start with 0. if (!$s3->doesObjectExist('agent.nosprawl.software', $environment == "production" ? 'block' : 'dev/latest')) { // Create zero latest $s3->putObject(array('Bucket' => 'agent.nosprawl.software', 'Key' => $environment == "production" ? 'latest' : 'dev/latest', 'ContentType' => 'text/plain', 'Body' => '0', 'ACL' => 'public-read')); } // Get current latest so we can increment it $result = $s3->getObject(array('Bucket' => 'agent.nosprawl.software', 'Key' => $environment == "production" ? 'latest' : 'dev/latest')); $current_latest = $result['Body'] . ""; $new_latest = $current_latest + 1; $ruby_agent = file_get_contents($environment == "production" ? 'deployments/agent.rb' : 'deployments/agent_dev.rb'); $ruby_agent_with_version_info = "VERSION = " . $new_latest . "\n\n" . $ruby_agent; // Upload new Ruby $result = $s3->putObject(array('Bucket' => 'agent.nosprawl.software', 'Key' => $environment == "production" ? $new_latest . "" : "dev/" . $new_latest . "", 'Body' => $ruby_agent_with_version_info, 'ContentType' => 'text/plain', 'ACL' => 'public-read')); // Delete latest $s3->deleteObject(array('Bucket' => 'agent.nosprawl.software', 'Key' => $environment == "production" ? 'latest' : 'dev/latest')); // Upload new latest $result = $s3->putObject(array('Bucket' => 'agent.nosprawl.software', 'Key' => $environment == "production" ? 'latest' : 'dev/latest', 'Body' => $new_latest . "", 'ContentType' => 'text/plain', 'ACL' => 'public-read')); // Delete the old version $s3->deleteObject(array('Bucket' => 'agent.nosprawl.software', 'Key' => $environment == "production" ? $current_latest : 'dev/' . $current_latest)); // Delete blockfile $s3->deleteObject(array('Bucket' => 'agent.nosprawl.software', 'Key' => $environment == "production" ? 'block' : 'dev/block')); }
public function __construct($args = array()) { $this->s3 = S3Client::factory($this->build_aws_config()); $this->s3Client = $this->s3->get('s3'); $this->uploadDir = '/maps/icons'; $this->bucket = 'assets.projects.newsday.com'; }
/** * Execute the console command. * * @return mixed */ public function fire() { $this->info('Backing up databases'); $client = \Aws\S3\S3Client::factory(['key' => \Config::get('laravel-backup::key'), 'secret' => \Config::get('laravel-backup::secret'), 'region' => \Config::get('laravel-backup::region')]); foreach (\Config::get('laravel-backup::databases') as $connection => $remote) { // Get the bucket and path $bucketAndPath = explode('/', $remote, 2); // Set the temporary file $file = basename($bucketAndPath[1]); $tempFile = storage_path() . '/' . $file; // Get database configuration $username = \Config::get('database.connections.' . $connection . '.username'); $password = \Config::get('database.connections.' . $connection . '.password'); $database = \Config::get('database.connections.' . $connection . '.database'); $host = \Config::get('database.connections.' . $connection . '.host'); $port = \Config::get('database.connections.' . $connection . '.port', 3306); // Create SQL Dump exec("mysqldump --routines --host={$host} --port={$port} --user={$username} --password={$password} {$database} > '{$tempFile}'"); // Compress the dump exec("gzip '{$tempFile}'"); // Upload to S3 $client->putObject(array('Bucket' => $bucketAndPath[0], 'Key' => $bucketAndPath[1] . '.gz', 'SourceFile' => $tempFile . '.gz', 'ACL' => 'public-read')); // Delete temp file unlink($tempFile . '.gz'); } }
public function __construct() { parent::__construct(); $this->client = S3Client::factory(["key" => AWS_NETSUITE_INTEGRATION_KEY, "secret" => AWS_NETSUITE_INTEGRATION_SECRET]); $this->Item = ClassRegistry::init('Item'); $this->ItemsItems = ClassRegistry::init('ItemsItems'); $this->ItemPrice = ClassRegistry::init('ItemPrices'); $this->ItemAvailabilityTimes = ClassRegistry::init('ItemAvailabilityTimes'); $this->NetsuiteAudit = ClassRegistry::init('NetsuiteAudit'); $this->NetSuite = ClassRegistry::init('NetSuite'); $this->ItemShipmentClass = ClassRegistry::init('ItemShipmentClass'); $this->Item->useDbConfig = 'default'; $this->ItemPrice->useDbConfig = 'default'; $this->ItemAvailabilityTimes->useDbConfig = 'default'; $this->ItemShipmentClass->useDbConfig = 'default'; $this->ItemsItems->useDbConfig = 'default'; $this->email = '*****@*****.**'; /*********** Populate $this->Markets *************** * Caution: There are two class variable with similar names: * 1. $this->Markets (plural) is an array of compiled market data. * 2. $this->Market (singular) is the instantiation for the Market model. */ $this->_loadMarkets(); $this->stdout->styles('magenta', array('text' => 'magenta')); }
public static function getBucket($dir, $ext = '*') { $app = App::getInstance(); $results = []; if ($s3conf = $app->config->getKey(self::stockUtilsKey)) { if (!empty($s3conf['access_key']) && !empty($s3conf['secret_key']) && !empty($s3conf['bucket_name'])) { try { if ($s3 = S3Client::factory(array('key' => $s3conf['access_key'], 'secret' => $s3conf['secret_key'], 'region' => @$s3conf['region'] ?: Region::US_EAST_1))) { if ($objects = $s3->getListObjectsIterator(['Bucket' => $s3conf['bucket_name'], 'Prefix' => sprintf('bgtracks/%s/', rtrim($dir, '/'))])) { foreach ($objects as $object) { $fn = $object['Key']; $name = basename($fn); if (empty($ext) || preg_match("/\\.({$ext})\$/", $name)) { $host = !empty($s3conf['cdn']) ? $s3conf['cdn'] : sprintf('%s.s3.amazonaws.com', $s3conf['bucket_name']); $result = ['name' => self::fix_name(pathinfo($name, PATHINFO_FILENAME)), 'url' => sprintf('http://%s/%s', $host, $fn)]; if (preg_match("!{$dir}/(\\w+)!", dirname($fn), $matches)) { $results[$matches[1]][] = $result; } else { $results[] = $result; } } } } } } catch (Exception $e) { throw new BgtracksError("Error connecting to S3: " . $e->getMessage(), $e); } } } return $results; }
private static function _init($settings) { pb_backupbuddy::status('details', 'Loading AWS SDK...'); require_once dirname(dirname(__FILE__)) . '/_s3lib2/aws-autoloader.php'; pb_backupbuddy::status('details', 'SDK loaded.'); // Format all settings. $settings = self::_formatSettings($settings); // If not connected with these exact settings (by comparisong signatue of $settings ) then connect & prepare bucket. //if ( ! isset( self::$_client ) ) { $newSignature = md5(serialize($settings)); if ($newSignature != self::$_client_signature) { self::$_client_signature = md5(serialize($settings)); $s3Config = self::getCredentials($settings); if ('0' == $settings['ssl']) { $s3Config['scheme'] = 'http'; pb_backupbuddy::status('details', 'SSL disabled.'); } self::$_client = S3Client::factory($s3Config); // Verify bucket exists; create if not. Also set region to the region bucket exists in. if (false === self::_prepareBucketAndRegion($settings)) { return self::_error('Error #983483437: Could not prepare bucket `' . $settings['bucket'] . '` in region `' . $settings['regision'] . '`.'); } } return $settings; // Formatted & updated settings. }
public static function get() { if (S3ClientBuilder::$client == null) { S3ClientBuilder::$client = S3Client::factory(); } return S3ClientBuilder::$client; }
public function getAdapter() { $this->validate(); $client = S3Client::factory(['credentials' => ['key' => $this->settings('key'), 'secret' => $this->settings('secret')], 'region' => $this->settings('region'), 'version' => $this->settings('version')]); $bucket = $this->settings('bucket'); return new AwsS3Adapter($client, $bucket); }
/** * Criar storage do aws S3 * * @param array $config * * @return StorageInterface */ protected function registerS3Storage(array $config) { $this->app['nwlaravel.filestorage.storage'] = $this->app->share(function ($app) use($config) { $s3 = S3Client::factory(array('key' => $config['access'], 'secret' => $config['secret'])); return new S3Storage($config['root'], $s3); }); }
/** * @param array $config */ public function __construct($config) { $this->client = S3Client::factory(array('key' => $config['application.files']['s3_key'], 'secret' => $config['application.files']['s3_secret'])); $this->bucket = $config['application.files']['s3_bucket']; $this->baseURI = $config['application.files']['s3_endpoint']; parent::__construct($config); }
/** * @return S3Client */ private function getMockS3Client() { $mock = new MockPlugin(array(new Response(200, null, '{"Records":[{"r1":"r1"},{"r2":"r2"},{"r3":"r3"}]}'), new Response(200, null, '{}'), new Response(200, null, '{"Records":[{"r4":"r4"},{"r5":"r5"}]}'))); $client = S3Client::factory(array('key' => 'foo', 'secret' => 'bar')); $client->addSubscriber($mock); return $client; }
/** * Creates adapter instance * * @param Enlight_Event_EventArgs $args * @return AdapterInterface */ public function createS3Adapter(Enlight_Event_EventArgs $args) { $defaultConfig = ['key' => '', 'secret' => '', 'region' => '', 'version' => 'latest', 'bucket' => '', 'prefix' => '']; $config = array_merge($defaultConfig, $args->get('config')); $client = S3Client::factory(['credentials' => ['key' => $config['key'], 'secret' => $config['secret']], 'region' => $config['region'], 'version' => $config['version']]); return new AwsS3Adapter($client, $config['bucket'], $config['prefix']); }
/** * Register specific services for the module */ public function registerServices(DiInterface $di) { $config = $di->get('config'); //Registering a dispatcher $di->set('dispatcher', function () { $dispatcher = new Dispatcher(); $dispatcher->setDefaultNamespace("Promoziti\\Modules\\Business\\Controllers"); return $dispatcher; }); $di->set('view', function () { $view = new View(); $view->setViewsDir(__DIR__ . '/views/'); $view->registerEngines(array('.volt' => function ($view, $di) { $volt = new VoltEngine($view, $di); $config = $di->get('config'); $volt->setOptions(array('compileAlways' => true, 'compiledPath' => $config->application->cache_dir . "volt/", 'compiledSeparator' => '_')); return $volt; })); return $view; }); $di->set('aws_s3', function () use($config) { //version 2.7 style $s3 = \Aws\S3\S3Client::factory(array('key' => $config->application->security->aws->key, 'secret' => $config->application->security->aws->secret, 'region' => 'us-west-2', 'version' => '2006-03-01')); return $s3; }); }
/** * @param string $name * @param array $config * @return League\Flysystem\Adapter\AbstractAdapter */ protected function prepareAdapter($name, $config) { if (!isset($this->adaptersMap[$name])) { throw new \Exception(sprintf('Unknown adapter "%s".', $name)); } $adapter = $this->adaptersMap[$name]; $class = $adapter['class']; // check required properties if (!empty($adapter['required'])) { foreach ($adapter['required'] as $prop) { if (!isset($config[$prop])) { throw new InvalidConfigException(sprintf('The "%s" property must be set.', $prop)); } } } switch ($name) { case 'local': return Yii::createObject($class, [$this->basePath]); break; case 'dropbox': return Yii::createObject($class, [Yii::createObject('Dropbox\\Client', [$config['token'], $config['app']]), isset($config['prefix']) ? $config['prefix'] : null]); break; case 'ftp': if (isset($config['root'])) { $config['root'] = Yii::getAlias($config['root']); } break; case 'sftp': if (!isset($config['password']) && !isset($config['privateKey'])) { throw new InvalidConfigException('Either "password" or "privateKey" property must be set.'); } if (isset($config['root'])) { $config['root'] = Yii::getAlias($config['root']); } break; case 'gridfs': return Yii::createObject($class, [(new \MongoClient($config['server']))->selectDB($config['database'])->getGridFS()]); break; case 'awss3': return Yii::createObject($class, [\Aws\S3\S3Client::factory($config), $config['bucket'], isset($config['prefix']) ? $config['prefix'] : null, isset($config['options']) ? $config['options'] : []]); break; case 'azure': return Yii::createObject($class, [\WindowsAzure\Common\ServicesBuilder::getInstance()->createBlobService(sprintf('DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s', base64_encode($config['accountName']), base64_encode($config['accountKey']))), $config['container']]); break; case 'copy': return Yii::createObject($class, [new \Barracuda\Copy\API($config['consumerKey'], $config['consumerSecret'], $config['accessToken'], $config['tokenSecret']), isset($config['prefix']) ? $config['prefix'] : null]); break; case 'rackspace': return Yii::createObject($class, [(new \OpenCloud\Rackspace($config['endpoint'], ['username' => $config['username'], 'apiKey' => $config['apiKey']]))->objectStoreService('cloudFiles', $config['region'])->getContainer($config['container']), isset($config['prefix']) ? $config['prefix'] : null]); break; case 'webdav': return Yii::createObject($class, [new \Sabre\DAV\Client($config['endpoint']), isset($config['prefix']) ? $config['prefix'] : null]); break; default: $class = 'League\\Flysystem\\Adapter\\NullAdapter'; break; } return Yii::createObject($class, [$config]); }