Commit 132a4b88 authored by Joe Hoyle's avatar Joe Hoyle
Browse files

Support for a S3_UPLOADS_USE_INSTANCE_PROFILE constant to use the

instance profile form the ec2 machine
parent d3bd79d5
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -17,7 +17,13 @@ class S3_Uploads {
	public static function get_instance() {

		if ( ! self::$instance ) {
			self::$instance = new S3_Uploads( S3_UPLOADS_BUCKET, S3_UPLOADS_KEY, S3_UPLOADS_SECRET, defined( 'S3_UPLOADS_BUCKET_URL' ) ? S3_UPLOADS_BUCKET_URL : null, defined( 'S3_UPLOADS_REGION' ) ? S3_UPLOADS_REGION : null );

			$key    = defined( 'S3_UPLOADS_KEY' ) ? S3_UPLOADS_KEY : null;
			$secret = defined( 'S3_UPLOADS_SECRET' ) ? S3_UPLOADS_SECRET : null;
			$url    = defined( 'S3_UPLOADS_BUCKET_URL' ) ? S3_UPLOADS_BUCKET_URL : null;
			$region = defined( 'S3_UPLOADS_REGION' ) ? S3_UPLOADS_REGION : null;

			self::$instance = new S3_Uploads( S3_UPLOADS_BUCKET, $key, $secret, $url, $region );
		}

		return self::$instance;
@@ -100,7 +106,12 @@ class S3_Uploads {
		if ( ! empty( $this->s3 ) )
			return $this->s3;

		$params = array( 'key' => $this->key, 'secret' => $this->secret );
		$params = array();

		if ( $this->key && $this->secret ) {
			$params['key'] = $this->key;
			$params['secret'] = $this->secret;
		}

		if ( $this->region ) {
			$params['signature'] = 'v4';
+5 −1
Original line number Diff line number Diff line
@@ -17,7 +17,11 @@ if ( defined( 'WP_CLI' ) && WP_CLI ) {
add_action( 'plugins_loaded', 's3_uploads_init' );

function s3_uploads_init() {
	if ( ! defined( 'S3_UPLOADS_BUCKET' ) || ! defined( 'S3_UPLOADS_KEY' ) || ! defined( 'S3_UPLOADS_SECRET' ) ) {
	if ( ! defined( 'S3_UPLOADS_BUCKET' ) ) {
		return;
	}

	if ( ( ! defined( 'S3_UPLOADS_KEY' ) || ! defined( 'S3_UPLOADS_SECRET' ) ) || ! defined( 'S3_UPLOADS_USE_INSTANCE_PROFILE' ) ) {
		return;
	}