1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace keika299\ConohaAPI; |
4
|
|
|
|
5
|
|
|
use keika299\ConohaAPI; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Conoha |
9
|
|
|
* |
10
|
|
|
* Create this object to use ConoHa API. |
11
|
|
|
* This class require your ConoHa API account to connect to API. |
12
|
|
|
* |
13
|
|
|
* @package keika299\ConohaAPI |
14
|
|
|
*/ |
15
|
|
|
class Conoha |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var array |
19
|
|
|
*/ |
20
|
|
|
private $data; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Conoha constructor. |
24
|
|
|
* |
25
|
|
|
* $data is your ConoHa API account information. |
26
|
|
|
* |
27
|
|
|
* For example, |
28
|
|
|
* $data = array( |
29
|
|
|
* 'username' => Your API Username, |
30
|
|
|
* 'password' => Your API Password, |
31
|
|
|
* 'tenantId' => Your API TenantID, |
32
|
|
|
* 'token' => Your API Token, |
33
|
|
|
* 'cookies' => [ |
34
|
|
|
* 'isStoreTokenCookie' => true or false, |
35
|
|
|
* 'storeTokenCookieName' => Cookie Name |
36
|
|
|
* ] |
37
|
|
|
* ); |
38
|
|
|
* |
39
|
|
|
* If it not contain 'token', this class create and set token automatically. |
40
|
|
|
* If it not contain 'username' or 'password' (or both data), You can connect API, |
41
|
|
|
* but this class cannot refresh token. |
42
|
|
|
* |
43
|
|
|
* @param array $data |
44
|
|
|
*/ |
45
|
55 |
|
public function __construct($data = array()) |
46
|
|
|
{ |
47
|
55 |
|
$this->data = $data; |
48
|
55 |
|
if(!isset($data['cookies'])) { |
49
|
55 |
|
$this->data['cookies'] = array(); |
50
|
55 |
|
} |
51
|
|
|
|
52
|
55 |
|
$token = new ConohaAPI\Common\DataStore\Token($this); |
53
|
55 |
|
$token->initToken(); |
54
|
55 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get username |
58
|
|
|
* |
59
|
|
|
* @return string|null |
60
|
|
|
*/ |
61
|
5 |
|
public function getUsername() |
62
|
|
|
{ |
63
|
5 |
|
return $this->data['username']; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Get user password |
68
|
|
|
* |
69
|
|
|
* @return string|null |
70
|
|
|
*/ |
71
|
5 |
|
public function getUserPassword() |
72
|
|
|
{ |
73
|
5 |
|
return $this->data['password']; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get tenant id |
78
|
|
|
* |
79
|
|
|
* @return string|null |
80
|
|
|
*/ |
81
|
17 |
|
public function getTenantId() |
82
|
|
|
{ |
83
|
17 |
|
return $this->data['tenantId']; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Get token. |
88
|
|
|
* |
89
|
|
|
* @return string|null |
90
|
|
|
*/ |
91
|
55 |
|
public function getToken() |
92
|
|
|
{ |
93
|
55 |
|
if (isset($this->data['token'])) { |
94
|
55 |
|
return $this->data['token']; |
95
|
|
|
} |
96
|
|
|
|
97
|
1 |
|
return null; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Set token. |
102
|
|
|
* |
103
|
|
|
* @param string $token |
104
|
|
|
*/ |
105
|
55 |
|
public function setToken($token) |
106
|
|
|
{ |
107
|
55 |
|
$this->data['token'] = $token; |
108
|
55 |
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Get cookies data. |
112
|
|
|
* |
113
|
|
|
* @return array |
114
|
|
|
*/ |
115
|
55 |
|
public function getCookiesData() |
116
|
|
|
{ |
117
|
55 |
|
return $this->data['cookies']; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Get account service object. |
122
|
|
|
* |
123
|
|
|
* @return Account\Service |
124
|
|
|
*/ |
125
|
15 |
|
public function accountService() |
126
|
|
|
{ |
127
|
15 |
|
return new ConohaAPI\Account\Service($this, 'https://account.tyo1.conoha.io'); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Get block storage service object. |
132
|
|
|
* |
133
|
|
|
* @return BlockStorage\Service |
134
|
|
|
*/ |
135
|
1 |
|
public function blockStorageService() |
136
|
|
|
{ |
137
|
1 |
|
return new ConohaAPI\BlockStorage\Service($this, 'https://block-storage.tyo1.conoha.io'); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Get compute service object. |
142
|
|
|
* |
143
|
|
|
* @return Compute\Service |
144
|
|
|
*/ |
145
|
1 |
|
public function computeService() |
146
|
|
|
{ |
147
|
1 |
|
return new ConohaAPI\Compute\Service($this, 'https://compute.tyo1.conoha.io'); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Get database service object. |
153
|
|
|
* |
154
|
|
|
* @return Database\Service |
155
|
|
|
*/ |
156
|
1 |
|
public function databaseService() |
157
|
|
|
{ |
158
|
1 |
|
return new ConohaAPI\Database\Service($this, 'https://database-hosting.tyo1.conoha.io'); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Get DNS service object. |
163
|
|
|
* |
164
|
|
|
* @return DNS\Service |
165
|
|
|
*/ |
166
|
15 |
|
public function dnsService() |
167
|
|
|
{ |
168
|
15 |
|
return new ConohaAPI\DNS\Service($this, 'https://dns-service.tyo1.conoha.io'); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Get identity service object. |
174
|
|
|
* |
175
|
|
|
* @return Identity\Service |
176
|
|
|
*/ |
177
|
7 |
|
public function identityService() |
178
|
|
|
{ |
179
|
7 |
|
return new ConohaAPI\Identity\Service($this, 'https://identity.tyo1.conoha.io'); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* Get image service object. |
184
|
|
|
* |
185
|
|
|
* @return Image\Service |
186
|
|
|
*/ |
187
|
1 |
|
public function imageService() |
188
|
|
|
{ |
189
|
1 |
|
return new ConohaAPI\Image\Service($this, 'https://image-service.tyo1.conoha.io'); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* Get mail service object. |
194
|
|
|
* |
195
|
|
|
* @return Mail\Service |
196
|
|
|
*/ |
197
|
1 |
|
public function mailService() |
198
|
|
|
{ |
199
|
1 |
|
return new ConohaAPI\Mail\Service($this, 'https://mail-hosting.tyo1.conoha.io'); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Get network service object. |
204
|
|
|
* |
205
|
|
|
* @return Network\Service |
206
|
|
|
*/ |
207
|
1 |
|
public function networkService() |
208
|
|
|
{ |
209
|
1 |
|
return new ConohaAPI\Network\Service($this, 'https://networking.tyo1.conoha.io'); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* Get object storage service object. |
214
|
|
|
* |
215
|
|
|
* @return ObjectStorage\Service |
216
|
|
|
*/ |
217
|
1 |
|
public function objectStorageService() |
218
|
|
|
{ |
219
|
1 |
|
return new ConohaAPI\ObjectStorage\Service($this, 'https://object-storage.tyo1.conoha.io'); |
220
|
|
|
} |
221
|
|
|
} |
222
|
|
|
|