コード例 #1
0
ファイル: Request.php プロジェクト: 4aficiona2/cli
 /**
  * Make a request to the Pantheon API
  *
  * @param [string] $realm   Permissions realm for data request (e.g. user,
  *   site organization, etc. Can also be "public" to simply pull read-only
  *   data that is not privileged.
  * @param [string] $uuid    The UUID of the item in the realm to access
  * @param [string] $path    API path (URL)
  * @param [string] $method  HTTP method to use
  * @param [mixed]  $options A native PHP data structure (e.g. int, string,
  *   array, or stdClass) to be sent along with the request
  * @return [array] $data
  */
 public function request($realm, $uuid, $path = false, $method = 'GET', $options = array())
 {
     $logger = Terminus::getLogger();
     try {
         $url = Endpoint::get(array('realm' => $realm, 'uuid' => $uuid, 'path' => $path));
         $logger->debug('Request URL: ' . $url);
         $response = $this->send($url, $method, $options);
         $data = array('data' => json_decode($response->getBody()->getContents()), 'headers' => $response->getHeaders(), 'status_code' => $response->getStatusCode());
         return $data;
     } catch (GuzzleHttp\Exception\BadResponseException $e) {
         $response = $e->getResponse();
         throw new TerminusException($response->getBody(true));
     } catch (GuzzleHttp\Exception\HttpException $e) {
         $request = $e->getRequest();
         $sanitized_request = Utils\stripSensitiveData((string) $request, $this->blacklist);
         throw new TerminusException('API Request Error. {msg} - Request: {req}', array('req' => $sanitized_request, 'msg' => $e->getMessage()));
     } catch (Exception $e) {
         throw new TerminusException('API Request Error: {msg}', array('msg' => $e->getMessage()));
     }
 }
コード例 #2
0
ファイル: test-utils.php プロジェクト: RazzYoshi/cli
 public function testStripSensitiveData()
 {
     $data = ['password' => 'password', 'key' => 'value', 'more' => ['password' => 'otherpassword']];
     $stripped_data = Utils\stripSensitiveData($data, ['password']);
     $this->assertTrue($stripped_data['password'] == '*****');
     $this->assertTrue($stripped_data['key'] == 'value');
     $this->assertTrue($stripped_data['more']['password'] == '*****');
 }