diff --git a/storage/bucket.go b/storage/bucket.go index bf4a813..b1dda36 100644 --- a/storage/bucket.go +++ b/storage/bucket.go @@ -9,9 +9,10 @@ import ( "strconv" "strings" + "net/http" + "github.com/qiniu/api.v7/auth/qbox" "github.com/qiniu/api.v7/conf" - "net/http" ) // 资源管理相关的默认域名 @@ -19,7 +20,7 @@ const ( DefaultRsHost = "rs.qiniu.com" DefaultRsfHost = "rsf.qiniu.com" DefaultAPIHost = "api.qiniu.com" - DefaultPubHost = "pu.qbox.me:10200" + DefaultPubHost = "pu.qbox.me" ) // FileInfo 文件基本信息 @@ -472,7 +473,7 @@ func (m *BucketManager) AsyncFetch(param AsyncFetchParam) (ret AsyncFetchRet, er reqUrl += "/sisyphus/fetch" - ctx := context.WithValue(context.TODO(), "mac", m.mac) + ctx := context.WithValue(context.TODO(), "mac:Qiniu", m.mac) headers := http.Header{} headers.Add("Content-Type", conf.CONTENT_TYPE_JSON) err = m.client.CallWithJson(ctx, &ret, "POST", reqUrl, headers, param) diff --git a/storage/bucket_test.go b/storage/bucket_test.go index 9952527..09942e6 100644 --- a/storage/bucket_test.go +++ b/storage/bucket_test.go @@ -193,7 +193,7 @@ func TestChangeType(t *testing.T) { func TestPrefetchAndImage(t *testing.T) { err := bucketManager.SetImage(testSiteUrl, testBucket) if err != nil { - t.Fatalf("SetImage() error, %s", err) + t.Fatalf("SetImage() error, %+v", err) } t.Log("set image success for bucket", testBucket) diff --git a/storage/form_upload_test.go b/storage/form_upload_test.go index 31695cf..26f3ca2 100644 --- a/storage/form_upload_test.go +++ b/storage/form_upload_test.go @@ -10,9 +10,18 @@ import ( ) var ( - testLocalFile = filepath.Join(os.Getenv("TRAVIS_BUILD_DIR"), "Makefile") + testLocalFile string ) +func init() { + pwd, err := os.Getwd() + if err != nil { + fmt.Println(err) + } + exPath := filepath.Dir(pwd) + testLocalFile = filepath.Join(exPath, "Makefile") +} + func TestFormUploadPutFile(t *testing.T) { var putRet PutRet ctx := context.TODO() diff --git a/storage/rpc.go b/storage/rpc.go index 2fda7ee..0bd2008 100644 --- a/storage/rpc.go +++ b/storage/rpc.go @@ -8,10 +8,6 @@ import ( "bytes" "encoding/json" "fmt" - "github.com/qiniu/api.v7/auth/qbox" - "github.com/qiniu/api.v7/conf" - "github.com/qiniu/x/reqid.v7" - . "golang.org/x/net/context" "io" "io/ioutil" "net/http" @@ -19,6 +15,11 @@ import ( "os" "runtime" "strings" + + "github.com/qiniu/api.v7/auth/qbox" + "github.com/qiniu/api.v7/conf" + "github.com/qiniu/x/reqid.v7" + . "golang.org/x/net/context" ) var UserAgent = "Golang qiniu/rpc package" @@ -53,6 +54,9 @@ func newRequest(ctx Context, method, reqUrl string, headers http.Header, body io //check access token mac, ok := ctx.Value("mac").(*qbox.Mac) + if !ok { + mac, ok = ctx.Value("mac:QBox").(*qbox.Mac) + } if ok { token, signErr := mac.SignRequest(req) if signErr != nil { @@ -60,6 +64,17 @@ func newRequest(ctx Context, method, reqUrl string, headers http.Header, body io return } req.Header.Add("Authorization", "QBox "+token) + return + } + mac, ok = ctx.Value("mac:Qiniu").(*qbox.Mac) + if ok { + token, signErr := mac.SignRequestV2(req) + if signErr != nil { + err = signErr + return + } + req.Header.Add("Authorization", "Qiniu "+token) + return } return diff --git a/test-env.sh b/test-env.sh old mode 100644 new mode 100755 index d412685..bd63ee9 --- a/test-env.sh +++ b/test-env.sh @@ -7,4 +7,3 @@ export QINIU_TEST_BUCKET_PRIVATE=gosdk.qiniudn.com export QINIU_TEST_DOMAIN=gosdk.qiniudn.com export QINIU_TEST_DOMAIN_PRIVATE=gosdk.qiniudn.com export QINIU_TEST_PIPELINE=sdktest -export TRAVIS_BUILD_DIR=/Users/jemy/Downloads \ No newline at end of file