当前位置: 首页>>代码示例>>PHP>>正文


PHP Scalr_Account_User::getEnvironments方法代码示例

本文整理汇总了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");
     }
 }
开发者ID:rickb838,项目名称:scalr,代码行数:49,代码来源:class.ScalrAPICore.php


注:本文中的Scalr_Account_User::getEnvironments方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。