cli/renew: skip random sleep if stdout is a terminal (#1659)

This commit is contained in:
Dominik Menke 2022-06-17 11:15:20 +02:00 committed by GitHub
commit 3e9e6ac847
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 6 deletions

View file

@ -4,12 +4,14 @@ import (
"crypto"
"crypto/x509"
"math/rand"
"os"
"time"
"github.com/go-acme/lego/v4/certcrypto"
"github.com/go-acme/lego/v4/certificate"
"github.com/go-acme/lego/v4/lego"
"github.com/go-acme/lego/v4/log"
"github.com/mattn/go-isatty"
"github.com/urfave/cli/v2"
)
@ -137,8 +139,9 @@ func renewForDomains(ctx *cli.Context, client *lego.Client, certsStorage *Certif
}
}
if !ctx.Bool("no-random-sleep") {
// https://github.com/go-acme/lego/issues/1656
// https://github.com/go-acme/lego/issues/1656
// https://github.com/certbot/certbot/blob/284023a1b7672be2bd4018dd7623b3b92197d4b0/certbot/certbot/_internal/renewal.py#L435-L440
if !isatty.IsTerminal(os.Stdout.Fd()) && !ctx.Bool("no-random-sleep") {
// https://github.com/certbot/certbot/blob/284023a1b7672be2bd4018dd7623b3b92197d4b0/certbot/certbot/_internal/renewal.py#L472
const jitter = 8 * time.Minute
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))