-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.php
104 lines (89 loc) · 2.79 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!DOCTYPE html>
<html>
<!-- Read from bound VCAP_CREDENTIALS -->
<?php
// use BlueMix VCAP_SERVICES environment
if ($services = getenv("VCAP_SERVICES")) {
$services_json = json_decode($services, true);
$authUrl = $services_json["Object-Storage"][0]["credentials"]["auth_url"] . "/v3";
$region = $services_json["Object-Storage"][0]["credentials"]["region"];
$userId = $services_json["Object-Storage"][0]["credentials"]["userId"];
$password = $services_json["Object-Storage"][0]["credentials"]["password"];
$projectId = $services_json["Object-Storage"][0]["credentials"]["projectId"];
} else {
throw new Exception('Not in Bluemix environment');
}
?>
<!-- Get Keystone Token -->
<?php
require 'vendor/autoload.php';
$openstack = new OpenStack\OpenStack([
'authUrl' => $authUrl,
'region' => $region,
'user' => [
'id' => $userId,
'password' => $password
],
'scope' => [
'project' => ['id' => $projectId]
]
]);
$identity = $openstack->identityV3();
$token = $identity->generateToken([
'user' => [
'id' => $userId,
'password' => $password
]
]);
$tokenId = $token->getId();
?>
<!-- Create a container and upload a file -->
<?php
$containerName = 'MyNewContainer';
$objectName = 'MyFile.txt';
$objectContent = 'MyFile.txt';
$service = $openstack->objectStoreV1();
$container = $service->createContainer([
'name' => $containerName
]);
//Upload file
$options = [
'name' => $objectName,
'content' => $objectContent,
];
$object = $openstack->objectStoreV1()
->getContainer($containerName)
->createObject($options);
?>
<!-- Display Information -->
<head>
<title>PHP & Object Storage</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="style.css" />
</head>
<body>
<table>
<tr>
<td style='width: 30%;'><img class = 'newappIcon' src='images/objectStoreIcon50.png'>
</td>
<td>
<h1 id = "message">PHP application using bound Object Storage Instance...</h1>
<h3>Reading in VCAP Credentials from bound Object Storage Instance...</h2>
<p class='description'><?php echo "Credentials from bound Object Storage: "; ?></p>
<ul>
<li><?php echo "Auth URL: " . $authUrl; ?></li>
<li><?php echo "Region: " . $region; ?></li>
<li><?php echo "User Id: " . $userId; ?></li>
<li><?php echo "Password: " . $password; ?></li>
<li><?php echo "Project Id: " . $projectId; ?></li>
</ul>
<h3>Getting Keystone Token...</h3>
<p><?php echo "My Keystone token: " . $tokenId; ?></p>
<h3>Creating 'MyNewContainer' and uploading "MyFile.txt"...</h3>
<p>Check the bound instance of Object Storage to view these two items in the file browser.</p>
</td>
</table>
<br />
<br />
</body>
</html>