Skip to content

Commit 865d872

Browse files
committed
fix(pfx_enroll): Added a condition to all subject parameters to check for <null> passed by terraform when a field is left empty.
1 parent 9b84660 commit 865d872

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

api/certificate.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -464,24 +464,24 @@ func (c *Client) RecoverCertificate(certId int, thumbprint string, serialNumber
464464
func createSubject(cs CertificateSubject) (string, error) {
465465
var subject string
466466

467-
if cs.SubjectCommonName != "" {
467+
if cs.SubjectCommonName != "" && cs.SubjectCommonName != "<null>" {
468468
subject = "CN=" + cs.SubjectCommonName + ","
469469
} else {
470470
return "", errors.New("build subject: common name required") // Common name is required!
471471
}
472-
if cs.SubjectOrganizationalUnit != "" {
472+
if cs.SubjectOrganizationalUnit != "" && cs.SubjectOrganizationalUnit != "<null>" {
473473
subject += "OU=" + cs.SubjectOrganizationalUnit + ","
474474
}
475-
if cs.SubjectOrganization != "" {
475+
if cs.SubjectOrganization != "" && cs.SubjectOrganization != "<null>" {
476476
subject += "O=" + cs.SubjectOrganization + ","
477477
}
478-
if cs.SubjectLocality != "" {
478+
if cs.SubjectLocality != "" && cs.SubjectLocality != "<null>" {
479479
subject += "L=" + cs.SubjectLocality + ","
480480
}
481-
if cs.SubjectState != "" {
481+
if cs.SubjectState != "" && cs.SubjectState != "<null>" {
482482
subject += "ST=" + cs.SubjectState + ","
483483
}
484-
if cs.SubjectCountry != "" {
484+
if cs.SubjectCountry != "" && cs.SubjectCountry != "<null>" {
485485
subject += "C=" + cs.SubjectCountry + ","
486486
}
487487
subject = strings.TrimRight(subject, ",") // remove trailing comma

0 commit comments

Comments
 (0)