-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathS3Provider.php
More file actions
52 lines (44 loc) · 1.67 KB
/
Copy pathS3Provider.php
File metadata and controls
52 lines (44 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace libReplay;
use libasyncio\s3\S3StorageCredentials;
use NetherGames\NGEssentials\NGEssentials;
use pocketmine\plugin\PluginBase;
use function getenv;
class S3Provider
{
private static ?S3StorageCredentials $credentials = null;
public function __construct(PluginBase $plugin)
{
$accessKey = getenv("REPLAYS_ACCESS_KEY");
$secretKey = getenv("REPLAYS_SECRET_KEY");
$region = getenv("REPLAYS_REGION");
$endpoint = getenv("REPLAYS_ENDPOINT");
$bucket = getenv("REPLAYS_BUCKET");
if (NGEssentials::isInDevelopmentMode()) {
$config = $plugin->getConfig();
if ($accessKey === false) {
$accessKey = $config->getNested("replays.access-key");
}
if ($secretKey === false) {
$secretKey = $config->getNested("replays.secret-key");
}
if ($region === false) {
$region = $config->getNested("replays.region");
}
if ($endpoint === false) {
$endpoint = $config->getNested("replays.endpoint");
}
if ($bucket === false) {
$bucket = $config->getNested("replays.bucket");
}
}
if ($accessKey !== false && $secretKey !== false && $region !== false && $endpoint !== false && $bucket !== false) {
// @phpstan-ignore-next-line
self::$credentials = new S3StorageCredentials((string)$bucket, (string)$accessKey, (string)$secretKey, (string)$region, (string)$endpoint);
}
}
public static function getStorageCredentials(): ?S3StorageCredentials
{
return self::$credentials;
}
}