Allow to use base64 when defining a template in the ca.json.

This commit is contained in:
Mariano Cano 2020-07-14 17:13:06 -07:00
parent b2ca3176f5
commit c58117b30d

View file

@ -2,6 +2,7 @@ package provisioner
import (
"encoding/json"
"strings"
"github.com/pkg/errors"
"github.com/smallstep/certificates/x509util"
@ -84,8 +85,18 @@ func CustomTemplateOptions(o *ProvisionerOptions, data x509util.TemplateData, de
x509util.WithTemplateFile(o.TemplateFile, data),
}
}
// Load a template from the Template fields
// 1. As a JSON in a string.
template := strings.TrimSpace(o.Template)
if strings.HasPrefix(template, "{") {
return []x509util.Option{
x509util.WithTemplate(template, data),
}
}
// 2. As a base64 encoded JSON.
return []x509util.Option{
x509util.WithTemplate(o.Template, data),
x509util.WithTemplateBase64(template, data),
}
}), nil
}