Вход Регистрация
Файл: sngine-v2.8/Script/includes/libs/AWS/Aws/Glacier/GlacierClient.php
Строк: 285
<?php
namespace AwsGlacier;

use 
AwsApiApiProvider;
use 
AwsApiDocModel;
use 
AwsApiService;
use 
AwsAwsClient;
use 
AwsCommandInterface;
use 
AwsExceptionCouldNotCreateChecksumException;
use 
AwsHashingStream;
use 
AwsMiddleware;
use 
AwsPhpHash;
use 
PsrHttpMessageRequestInterface;

/**
 * This client is used to interact with the **Amazon Glacier** service.
 *
 * @method AwsResult abortMultipartUpload(array $args = [])
 * @method GuzzleHttpPromisePromise abortMultipartUploadAsync(array $args = [])
 * @method AwsResult abortVaultLock(array $args = [])
 * @method GuzzleHttpPromisePromise abortVaultLockAsync(array $args = [])
 * @method AwsResult addTagsToVault(array $args = [])
 * @method GuzzleHttpPromisePromise addTagsToVaultAsync(array $args = [])
 * @method AwsResult completeMultipartUpload(array $args = [])
 * @method GuzzleHttpPromisePromise completeMultipartUploadAsync(array $args = [])
 * @method AwsResult completeVaultLock(array $args = [])
 * @method GuzzleHttpPromisePromise completeVaultLockAsync(array $args = [])
 * @method AwsResult createVault(array $args = [])
 * @method GuzzleHttpPromisePromise createVaultAsync(array $args = [])
 * @method AwsResult deleteArchive(array $args = [])
 * @method GuzzleHttpPromisePromise deleteArchiveAsync(array $args = [])
 * @method AwsResult deleteVault(array $args = [])
 * @method GuzzleHttpPromisePromise deleteVaultAsync(array $args = [])
 * @method AwsResult deleteVaultAccessPolicy(array $args = [])
 * @method GuzzleHttpPromisePromise deleteVaultAccessPolicyAsync(array $args = [])
 * @method AwsResult deleteVaultNotifications(array $args = [])
 * @method GuzzleHttpPromisePromise deleteVaultNotificationsAsync(array $args = [])
 * @method AwsResult describeJob(array $args = [])
 * @method GuzzleHttpPromisePromise describeJobAsync(array $args = [])
 * @method AwsResult describeVault(array $args = [])
 * @method GuzzleHttpPromisePromise describeVaultAsync(array $args = [])
 * @method AwsResult getDataRetrievalPolicy(array $args = [])
 * @method GuzzleHttpPromisePromise getDataRetrievalPolicyAsync(array $args = [])
 * @method AwsResult getJobOutput(array $args = [])
 * @method GuzzleHttpPromisePromise getJobOutputAsync(array $args = [])
 * @method AwsResult getVaultAccessPolicy(array $args = [])
 * @method GuzzleHttpPromisePromise getVaultAccessPolicyAsync(array $args = [])
 * @method AwsResult getVaultLock(array $args = [])
 * @method GuzzleHttpPromisePromise getVaultLockAsync(array $args = [])
 * @method AwsResult getVaultNotifications(array $args = [])
 * @method GuzzleHttpPromisePromise getVaultNotificationsAsync(array $args = [])
 * @method AwsResult initiateJob(array $args = [])
 * @method GuzzleHttpPromisePromise initiateJobAsync(array $args = [])
 * @method AwsResult initiateMultipartUpload(array $args = [])
 * @method GuzzleHttpPromisePromise initiateMultipartUploadAsync(array $args = [])
 * @method AwsResult initiateVaultLock(array $args = [])
 * @method GuzzleHttpPromisePromise initiateVaultLockAsync(array $args = [])
 * @method AwsResult listJobs(array $args = [])
 * @method GuzzleHttpPromisePromise listJobsAsync(array $args = [])
 * @method AwsResult listMultipartUploads(array $args = [])
 * @method GuzzleHttpPromisePromise listMultipartUploadsAsync(array $args = [])
 * @method AwsResult listParts(array $args = [])
 * @method GuzzleHttpPromisePromise listPartsAsync(array $args = [])
 * @method AwsResult listProvisionedCapacity(array $args = [])
 * @method GuzzleHttpPromisePromise listProvisionedCapacityAsync(array $args = [])
 * @method AwsResult listTagsForVault(array $args = [])
 * @method GuzzleHttpPromisePromise listTagsForVaultAsync(array $args = [])
 * @method AwsResult listVaults(array $args = [])
 * @method GuzzleHttpPromisePromise listVaultsAsync(array $args = [])
 * @method AwsResult purchaseProvisionedCapacity(array $args = [])
 * @method GuzzleHttpPromisePromise purchaseProvisionedCapacityAsync(array $args = [])
 * @method AwsResult removeTagsFromVault(array $args = [])
 * @method GuzzleHttpPromisePromise removeTagsFromVaultAsync(array $args = [])
 * @method AwsResult setDataRetrievalPolicy(array $args = [])
 * @method GuzzleHttpPromisePromise setDataRetrievalPolicyAsync(array $args = [])
 * @method AwsResult setVaultAccessPolicy(array $args = [])
 * @method GuzzleHttpPromisePromise setVaultAccessPolicyAsync(array $args = [])
 * @method AwsResult setVaultNotifications(array $args = [])
 * @method GuzzleHttpPromisePromise setVaultNotificationsAsync(array $args = [])
 * @method AwsResult uploadArchive(array $args = [])
 * @method GuzzleHttpPromisePromise uploadArchiveAsync(array $args = [])
 * @method AwsResult uploadMultipartPart(array $args = [])
 * @method GuzzleHttpPromisePromise uploadMultipartPartAsync(array $args = [])
 */
class GlacierClient extends AwsClient
{
    public function 
__construct(array $args)
    {
        
parent::__construct($args);

        
// Setup middleware.
        
$stack $this->getHandlerList();
        
$stack->appendBuild($this->getApiVersionMiddleware(), 'glacier.api_version');
        
$stack->appendBuild($this->getChecksumsMiddleware(), 'glacier.checksum');
        
$stack->appendBuild(
            
Middleware::contentType(['UploadArchive''UploadPart']),
            
'glacier.content_type'
        
);
        
$stack->appendInit(
            
Middleware::sourceFile($this->getApi(), 'body''sourceFile'),
            
'glacier.source_file'
        
);
    }

    
/**
     * {@inheritdoc}
     *
     * Sets the default accountId to "-" for all operations.
     */
    
public function getCommand($name, array $args = [])
    {
        return 
parent::getCommand($name$args + ['accountId' => '-']);
    }

    
/**
     * Creates a middleware that updates a command with the content and tree
     * hash headers for upload operations.
     *
     * @return callable
     * @throws CouldNotCreateChecksumException if the body is not seekable.
     */
    
private function getChecksumsMiddleware()
    {
        return function (callable 
$handler) {
            return function (
                
CommandInterface $command,
                
RequestInterface $request null
            
) use ($handler) {
                
// Accept "ContentSHA256" with a lowercase "c" to match other Glacier params.
                
if (!$command['ContentSHA256'] && $command['contentSHA256']) {
                    
$command['ContentSHA256'] = $command['contentSHA256'];
                    unset(
$command['contentSHA256']);
                }

                
// If uploading, then make sure checksums are added.
                
$name $command->getName();
                if ((
$name === 'UploadArchive' || $name === 'UploadMultipartPart')
                    && (!
$command['checksum'] || !$command['ContentSHA256'])
                ) {
                    
$body $request->getBody();
                    if (!
$body->isSeekable()) {
                        throw new 
CouldNotCreateChecksumException('sha256');
                    }

                    
// Add a tree hash if not provided.
                    
if (!$command['checksum']) {
                        
$body = new HashingStream(
                            
$body, new TreeHash(),
                            function (
$result) use (&$request) {
                                
$request $request->withHeader(
                                    
'x-amz-sha256-tree-hash',
                                    
bin2hex($result)
                                );
                            }
                        );
                    }

                    
// Add a linear content hash if not provided.
                    
if (!$command['ContentSHA256']) {
                        
$body = new HashingStream(
                            
$body, new PhpHash('sha256'),
                            function (
$result) use ($command) {
                                
$command['ContentSHA256'] = bin2hex($result);
                            }
                        );
                    }

                    
// Read the stream in order to calculate the hashes.
                    
while (!$body->eof()) {
                        
$body->read(1048576);
                    }
                    
$body->seek(0);
                }

                
// Set the content hash header if a value is in the command.
                
if ($command['ContentSHA256']) {
                    
$request $request->withHeader(
                        
'x-amz-content-sha256',
                        
$command['ContentSHA256']
                    );
                }

                return 
$handler($command$request);
            };
        };
    }

    
/**
     * Creates a middleware that adds the API version header for all requests.
     *
     * @return callable
     */
    
private function getApiVersionMiddleware()
    {
        return function (callable 
$handler) {
            return function (
                
CommandInterface $command,
                
RequestInterface $request null
            
) use ($handler) {
                return 
$handler($command$request->withHeader(
                    
'x-amz-glacier-version',
                    
$this->getApi()->getMetadata('apiVersion')
                ));
            };
        };
    }

    
/**
     * @internal
     * @codeCoverageIgnore
     */
    
public static function applyDocFilters(array $api, array $docs)
    {
        
// Add the SourceFile parameter.
        
$docs['shapes']['SourceFile']['base'] = 'The path to a file on disk to use instead of the body parameter.';
        
$api['shapes']['SourceFile'] = ['type' => 'string'];
        
$api['shapes']['UploadArchiveInput']['members']['sourceFile'] = ['shape' => 'SourceFile'];
        
$api['shapes']['UploadMultipartPartInput']['members']['sourceFile'] = ['shape' => 'SourceFile'];

        
// Add the ContentSHA256 parameter.
        
$docs['shapes']['ContentSHA256']['base'] = 'A SHA256 hash of the content of the request body';
        
$api['shapes']['ContentSHA256'] = ['type' => 'string'];
        
$api['shapes']['UploadArchiveInput']['members']['contentSHA256'] = ['shape' => 'ContentSHA256'];
        
$api['shapes']['UploadMultipartPartInput']['members']['contentSHA256'] = ['shape' => 'ContentSHA256'];

        
// Add information about "checksum" and "ContentSHA256" being optional.
        
$optional '<div class="alert alert-info">The SDK will compute this value '
            
'for you on your behalf if it is not supplied.</div>';
        
$docs['shapes']['checksum']['append'] = $optional;
        
$docs['shapes']['ContentSHA256']['append'] = $optional;

        
// Make "accountId" optional for all operations.
        
foreach ($api['operations'] as $operation) {
            
$inputShape =& $api['shapes'][$operation['input']['shape']];
            
$accountIdIndex array_search('accountId'$inputShape['required']);
            unset(
$inputShape['required'][$accountIdIndex]);
        }
        
// Add information about the default value for "accountId".
        
$optional '<div class="alert alert-info">The SDK will set this value to "-" by default.</div>';
        foreach (
$docs['shapes']['string']['refs'] as $name => &$ref) {
            if (
strpos($name'accountId')) {
                
$ref .= $optional;
            }
        }

        return [
            new 
Service($apiApiProvider::defaultProvider()),
            new 
DocModel($docs)
        ];
    }
}
Онлайн: 1
Реклама