Fixes and adding operations for cert mappings
diff --git a/rackspace/lb/v1/ssl/requests.go b/rackspace/lb/v1/ssl/requests.go
index d66cae3..5c5cb1b 100644
--- a/rackspace/lb/v1/ssl/requests.go
+++ b/rackspace/lb/v1/ssl/requests.go
@@ -1,4 +1,4 @@
-package throttle
+package ssl
import (
"errors"
@@ -6,6 +6,7 @@
"github.com/racker/perigee"
"github.com/rackspace/gophercloud"
+ "github.com/rackspace/gophercloud/pagination"
)
// UpdateOptsBuilder is the interface options structs have to satisfy in order
@@ -36,6 +37,12 @@
SecureTrafficOnly *bool
}
+var (
+ errPrivateKey = errors.New("PrivateKey is a required field")
+ errCertificate = errors.New("Certificate is a required field")
+ errIntCertificate = errors.New("IntCertificate is a required field")
+)
+
// ToSSLUpdateMap casts a CreateOpts struct to a map.
func (opts UpdateOpts) ToSSLUpdateMap() (map[string]interface{}, error) {
ssl := make(map[string]interface{})
@@ -44,19 +51,19 @@
return ssl, errors.New("SecurePort needs to be an integer greater than 0")
}
if opts.PrivateKey == "" {
- return ssl, errors.New("PrivateKey is a required field")
+ return ssl, errPrivateKey
}
if opts.Certificate == "" {
- return ssl, errors.New("Certificate is a required field")
+ return ssl, errCertificate
}
if opts.IntCertificate == "" {
- return ssl, errors.New("IntCertificate is a required field")
+ return ssl, errIntCertificate
}
ssl["securePort"] = opts.SecurePort
ssl["privateKey"] = opts.PrivateKey
ssl["certificate"] = opts.Certificate
- ssl["intermediatecertificate"] = opts.IntCertificate
+ ssl["intermediateCertificate"] = opts.IntCertificate
if opts.Enabled != nil {
ssl["enabled"] = &opts.Enabled
@@ -116,3 +123,64 @@
return res
}
+
+func ListCertMappings(c *gophercloud.ServiceClient, lbID int) pagination.Pager {
+ url := certURL(c, lbID)
+ return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
+ return CertMappingPage{pagination.LinkedPageBase{PageResult: r}}
+ })
+}
+
+type CertMappingCreateOptsBuilder interface {
+ ToCertMappingCreateMap() (map[string]interface{}, error)
+}
+
+type CertMappingCreateOpts struct {
+ HostName string
+ PrivateKey string
+ Certificate string
+ IntCertificate string
+}
+
+func (opts CertMappingCreateOpts) ToCertMappingCreateMap() (map[string]interface{}, error) {
+ cm := make(map[string]interface{})
+
+ if opts.HostName == "" {
+ return cm, errors.New("HostName is a required option")
+ }
+ if opts.PrivateKey == "" {
+ return cm, errPrivateKey
+ }
+ if opts.Certificate == "" {
+ return cm, errCertificate
+ }
+
+ cm["hostName"] = opts.HostName
+ cm["privateKey"] = opts.PrivateKey
+ cm["certificate"] = opts.Certificate
+
+ if opts.IntCertificate != "" {
+ cm["intermediateCertificate"] = opts.IntCertificate
+ }
+
+ return map[string]interface{}{"certificateMapping": cm}, nil
+}
+
+func AddCertMapping(c *gophercloud.ServiceClient, lbID int, opts CertMappingCreateOptsBuilder) CreateCertMappingResult {
+ var res CreateCertMappingResult
+
+ reqBody, err := opts.ToCertMappingCreateMap()
+ if err != nil {
+ res.Err = err
+ return res
+ }
+
+ _, res.Err = perigee.Request("POST", certURL(c, lbID), perigee.Options{
+ MoreHeaders: c.AuthenticatedHeaders(),
+ ReqBody: &reqBody,
+ Results: &res.Body,
+ OkCodes: []int{200},
+ })
+
+ return res
+}