Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
namespace core\aws;
18
use Aws\AwsClient;
19
 
20
/**
21
 * AWS Client factory. Retrieves a client with moodle specific HTTP configuration.
22
 *
23
 * @copyright  2022 Catalyst IT
24
 * @author     Peter Burnett <peterburnett@catalyst-au.net>
25
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
1441 ariadna 26
 * @deprecated Since Moodle 4.5
27
 * @todo       MDL-82459 Final deprecation in Moodle 5.0.
1 efrain 28
 */
29
class client_factory {
30
    /**
31
     * Get an AWS client with moodle specific HTTP configuration.
32
     *
33
     * @param string $class Fully qualified AWS classname e.g. \Aws\S3\S3Client
34
     * @param array $opts array of constructor options for AWS Client.
35
     * @return AwsClient
1441 ariadna 36
     * @deprecated Since Moodle 4.5
1 efrain 37
     */
1441 ariadna 38
    #[\core\attribute\deprecated(
39
        'client_factory::get_client()',
40
        since: '4.5',
41
        mdl: 'MDL-80962',
42
    )]
1 efrain 43
    public static function get_client(string $class, array $opts): AwsClient {
1441 ariadna 44
        \core\deprecation::emit_deprecation(__FUNCTION__);
1 efrain 45
        // Modify the opts to add HTTP timeouts.
46
        if (empty($opts['http'])) {
47
            $opts['http'] = ['connect_timeout' => HOURSECS];
48
        } else if (!array_key_exists('connect_timeout', $opts['http'])) {
49
            // Try not to override existing settings.
50
            $opts['http']['connect_timeout'] = HOURSECS;
51
        }
52
 
53
        // Blindly trust the call here. If it exceptions, the raw message is the most useful.
54
        $client = new $class($opts);
55
        if (!$client instanceof \Aws\AwsClient) {
56
            throw new \moodle_exception('clientnotfound', 'factor_sms');
57
        }
58
 
59
        // Now we can configure the proxy with the routing aware middleware.
60
        return aws_helper::configure_client_proxy($client);
61
    }
62
}