Skip to content

Commit

Permalink
Add AutoSSL and GlobalRegions to load balancers (#350)
Browse files Browse the repository at this point in the history
* add AutoSSL and GlobalRegions struct

* Add delete methods for SSL and AutoSSL

* update json tag
  • Loading branch information
mondragonfx authored Jan 15, 2025
1 parent 272584e commit 7cff7b0
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type LoadBalancerService interface {
Get(ctx context.Context, lbID string) (*LoadBalancer, *http.Response, error)
Update(ctx context.Context, lbID string, updateReq *LoadBalancerReq) error
Delete(ctx context.Context, lbID string) error
DeleteSSL(ctx context.Context, lbID string) error
DeleteAutoSSL(ctx context.Context, lbID string) error
List(ctx context.Context, options *ListOptions) ([]LoadBalancer, *Meta, *http.Response, error)
CreateForwardingRule(ctx context.Context, lbID string, rule *ForwardingRule) (*ForwardingRule, *http.Response, error)
GetForwardingRule(ctx context.Context, lbID string, ruleID string) (*ForwardingRule, *http.Response, error)
Expand Down Expand Up @@ -49,6 +51,7 @@ type LoadBalancer struct {
HTTP3 *bool `json:"http3,omitempty"`
ForwardingRules []ForwardingRule `json:"forwarding_rules,omitempty"`
FirewallRules []LBFirewallRule `json:"firewall_rules,omitempty"`
GlobalRegions []string `json:"global_regions,omitempty"`
}

// LoadBalancerReq gives options for creating or updating a load balancer
Expand All @@ -61,6 +64,7 @@ type LoadBalancerReq struct {
StickySessions *StickySessions `json:"sticky_session,omitempty"`
ForwardingRules []ForwardingRule `json:"forwarding_rules,omitempty"`
SSL *SSL `json:"ssl,omitempty"`
AutoSSL *SSL `json:"auto_ssl,omitempty"`
SSLRedirect *bool `json:"ssl_redirect,omitempty"`
HTTP2 *bool `json:"http2,omitempty"`
HTTP3 *bool `json:"http3,omitempty"`
Expand All @@ -69,6 +73,7 @@ type LoadBalancerReq struct {
FirewallRules []LBFirewallRule `json:"firewall_rules,omitempty"`
Timeout int `json:"timeout,omitempty"`
VPC *string `json:"vpc,omitempty"`
GlobalRegions []string `json:"global_regions,omitempty"`
}

// InstanceList represents instances that are attached to your load balancer
Expand Down Expand Up @@ -348,3 +353,27 @@ func (l *LoadBalancerHandler) ListFirewallRules(ctx context.Context, lbID string

return fwRules.FirewallRules, fwRules.Meta, resp, nil
}

// DeleteSSL removes the SSL configuration from a load balancer subscription.
func (l *LoadBalancerHandler) DeleteSSL(ctx context.Context, lbID string) error {
uri := fmt.Sprintf("%s/%s/ssl", lbPath, lbID)
req, err := l.client.NewRequest(ctx, http.MethodDelete, uri, nil)
if err != nil {
return err
}

_, err = l.client.DoWithContext(ctx, req, nil)
return err
}

// DeleteAutoSSL removes the AutoSSL configuration from a load balancer subscription.
func (l *LoadBalancerHandler) DeleteAutoSSL(ctx context.Context, lbID string) error {
uri := fmt.Sprintf("%s/%s/auto_ssl", lbPath, lbID)
req, err := l.client.NewRequest(ctx, http.MethodDelete, uri, nil)
if err != nil {
return err
}

_, err = l.client.DoWithContext(ctx, req, nil)
return err
}

0 comments on commit 7cff7b0

Please sign in to comment.