Преглед на файлове

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

Mariano Cano преди 6 години
родител
ревизия
c58117b30d
променени са 1 файла, в които са добавени 12 реда и са изтрити 1 реда
  1. 12 1
      authority/provisioner/options.go

+ 12 - 1
authority/provisioner/options.go

@@ -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
 }