Skip to content

Commit d5a8cd4

Browse files
committed
cli/command/trust: use lazyregexp to compile regexes on first use
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 01d8642 commit d5a8cd4

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

cli/command/trust/key_generate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8-
"regexp"
98
"strings"
109

1110
"github.com/docker/cli/cli"
1211
"github.com/docker/cli/cli/command"
1312
"github.com/docker/cli/cli/trust"
13+
"github.com/docker/cli/internal/lazyregexp"
1414
"github.com/pkg/errors"
1515
"github.com/spf13/cobra"
1616
"github.com/theupdateframework/notary"
@@ -41,7 +41,7 @@ func newKeyGenerateCommand(dockerCli command.Streams) *cobra.Command {
4141
}
4242

4343
// key names can use lowercase alphanumeric + _ + - characters
44-
var validKeyName = regexp.MustCompile(`^[a-z0-9][a-z0-9\_\-]*$`).MatchString
44+
var validKeyName = lazyregexp.New(`^[a-z0-9][a-z0-9\_\-]*$`).MatchString
4545

4646
// validate that all of the key names are unique and are alphanumeric + _ + -
4747
// and that we do not already have public key files in the target dir on disk

cli/command/trust/signer_add.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import (
66
"io"
77
"os"
88
"path"
9-
"regexp"
109
"strings"
1110

1211
"github.com/docker/cli/cli"
1312
"github.com/docker/cli/cli/command"
1413
"github.com/docker/cli/cli/command/image"
1514
"github.com/docker/cli/cli/trust"
15+
"github.com/docker/cli/internal/lazyregexp"
1616
"github.com/docker/cli/opts"
1717
"github.com/pkg/errors"
1818
"github.com/spf13/cobra"
@@ -45,7 +45,7 @@ func newSignerAddCommand(dockerCLI command.Cli) *cobra.Command {
4545
return cmd
4646
}
4747

48-
var validSignerName = regexp.MustCompile(`^[a-z0-9][a-z0-9\_\-]*$`).MatchString
48+
var validSignerName = lazyregexp.New(`^[a-z0-9][a-z0-9\_\-]*$`).MatchString
4949

5050
func addSigner(ctx context.Context, dockerCLI command.Cli, options signerAddOptions) error {
5151
signerName := options.signer

0 commit comments

Comments
 (0)