Skip to content

Commit

Permalink
MDL-51710 repository_s3: Use proxy settings when communicating with S3
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Massart committed Jan 8, 2016
1 parent afbb53d commit 2a5920c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions repository/s3/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class repository_s3 extends repository {
* @param array $options
*/
public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array()) {
global $CFG;
parent::__construct($repositoryid, $context, $options);
$this->access_key = get_config('s3', 'access_key');
$this->secret_key = get_config('s3', 'secret_key');
Expand All @@ -52,6 +53,26 @@ public function __construct($repositoryid, $context = SYSCONTEXTID, $options = a
}
$this->s = new S3($this->access_key, $this->secret_key, false, $this->endpoint);
$this->s->setExceptions(true);

// Port of curl::__construct().
if (!empty($CFG->proxyhost)) {
if (empty($CFG->proxyport)) {
$proxyhost = $CFG->proxyhost;
} else {
$proxyhost = $CFG->proxyhost . ':' . $CFG->proxyport;
}
$proxytype = CURLPROXY_HTTP;
$proxyuser = null;
$proxypass = null;
if (!empty($CFG->proxyuser) and !empty($CFG->proxypassword)) {
$proxyuser = $CFG->proxyuser;
$proxypass = $CFG->proxypassword;
}
if (!empty($CFG->proxytype) && $CFG->proxytype == 'SOCKS5') {
$proxytype = CURLPROXY_SOCKS5;
}
$this->s->setProxy($proxyhost, $proxyuser, $proxypass, $proxytype);
}
}

/**
Expand Down

0 comments on commit 2a5920c

Please sign in to comment.