예제 #1
0
파일: Client.php 프로젝트: nixuehan/koala
 /**
  * Put logs to Log Service.
  * Unsuccessful opertaion will cause an Aliyun_Log_Exception.
  *
  * @param Aliyun_Log_Models_PutLogsRequest $request the PutLogs request parameters class
  * @throws Aliyun_Log_Exception
  * @return Aliyun_Log_Models_PutLogsResponse
  */
 public function putLogs(Aliyun_Log_Models_PutLogsRequest $request)
 {
     if (count($request->getLogitems()) > 4096) {
         throw new Aliyun_Log_Exception('InvalidLogSize', "logItems' length exceeds maximum limitation: 4096 lines.");
     }
     $logGroup = new LogGroup();
     $topic = $request->getTopic() !== null ? $request->getTopic() : '';
     $logGroup->setTopic($request->getTopic());
     $source = $request->getSource();
     if (!$source) {
         $source = $this->source;
     }
     $logGroup->setSource($source);
     $logitems = $request->getLogitems();
     foreach ($logitems as $logItem) {
         $log = new Log();
         $log->setTime($logItem->getTime());
         $content = $logItem->getContents();
         foreach ($content as $key => $value) {
             $content = new Log_Content();
             $content->setKey($key);
             $content->setValue($value);
             $log->addContents($content);
         }
         $logGroup->addLogs($log);
     }
     $body = Aliyun_Log_Util::toBytes($logGroup);
     unset($logGroup);
     $bodySize = strlen($body);
     if ($bodySize > 3 * 1024 * 1024) {
         // 3 MB
         throw new Aliyun_Log_Exception('InvalidLogSize', "logItems' size exceeds maximum limitation: 3 MB.");
     }
     $params = array();
     $headers = array();
     $headers["x-log-bodyrawsize"] = $bodySize;
     $headers['x-log-compresstype'] = 'deflate';
     $headers['Content-Type'] = 'application/x-protobuf';
     $body = gzcompress($body, 6);
     $logstore = $request->getLogstore() !== null ? $request->getLogstore() : '';
     $project = $request->getProject() !== null ? $request->getProject() : '';
     $resource = "/logstores/" . $logstore;
     list($resp, $header) = $this->send("POST", $project, $body, $resource, $params, $headers);
     $requestId = isset($header['x-log-requestid']) ? $header['x-log-requestid'] : '';
     $resp = $this->parseToJson($resp, $requestId);
     return new Aliyun_Log_Models_PutLogsResponse($header);
 }
예제 #2
0
파일: Util.php 프로젝트: nixuehan/koala
 /**
  * Get request authorization string as defined.
  *
  * @return string
  */
 public static function getRequestAuthorization($method, $resource, $key, $stsToken, $params, $headers)
 {
     if (!$key) {
         return '';
     }
     $content = $method . "\n";
     if (isset($headers['Content-MD5'])) {
         $content .= $headers['Content-MD5'];
     }
     $content .= "\n";
     if (isset($headers['Content-Type'])) {
         $content .= $headers['Content-Type'];
     }
     $content .= "\n";
     $content .= $headers['Date'] . "\n";
     $content .= Aliyun_Log_Util::canonicalizedLOGHeaders($headers) . "\n";
     $content .= Aliyun_Log_Util::canonicalizedResource($resource, $params);
     return Aliyun_Log_Util::hmacSHA1($content, $key);
 }