/** * Generate BCE Authorization Signature * * @param string $method HTTP Request Method. * @param string $resource The resource path. * @param array $params The query strings. * @param array $headers The extra http request headers. * @param number $timestamp The customized timestamp, if it's 0, the will use time() instead. * @param number $expiration_in_seconds The valid time in seconds. * @param array $headers_to_sign The extra http request headers will be included in the signature * * @return string */ public function generateAuthorization($method, $resource, $params = array(), $headers = array(), $timestamp = 0, $expiration_in_seconds = 1800, $headers_to_sign = null) { $raw_session_key = sprintf("bce-auth-v%s/%s/%s/%d", "1", $this->access_key, baidubce_util_Time::bceTimeNow($timestamp), $expiration_in_seconds); $session_key = hash_hmac("sha256", $raw_session_key, $this->access_key_secret, false); $canonical_uri = "/v1" . baidubce_util_Coder::urlEncodeExceptSlash($resource); $canonical_query_string = $this->queryStringCanonicalization($params); list($canonical_headers, $signed_headers) = $this->headersCanonicalization($headers, $headers_to_sign); $raw_signature = $method . "\n" . $canonical_uri . "\n" . $canonical_query_string . "\n" . $canonical_headers; $signature = hash_hmac("sha256", $raw_signature, $session_key, false); if (count($signed_headers) > 0) { return sprintf('%s/%s/%s', $raw_session_key, implode(';', $signed_headers), $signature); } return sprintf('%s//%s', $raw_session_key, $signature); }
/** * Copy one object to another. * * @param string $source_bucket The source bucket name. * @param string $source_key The source object path. * @param string $target_bucket The target bucket name. * @param string $target_key The target object path. * @param mixed $options * * @return mixed */ public function copyObject($source_bucket, $source_key, $target_bucket, $target_key, $options = array()) { if (empty($source_bucket) || empty($target_bucket)) { throw new baidubce_exception_BceIllegalArgumentException('Bucket is empty.'); } if (empty($source_key) || empty($target_key)) { throw new baidubce_exception_BceIllegalArgumentException('Key is empty.'); } list($headers, $params) = $this->checkOptions($options); $copy_source = sprintf("/%s/%s", $source_bucket, $source_key); $headers['x-bce-copy-source'] = baidubce_util_Coder::urlEncodeExceptSlash($copy_source); return $this->http_client->sendRequest('PUT', $target_bucket, $target_key, $headers, '', $params); }
/** * @param string $resource The bucket and object path. * @param array @param The query strings * * @return string The complete request url path with query string. */ private function getRequestUrl($resource, $params) { $uri = "/v1" . baidubce_util_Coder::urlEncodeExceptSlash($resource); // TODO(leeight) // k = k.replace('_', '-') $query_string = implode("&", array_map(array($this, 'encodeValue'), array_keys($params), $params)); if (!is_null($query_string) && $query_string != "") { return $uri . "?" . $query_string; } return $uri; }