2020-07-02 01:30:41 +00:00
|
|
|
package x509util
|
|
|
|
|
2020-07-08 01:56:05 +00:00
|
|
|
const (
|
|
|
|
UserKey = "User"
|
|
|
|
SubjectKey = "Subject"
|
|
|
|
SANsKey = "SANs"
|
2020-07-08 22:53:11 +00:00
|
|
|
TokenKey = "Token"
|
2020-07-08 01:56:05 +00:00
|
|
|
)
|
|
|
|
|
2020-07-08 22:53:11 +00:00
|
|
|
// TemplateData is an alias for map[string]interface{}. It represents the data
|
|
|
|
// passed to the templates.
|
|
|
|
type TemplateData map[string]interface{}
|
|
|
|
|
|
|
|
func (t TemplateData) Set(key string, v interface{}) {
|
|
|
|
t[key] = v
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t TemplateData) SetUserData(v Subject) {
|
|
|
|
t[UserKey] = v
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t TemplateData) SetSubject(v Subject) {
|
|
|
|
t[SubjectKey] = v
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t TemplateData) SetSANs(sans []string) {
|
|
|
|
t[SANsKey] = CreateSANs(sans)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t TemplateData) SetToken(v interface{}) {
|
|
|
|
t[TokenKey] = v
|
|
|
|
}
|
|
|
|
|
2020-07-02 01:30:41 +00:00
|
|
|
const DefaultLeafTemplate = `{
|
|
|
|
"subject": {{ toJson .Subject }},
|
2020-07-08 01:56:05 +00:00
|
|
|
"sans": {{ toJson .SANs }},
|
2020-07-02 01:30:41 +00:00
|
|
|
"keyUsage": ["keyEncipherment", "digitalSignature"],
|
|
|
|
"extKeyUsage": ["serverAuth", "clientAuth"]
|
|
|
|
}`
|