region = $region; $this->__AWS_OPTIONS['version'] = CONFIG::AWS_SDK['S3CLIENT_VERS']; $this->s3Client = new S3Client($this->__AWS_OPTIONS); $this->__AWS_OPTIONS['version'] = CONFIG::AWS_SDK['S3CONTROL_VERS']; $this->s3Control = new S3ControlClient($this->__AWS_OPTIONS); $this->__loadDrivers(); } ## Might need to loops function getResources(){ global $CONFIG; $buckets = $CONFIG->get('s3::buckets', []); # $buckets = ['ap-southeast-1' => ['kuettai-personal']]; if(empty($buckets)){ $buckets = []; $results = $this->s3Client->listBuckets(); $arr = $results->get('Buckets'); while($results->get('Maker') !== null){ $results = $this->s3Client->listBuckets([ 'Maker' => $results->get('Maker') ]); $arr = array_merge($arr, $results->get('Buckets')); } foreach($arr as $ind => $bucket){ $loc = $this->s3Client->getBucketLocation([ 'Bucket' => $bucket['Name'] ]); $reg = $loc->get('LocationConstraint'); $buckets[$reg][] = $arr[$ind]; } $CONFIG->set('s3::buckets', $buckets); } if(isset($buckets[$this->region])) $__buckets = $buckets[$this->region]; else return []; if(empty($this->tags)) return $__buckets; $filteredBuckets = []; foreach($__buckets as $bucket){ try{ $result = $this->s3Client->getBucketTagging(['Bucket' => $bucket['Name']]); $tags =$result->get('TagSet'); if($this->resourceHasTags($tags)) $filteredBuckets[] = $bucket; }catch(S3E $e){ ## Do nothing, no tags has been define;clear } } return $filteredBuckets; } function advise(){ global $GLOBALRESOURCES; $objs = []; $driver = 's3_control'; if (class_exists($driver)){ __info('... (S3Account) inspecting '); $obj = new $driver($this->s3Control); $obj->run(); $objs["Account::Bucket"] = $obj->getInfo(); $GLOBALRESOURCES = $objs; $objs = []; unset($obj); } $buckets = $this->getResources(); foreach($buckets as $bucket){ __info('... (S3Bucket) inspecting ' . $bucket['Name']); $driver = 's3_s3'; if (class_exists($driver)){ $obj = new $driver($bucket['Name'], $this->s3Client); $obj->run(); $objs[$bucket['Name']] = $obj->getInfo(); unset($obj); } } return $objs; } function __loadDrivers(){ $path = __DIR__ .'/drivers/'; $files = scandir($path); foreach($files as $file){ if ($file[0] == '.') continue; include_once($path . $file); } } }