Skip to content

Commit

Permalink
Update generate.go
Browse files Browse the repository at this point in the history
Apply suggestion by @jrasell to compose the function off the struct.
  • Loading branch information
lhaig committed Jun 8, 2023
1 parent 47b7fa2 commit 3ca5aa6
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions helper/tlsutil/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,18 @@ type CertOpts struct {
ExtKeyUsage []x509.ExtKeyUsage
}

// Check if any of CAOpts the variables are populated
func AreCARequiredFieldsEmpty(caOpts CAOpts) bool {
return caOpts.Days == 0 &&
caOpts.Country == "" &&
caOpts.PostalCode == "" &&
caOpts.Province == "" &&
caOpts.Locality == "" &&
caOpts.StreetAddress == "" &&
caOpts.Organization == "" &&
caOpts.OrganizationalUnit == "" &&
caOpts.Name == ""
// IsEmpty checks whether any of CAOpts parameters have been populated with
// non-default values.
func (c CAOpts) IsEmpty() bool {
return c.Days == 0 &&
c.Country == "" &&
c.PostalCode == "" &&
c.Province == "" &&
c.Locality == "" &&
c.StreetAddress == "" &&
c.Organization == "" &&
c.OrganizationalUnit == "" &&
c.Name == ""
}

// GenerateCA generates a new CA for agent TLS (not to be confused with Connect TLS)
Expand All @@ -112,9 +113,7 @@ func GenerateCA(opts CAOpts) (string, string, error) {
sn = opts.Serial
)

// Check if opts required fields are empty
isEmpty := AreCARequiredFieldsEmpty(opts)
if isEmpty {
if opts.IsEmpty() {

if signer == nil {
var err error
Expand Down

0 comments on commit 3ca5aa6

Please sign in to comment.