/** * Put logs to SLS. * Unsuccessful opertaion will cause an Aliyun_Sls_Exception. * * @param Aliyun_Sls_Models_PutLogsRequest $request the PutLogs request parameters class * @throws Aliyun_Sls_Exception * @return Aliyun_Sls_Models_PutLogsResponse */ public function putLogs(Aliyun_Sls_Models_PutLogsRequest $request) { if (count($request->getLogitems()) > 4096) { throw new Aliyun_Sls_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_Sls_Util::toBytes($logGroup); unset($logGroup); $bodySize = strlen($body); if ($bodySize > 3 * 1024 * 1024) { // 3 MB throw new Aliyun_Sls_Exception('InvalidLogSize', "logItems' size exceeds maximum limitation: 3 MB."); } $params = array(); $headers = array(); $headers["x-sls-bodyrawsize"] = $bodySize; $headers['x-sls-compresstype'] = 'deflate'; $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); return new Aliyun_Sls_Models_PutLogsResponse($header); }
/** * Get request authorization string as defined. * * @return string */ public static function getRequestAuthorization($method, $resource, $key, $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_Sls_Util::canonicalizedSLSHeaders($headers) . "\n"; $content .= Aliyun_Sls_Util::canonicalizedResource($resource, $params); return Aliyun_Sls_Util::hmacSHA1($content, $key); }