-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtls.go
More file actions
69 lines (63 loc) · 2.14 KB
/
tls.go
File metadata and controls
69 lines (63 loc) · 2.14 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
package api
import (
"fmt"
)
type Event = map[string]string
// TLS is the structure of an app's TLS settings.
type TLS struct {
// Owner is the app owner. It cannot be updated with TLS.Set(). See app.Transfer().
Owner string `json:"owner,omitempty"`
// App is the app the tls settings apply to and cannot be updated.
App string `json:"app,omitempty"`
// Created is the time that the TLS settings was created and cannot be updated.
Created string `json:"created,omitempty"`
// Updated is the last time the TLS settings was changed and cannot be updated.
Updated string `json:"updated,omitempty"`
// UUID is a unique string reflecting the TLS settings in its current state.
// It changes every time the TLS settings is changed and cannot be updated.
UUID string `json:"uuid,omitempty"`
//HTTPSEnforced determines if the router should enable or disable https-only requests.
HTTPSEnforced *bool `json:"https_enforced,omitempty"`
//Use ACME to automatically generate certificates if CertsAuto enable
CertsAutoEnabled *bool `json:"certs_auto_enabled,omitempty"`
Issuer *Issuer `json:"issuer,omitempty"`
Events []Event `json:"events,omitempty"`
}
// Issuer is the structure of POST /v2/app/<app id>/tls/.
type Issuer struct {
Email string `json:"email"`
Server string `json:"server"`
KeyID string `json:"key_id"`
KeySecret string `json:"key_secret"`
}
// NewTLS creates a new TLS object with fields properly zeroed
func NewTLS() *TLS {
return &TLS{
HTTPSEnforced: new(bool),
CertsAutoEnabled: new(bool),
}
}
func (t TLS) String() string {
tpl := `--- HTTPS Enforced: %s
--- Certs Auto: %s
--- Issuer: %s`
issuerTpl := `
email: %s
server: %s
key-id: %s
key-secret: %s
`
httpsEnforced := "not set"
if t.HTTPSEnforced != nil {
httpsEnforced = fmt.Sprintf("%t", *(t.HTTPSEnforced))
}
certsAutoEnabled := "not set"
if t.CertsAutoEnabled != nil {
certsAutoEnabled = fmt.Sprintf("%t", *(t.CertsAutoEnabled))
}
issuer := "not set"
if t.Issuer != nil {
issuer = fmt.Sprintf(issuerTpl, t.Issuer.Email, t.Issuer.Server, t.Issuer.KeyID, t.Issuer.KeySecret)
}
return fmt.Sprintf(tpl, httpsEnforced, certsAutoEnabled, issuer)
}