Skip to content

Commit

Permalink
add ssl, use go mod and improve http client (#36)
Browse files Browse the repository at this point in the history
FEATURES:

- Add `UpdateSSLBinding`as public api
- Add `BindSSL`as public api
- Add `CreateSSL`as public api
- Add `DeleteSSL`as public api
- Add `DescribeSSL`as public api
- Add `UnbindSSL`as public api
- Add `UpdateSSLBinding`as public api
- Add `UpdateSSLBinding`as public api
- Add `CheckURedisAllowance` as private api

ENHANCEMENTS:

- Use `go mod` instead of `dep`
- Move query string into http body
  • Loading branch information
yufeiminds authored Jan 16, 2019
1 parent 1acb6fc commit f18d177
Show file tree
Hide file tree
Showing 21 changed files with 1,232 additions and 75 deletions.
39 changes: 0 additions & 39 deletions Gopkg.lock

This file was deleted.

30 changes: 0 additions & 30 deletions Gopkg.toml

This file was deleted.

9 changes: 9 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module github.com/ucloud/ucloud-sdk-go

require (
github.com/Sirupsen/logrus v0.8.7
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pkg/errors v0.8.0
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.2.2
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github.com/Sirupsen/logrus v0.8.7 h1:hGa+d4KZNNNDmzAj6vlkeOQsgjrh8zg4EXB81mWoTm4=
github.com/Sirupsen/logrus v0.8.7/go.mod h1:rmk17hk6i8ZSAJkSDa7nOxamrG+SP4P0mm+DAvExv4U=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
13 changes: 13 additions & 0 deletions private/protocol/http/http_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package http

import (
"io/ioutil"
"testing"
"time"

Expand Down Expand Up @@ -45,6 +46,18 @@ func TestHTTPRequest(t *testing.T) {
body := []byte("data")
req.SetRequestBody(body)
assert.Equal(t, req.GetRequestBody(), body)

req = NewHttpRequest()
req.SetQuery("key1", "value1")
req.SetQuery("key2", "value2")

httpReq, err := req.buildHTTPRequest()
assert.NoError(t, err)

body, err = ioutil.ReadAll(httpReq.Body)
assert.NoError(t, err)

assert.Equal(t, body, []byte("key1=value1&key2=value2"))
}

func TestClientSend(t *testing.T) {
Expand Down
4 changes: 1 addition & 3 deletions private/protocol/http/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,7 @@ func (h *HttpRequest) buildHTTPRequest() (*http.Request, error) {
return nil, errors.Errorf("cannot build query string, %s", err)
}

// NOTE: api.ucloud.cn has been supported request via form urlencoded data
url := fmt.Sprintf("%s?%s", h.GetURL(), qs)
httpReq, err := http.NewRequest(h.GetMethod(), url, nil)
httpReq, err := http.NewRequest(h.GetMethod(), h.GetURL(), strings.NewReader(qs))
if err != nil {
return nil, errors.Errorf("cannot build request, %s", err)
}
Expand Down
19 changes: 19 additions & 0 deletions private/services/ulb/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ulb

import (
"github.com/ucloud/ucloud-sdk-go/ucloud"
"github.com/ucloud/ucloud-sdk-go/ucloud/auth"
)

// ULBClient is the client of ULB
type ULBClient struct {
client *ucloud.Client
}

// NewClient will return a instance of ULBClient
func NewClient(config *ucloud.Config, credential *auth.Credential) *ULBClient {
client := ucloud.NewClient(config, credential)
return &ULBClient{
client: client,
}
}
11 changes: 11 additions & 0 deletions private/services/ulb/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
Package ulb include resources of ucloud ulb product
See also
- API: https://docs.ucloud.cn/api/ulb-api/index
- Product: https://www.ucloud.cn/site/product/ulb.html
for detail.
*/
package ulb
62 changes: 62 additions & 0 deletions private/services/ulb/update_sslbinding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//Code is generated by ucloud code generator, don't modify it by hand, it will cause undefined behaviors.
//go:generate ucloud-gen-go-api ULB UpdateSSLBinding

package ulb

import (
"github.com/ucloud/ucloud-sdk-go/ucloud/request"
"github.com/ucloud/ucloud-sdk-go/ucloud/response"
)

// UpdateSSLBindingRequest is request schema for UpdateSSLBinding action
type UpdateSSLBindingRequest struct {
request.CommonBase

// 所操作ULB实例ID
ULBId *string `required:"true"`

// 所操作VServer实例ID
VServerId *string `required:"true"`

// VServer实例绑定的旧的证书
OldSSLId *string `required:"true"`

// VServer实例需要绑定的新的证书
NewSSLId *string `required:"true"`
}

// UpdateSSLBindingResponse is response schema for UpdateSSLBinding action
type UpdateSSLBindingResponse struct {
response.CommonBase

// 返回码
RetCode int

// 响应名称
Action string
}

// NewUpdateSSLBindingRequest will create request of UpdateSSLBinding action.
func (c *ULBClient) NewUpdateSSLBindingRequest() *UpdateSSLBindingRequest {
req := &UpdateSSLBindingRequest{}

// setup request with client config
c.client.SetupRequest(req)

// setup retryable with default retry policy (retry for non-create action and common error)
req.SetRetryable(true)
return req
}

// UpdateSSLBinding - 将VServer绑定的证书更换为另一个证书
func (c *ULBClient) UpdateSSLBinding(req *UpdateSSLBindingRequest) (*UpdateSSLBindingResponse, error) {
var err error
var res UpdateSSLBindingResponse

err = c.client.InvokeAction("UpdateSSLBinding", req, &res)
if err != nil {
return &res, err
}

return &res, nil
}
65 changes: 65 additions & 0 deletions private/services/umem/check_uredis_allowance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//Code is generated by ucloud code generator, don't modify it by hand, it will cause undefined behaviors.
//go:generate ucloud-gen-go-api UMem CheckURedisAllowance

package umem

import (
"github.com/ucloud/ucloud-sdk-go/ucloud/request"
"github.com/ucloud/ucloud-sdk-go/ucloud/response"
)

// CheckURedisAllowanceRequest is request schema for CheckURedisAllowance action
type CheckURedisAllowanceRequest struct {
request.CommonBase

// 可用区。参见 [可用区列表](../summary/regionlist.html)
Zone *string `required:"true"`

// 创建实例的容量大小, 单位:GB 目前仅支持1/2/4/8/16/32六种规格
Size *string `required:"true"`

// 创建实例的数量,[1-10]
Count *int `required:"true"`

//
Protocol *string `required:"false"`

// 是否是跨机房URedis(默认false)
RegionFlag *bool `required:"false"`

//
SlaveZone *string `required:"false"`
}

// CheckURedisAllowanceResponse is response schema for CheckURedisAllowance action
type CheckURedisAllowanceResponse struct {
response.CommonBase

// 可创建的数量
Count int
}

// NewCheckURedisAllowanceRequest will create request of CheckURedisAllowance action.
func (c *UMemClient) NewCheckURedisAllowanceRequest() *CheckURedisAllowanceRequest {
req := &CheckURedisAllowanceRequest{}

// setup request with client config
c.client.SetupRequest(req)

// setup retryable with default retry policy (retry for non-create action and common error)
req.SetRetryable(true)
return req
}

// CheckURedisAllowance - 检查主备Redis的资源是否足够创建新实例
func (c *UMemClient) CheckURedisAllowance(req *CheckURedisAllowanceRequest) (*CheckURedisAllowanceResponse, error) {
var err error
var res CheckURedisAllowanceResponse

err = c.client.InvokeAction("CheckURedisAllowance", req, &res)
if err != nil {
return &res, err
}

return &res, nil
}
1 change: 1 addition & 0 deletions scripts/gofmtcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ if [[ -n ${gofmt_files} ]]; then
fi

exit 0

53 changes: 53 additions & 0 deletions services/ulb/bind_ssl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//Code is generated by ucloud code generator, don't modify it by hand, it will cause undefined behaviors.
//go:generate ucloud-gen-go-api ULB BindSSL

package ulb

import (
"github.com/ucloud/ucloud-sdk-go/ucloud/request"
"github.com/ucloud/ucloud-sdk-go/ucloud/response"
)

// BindSSLRequest is request schema for BindSSL action
type BindSSLRequest struct {
request.CommonBase

// 所绑定ULB实例ID
ULBId *string `required:"true"`

// 所绑定VServer实例ID
VServerId *string `required:"true"`

// SSL证书的Id
SSLId *string `required:"true"`
}

// BindSSLResponse is response schema for BindSSL action
type BindSSLResponse struct {
response.CommonBase
}

// NewBindSSLRequest will create request of BindSSL action.
func (c *ULBClient) NewBindSSLRequest() *BindSSLRequest {
req := &BindSSLRequest{}

// setup request with client config
c.client.SetupRequest(req)

// setup retryable with default retry policy (retry for non-create action and common error)
req.SetRetryable(true)
return req
}

// BindSSL - 将SSL证书绑定到VServer
func (c *ULBClient) BindSSL(req *BindSSLRequest) (*BindSSLResponse, error) {
var err error
var res BindSSLResponse

err = c.client.InvokeAction("BindSSL", req, &res)
if err != nil {
return &res, err
}

return &res, nil
}
Loading

0 comments on commit f18d177

Please sign in to comment.