Skip to content

Commit 37b8468

Browse files
committed
feat(certs-auto): add certs-auto support
1 parent 126670a commit 37b8468

2 files changed

Lines changed: 30 additions & 28 deletions

File tree

api/tls.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,20 @@ type TLS struct {
1919
UUID string `json:"uuid,omitempty"`
2020
//HTTPSEnforced determines if the router should enable or disable https-only requests.
2121
HTTPSEnforced *bool `json:"https_enforced,omitempty"`
22+
//Use ACME to automatically generate certificates if CertsAuto enable
23+
CertsAutoEnabled *bool `json:"certs_auto_enabled,omitempty"`
2224
}
2325

2426
// NewTLS creates a new TLS object with fields properly zeroed
2527
func NewTLS() *TLS {
2628
return &TLS{
27-
HTTPSEnforced: new(bool),
29+
HTTPSEnforced: new(bool),
30+
CertsAutoEnabled: new(bool),
2831
}
2932
}
3033

3134
func (t TLS) String() string {
32-
if t.HTTPSEnforced != nil {
33-
return fmt.Sprintf("HTTPS Enforced: %t", *t.HTTPSEnforced)
34-
}
35-
return "HTTPS Enforced: not set"
35+
tpl := `HTTPSEnforced: %d
36+
CertsAutoEnabled: %s`
37+
return fmt.Sprintf(tpl, *(t.HTTPSEnforced) == true, *(t.CertsAutoEnabled) == true)
3638
}

tls/tls.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ func Info(c *drycc.Client, app string) (api.TLS, error) {
2727
return tls, reqErr
2828
}
2929

30-
// Enable enables the router to enforce https-only requests to the application.
31-
func Enable(c *drycc.Client, app string) (api.TLS, error) {
30+
// changeTLS enables the router to enforce https-only requests to the application.
31+
func changeTLS(c *drycc.Client, app string, httpsEnforced, certsAutoEnabled *bool) (api.TLS, error) {
3232
t := api.NewTLS()
33-
b := true
34-
t.HTTPSEnforced = &b
33+
t.HTTPSEnforced = httpsEnforced
34+
t.CertsAutoEnabled = certsAutoEnabled
3535
body, err := json.Marshal(t)
3636

3737
if err != nil {
@@ -54,26 +54,26 @@ func Enable(c *drycc.Client, app string) (api.TLS, error) {
5454
return newTLS, reqErr
5555
}
5656

57-
// Disable disables the router from enforcing https-only requests to the application.
58-
func Disable(c *drycc.Client, app string) (api.TLS, error) {
59-
body, err := json.Marshal(api.NewTLS())
60-
61-
if err != nil {
62-
return api.TLS{}, err
63-
}
64-
65-
u := fmt.Sprintf("/v2/apps/%s/tls/", app)
57+
// EnableHTTPSEnforced enables the router to enforce https-only requests to the application.
58+
func EnableHTTPSEnforced(c *drycc.Client, app string) (api.TLS, error) {
59+
b := true
60+
return changeTLS(c, app, &b, nil)
61+
}
6662

67-
res, reqErr := c.Request("POST", u, body)
68-
if reqErr != nil {
69-
return api.TLS{}, reqErr
70-
}
71-
defer res.Body.Close()
63+
// DisableHTTPSEnforced disables the router from enforcing https-only requests to the application.
64+
func DisableHTTPSEnforced(c *drycc.Client, app string) (api.TLS, error) {
65+
b := false
66+
return changeTLS(c, app, &b, nil)
67+
}
7268

73-
newTLS := api.TLS{}
74-
if err = json.NewDecoder(res.Body).Decode(&newTLS); err != nil {
75-
return api.TLS{}, err
76-
}
69+
// EnableCertsAutoEnabled enables ACME to automatically generate certificates.
70+
func EnableCertsAutoEnabled(c *drycc.Client, app string) (api.TLS, error) {
71+
b := true
72+
return changeTLS(c, app, nil, &b)
73+
}
7774

78-
return newTLS, reqErr
75+
// DisableCertsAutoEnabled disables ACME to automatically generate certificates.
76+
func DisableCertsAutoEnabled(c *drycc.Client, app string) (api.TLS, error) {
77+
b := false
78+
return changeTLS(c, app, nil, &b)
7979
}

0 commit comments

Comments
 (0)