Skip to content

Commit

Permalink
cleanup unused parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonTian committed Jul 30, 2024
1 parent ee9cb9f commit 521f688
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions sdk/auth/roa_signature_composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ func init() {
debug = utils.Init("sdk")
}

func signRoaRequest(request requests.AcsRequest, signer Signer, regionId string) (err error) {
func signRoaRequest(request requests.AcsRequest, signer Signer) (err error) {
// 先获取 accesskey,确保刷新 credential
accessKeyId, err := signer.GetAccessKeyId()
if err != nil {
return err
}

completeROASignParams(request, signer, regionId)
completeROASignParams(request, signer)
stringToSign := buildRoaStringToSign(request)
request.SetStringToSign(stringToSign)

Expand All @@ -50,7 +50,7 @@ func signRoaRequest(request requests.AcsRequest, signer Signer, regionId string)
return
}

func completeROASignParams(request requests.AcsRequest, signer Signer, regionId string) {
func completeROASignParams(request requests.AcsRequest, signer Signer) {
headerParams := request.GetHeaders()

// complete query params
Expand Down
11 changes: 6 additions & 5 deletions sdk/auth/roa_signature_composer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestRoaSignatureComposer(t *testing.T) {
origTestHookGetDate := hookGetDate
defer func() { hookGetDate = origTestHookGetDate }()
hookGetDate = mockDate
signRoaRequest(request, signer, "regionId")
signRoaRequest(request, signer)
assert.Equal(t, "mock date", request.GetHeaders()["Date"])
assert.Equal(t, "acs accessKeyId:degLHXLEN6rMojj+bOlK74U9iic=", request.GetHeaders()["Authorization"])
}
Expand All @@ -63,7 +63,7 @@ func TestRoaSignatureComposer2(t *testing.T) {
origTestHookLookupIP := hookGetDate
defer func() { hookGetDate = origTestHookLookupIP }()
hookGetDate = mockDate
signRoaRequest(request, signer, "regionId")
signRoaRequest(request, signer)
assert.Equal(t, "application/x-www-form-urlencoded", request.GetHeaders()["Content-Type"])
assert.Equal(t, "mock date", request.GetHeaders()["Date"])
assert.Equal(t, "application/xml", request.GetHeaders()["Accept"])
Expand All @@ -81,19 +81,20 @@ func TestRoaSignatureComposer3(t *testing.T) {
origTestHookGetDate := hookGetDate
defer func() { hookGetDate = origTestHookGetDate }()
hookGetDate = mockDate
signRoaRequest(request, signer, "regionId")
signRoaRequest(request, signer)
assert.Equal(t, "mock date", request.GetHeaders()["Date"])
}

func TestCompleteROASignParams(t *testing.T) {
req := requests.NewCommonRequest()
req.TransToAcsRequest()
sign := signers.NewBearerTokenSigner(credentials.NewBearerTokenCredential("Bearer.Token"))
completeROASignParams(req, sign, "cn-hangzhou")
completeROASignParams(req, sign)
head := req.GetHeaders()
assert.Equal(t, "Bearer.Token", head["x-acs-bearer-token"])

sign1 := signers.NewStsTokenSigner(credentials.NewStsTokenCredential("accessKeyId", "accessKeySecret", "accessKeyStsToken"))
completeROASignParams(req, sign1, "cn-hangzhou")
completeROASignParams(req, sign1)
head = req.GetHeaders()
assert.Equal(t, "accessKeyStsToken", head["x-acs-security-token"])
}
5 changes: 2 additions & 3 deletions sdk/auth/rpc_signature_composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ func signRpcRequest(request requests.AcsRequest, signer Signer, regionId string)
return
}
// remove while retry
if _, containsSign := request.GetQueryParams()["Signature"]; containsSign {
delete(request.GetQueryParams(), "Signature")
}
delete(request.GetQueryParams(), "Signature")

stringToSign := buildRpcStringToSign(request)
request.SetStringToSign(stringToSign)
signature := signer.Sign(stringToSign, "&")
Expand Down
2 changes: 1 addition & 1 deletion sdk/auth/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func Sign(request requests.AcsRequest, signer Signer, regionId string) (err erro
switch request.GetStyle() {
case requests.ROA:
{
err = signRoaRequest(request, signer, regionId)
err = signRoaRequest(request, signer)
}
case requests.RPC:
{
Expand Down

0 comments on commit 521f688

Please sign in to comment.