-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscalr.class.php
90 lines (78 loc) · 2.15 KB
/
scalr.class.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
<?php
require('xml2array.class.php');
class ScalrClient
{
private $valid_api_methods=array(
'ApacheVhostCreate',
'ApacheVhostsList',
'BundleTaskGetStatus',
'DmApplicationDeploy',
'DmApplicationsList',
'DmSourcesList',
'DNSZoneCreate',
'DNSZoneRecordAdd',
'DNSZoneRecordRemove',
'DNSZoneRecordsList',
'DNSZonesList',
'EventsList',
'FarmGetDetails',
'FarmGetStats',
'FarmsList',
'FarmTerminate',
'FarmLaunch',
'LogsList',
'RolesList',
'ScriptExecute',
'ScriptGetDetails',
'ScriptsList',
'ServerImageCreate',
'ServerLaunch',
'ServerReboot',
'ServerTerminate',
'StatisticsGetGraphURL');
private $api_key = '';
private $secret_key = '';
private $url = '';
private $api_version = '';
function __construct($api_key, $secret_key, $url='https://api.scalr.net/', $api_version='2.3.0')
{
$this->api_key = $api_key;
$this->secret_key = $secret_key;
$this->url = $url;
$this->api_version = $api_version;
}
function __call($name, $arguments=null)
{
if (in_array($name, $this->valid_api_methods))
{
return $this->call($name, $arguments);
}
}
function call($action, $more_params=null)
{
// Build query arguments list
$params = array(
'Action' => $action,
'KeyID' => $this->api_key,
'Version' => $this->api_version,
'Timestamp' => date("c")
);
if ($more_params && is_array($more_params)) {
$params = array_merge($params, $more_params);
}
// Sort arguments
ksort($params);
// Generate string for sign
$string_to_sign = "";
foreach ($params as $k => $v)
$string_to_sign .= "{$k}{$v}";
// Generate signature
$params['Signature'] = base64_encode(hash_hmac('SHA256', $string_to_sign, $this->secret_key, 1));
// Build query
$query = http_build_query($params);
// Execute query
$reply = file_get_contents($this->url."?{$query}");
return ArrayToXML::toArray($reply);
}
}
?>