From 5a04e3b36d43563098c0792843f4843eaddd7fa6 Mon Sep 17 00:00:00 2001 From: Mariano Cano Date: Wed, 8 Jul 2020 15:53:11 -0700 Subject: [PATCH] Add methods to add data to the template data. --- x509util/options.go | 4 ---- x509util/templates.go | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/x509util/options.go b/x509util/options.go index f82e9de9..2915110e 100644 --- a/x509util/options.go +++ b/x509util/options.go @@ -24,10 +24,6 @@ func (o *Options) apply(opts []Option) (*Options, error) { return o, nil } -// TemplateData is an alias for map[string]interface{}. It represents the data -// passed to the templates. -type TemplateData map[string]interface{} - // Option is the type used as a variadic argument in NewCertificate. type Option func(o *Options) error diff --git a/x509util/templates.go b/x509util/templates.go index e0fa87c5..fe2f3386 100644 --- a/x509util/templates.go +++ b/x509util/templates.go @@ -4,8 +4,33 @@ const ( UserKey = "User" SubjectKey = "Subject" SANsKey = "SANs" + TokenKey = "Token" ) +// 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 +} + const DefaultLeafTemplate = `{ "subject": {{ toJson .Subject }}, "sans": {{ toJson .SANs }},