本文整理汇总了PHP中Scalr_Account_User::getEnvironments方法的典型用法代码示例。如果您正苦于以下问题:PHP Scalr_Account_User::getEnvironments方法的具体用法?PHP Scalr_Account_User::getEnvironments怎么用?PHP Scalr_Account_User::getEnvironments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scalr_Account_User
的用法示例。
在下文中一共展示了Scalr_Account_User::getEnvironments方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: AuthenticateREST
private function AuthenticateREST($request)
{
if (!$request['Signature']) {
throw new Exception("Signature is missing");
}
if (!$request['KeyID']) {
throw new Exception("KeyID is missing");
}
if (!$request['Timestamp'] && !$request['TimeStamp']) {
throw new Exception("Timestamp is missing");
}
ksort($request);
$string_to_sign = "";
foreach ($request as $k => $v) {
if (!in_array($k, array("Signature"))) {
if (is_array($v)) {
foreach ($v as $kk => $vv) {
$string_to_sign .= "{$k}[{$kk}]{$vv}";
}
} else {
$string_to_sign .= "{$k}{$v}";
}
}
}
$this->debug['stringToSign'] = $string_to_sign;
$this->user = Scalr_Account_User::init()->loadByApiAccessKey($request['KeyID']);
if (!$this->user) {
throw new Exception("API Key #{$request['KeyID']} not found in database");
}
$auth_key = $this->user->getSetting(Scalr_Account_User::SETTING_API_SECRET_KEY);
if ($this->user->getAccountId()) {
if (!$request['EnvID']) {
$envs = $this->user->getEnvironments();
if (!$envs[0]['id']) {
throw new Exception("User has no access to any environemnts");
}
$this->Environment = Scalr_Environment::init()->loadById($envs[0]['id']);
} else {
$this->Environment = Scalr_Environment::init()->loadById($request['EnvID']);
}
$this->user->getPermissions()->setEnvironmentId($this->Environment->id)->validate($this->Environment);
//We must set environment to DI Container.
$this->getContainer()->environment = $this->Environment;
}
$valid_sign = base64_encode(hash_hmac(self::HASH_ALGO, trim($string_to_sign), $auth_key, 1));
if ($valid_sign != $request['Signature']) {
throw new Exception("Signature doesn't match");
}
}