Exemplo n.º 1
0
 public function __construct($accessKeyId, $secretAccessKey, $bucket, $region, $host)
 {
     $this->bucket = $bucket;
     $this->host = $host;
     $this->accesKeyId = $accessKeyId;
     $this->aws = Aws::factory(array('key' => $accessKeyId, 'secret' => $secretAccessKey, 'region' => $region));
     $this->s3 = $this->aws->get('s3');
 }
 function getSnsClient()
 {
     if ($this->snsClient) {
         return $this->snsClient;
     }
     $this->snsClient = $this->aws->get('sns');
     $this->snsClient->setRegion($this->topicRegion);
     return $this->snsClient;
 }
 /**
  * @return \Aws\Swf\SwfClient
  */
 private function getSwfClient()
 {
     $config = json_decode(file_get_contents(ROOT_PATH . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'parameters.json'), true);
     $awsFactory = Aws::factory(array('credentials' => array('key' => $config['aws_access_key_id'], 'secret' => $config['aws_secret_access_key']), 'region' => $config['aws_region']));
     $serviceFactory = new AwsSwfClientProvider($awsFactory);
     return $serviceFactory->getSwfClient();
 }
 function __construct($group_id = "", $region_id = "")
 {
     parent::__construct($group_id, $region_id);
     $this->credentials = new Credentials($this->config['aws_access_key_id'], $this->config['aws_secret_access_key']);
     $region = $this->region()->getRegion();
     $this->AWS = Aws::factory(array('credentials' => $this->credentials, 'region' => $region['id']));
 }
Exemplo n.º 5
0
 public function updateImageCover()
 {
     $sessionToken = $this->input->post('SessionToken');
     $accessKeyId = $this->input->post('AccessKeyId');
     $secretAccessKey = $this->input->post('SecretAccessKey');
     $userId = $this->input->post('userId');
     $coverAvatar = $_FILES['CoverFile']['name'];
     $sourceCover = $_FILES['CoverFile']['tmp_name'];
     $ext = Myclass::getFileExtension($coverAvatar);
     $coverAvatar = sha1(time()) . '.' . $ext;
     $config = array('key' => $accessKeyId, 'secret' => $secretAccessKey, 'token' => $sessionToken);
     //print_r($config);exit;
     $aws = Aws::factory($config);
     $s3AWS = $aws->get('S3');
     $bucket = 'superchat-dev';
     try {
         //Create folder and Upload image into S3 Amazon by userId
         $result = $s3AWS->putObject(array('Bucket' => $bucket, 'Key' => $userId . '/' . $coverAvatar, 'SourceFile' => $sourceCover, 'Body' => "", 'ACL' => 'public-read'));
         if ($result) {
             echo '<img src="' . S3_AMAZONE_AWS_SUPERCHAT_DEV . '/' . $userId . '/' . $coverAvatar . '" height="300" id="aws-img-cover">';
         }
     } catch (Exeption $e) {
         die($e->getMessage());
     }
 }
Exemplo n.º 6
0
 public function getAws()
 {
     if ($this->_aws === null) {
         $this->_aws = Aws::factory($this->_config);
     }
     return $this->_aws;
 }
Exemplo n.º 7
0
 public function __construct()
 {
     $module = \Yii::$app->controller->module;
     $this->key = isset($module->storage['s3']['key']) ? $module->storage['s3']['key'] : '';
     $this->secret = isset($module->storage['s3']['secret']) ? $module->storage['s3']['secret'] : '';
     $this->bucket = isset($module->storage['s3']['bucket']) ? $module->storage['s3']['bucket'] : '';
     if ($this->key == '') {
         throw new InvalidConfigException('Key cannot be empty!');
     }
     if ($this->secret == '') {
         throw new InvalidConfigException('Secret cannot be empty!');
     }
     if ($this->bucket == '') {
         throw new InvalidConfigException('Bucket cannot be empty!');
     }
     $param = ['key' => $this->key, 'secret' => $this->secret];
     if (isset($module->storage['s3']['region'])) {
         $param['region'] = $module->storage['s3']['region'];
     }
     if (isset($module->storage['s3']['proxy'])) {
         $param['request.options']['proxy'] = $module->storage['s3']['proxy'];
     }
     $aws = Aws::factory($param);
     $this->s3 = $aws->get('S3');
 }
 protected function _init()
 {
     if (FALSE === $this->_initialized) {
         $baseArn = NULL;
         $apiKey = NULL;
         $apiSecret = NULL;
         $region = NULL;
         if (class_exists('Configure') && NULL !== Configure::constant('AWS_SNS_ARN_BASE')) {
             $baseArn = Configure::AWS_SNS_ARN_BASE;
         }
         if (class_exists('Configure') && NULL !== Configure::constant('AWS_KEY')) {
             $apiKey = Configure::AWS_KEY;
         }
         if (class_exists('Configure') && NULL !== Configure::constant('AWS_SNS_API_KEY')) {
             $apiKey = Configure::AWS_SNS_API_KEY;
         }
         if (class_exists('Configure') && NULL !== Configure::constant('AWS_SECRET')) {
             $apiSecret = Configure::AWS_SECRET;
         }
         if (class_exists('Configure') && NULL !== Configure::constant('AWS_SNS_API_SECRET')) {
             $apiSecret = Configure::AWS_SNS_API_SECRET;
         }
         if (class_exists('Configure') && NULL !== Configure::constant('AWS_REGION')) {
             $region = Configure::AWS_REGION;
         }
         if (class_exists('Configure') && NULL !== Configure::constant('AWS_SNS_REGION')) {
             $region = Configure::AWS_SNS_REGION;
         } elseif (defined('PROJECT_NAME') && strlen(PROJECT_NAME) > 0 && class_exists(PROJECT_NAME . 'Configure')) {
             $ProjectConfigure = PROJECT_NAME . 'Configure';
             if (NULL !== $ProjectConfigure::constant('AWS_SNS_ARN_BASE')) {
                 $baseArn = $ProjectConfigure::AWS_SNS_ARN_BASE;
             }
             if (NULL !== $ProjectConfigure::constant('AWS_KEY')) {
                 $apiKey = $ProjectConfigure::AWS_KEY;
             }
             if (NULL !== $ProjectConfigure::constant('AWS_SNS_API_KEY')) {
                 $apiKey = $ProjectConfigure::AWS_SNS_API_KEY;
             }
             if (NULL !== $ProjectConfigure::constant('AWS_SECRET')) {
                 $apiSecret = $ProjectConfigure::AWS_SECRET;
             }
             if (NULL !== $ProjectConfigure::constant('AWS_SNS_API_SECRET')) {
                 $apiSecret = $ProjectConfigure::AWS_SNS_API_SECRET;
             }
             if (NULL !== $ProjectConfigure::constant('AWS_REGION')) {
                 $region = $ProjectConfigure::AWS_REGION;
             }
             if (NULL !== $ProjectConfigure::constant('AWS_SNS_REGION')) {
                 $region = $ProjectConfigure::AWS_SNS_REGION;
             }
         }
         $arns = explode('://', $baseArn);
         $this->_arnBase = 'arn:aws:sns:' . $arns[0] . ':app/%target_pratform%/' . $arns[1];
         $this->_initialized = TRUE;
         if (NULL === $this->_AWS) {
             $this->_AWS = Aws::factory(array('key' => $apiKey, 'secret' => $apiSecret, 'region' => Region::TOKYO))->get('sns');
         }
     }
 }
 public function __construct($debug)
 {
     $this->debug = $debug;
     // Create AWS SDK instance.
     // We expect an AWS role or the proper AWS env variable sets for KEY/SECRET
     $aws = Aws::factory(array('region' => getenv("AWS_DEFAULT_REGION")));
     $this->sqs = $aws->get('Sqs');
 }
Exemplo n.º 10
0
 public function getPublicDNSFromEBEnvironmentName($envName)
 {
     $ec2Client = $this->providedAws->get('ec2');
     $result = $ec2Client->describeInstances(array('Filters' => array(array('Name' => 'tag-key', 'Values' => array('elasticbeanstalk:environment-name')), array('Name' => 'tag-value', 'Values' => array($envName)))));
     $dnsArray = array();
     //ugh, no dot notation checks
     $reservations = $result->get('Reservations', array());
     if (count($reservations) > 0) {
         foreach ($reservations as $reservation) {
             if (isset($reservation['Instances']) && count($reservation['Instances']) > 0) {
                 $instance = $reservation['Instances'][0];
                 $dnsArray[] = $instance['PublicDnsName'];
             }
         }
     }
     return $dnsArray;
 }
Exemplo n.º 11
0
 /**
  * 
  */
 protected function setUp()
 {
     $this->sBucketName = 'your-s3-bucket';
     $aConfig = (include self::CONFIG_FILE);
     $oAWS = Aws::factory($aConfig);
     $oClient = $oAWS->get('S3');
     $this->oService = new AwsS3Service($oClient);
 }
 private function createProvidedAws()
 {
     $accessKey = $this->app->make('config')->get('laravel-aws-ssh::aws.access_key');
     $secretKey = $this->app->make('config')->get('laravel-aws-ssh::aws.secret_key');
     $region = $this->app->make('config')->get('laravel-aws-ssh::aws.region', 'us-east-1');
     $providedAws = ProvidedAWS::factory(array('key' => $accessKey, 'secret' => $secretKey, 'region' => $region));
     return $providedAws;
 }
Exemplo n.º 13
0
 public function init_s3($access_key, $secret_key, $region = null)
 {
     if (!isset($region)) {
         $region = Region::AP_NORTHEAST_1;
     }
     $s3 = Aws::factory(array('key' => $access_key, 'secret' => $secret_key, 'region' => $this->get_region($region)))->get('s3');
     $this->s3 = $s3;
     return $s3;
 }
Exemplo n.º 14
0
 protected function getClient()
 {
     if (!$this->client) {
         $bucket = Config::get('storage.bucket', 'default');
         $key = Config::get('storage.key');
         $secret = Config::get('storage.secret');
         $this->client = Aws::factory(array('bucket' => $bucket, 'key' => $key, 'secret' => $secret))->get('s3');
     }
     return $this->client;
 }
Exemplo n.º 15
0
function sendMailSES($text, $html, $subject, $from, $to = array())
{
    try {
        $client = Aws::factory(getServerRoot() . '/modulos/aws/modelos/configurationFile.php')->get('ses');
        $messageId = $client->sendEmail(array('Source' => $from, 'Destination' => array('ToAddresses' => $to), 'Message' => array('Subject' => array('Data' => $subject), 'Body' => array('Text' => array('Data' => $text), 'Html' => array('Data' => $html)))));
        return true;
    } catch (Exception $e) {
        return false;
    }
}
Exemplo n.º 16
0
 /**
  * Get aws object or aws service
  *
  * @return mixed
  */
 protected function getAws($service = null)
 {
     if (is_null($this->aws)) {
         $this->aws = Aws::factory($this->getAwsCredentials());
     }
     if (!is_null($service)) {
         return $this->aws->get($service);
     }
     return $this->aws;
 }
Exemplo n.º 17
0
 public function init_s3($access_key, $secret_key, $region = null)
 {
     if (!isset($region)) {
         $region = Region::AP_NORTHEAST_1;
     }
     $param = array('key' => $access_key, 'secret' => $secret_key, 'region' => $this->get_region($region));
     $s3 = Aws::factory(apply_filters('nephila_clavata_credential', $param))->get('s3');
     $this->s3 = $s3;
     return $s3;
 }
Exemplo n.º 18
0
 /**
  * Returns the aws service builder
  * @return Guzzle\Service\Builder\ServiceBuilder
  * @throws CException
  */
 public function getAws()
 {
     if (null === $this->_aws) {
         $config = $this->_config !== null ? $this->_config : __DIR__ . '/../config/aws-config.php';
         if (is_scalar($config) && !@file_exists($config)) {
             throw new CException(Yii::t('zii', '"aws-config.php" configuration file not found'));
         }
         $this->_aws = Aws::factory($config);
     }
     return $this->_aws;
 }
Exemplo n.º 19
0
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->app->singleton('aws', function ($app) {
         $config = $app['config']->get('aws');
         if (isset($config['config_file'])) {
             $config = $config['config_file'];
         }
         return Aws::factory($config);
     });
     $this->app->alias('aws', 'Aws\\Common\\Aws');
 }
Exemplo n.º 20
0
function deleteMessageFromQueue($receiptHandle)
{
    $client = Aws::factory(getServerRoot() . '/modulos/aws/modelos/configurationFile.php')->get('sqs');
    $res = false;
    try {
        $res = $client->deleteMessage(array('QueueUrl' => getQueueUrl(), 'ReceiptHandle' => $receiptHandle));
        return true;
    } catch (SqsException $e) {
        //Ocurrió un error al borrar el mensaje
        return false;
    }
}
Exemplo n.º 21
0
 public function __construct($config, $sesClient = null)
 {
     $this->sesClient = $sesClient;
     if (is_null($this->sesClient)) {
         $sesConfig = $config->getEmailSesConfig();
         if (!isset($sesConfig['aws-access-key']) || !isset($sesConfig['aws-secret-key']) || !isset($sesConfig['region'])) {
             throw new \Exception('Unable to initiate Emailer due to missing ' . 'configuration variables.  Please check your config.');
         }
         $aws = Aws::factory(array('ses' => array('alias' => 'Ses', 'class' => 'Aws\\Ses\\SesClient', 'extends' => 'default_settings'), 'key' => $sesConfig['aws-access-key'], 'secret' => $sesConfig['aws-secret-key'], 'region' => $sesConfig['region']))->enableFacades('ses');
         $this->sesClient = $aws->get('ses');
     }
 }
Exemplo n.º 22
0
 public function connect()
 {
     $config = $this->config;
     $this->connected = false;
     try {
         $this->_connection = Aws::factory($config);
         $this->connected = true;
     } catch (Exception $e) {
         throw new MissingConnectionException(array('class' => get_class($this), 'message' => $e->getMessage()));
     }
     return $this->connected;
 }
Exemplo n.º 23
0
 public function getAwsClientFactory()
 {
     // what are we doing?
     $log = usingLog()->startAction("create AWS client factory using official SDK");
     // get the settings for Aws
     $awsSettings = fromConfig()->getModuleSetting('aws');
     // create the AWS client factory
     $awsFactory = Aws::factory(array('key' => $awsSettings->key, 'secret' => $awsSettings->secret, 'region' => $awsSettings->region));
     // all done
     $log->endAction();
     return $awsFactory;
 }
 public function __construct($debug, $cpeLogger = null)
 {
     $this->debug = $debug;
     // Create AWS SDK instance
     $aws = Aws::factory(array('region' => getenv("AWS_DEFAULT_REGION")));
     $this->sqs = $aws->get('Sqs');
     // Logger
     if (!$cpeLogger) {
         $this->cpeLogger = new CpeSdk\CpeLogger();
     } else {
         $this->cpeLogger = $cpeLogger;
     }
 }
Exemplo n.º 25
0
 /**
  * @param Application $app
  */
 public function boot(Application $app)
 {
     $options = $this->options;
     $app->getDI()->setShared('aws', function () use($options) {
         $aws = Aws::factory($options);
         $aws->getEventDispatcher()->addListener('service_builder.create_client', function (Event $event) {
             $clientConfig = $event['client']->getConfig();
             $commandParams = $clientConfig->get(Client::COMMAND_PARAMS) ?: array();
             $clientConfig->set(Client::COMMAND_PARAMS, array_merge_recursive($commandParams, array(UserAgentListener::OPTION => 'Phalcon/' . Application::VERSION)));
         });
         return $aws;
     });
 }
Exemplo n.º 26
0
 /**
  * connect
  */
 public function connect($uri, $options = array())
 {
     list($region) = explode('/', $uri);
     if (is_null($region) || strlen($region) == 0) {
         throw new \mychaelstyle\Exception('Fail to connect aws! option \'region\' is required!', \mychaelstyle\Exception::ERROR_PROVIDER_CONNECTION);
     }
     $defRegion = @constant('Aws\\Common\\Enum\\Region::' . $region);
     $this->region = is_null($defRegion) ? $region : $defRegion;
     $options['region'] = $this->region;
     try {
         $aws = \Aws\Common\Aws::factory($options);
         $this->client = $aws->get($this->getServiceName());
     } catch (\Exception $e) {
         throw new \mychaelstyle\Exception('Fail to connect aws!', \mychaelstyle\Exception::ERROR_PROVIDER_CONNECTION, $e);
     }
 }
Exemplo n.º 27
0
 /**
  * @covers \Drupal\amazons3\S3Client::validateBucketExists
  */
 public function testValidateBucketExists()
 {
     // Instantiate the AWS service builder.
     $config = array('includes' => array(0 => '_aws'), 'services' => array('default_settings' => array('params' => array('region' => 'us-east-1')), 'cloudfront' => array('extends' => 'cloudfront', 'params' => array('private_key' => 'change_me', 'key_pair_id' => 'change_me'))), 'credentials' => array('key' => 'placeholder', 'secret' => 'placeholder'));
     $aws = \Aws\Common\Aws::factory($config);
     // Configure the tests to use the instantiated AWS service builder
     \Guzzle\Tests\GuzzleTestCase::setServiceBuilder($aws);
     $client = $this->getServiceBuilder()->get('s3', true);
     $this->setMockResponse($client, array(new Response(200)));
     $exception = NULL;
     try {
         DrupalS3Client::validateBucketExists('bucket', $client);
     } catch (\Exception $exception) {
     }
     $this->assertNull($exception, 'The bucket was validated to exist.');
 }
 /**
  * test case startup
  *
  * @return void
  */
 public static function setupBeforeClass()
 {
     self::$_sessionBackup = Configure::read('Session');
     // Connection to DynamoDB Local
     $aws = Aws::factory(array('key' => 'XXXXXXXXXXXXXX', 'secret' => 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyy', 'region' => 'us-east-1', 'base_url' => 'http://localhost:8000'));
     Configure::write('Session.handler', array('engine' => 'AwsUtils.DynamoDBSession', 'aws' => $aws));
     Configure::write('Session.timeout', 100);
     $dynamoDB = $aws->get('dynamodb');
     $found = false;
     $response = $dynamoDB->listTables(array());
     if (!in_array(DynamoDBSession::DEFAULT_TABLE_NAME, $response['TableNames'])) {
         $handler = new DynamoDBSession();
         $aws_handler = $handler->getSessionHandler();
         $aws_handler->createSessionsTable(5, 5);
     }
 }
Exemplo n.º 29
0
 /**
  * @param string $group configuration group to be used.
  * @param string $global_params
  */
 public static function factory($group = null, array $global_params = array())
 {
     if (empty($group)) {
         $group = self::$_config_group;
     }
     if (is_string($group)) {
         $config = Kohana::$config->load(self::DEFAULT_CONFIG_PATH)->as_array();
         // load configuration from kohana config file.
         if (empty($config[$group])) {
             throw new Kohana_Exception('Cannot find :class configuration group `:group` on file `:file`', array(':class' => __CLASS__, ':group' => $group, ':file' => self::DEFAULT_CONFIG_PATH));
             return false;
         }
         $group = $config[$group];
     }
     return parent::factory($group, $config);
 }
 function getAWSService($region, $accprov)
 {
     $providerArray = json_decode($this->getAppContext()->getCloudproviders());
     $awsacesskey = $providerArray->{$accprov}->accessKey;
     $secretkey = $providerArray->{$accprov}->secretKey;
     try {
         loghandler(DEBUG, "Creating service factory");
         //echo "\ncreating service factory ....................:";
         $aws = Aws::factory(array('key' => $awsacesskey, 'secret' => $secretkey, 'region' => $region));
         loghandler(DEBUG, "Got service factory");
         return $aws;
     } catch (Exception $se) {
         $message = $se->getMessage();
         trigger_error($message, E_USER_ERROR);
     }
     return null;
 }