Problem/Motivation

Thanks for your simple but powerfull integration of aws s3 client. This module could provide a way to fully customize client's options to use this module with other providers than AWS.

We need to be able to change the endpoint, maybe the version :

/**
 * @see https://stackoverflow.com/a/71709116/9266823
 */ 
$client = new Aws\S3\S3Client([
    'version' => 'latest',
    'region' => 'bucketregion', //eg. 'fr-par'
    'credentials' => [
        'key'    => 'your access key',
        'secret' => 'your secret key',
    ],
    'endpoint' => 'http://mybucket.s3.fr-par.scw.cloud',
    'bucket_endpoint' => true
]);

Steps to reproduce

Try to use the module to access a bucket on another provider than AWS.

Proposed resolution

We can imagine having a new "endpoint" variable, but I think a fully customisable option array would be an overall solution that can cover all needs (If we need to touch the version for example).

Issue fork s3client-3543332

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

colin.eininger created an issue. See original summary.

colin.eininger changed the visibility of the branch 3543332-add-the-possibility to hidden.

colin.eininger changed the visibility of the branch 3543332-add-the-possibility to active.

colin.eininger’s picture

Issue summary: View changes
Status: Active » Needs review
colin.eininger’s picture

Title: Add the possibility to fully customize client otpions » Add the possibility to fully customize client options

fix typo in title

larowlan’s picture

Status: Needs review » Reviewed & tested by the community

Seems reasonable to me.
Can you provide a snippet of docs for the additional settings that I can add to the project page on merge?

colin.eininger’s picture

Thanks for reviewing the MR.

Here are the snippets to update the project page.

Configuration

$settings['s3client.default_key'] = 'YOUR KEY HERE';
$settings['s3client.default_secret'] = 'YOUR SECRET HERE';
$settings['s3client.default_region'] = 'us-east-1'; // Or your preferred region.
$settings['s3client.default_endpoint'] = 'https://s3.example.com'; // Not required with AWS endpoint.
$settings['s3client.default_bucket_endpoint'] = TRUE; // If your endpoint is directly pointing to your bucket, you want to set this to TRUE. It has no effect if s3client.default_endpoint is undefined, default: FALSE.
$settings['s3client.default_version'] = 'latest'; // Default: 2006-03-01.

Injecting the factory

// $endpoint, $bucketEndpoint and $version are optionnals.
$client = $factory->createClient($key, $secret, $region, $endpoint, $bucketEndpoint, $version);

larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, I'll cut a 1.2.0 release and add the above to the docs page

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

larowlan’s picture

  • larowlan committed 30731978 on 1.x
    [#3543332] feat: Add the possibility to fully customize client options...
colin.eininger’s picture

Status: Fixed » Closed (fixed)

Thanks for your quick actions

acbramley’s picture

FYI this change means sites without a key or secret set (e.g for local or CI environments) you'll get a PHP fatal error

TypeError: Drupal\s3client\S3ClientFactory::createClient(): Argument #2 ($secret) or TypeError: Drupal\s3client\S3ClientFactory::createClient(): Argument #1 ($key)

colin.eininger’s picture

Sorry, I did not realised it was a use case. Adding nullable declaration to the $key and $secret types of createClient should do the trick. Before my modifications, Credentials could be instanciated with null values. Another solution is to add an empty string as default settings for s3client.default_key and s3client.default_secret.

Maybe in case of no key and/or secret given we can skip the credentials option ?