-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
56 lines (52 loc) · 1.71 KB
/
index.php
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
53
54
55
56
<?php
require 'vendor/autoload.php';
header('Content-Type: application/json');
$result = [
'welcome' => 'This is a POC that returns the ACL data of an AWS S3',
'instructions' => 'Just do a GET request with the required query params',
'params' => [
'cred_key' => [
'type' => 'string',
'required' => true
],
'cred_secret' => [
'type' => 'string',
'required' => true
],
'bucket' => [
'type' => 'string',
'required' => true
],
],
'errorTypes' =>[
'InvalidAccessKeyId' => 'Invalid key',
'SignatureDoesNotMatch' => 'Invalid signature',
'NoSuchBucket' => 'Credentials OK but the bucket does not exist'
]
];
if ( $_GET['cred_key'] && $_GET['cred_secret'] && $_GET['bucket']) {
$s3 = new Aws\S3\S3Client([
'version' => 'latest',
'region' => 'us-east-1',
'credentials' => [
'key' => $_GET['cred_key'],
'secret' => $_GET['cred_secret']
]
]);
try{
$bucket = $s3->getBucketAcl([
'Bucket' => $_GET['bucket']
]);
$result = $bucket->toArray();
}
catch(AWS\S3\Exception\S3Exception $exception){
http_response_code($exception->getStatusCode());
$result = [
'error' => $exception->getAwsErrorCode(),
'type' => $exception->getAwsErrorType(),
'message' => $exception->getMessage()
];
}
}
echo json_encode($result);
?>