当前位置: 首页>>代码示例>>PHP>>正文


PHP AmazonS3::ListBuckets方法代码示例

本文整理汇总了PHP中AmazonS3::ListBuckets方法的典型用法代码示例。如果您正苦于以下问题:PHP AmazonS3::ListBuckets方法的具体用法?PHP AmazonS3::ListBuckets怎么用?PHP AmazonS3::ListBuckets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AmazonS3的用法示例。


在下文中一共展示了AmazonS3::ListBuckets方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: xListBucketsAction

 public function xListBucketsAction()
 {
     // Create Amazon s3 client object
     $AmazonS3 = new AmazonS3($this->environment->getPlatformConfigValue(Modules_Platforms_Ec2::ACCESS_KEY), $this->environment->getPlatformConfigValue(Modules_Platforms_Ec2::SECRET_KEY));
     $AmazonCloudFront = new AmazonCloudFront($this->environment->getPlatformConfigValue(Modules_Platforms_Ec2::ACCESS_KEY), $this->environment->getPlatformConfigValue(Modules_Platforms_Ec2::SECRET_KEY));
     //Create cloundfront object
     $distributions = $AmazonCloudFront->ListDistributions();
     // Get list of all user buckets
     $buckets = array();
     foreach ($AmazonS3->ListBuckets() as $bucket) {
         if (!$distributions[$bucket->Name]) {
             $info = array("name" => $bucket->Name);
         } else {
             $info = array("name" => $bucket->Name, "cfid" => $distributions[$bucket->Name]['ID'], "cfurl" => $distributions[$bucket->Name]['DomainName'], "cname" => $distributions[$bucket->Name]['CNAME'], "status" => $distributions[$bucket->Name]['Status'], "enabled" => $distributions[$bucket->Name]['Enabled']);
         }
         $c = explode("-", $info['name']);
         if ($c[0] == 'farm') {
             $hash = $c[1];
             $farm = $this->db->GetRow("SELECT id, name FROM farms WHERE hash=? AND env_id = ?", array($hash, $this->environment->id));
             if ($farm) {
                 $info['farmId'] = $farm['id'];
                 $info['farmName'] = $farm['name'];
             }
         }
         $buckets[] = $info;
     }
     $response = $this->buildResponseFromData($buckets, array('name', 'farmName'));
     $this->response->data($response);
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:29,代码来源:S3.php

示例2:

 function _testS3Bucket()
 {
     $AmazonS3 = new AmazonS3("", "");
     $res = $AmazonS3->ListBuckets();
     $this->assertTrue(is_array($res->Bucket), "ListBuckets returned array");
     $res = $AmazonS3->CreateBucket("MySQLDumps");
     $this->assertTrue($res, "Bucket successfull created");
     $res = $AmazonS3->CreateObject("fonts/test.ttf", "offload-public", "/tmp/PhotoEditService.wsdl", "plain/text");
     $this->assertTrue($res, "Object successfull created");
     $res = $AmazonS3->DownloadObject("fonts/test.ttf", "offload-public");
     $this->assertTrue($res, "Object successfull downloaded");
     $res = $AmazonS3->DeleteObject("fonts/test.ttf", "offload-public");
     $this->assertTrue($res, "Object successfull removed");
 }
开发者ID:jasherai,项目名称:libwebta,代码行数:14,代码来源:tests.php

示例3:

 function _testS3Bucket()
 {
     $AmazonS3 = new AmazonS3("0EJNVE9QFYY3TD554T02", "VOtWnbI2PmsqKOqDNVVgfLVsEnGD/6miiYDY552S");
     $res = $AmazonS3->ListBuckets();
     $this->assertTrue(is_array($res->Bucket), "ListBuckets returned array");
     $res = $AmazonS3->CreateBucket("MySQLDumps");
     $this->assertTrue($res, "Bucket successfull created");
     $res = $AmazonS3->CreateObject("fonts/test.ttf", "offload-public", "/tmp/PhotoEditService.wsdl", "plain/text");
     $this->assertTrue($res, "Object successfull created");
     $res = $AmazonS3->DownloadObject("fonts/test.ttf", "offload-public");
     $this->assertTrue($res, "Object successfull downloaded");
     $res = $AmazonS3->DeleteObject("fonts/test.ttf", "offload-public");
     $this->assertTrue($res, "Object successfull removed");
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:14,代码来源:tests.php

示例4: xSaveEc2Action

 public function xSaveEc2Action()
 {
     $pars = array();
     $enabled = false;
     if ($this->getParam('ec2_is_enabled')) {
         $enabled = true;
         $pars[Modules_Platforms_Ec2::ACCOUNT_ID] = $this->checkVar(Modules_Platforms_Ec2::ACCOUNT_ID, 'string', "AWS Account Number required");
         if (!is_numeric($pars[Modules_Platforms_Ec2::ACCOUNT_ID]) || strlen($pars[Modules_Platforms_Ec2::ACCOUNT_ID]) != 12) {
             //$err[Modules_Platforms_Ec2::ACCOUNT_ID] = _("AWS numeric account ID required (See <a href='/faq.html'>FAQ</a> for info on where to get it).");
             $this->checkVarError[Modules_Platforms_Ec2::ACCOUNT_ID] = _("AWS Account Number should be numeric");
         } else {
             $pars[Modules_Platforms_Ec2::ACCOUNT_ID] = preg_replace("/[^0-9]+/", "", $pars[Modules_Platforms_Ec2::ACCOUNT_ID]);
         }
         $pars[Modules_Platforms_Ec2::ACCESS_KEY] = $this->checkVar(Modules_Platforms_Ec2::ACCESS_KEY, 'string', "AWS Access Key required");
         $pars[Modules_Platforms_Ec2::SECRET_KEY] = $this->checkVar(Modules_Platforms_Ec2::SECRET_KEY, 'password', "AWS Access Key required");
         $pars[Modules_Platforms_Ec2::PRIVATE_KEY] = trim($this->checkVar(Modules_Platforms_Ec2::PRIVATE_KEY, 'file', "AWS x.509 Private Key required"));
         $pars[Modules_Platforms_Ec2::CERTIFICATE] = trim($this->checkVar(Modules_Platforms_Ec2::CERTIFICATE, 'file', "AWS x.509 Certificate required"));
         // the same as EC2
         $pars[Modules_Platforms_Rds::ACCOUNT_ID] = $pars[Modules_Platforms_Ec2::ACCOUNT_ID];
         $pars[Modules_Platforms_Rds::ACCESS_KEY] = $pars[Modules_Platforms_Ec2::ACCESS_KEY];
         $pars[Modules_Platforms_Rds::SECRET_KEY] = $pars[Modules_Platforms_Ec2::SECRET_KEY];
         $pars[Modules_Platforms_Rds::PRIVATE_KEY] = $pars[Modules_Platforms_Ec2::PRIVATE_KEY];
         $pars[Modules_Platforms_Rds::CERTIFICATE] = $pars[Modules_Platforms_Ec2::CERTIFICATE];
         if (!count($this->checkVarError)) {
             if ($pars[Modules_Platforms_Ec2::ACCOUNT_ID] != $this->env->getPlatformConfigValue(Modules_Platforms_Ec2::ACCOUNT_ID) or $pars[Modules_Platforms_Ec2::ACCESS_KEY] != $this->env->getPlatformConfigValue(Modules_Platforms_Ec2::ACCESS_KEY) or $pars[Modules_Platforms_Ec2::SECRET_KEY] != $this->env->getPlatformConfigValue(Modules_Platforms_Ec2::SECRET_KEY) or $pars[Modules_Platforms_Ec2::PRIVATE_KEY] != $this->env->getPlatformConfigValue(Modules_Platforms_Ec2::PRIVATE_KEY) or $pars[Modules_Platforms_Ec2::CERTIFICATE] != $this->env->getPlatformConfigValue(Modules_Platforms_Ec2::CERTIFICATE)) {
                 try {
                     $AmazonEC2Client = Scalr_Service_Cloud_Aws::newEc2('us-east-1', $pars[Modules_Platforms_Ec2::PRIVATE_KEY], $pars[Modules_Platforms_Ec2::CERTIFICATE]);
                     $AmazonEC2Client->describeInstances();
                 } catch (Exception $e) {
                     throw new Exception(_("Incorrect format of X.509 certificate or private key. Make sure that you are using files downloaded from AWS profile. ({$e->getMessage()})"));
                 }
                 try {
                     $AmazonS3 = new AmazonS3($pars[Modules_Platforms_Ec2::ACCESS_KEY], $pars[Modules_Platforms_Ec2::SECRET_KEY]);
                     $buckets = $AmazonS3->ListBuckets();
                 } catch (Exception $e) {
                     throw new Exception(sprintf(_("Failed to verify your EC2 access key and secret key: %s"), $e->getMessage()));
                 }
             }
         } else {
             $this->response->failure();
             $this->response->data(array('errors' => $this->checkVarError));
             return;
         }
     }
     $this->db->BeginTrans();
     try {
         $this->env->enablePlatform(SERVER_PLATFORMS::EC2, $enabled);
         $this->env->enablePlatform(SERVER_PLATFORMS::RDS, $enabled);
         if ($enabled) {
             $this->env->setPlatformConfig($pars);
         }
         if (!$this->user->getAccount()->getSetting(Scalr_Account::SETTING_DATE_ENV_CONFIGURED)) {
             $this->user->getAccount()->setSetting(Scalr_Account::SETTING_DATE_ENV_CONFIGURED, time());
         }
         if ($this->user->getAccount()->getSetting(Scalr_Account::SETTING_IS_TRIAL) == 1) {
             if ($this->db->GetOne("SELECT COUNT(*) FROM farms WHERE clientid = ?", array($this->user->getAccountId())) == 0) {
                 //Create demo farm
                 try {
                     $dbFarm = DBFarm::LoadByID(9670);
                     // LAMP-PROTOTYPE
                     $dbFarm->cloneFarm('My First LAMP Farm');
                     $demoFarm = true;
                 } catch (Exception $e) {
                     throw new Exception("Demo farm creation failed: {$e->getMessage()}");
                 }
             }
         }
         $this->response->success('Environment saved');
         $this->response->data(array('enabled' => $enabled, 'demoFarm' => $demoFarm));
     } catch (Exception $e) {
         $this->db->RollbackTrans();
         throw new Exception(_("Failed to save AWS settings: {$e->getMessage()}"));
     }
     $this->db->CommitTrans();
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:75,代码来源:Platform.php

示例5: farmSave

 public static function farmSave(DBFarm $DBFarm, array $roles)
 {
     $buckets = array();
     foreach ($roles as $DBFarmRole) {
         if ($DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_S3_BUCKET)) {
             $buckets[$DBFarmRole->CloudLocation] = $DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_S3_BUCKET);
         }
     }
     foreach ($roles as $DBFarmRole) {
         if ($DBFarmRole->Platform != SERVER_PLATFORMS::EC2) {
             continue;
         }
         $location = $DBFarmRole->CloudLocation;
         $sshKey = Scalr_Model::init(Scalr_Model::SSH_KEY);
         if (!$sshKey->loadGlobalByFarmId($DBFarm->ID, $location)) {
             $key_name = "FARM-{$DBFarm->ID}";
             $AmazonEC2Client = Scalr_Service_Cloud_Aws::newEc2($location, $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::PRIVATE_KEY), $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::CERTIFICATE));
             $result = $AmazonEC2Client->CreateKeyPair($key_name);
             if ($result->keyMaterial) {
                 $sshKey->farmId = $DBFarm->ID;
                 $sshKey->clientId = $DBFarm->ClientID;
                 $sshKey->envId = $DBFarm->EnvID;
                 $sshKey->type = Scalr_SshKey::TYPE_GLOBAL;
                 $sshKey->cloudLocation = $location;
                 $sshKey->cloudKeyName = $key_name;
                 $sshKey->platform = SERVER_PLATFORMS::EC2;
                 $sshKey->setPrivate($result->keyMaterial);
                 $sshKey->save();
             }
         }
         try {
             if (!$DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_S3_BUCKET)) {
                 if (!$buckets[$location]) {
                     $aws_account_id = $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::ACCOUNT_ID);
                     $bucket_name = "farm-{$DBFarm->Hash}-{$aws_account_id}-{$location}";
                     //
                     // Create S3 Bucket (For MySQL, BackUs, etc.)
                     //
                     $AmazonS3 = new AmazonS3($DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::ACCESS_KEY), $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::SECRET_KEY));
                     $buckets = $AmazonS3->ListBuckets();
                     $create_bucket = true;
                     foreach ($buckets as $bucket) {
                         if ($bucket->Name == $bucket_name) {
                             $create_bucket = false;
                             $buckets[$location] = $bucket_name;
                             break;
                         }
                     }
                     if ($create_bucket) {
                         if ($AmazonS3->CreateBucket($bucket_name, $location)) {
                             $buckets[$location] = $bucket_name;
                         }
                     }
                 }
                 $DBFarmRole->SetSetting(DBFarmRole::SETTING_AWS_S3_BUCKET, $buckets[$location]);
             }
         } catch (Exception $e) {
             throw new Exception("Amazon S3: {$e->getMessage()}");
         }
     }
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:61,代码来源:Ec2.php


注:本文中的AmazonS3::ListBuckets方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。