Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump to 7.13.0 #431

Merged
merged 6 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 7.13.0 (2024-09-05)
* 对象存储,验证回调方法新增支持 Qiniu 签名
* 对象存储,调整查询空间区域域名顺序与默认空间管理域名
* 支持闲时任务配置

## 7.12.1 (2024-02-21)
* 对象存储,添加上传策略部分字段

Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
],
"require": {
"php": ">=5.3.3",
"ext-xml": "*",
"ext-curl": "*",
"myclabs/php-enum": "~1.5.2 || ~1.6.6 || ~1.7.7 || ~1.8.4"
},
"require-dev": {
Expand Down
33 changes: 29 additions & 4 deletions src/Qiniu/Auth.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Qiniu;

use Qiniu\Http\Header;
Expand Down Expand Up @@ -94,7 +95,7 @@ public function signQiniuAuthorization($urlString, $method = "GET", $body = "",
$data .= ":" . $url["port"];
}

// try append content type
// try to append content type
if ($headers != null && isset($headers["Content-Type"])) {
// append content type
$data .= "\n";
Expand Down Expand Up @@ -133,9 +134,32 @@ public function signQiniuAuthorization($urlString, $method = "GET", $body = "",
return array($this->sign($data), null);
}

public function verifyCallback($contentType, $originAuthorization, $url, $body)
{
$authorization = 'QBox ' . $this->signRequest($url, $body, $contentType);
public function verifyCallback(
$contentType,
$originAuthorization,
$url,
$body,
$method = "GET",
$headers = array()
) {
if (strpos($originAuthorization, 'Qiniu') === 0) {
$qnHeaders = new Header($headers);
if (!isset($qnHeaders['Content-Type'])) {
$qnHeaders['Content-Type'] = $contentType;
}
list($sign, $err) = $this->signQiniuAuthorization(
$url,
$method,
$body,
$qnHeaders
);
if ($err !== null) {
return false;
}
$authorization = 'Qiniu ' . $sign;
} else {
$authorization = 'QBox ' . $this->signRequest($url, $body, $contentType);
}
return $originAuthorization === $authorization;
}

Expand Down Expand Up @@ -198,6 +222,7 @@ public function uploadToken($bucket, $key = null, $expires = 3600, $policy = nul
'persistentOps',
'persistentNotifyUrl',
'persistentPipeline',
'persistentType', // 为 `1` 时开启闲时任务

'deleteAfterDays',
'fileType',
Expand Down
10 changes: 5 additions & 5 deletions src/Qiniu/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

final class Config
{
const SDK_VER = '7.12.1';
const SDK_VER = '7.13.0';

const BLOCK_SIZE = 4194304; //4*1024*1024 分块上传块大小,该参数为接口规格,不能修改

const RSF_HOST = 'rsf.qiniuapi.com';
const API_HOST = 'api.qiniuapi.com';
const RS_HOST = 'rs.qiniuapi.com'; //RS Host
const UC_HOST = 'uc.qbox.me'; //UC Host
const QUERY_REGION_HOST = 'kodo-config.qiniuapi.com';
const RS_HOST = 'rs.qiniuapi.com'; // RS Host
const UC_HOST = 'uc.qiniuapi.com'; // UC Host
const QUERY_REGION_HOST = Config::UC_HOST;
const RTCAPI_HOST = 'http://rtc.qiniuapi.com';
const ARGUS_HOST = 'ai.qiniuapi.com';
const CASTER_HOST = 'pili-caster.qiniuapi.com';
Expand Down Expand Up @@ -50,8 +50,8 @@ public function __construct(Region $z = null)
$this->ucHost = Config::UC_HOST;
$this->queryRegionHost = Config::QUERY_REGION_HOST;
$this->backupQueryRegionHosts = array(
"kodo-config.qiniuapi.com",
"uc.qbox.me",
"api.qiniu.com"
);
$this->backupUcHostsRetryTimes = 2;
}
Expand Down
14 changes: 12 additions & 2 deletions src/Qiniu/Http/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@ public function __construct($obj = array())
foreach ($obj as $key => $values) {
$normalizedKey = self::normalizeKey($key);
$normalizedValues = array();
foreach ($values as $value) {
array_push($normalizedValues, self::normalizeValue($value));
if (!is_array($values)) {
array_push(
$normalizedValues,
self::normalizeValue($values)
);
} else {
foreach ($values as $value) {
array_push(
$normalizedValues,
self::normalizeValue($value)
);
}
}
$this->data[$normalizedKey] = $normalizedValues;
}
Expand Down
38 changes: 32 additions & 6 deletions src/Qiniu/Processing/PersistentFop.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Qiniu\Http\Error;
use Qiniu\Http\Client;
use Qiniu\Http\Proxy;
use Qiniu\Zone;

/**
* 持久化处理类,该类用于主动触发异步持久化操作.
Expand Down Expand Up @@ -45,25 +46,34 @@ public function __construct($auth, $config = null, $proxy = null, $proxy_auth =
* 对资源文件进行异步持久化处理
* @param string $bucket 资源所在空间
* @param string $key 待处理的源文件
* @param string $fops string|array 待处理的pfop操作,多个pfop操作以array的形式传入。
* @param string|array $fops 待处理的pfop操作,多个pfop操作以array的形式传入。
* eg. avthumb/mp3/ab/192k, vframe/jpg/offset/7/w/480/h/360
* @param string $pipeline 资源处理队列
* @param string $notify_url 处理结果通知地址
* @param bool $force 是否强制执行一次新的指令
* @param int $type 为 `1` 时开启闲时任务
*
*
* @return array 返回持久化处理的persistentId, 和返回的错误
* @return array 返回持久化处理的 persistentId 与可能出现的错误
*
* @link http://developer.qiniu.com/docs/v6/api/reference/fop/
*/
public function execute($bucket, $key, $fops, $pipeline = null, $notify_url = null, $force = false)
{
public function execute(
$bucket,
$key,
$fops,
$pipeline = null,
$notify_url = null,
$force = false,
$type = null
) {
if (is_array($fops)) {
$fops = implode(';', $fops);
}
$params = array('bucket' => $bucket, 'key' => $key, 'fops' => $fops);
\Qiniu\setWithoutEmpty($params, 'pipeline', $pipeline);
\Qiniu\setWithoutEmpty($params, 'notifyURL', $notify_url);
\Qiniu\setWithoutEmpty($params, 'type', $type);
if ($force) {
$params['force'] = 1;
}
Expand All @@ -72,7 +82,8 @@ public function execute($bucket, $key, $fops, $pipeline = null, $notify_url = nu
if ($this->config->useHTTPS === true) {
$scheme = "https://";
}
$url = $scheme . Config::API_HOST . '/pfop/';
$apiHost = $this->getApiHost();
$url = $scheme . $apiHost . '/pfop/';
$headers = $this->auth->authorization($url, $data, 'application/x-www-form-urlencoded');
$headers['Content-Type'] = 'application/x-www-form-urlencoded';
$response = Client::post($url, $data, $headers, $this->proxy->makeReqOpt());
Expand All @@ -84,18 +95,33 @@ public function execute($bucket, $key, $fops, $pipeline = null, $notify_url = nu
return array($id, null);
}

/**
* @param string $id
* @return array 返回任务状态与可能出现的错误
*/
public function status($id)
{
$scheme = "http://";

if ($this->config->useHTTPS === true) {
$scheme = "https://";
}
$url = $scheme . Config::API_HOST . "/status/get/prefop?id=$id";
$apiHost = $this->getApiHost();
$url = $scheme . $apiHost . "/status/get/prefop?id=$id";
$response = Client::get($url, array(), $this->proxy->makeReqOpt());
if (!$response->ok()) {
return array(null, new Error($url, $response));
}
return array($response->json(), null);
}

private function getApiHost()
{
if (!empty($this->config->zone) && !empty($this->config->zone->apiHost)) {
$apiHost = $this->config->zone->apiHost;
} else {
$apiHost = Config::API_HOST;
}
return $apiHost;
}
}
26 changes: 26 additions & 0 deletions tests/Qiniu/Tests/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,5 +236,31 @@ public function testDisableQiniuTimestampSignatureEnvBeIgnored()
$this->assertArrayHasKey("X-Qiniu-Date", $authedHeaders);
putenv('DISABLE_QINIU_TIMESTAMP_SIGNATURE');
}
public function testQboxVerifyCallback()
{
$auth = new Auth('abcdefghklmnopq', '1234567890');
$ok = $auth->verifyCallback(
'application/x-www-form-urlencoded',
'QBox abcdefghklmnopq:T7F-SjxX7X2zI4Fc1vANiNt1AUE=',
'https://test.qiniu.com/callback',
'name=sunflower.jpg&hash=Fn6qeQi4VDLQ347NiRm-RlQx_4O2&location=Shanghai&price=1500.00&uid=123'
);
$this->assertTrue($ok);
}
public function testQiniuVerifyCallback()
{
$auth = new Auth('abcdefghklmnopq', '1234567890');
$ok = $auth->verifyCallback(
'application/x-www-form-urlencoded',
'Qiniu abcdefghklmnopq:ZqS7EZuAKrhZaEIxqNGxDJi41IQ=',
'https://test.qiniu.com/callback',
'name=sunflower.jpg&hash=Fn6qeQi4VDLQ347NiRm-RlQx_4O2&location=Shanghai&price=1500.00&uid=123',
'GET',
array(
'X-Qiniu-Bbb' => 'BBB'
)
);
$this->assertTrue($ok);
}
}
}
8 changes: 4 additions & 4 deletions tests/Qiniu/Tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ public function testGetApiHostV2Errored()
public function testSetUcHost()
{
$conf = new Config();
$this->assertEquals("http://uc.qbox.me", $conf->getUcHost());
$this->assertEquals('http://' . Config::UC_HOST, $conf->getUcHost());
$conf->setUcHost("uc.example.com");
$this->assertEquals("http://uc.example.com", $conf->getUcHost());

$conf = new Config();
$conf->useHTTPS = true;
$this->assertEquals("https://uc.qbox.me", $conf->getUcHost());
$this->assertEquals('https://' . Config::UC_HOST, $conf->getUcHost());
$conf->setUcHost("uc.example.com");
$this->assertEquals("https://uc.example.com", $conf->getUcHost());
}
Expand All @@ -94,7 +94,7 @@ public function testGetRegionWithBackupDomains()
"fake-uc.phpsdk.qiniu.com",
array(
"unavailable-uc.phpsdk.qiniu.com",
"uc.qbox.me" // real uc
Config::UC_HOST // real uc
)
);
list(, $err) = $conf->getRsHostV2($this->accessKey, $this->bucketName);
Expand All @@ -108,7 +108,7 @@ public function testGetRegionWithUcAndBackupDomains()
$conf->setBackupQueryRegionHosts(
array(
"unavailable-uc.phpsdk.qiniu.com",
"uc.qbox.me" // real uc
Config::UC_HOST // real uc
)
);
list(, $err) = $conf->getRsHostV2($this->accessKey, $this->bucketName);
Expand Down
10 changes: 5 additions & 5 deletions tests/Qiniu/Tests/MiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function testSendWithMiddleware()

$request = new Request(
"GET",
"https://qiniu.com/index.html",
"http://localhost:9000/ok.php",
array(),
null,
$reqOpt
Expand All @@ -79,7 +79,7 @@ public function testSendWithRetryDomains()
new Middleware\RetryDomainsMiddleware(
array(
"unavailable.phpsdk.qiniu.com",
"qiniu.com",
"localhost:9000",
),
3
),
Expand All @@ -88,7 +88,7 @@ public function testSendWithRetryDomains()

$request = new Request(
"GET",
"https://fake.phpsdk.qiniu.com/index.html",
"http://fake.phpsdk.qiniu.com/ok.php",
array(),
null,
$reqOpt
Expand Down Expand Up @@ -130,7 +130,7 @@ public function testSendFailFastWithRetryDomains()
new Middleware\RetryDomainsMiddleware(
array(
"unavailable.phpsdk.qiniu.com",
"qiniu.com",
"localhost:9000",
),
3,
function () {
Expand All @@ -142,7 +142,7 @@ function () {

$request = new Request(
"GET",
"https://fake.phpsdk.qiniu.com/index.html",
"http://fake.phpsdk.qiniu.com/ok.php",
array(),
null,
$reqOpt
Expand Down
Loading
Loading