-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtls.go
More file actions
79 lines (61 loc) · 1.66 KB
/
tls.go
File metadata and controls
79 lines (61 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Package tls provides methods for managing tls configuration for apps.
package tls
import (
"encoding/json"
"fmt"
deis "github.com/deis/controller-sdk-go"
"github.com/deis/controller-sdk-go/api"
)
// Info displays an app's tls config.
func Info(c *deis.Client, app string) (api.TLS, error) {
u := fmt.Sprintf("/v2/apps/%s/tls/", app)
res, reqErr := c.Request("GET", u, nil)
if reqErr != nil {
return api.TLS{}, reqErr
}
defer res.Body.Close()
tls := api.TLS{}
if err := json.NewDecoder(res.Body).Decode(&tls); err != nil {
return api.TLS{}, err
}
return tls, reqErr
}
// Enable enables the router to enforce https-only requests to the application.
func Enable(c *deis.Client, app string) (api.TLS, error) {
t := api.NewTLS()
b := true
t.HTTPSEnforced = &b
body, err := json.Marshal(t)
if err != nil {
return api.TLS{}, err
}
u := fmt.Sprintf("/v2/apps/%s/tls/", app)
res, reqErr := c.Request("POST", u, body)
if reqErr != nil {
return api.TLS{}, reqErr
}
defer res.Body.Close()
newTLS := api.TLS{}
if err = json.NewDecoder(res.Body).Decode(&newTLS); err != nil {
return api.TLS{}, err
}
return newTLS, reqErr
}
// Disable disables the router from enforcing https-only requests to the application.
func Disable(c *deis.Client, app string) (api.TLS, error) {
body, err := json.Marshal(api.NewTLS())
if err != nil {
return api.TLS{}, err
}
u := fmt.Sprintf("/v2/apps/%s/tls/", app)
res, reqErr := c.Request("POST", u, body)
if reqErr != nil {
return api.TLS{}, reqErr
}
defer res.Body.Close()
newTLS := api.TLS{}
if err = json.NewDecoder(res.Body).Decode(&newTLS); err != nil {
return api.TLS{}, err
}
return newTLS, reqErr
}