Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to supply configuration using _ss_environment file #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ Injector:
signature_version: 'v4'
```

An alternative way of providing credentials is to add those to the _ss_environment.php file, as shown below;
If you use this method, then you don't need to supply the credentials in the YML configuation.

```
define('SS_AWS_KEY', '<key>');
define('SS_AWS_SECRET', '<secret>');
```

If your SES account is configured with a single 'from' address having being
verified, you can set an 'always from' email address which will always be the
Expand Down
12 changes: 12 additions & 0 deletions code/mail/SESMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ class SESMailer extends \Mailer {
public $alwaysFrom;

public function __construct($config) {
if (!empty($config) && !isset($config['credentials'])) {
// try to load the credentials from the Silverstripe configuration file
if (!defined('SS_AWS_KEY') || !defined('SS_AWS_SECRET')) {
throw new Exception("Undefined SS_AWS_KEY or SS_AWS_SECRET, unable to construct the AWS mailer");
}

$config['credentials'] = array(
'key' => defined('SS_AWS_KEY') ? SS_AWS_KEY : '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The defined check for these isn't needed if you're already checking the defined above and throwing an exception. Other than that, this looks good to merge!

'secret' => defined('SS_AWS_SECRET') ? SS_AWS_SECRET : '',
);
}

$this->client = SesClient::factory($config);
parent::__construct();
}
Expand Down