Skip to content

Commit

Permalink
review: move MakeARICertID call
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Nov 11, 2024
1 parent a3873fa commit ede2825
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions cmd/cmd_renew.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,24 @@ func renewForDomains(ctx *cli.Context, client *lego.Client, certsStorage *Certif
cert := certificates[0]

var ariRenewalTime *time.Time
var replacesCertID string

if !ctx.Bool(flgARIDisable) {
ariRenewalTime = getARIRenewalTime(ctx, cert, domain, client)
if ariRenewalTime != nil {
now := time.Now().UTC()

// Figure out if we need to sleep before renewing.
if ariRenewalTime.After(now) {
log.Infof("[%s] Sleeping %s until renewal time %s", domain, ariRenewalTime.Sub(now), ariRenewalTime)
time.Sleep(ariRenewalTime.Sub(now))
}
}

replacesCertID, err = certificate.MakeARICertID(cert)
if err != nil {
log.Fatalf("Error while construction the ARI CertID for domain %s\n\t%v", domain, err)
}
}

if ariRenewalTime == nil && !needRenewal(cert, domain, ctx.Int(flgDays)) {
Expand Down Expand Up @@ -209,11 +217,8 @@ func renewForDomains(ctx *cli.Context, client *lego.Client, certsStorage *Certif
AlwaysDeactivateAuthorizations: ctx.Bool(flgAlwaysDeactivateAuthorizations),
}

if !ctx.Bool(flgARIDisable) {
request.ReplacesCertID, err = certificate.MakeARICertID(cert)
if err != nil {
log.Fatalf("Error while construction the ARI CertID for domain %s\n\t%v", domain, err)
}
if replacesCertID != "" {
request.ReplacesCertID = replacesCertID
}

certRes, err := client.Certificate.Obtain(request)
Expand Down Expand Up @@ -250,16 +255,24 @@ func renewForCSR(ctx *cli.Context, client *lego.Client, certsStorage *Certificat
cert := certificates[0]

var ariRenewalTime *time.Time
var replacesCertID string

if !ctx.Bool(flgARIDisable) {
ariRenewalTime = getARIRenewalTime(ctx, cert, domain, client)
if ariRenewalTime != nil {
now := time.Now().UTC()

// Figure out if we need to sleep before renewing.
if ariRenewalTime.After(now) {
log.Infof("[%s] Sleeping %s until renewal time %s", domain, ariRenewalTime.Sub(now), ariRenewalTime)
time.Sleep(ariRenewalTime.Sub(now))
}
}

replacesCertID, err = certificate.MakeARICertID(cert)
if err != nil {
log.Fatalf("Error while construction the ARI CertID for domain %s\n\t%v", domain, err)
}
}

if ariRenewalTime == nil && !needRenewal(cert, domain, ctx.Int(flgDays)) {
Expand All @@ -279,11 +292,8 @@ func renewForCSR(ctx *cli.Context, client *lego.Client, certsStorage *Certificat
AlwaysDeactivateAuthorizations: ctx.Bool(flgAlwaysDeactivateAuthorizations),
}

if !ctx.Bool(flgARIDisable) {
request.ReplacesCertID, err = certificate.MakeARICertID(cert)
if err != nil {
log.Fatalf("Error while construction the ARI CertID for domain %s\n\t%v", domain, err)
}
if replacesCertID != "" {
request.ReplacesCertID = replacesCertID
}

certRes, err := client.Certificate.ObtainForCSR(request)
Expand Down

0 comments on commit ede2825

Please sign in to comment.