blob: fc2a7128993687d50ad2bb5ab26a979a9fde7338 [file] [log] [blame]
Jamie Hannaford249bb622014-11-07 12:11:26 +01001package ssl
Jamie Hannaford276a0322014-11-06 14:26:12 +01002
3import (
4 "github.com/mitchellh/mapstructure"
Jamie Hannaford249bb622014-11-07 12:11:26 +01005
Jamie Hannaford276a0322014-11-06 14:26:12 +01006 "github.com/rackspace/gophercloud"
Jamie Hannaford249bb622014-11-07 12:11:26 +01007 "github.com/rackspace/gophercloud/pagination"
Jamie Hannaford276a0322014-11-06 14:26:12 +01008)
9
10// SSLTermConfig represents the SSL configuration for a particular load balancer.
11type SSLTermConfig struct {
12 // The port on which the SSL termination load balancer listens for secure
13 // traffic. The value must be unique to the existing LB protocol/port
14 // combination
15 SecurePort int `mapstructure:"securePort"`
16
17 // The private key for the SSL certificate which is validated and verified
18 // against the provided certificates.
19 PrivateKey string `mapstructure:"privatekey"`
20
21 // The certificate used for SSL termination, which is validated and verified
22 // against the key and intermediate certificate if provided.
23 Certificate string
24
25 // The intermediate certificate (for the user). The intermediate certificate
26 // is validated and verified against the key and certificate credentials
27 // provided. A user may only provide this value when accompanied by a
28 // Certificate, PrivateKey, and SecurePort. It may not be added or updated as
29 // a single attribute in a future operation.
30 IntCertificate string `mapstructure:"intermediatecertificate"`
31
32 // Determines if the load balancer is enabled to terminate SSL traffic or not.
33 // If this is set to false, the load balancer retains its specified SSL
34 // attributes but does not terminate SSL traffic.
35 Enabled bool
36
37 // Determines if the load balancer can only accept secure traffic. If set to
38 // true, the load balancer will not accept non-secure traffic.
39 SecureTrafficOnly bool
40}
41
42// DeleteResult represents the result of a delete operation.
43type DeleteResult struct {
44 gophercloud.ErrResult
45}
46
47// UpdateResult represents the result of an update operation.
48type UpdateResult struct {
49 gophercloud.ErrResult
50}
51
52// GetResult represents the result of a get operation.
53type GetResult struct {
54 gophercloud.Result
55}
56
57// Extract interprets a GetResult as a SSLTermConfig struct, if possible.
58func (r GetResult) Extract() (*SSLTermConfig, error) {
59 if r.Err != nil {
60 return nil, r.Err
61 }
62
63 var response struct {
64 SSL SSLTermConfig `mapstructure:"sslTermination"`
65 }
66
67 err := mapstructure.Decode(r.Body, &response)
68
69 return &response.SSL, err
70}
Jamie Hannaford249bb622014-11-07 12:11:26 +010071
72type CertificateMapping struct {
73 ID int
74 HostName string
75 Certificate string
76 IntCertificate string `mapstructure:"intermediateCertificate"`
77}
78
79type CertMappingPage struct {
80 pagination.LinkedPageBase
81}
82
83// IsEmpty checks whether a CertMappingPage struct is empty.
84func (p CertMappingPage) IsEmpty() (bool, error) {
85 is, err := ExtractCertMappings(p)
86 if err != nil {
87 return true, nil
88 }
89 return len(is) == 0, nil
90}
91
92// ExtractCertMappings accepts a Page struct, specifically a CertMappingPage struct, and extracts
93// the elements into a slice of CertMapping structs. In other words, a generic
94// collection is mapped into a relevant slice.
95func ExtractCertMappings(page pagination.Page) ([]CertificateMapping, error) {
96 type NestedMap struct {
97 CertMap CertificateMapping `mapstructure:"certificateMapping" json:"certificateMapping"`
98 }
99 var resp struct {
100 CertMappings []NestedMap `mapstructure:"certificateMappings" json:"certificateMappings"`
101 }
102
103 err := mapstructure.Decode(page.(CertMappingPage).Body, &resp)
104
105 slice := []CertificateMapping{}
106
107 for _, cert := range resp.CertMappings {
108 slice = append(slice, cert.CertMap)
109 }
110
111 return slice, err
112}
113
Jamie Hannafordcba541e2014-11-07 13:36:54 +0100114type certResult struct {
Jamie Hannaford249bb622014-11-07 12:11:26 +0100115 gophercloud.Result
116}
117
118// Extract interprets a result as a CertMapping struct, if possible.
Jamie Hannafordcba541e2014-11-07 13:36:54 +0100119func (r certResult) Extract() (*CertificateMapping, error) {
Jamie Hannaford249bb622014-11-07 12:11:26 +0100120 if r.Err != nil {
121 return nil, r.Err
122 }
123
124 var response struct {
125 CertMapping CertificateMapping `mapstructure:"certificateMapping"`
126 }
127
128 err := mapstructure.Decode(r.Body, &response)
129
130 return &response.CertMapping, err
131}
Jamie Hannafordcba541e2014-11-07 13:36:54 +0100132
133type CreateCertMappingResult struct {
134 certResult
135}
136
137type GetCertMappingResult struct {
138 certResult
139}
140
141type UpdateCertMappingResult struct {
142 certResult
143}