Skip to content

Commit

Permalink
lb allow label + ssl in create
Browse files Browse the repository at this point in the history
  • Loading branch information
ddymko committed Mar 10, 2020
1 parent d493cc5 commit 8271c02
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
17 changes: 15 additions & 2 deletions load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type LoadBalancerService interface {
CreateForwardingRule(ctx context.Context, ID int, rule *ForwardingRule) (*ForwardingRule, error)
GetFullConfig(ctx context.Context, ID int) (*LBConfig, error)
HasSSL(ctx context.Context, ID int) (*struct{ SSLInfo bool `json:"has_ssl"` }, error)
Create(ctx context.Context, region int, genericInfo *GenericInfo, healthCheck *HealthCheck, rules []ForwardingRule) (*LoadBalancers, error)
Create(ctx context.Context, region int, label string, genericInfo *GenericInfo, healthCheck *HealthCheck, rules []ForwardingRule, ssl *SSL) (*LoadBalancers, error)
UpdateGenericInfo(ctx context.Context, ID int, label string, genericInfo *GenericInfo) error
AddSSL(ctx context.Context, ID int, ssl *SSL) error
RemoveSSL(ctx context.Context, ID int) error
Expand Down Expand Up @@ -451,13 +451,17 @@ func (l *LoadBalancerHandler) HasSSL(ctx context.Context, ID int) (*struct{ SSLI
}

// Create a load balancer
func (l *LoadBalancerHandler) Create(ctx context.Context, region int, genericInfo *GenericInfo, healthCheck *HealthCheck, rules []ForwardingRule) (*LoadBalancers, error) {
func (l *LoadBalancerHandler) Create(ctx context.Context, region int, label string, genericInfo *GenericInfo, healthCheck *HealthCheck, rules []ForwardingRule, ssl *SSL) (*LoadBalancers, error) {
uri := "/v1/loadbalancer/create"

values := url.Values{
"DCID": {strconv.Itoa(region)},
}

if label != "" {
values.Add("label", label)
}

// Check generic info struct
if genericInfo != nil {
if *genericInfo.SSLRedirect == true {
Expand Down Expand Up @@ -489,6 +493,15 @@ func (l *LoadBalancerHandler) Create(ctx context.Context, region int, genericInf
values.Add("forwarding_rules", string(t))
}

if ssl != nil {
values.Add("ssl_private_key", ssl.PrivateKey)
values.Add("ssl_certificate", ssl.Certificate)

if ssl.Chain != "" {
values.Add("ssl_chain", ssl.Chain)
}
}

req, err := l.client.NewRequest(ctx, http.MethodPost, uri, values)
if err != nil {
return nil, err
Expand Down
17 changes: 11 additions & 6 deletions load_balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,20 @@ func TestLoadBalancerHandler_Create(t *testing.T) {

rules := []ForwardingRule{
{
FrontendProtocol: "http",
FrontendProtocol: "https",
FrontendPort: 80,
BackendProtocol: "http",
BackendPort: 80,
},
}

lb, err := client.LoadBalancer.Create(ctx, 1, &info, &health, rules)
ssl := SSL{
PrivateKey: "key",
Certificate: "cert",
Chain: "chain",
}

lb, err := client.LoadBalancer.Create(ctx, 1, "label", &info, &health, rules, &ssl)
if err != nil {
t.Errorf("LoadBalancer.Create returned %+v", err)
}
Expand Down Expand Up @@ -422,15 +428,14 @@ func TestLoadBalancerHandler_UpdateGenericInfo(t *testing.T) {
}
}

func TestLoadBalancerHandler_AddSSL (t *testing.T) {
func TestLoadBalancerHandler_AddSSL(t *testing.T) {
setup()
defer teardown()

mux.HandleFunc("/v1/loadbalancer/ssl_add", func(writer http.ResponseWriter, request *http.Request) {
fmt.Fprint(writer)
})


ssl := &SSL{
PrivateKey: "key",
Certificate: "crt",
Expand All @@ -443,7 +448,7 @@ func TestLoadBalancerHandler_AddSSL (t *testing.T) {
}
}

func TestLoadBalancerHandler_RemoveSSL (t *testing.T) {
func TestLoadBalancerHandler_RemoveSSL(t *testing.T) {
setup()
defer teardown()

Expand All @@ -456,4 +461,4 @@ func TestLoadBalancerHandler_RemoveSSL (t *testing.T) {
if err != nil {
t.Errorf("LoadBalancer.RemoveSSL returned %+v", err)
}
}
}

0 comments on commit 8271c02

Please sign in to comment.