aliyun / alibaba-cloud-sdk-go

Alibaba Cloud SDK for Go
Apache License 2.0
1.16k stars 271 forks source link

Vpc request always get empty response,but OpenApiExploere will not #237

Closed laoshancun closed 5 years ago

laoshancun commented 5 years ago

import ( "fmt"

"github.com/aliyun/alibaba-cloud-sdk-go/services/vpc"

)

func main() { client, err := vpc.NewClientWithAccessKey("cn-beijing", "", "")

request := vpc.CreateDescribeEipAddressesRequest()

request.AllocationId = "eip-instanceId"

response, err := client.DescribeEipAddresses(request) if err != nil { fmt.Print(err.Error()) } fmt.Printf("response is %#v\n", response) }



<!-- Please provide more details below this comment. -->
wenzuochao commented 5 years ago
  • Product and API: VPC DescribeEipAddresses
  • Platform: Windows 10 with go version go1.11.5 windows/amd64
  • How to Reproduce
  1. using OpenApiExplorer to generate golang example code
package main

import (
  "fmt"

  "github.com/aliyun/alibaba-cloud-sdk-go/services/vpc"
)

func main() {
  client, err := vpc.NewClientWithAccessKey("cn-beijing", "<accessKeyId>", "<accessSecret>")

  request := vpc.CreateDescribeEipAddressesRequest()

  request.AllocationId = "eip-instanceId"

  response, err := client.DescribeEipAddresses(request)
  if err != nil {
    fmt.Print(err.Error())
  }
  fmt.Printf("response is %#v\n", response)
}

Thanks for your support to us, could you please add an environment variable DEBUG=sdk? It can help you to view the HTTP request process.

laoshancun commented 5 years ago

Ok,here you are.

resolve endpoint with {"Domain":"location-readonly.aliyuncs.com","Product":"Location","RegionId":"cn-beijing","LocationProduct":"","LocationEndpointType":""}

    location-readonly.aliyuncs.com by resolver(simple host resolver)

> GET /?AccessKeyId=AccessKeyId&Action=DescribeEndpoints&Format=JSON&Id=cn-beijing&RegionId=cn-beijing&ServiceCode=vpc&Signature=iFZb%2BcYZF7m1JJdyX9mxa6IVAd0%3D&SignatureMethod=HMAC-SHA1&SignatureNonce=f41ed089ee4e4c7aad9683d7befc01de&SignatureType=&SignatureVersion=1.0&Timestamp=2019-03-21T02%3A35%3A19Z&Type=openAPI&Version=2015-06-12 HTTP/1.1
> Host: location-readonly.aliyuncs.com
> x-sdk-core-version: 0.0.1
> Content-Type: application/x-www-form-urlencoded
> User-Agent: AlibabaCloud (windows; amd64) Golang/1.12.1 Core/0.0.1
> x-sdk-client: golang/1.0.0
> x-sdk-invoke-type: common
> Accept-Encoding: identity
>
< HTTP/1.1 200 OK
< Access-Control-Max-Age: 172800
< Content-Type: application/json; charset=UTF-8
< Content-Length: 239
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: POST, GET, OPTIONS
< Access-Control-Allow-Headers: X-Requested-With, X-Sequence, _aop_secret, _aop_signature
< Server: Jetty(7.2.2.v20101205)
< Date: Thu, 21 Mar 2019 02:35:20 GMT
<
{"Endpoints":{"Endpoint":[{"Protocols":{"Protocols":["HTTP","HTTPS"]},"Type":"openAPI","Namespace":"","Id":"cn-beijing","SerivceCode":"vpc","Endpoint":"vpc.aliyuncs.com"}]},"RequestId":"3E589032-2704-46A0-8AF4-B341A99E55BA","Success":true}
resolve endpoint with {"Domain":"","Product":"Vpc","RegionId":"cn-beijing","LocationProduct":"vpc","LocationEndpointType":"openAPI"}

    vpc.aliyuncs.com by resolver(location resolver)

> POST /?AccessKeyId=AccessKeyId&Action=DescribeEipAddresses&Format=JSON&RegionId=cn-beijing&Signature=fA%2B9sa7KetP%2FDVWJp1EejEL%2F5F8%3D&SignatureMethod=HMAC-SHA1&SignatureNonce=4daebbb7fa6e4e2ca85317d7a035548e&SignatureType=&SignatureVersion=1.0&Timestamp=2019-03-21T02%3A35%3A19Z&Version=2016-04-28 HTTP/1.1
> Host: vpc.aliyuncs.com
> x-sdk-client: golang/1.0.0
> x-sdk-invoke-type: normal
> Accept-Encoding: identity
> x-sdk-core-version: 0.0.1
> Content-Type: application/x-www-form-urlencoded
> User-Agent: AlibabaCloud (windows; amd64) Golang/1.12.1 Core/0.0.1
>
< HTTP/1.1 200 OK
< Date: Thu, 21 Mar 2019 02:35:20 GMT
< Content-Type: application/json; charset=UTF-8
< Content-Length: 129
< Access-Control-Allow-Headers: X-Requested-With, X-Sequence, _aop_secret, _aop_signature
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: POST, GET, OPTIONS
< Access-Control-Max-Age: 172800
< Server: Jetty(7.2.2.v20101205)
<
{"PageNumber":1,"EipAddresses":{"EipAddress":[]},"TotalCount":0,"PageSize":10,"RequestId":"C96FE41D-327D-483A-8CA7-FD3791C3729B"}
response is &vpc.DescribeEipAddressesResponse{BaseResponse:(*responses.BaseResponse)(0xc000056780), RequestId:"C96FE41D-327D-483A-8CA7-FD3791C3729B", TotalCount:0, PageNumber:1, PageSize:10, EipAddresses:vpc.EipAddresses{EipAddress:[]vpc.EipAddress{}}}
wenzuochao commented 5 years ago

Ok,here you are.

resolve endpoint with {"Domain":"location-readonly.aliyuncs.com","Product":"Location","RegionId":"cn-beijing","LocationProduct":"","LocationEndpointType":""}

  location-readonly.aliyuncs.com by resolver(simple host resolver)

> GET /?AccessKeyId=AccessKeyId&Action=DescribeEndpoints&Format=JSON&Id=cn-beijing&RegionId=cn-beijing&ServiceCode=vpc&Signature=iFZb%2BcYZF7m1JJdyX9mxa6IVAd0%3D&SignatureMethod=HMAC-SHA1&SignatureNonce=f41ed089ee4e4c7aad9683d7befc01de&SignatureType=&SignatureVersion=1.0&Timestamp=2019-03-21T02%3A35%3A19Z&Type=openAPI&Version=2015-06-12 HTTP/1.1
> Host: location-readonly.aliyuncs.com
> x-sdk-core-version: 0.0.1
> Content-Type: application/x-www-form-urlencoded
> User-Agent: AlibabaCloud (windows; amd64) Golang/1.12.1 Core/0.0.1
> x-sdk-client: golang/1.0.0
> x-sdk-invoke-type: common
> Accept-Encoding: identity
>
< HTTP/1.1 200 OK
< Access-Control-Max-Age: 172800
< Content-Type: application/json; charset=UTF-8
< Content-Length: 239
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: POST, GET, OPTIONS
< Access-Control-Allow-Headers: X-Requested-With, X-Sequence, _aop_secret, _aop_signature
< Server: Jetty(7.2.2.v20101205)
< Date: Thu, 21 Mar 2019 02:35:20 GMT
<
{"Endpoints":{"Endpoint":[{"Protocols":{"Protocols":["HTTP","HTTPS"]},"Type":"openAPI","Namespace":"","Id":"cn-beijing","SerivceCode":"vpc","Endpoint":"vpc.aliyuncs.com"}]},"RequestId":"3E589032-2704-46A0-8AF4-B341A99E55BA","Success":true}
resolve endpoint with {"Domain":"","Product":"Vpc","RegionId":"cn-beijing","LocationProduct":"vpc","LocationEndpointType":"openAPI"}

  vpc.aliyuncs.com by resolver(location resolver)

> POST /?AccessKeyId=AccessKeyId&Action=DescribeEipAddresses&Format=JSON&RegionId=cn-beijing&Signature=fA%2B9sa7KetP%2FDVWJp1EejEL%2F5F8%3D&SignatureMethod=HMAC-SHA1&SignatureNonce=4daebbb7fa6e4e2ca85317d7a035548e&SignatureType=&SignatureVersion=1.0&Timestamp=2019-03-21T02%3A35%3A19Z&Version=2016-04-28 HTTP/1.1
> Host: vpc.aliyuncs.com
> x-sdk-client: golang/1.0.0
> x-sdk-invoke-type: normal
> Accept-Encoding: identity
> x-sdk-core-version: 0.0.1
> Content-Type: application/x-www-form-urlencoded
> User-Agent: AlibabaCloud (windows; amd64) Golang/1.12.1 Core/0.0.1
>
< HTTP/1.1 200 OK
< Date: Thu, 21 Mar 2019 02:35:20 GMT
< Content-Type: application/json; charset=UTF-8
< Content-Length: 129
< Access-Control-Allow-Headers: X-Requested-With, X-Sequence, _aop_secret, _aop_signature
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: POST, GET, OPTIONS
< Access-Control-Max-Age: 172800
< Server: Jetty(7.2.2.v20101205)
<
{"PageNumber":1,"EipAddresses":{"EipAddress":[]},"TotalCount":0,"PageSize":10,"RequestId":"C96FE41D-327D-483A-8CA7-FD3791C3729B"}
response is &vpc.DescribeEipAddressesResponse{BaseResponse:(*responses.BaseResponse)(0xc000056780), RequestId:"C96FE41D-327D-483A-8CA7-FD3791C3729B", TotalCount:0, PageNumber:1, PageSize:10, EipAddresses:vpc.EipAddresses{EipAddress:[]vpc.EipAddress{}}}

When TotalCount is 0, that means you have no EipAddresses in this accout when your regionid is cn-beijing.

laoshancun commented 5 years ago

Yes,it seems to be the truth,but why i can get eip data on OpenApiExplorer? Is there any policy should be add to ak except 'AliyunVPCFullAccess'?

wenzuochao commented 5 years ago

Yes,it seems to be the truth,but why i can get eip data on OpenApiExplorer? Is there any policy should be add to ak except 'AliyunVPCFullAccess'?

When response returns 200, it means you have permission to call the api. It seems that you use different ak or different regionid.

laoshancun commented 5 years ago

I am sure that is same ak and same region.

laoshancun commented 5 years ago

Also,i had created a workorder on aliyun console,and id is CAA0BUA.

wenzuochao commented 5 years ago

Also,i had created a workorder on aliyun console,and id is CAA0BUA.

Could you show me the real request urls when you call the api by sdk and by OpenApiExplorer?

laoshancun commented 5 years ago

Ok,according to reply of the workorder,It seems that policy AliyunEIPFullAccess is required. THX :)

laoshancun commented 5 years ago
  1. Maybe we should response with 401 instead of 200.
  2. If we can describe what kinds of policyies are required by api more clearly,that will be good.
wenzuochao commented 5 years ago
  1. Maybe we should response with 401 instead of 200.
  2. If we can describe what kinds of policyies are required by api more clearly,that will be good.

If you have no permission to call the api, the server will return the error to tell you that.It may is the fault of vpc, so it's hard for us to response with 401 instead of 200.

JacksonTian commented 5 years ago

@laoshancun I have submit your question to product team, Maybe the API should be improved just like you said.

laoshancun commented 5 years ago

Change response code is not a good idea,but server should return an error rather than return a normal empty response.

laoshancun commented 5 years ago

@JacksonTian THX.