Skip to content

Commit

Permalink
Merge pull request #685 from formapro-forks/aws-sdk-v3
Browse files Browse the repository at this point in the history
Aws sdk v3
  • Loading branch information
makasim committed Dec 27, 2015
2 parents 0a1782d + b2a21b2 commit b6302c0
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 2 deletions.
5 changes: 3 additions & 2 deletions DependencyInjection/Factory/Resolver/AwsS3ResolverFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ public function addConfiguration(ArrayNodeDefinition $builder)
->scalarNode('cache_prefix')->defaultValue(null)->end()
->arrayNode('client_config')
->isRequired()
->useAttributeAsKey('key')
->prototype('scalar')->end()
->prototype('variable')
->treatNullLike(array())
->end()
->end()
/* @deprecated Use `get_options` instead */
->arrayNode('url_options')
Expand Down
26 changes: 26 additions & 0 deletions Resources/doc/cache-resolver/aws_s3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ Create resolver using factory
put_options:
CacheControl: 'max-age=86400'
If you use `aws-sdk-php`_ library version >= 3.0.0 client config credentials
must be an associative array containing key and secret.

.. code-block:: yaml
aws_s3:
client_config:
credentials:
key: %amazon.s3.key%
secret: %amazon.s3.secret%
region: %amazon.s3.region%
Create resolver as a service
----------------------------

Expand All @@ -68,6 +80,20 @@ You have to set up the services required:
tags:
- { name: 'liip_imagine.cache.resolver', resolver: 'profile_photos' }
If you use `aws-sdk-php`_ library version >= 3.0.0 client config credentials
must be an associative array containing key and secret.

.. code-block:: yaml
acme.amazon_s3:
class: Aws\S3\S3Client
factory_class: Aws\S3\S3Client
factory_method: factory
arguments:
-
credentials: { key: %amazon.s3.key%, secret: %amazon.s3.secret% }
region: %amazon.s3.region%
Usage
-----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,73 @@ public function testAddDefaultOptionsIfNotSetOnAddConfiguration()
$this->assertNull($config['cache_prefix']);
}

public function testSupportAwsV3ClientConfig()
{
$expectedClientConfig = array(
'credentials' => array(
'key' => 'theKey',
'secret' => 'theSecret',
'token' => 'theToken',
),
'region' => 'theRegion',
'version' => 'theVersion',
);
$expectedUrlOptions = array(
'theKey' => 'theUrlOptionsVal',
'theOtherKey' => 'theOtherUrlOptionsValue',
);
$expectedGetOptions = array(
'theKey' => 'theGetOptionsVal',
'theOtherKey' => 'theOtherGetOptionsValue',
);
$expectedObjectOptions = array(
'theKey' => 'theObjectOptionsVal',
'theOtherKey' => 'theOtherObjectOptionsValue',
);
$expectedBucket = 'theBucket';
$expectedAcl = 'theAcl';
$expectedCachePrefix = 'theCachePrefix';

$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('aws_s3', 'array');

$resolver = new AwsS3ResolverFactory();
$resolver->addConfiguration($rootNode);

$config = $this->processConfigTree($treeBuilder, array(
'aws_s3' => array(
'bucket' => $expectedBucket,
'acl' => $expectedAcl,
'client_config' => $expectedClientConfig,
'url_options' => $expectedUrlOptions,
'get_options' => $expectedGetOptions,
'put_options' => $expectedObjectOptions,
'cache_prefix' => $expectedCachePrefix,
),
));

$this->assertArrayHasKey('bucket', $config);
$this->assertEquals($expectedBucket, $config['bucket']);

$this->assertArrayHasKey('acl', $config);
$this->assertEquals($expectedAcl, $config['acl']);

$this->assertArrayHasKey('client_config', $config);
$this->assertEquals($expectedClientConfig, $config['client_config']);

$this->assertArrayHasKey('url_options', $config);
$this->assertEquals($expectedUrlOptions, $config['url_options']);

$this->assertArrayHasKey('get_options', $config);
$this->assertEquals($expectedGetOptions, $config['get_options']);

$this->assertArrayHasKey('put_options', $config);
$this->assertEquals($expectedObjectOptions, $config['put_options']);

$this->assertArrayHasKey('cache_prefix', $config);
$this->assertEquals($expectedCachePrefix, $config['cache_prefix']);
}

/**
* @param TreeBuilder $treeBuilder
* @param array $configs
Expand Down

0 comments on commit b6302c0

Please sign in to comment.