mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-08 00:22:14 +01:00
Apply suggestions from code review
Co-authored-by: Julien Neuhart <j.neuhart@thecodingmachine.com>
This commit is contained in:
@@ -58,9 +58,11 @@ The hard limit is 100 MB and is defined by Google Chrome itself.
|
||||
> The default Google Chrome rpcc buffer size may also be overridden per request thanks to the form field `googleChromeRpccBufferSize`.
|
||||
> See the [rpcc buffer size section](#html.rpcc_buffer_size).
|
||||
|
||||
## Ignore certificate errors
|
||||
## Google Chrome ignore certificate errors
|
||||
|
||||
By default Chrome will not accept certificate errors when using the URL print method. Setting this environment variable to `"1"` will allow insecure connections to be used. In dev environment for example. Be careful with this! Do not use in production.
|
||||
When performing a [URL](#url) conversion, Google Chrome will not accept certificate errors .
|
||||
|
||||
You may allow insecure connections by setting `GOOGLE_CHROME_IGNORE_CERTIFICATE_ERRORS` variable to `"1"`. **You should be careful with this feature and only enable it in your development environment.**
|
||||
|
||||
## Disable LibreOffice (unoconv)
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ func main() {
|
||||
systemLogger.DebugOpf(op, "configuration: %+v", config)
|
||||
if !config.DisableGoogleChrome() {
|
||||
// start Google Chrome headless.
|
||||
if err := chrome.Start(systemLogger, config.IgnoreCertificateErrors()); err != nil {
|
||||
if err := chrome.Start(systemLogger, config.GoogleChromeIgnoreCertificateErrors()); err != nil {
|
||||
systemLogger.FatalOp(op, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,11 +16,11 @@ import (
|
||||
)
|
||||
|
||||
// Start starts Google Chrome headless in background.
|
||||
func Start(logger xlog.Logger, urlIgnoreCertificateErrors bool) error {
|
||||
func Start(logger xlog.Logger, ignoreCertificateErrors bool) error {
|
||||
const op string = "chrome.Start"
|
||||
logger.DebugOp(op, "starting new Google Chrome headless process on port 9222...")
|
||||
resolver := func() error {
|
||||
cmd, err := cmd(logger, urlIgnoreCertificateErrors)
|
||||
cmd, err := cmd(logger, ignoreCertificateErrors)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -32,7 +32,7 @@ func Start(logger xlog.Logger, urlIgnoreCertificateErrors bool) error {
|
||||
// if the process failed to start correctly,
|
||||
// we have to restart it.
|
||||
if !isViable(logger) {
|
||||
return restart(logger, cmd.Process, urlIgnoreCertificateErrors)
|
||||
return restart(logger, cmd.Process, ignoreCertificateErrors)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -42,7 +42,7 @@ func Start(logger xlog.Logger, urlIgnoreCertificateErrors bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func cmd(logger xlog.Logger, urlIgnoreCertificateErrors bool) (*exec.Cmd, error) {
|
||||
func cmd(logger xlog.Logger, ignoreCertificateErrors bool) (*exec.Cmd, error) {
|
||||
const op string = "chrome.cmd"
|
||||
binary := "google-chrome-stable"
|
||||
args := []string{
|
||||
@@ -67,7 +67,7 @@ func cmd(logger xlog.Logger, urlIgnoreCertificateErrors bool) (*exec.Cmd, error)
|
||||
"--no-first-run",
|
||||
}
|
||||
|
||||
if urlIgnoreCertificateErrors {
|
||||
if ignoreCertificateErrors {
|
||||
args = append(args, "--ignore-certificate-errors")
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ func kill(logger xlog.Logger, proc *os.Process) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func restart(logger xlog.Logger, proc *os.Process, urlIgnoreCertificateErrors bool) error {
|
||||
func restart(logger xlog.Logger, proc *os.Process, ignoreCertificateErrors bool) error {
|
||||
const op string = "chrome.restart"
|
||||
logger.DebugOp(op, "restarting Google Chrome headless process using port 9222...")
|
||||
resolver := func() error {
|
||||
@@ -106,7 +106,7 @@ func restart(logger xlog.Logger, proc *os.Process, urlIgnoreCertificateErrors bo
|
||||
if err := kill(logger, proc); err != nil {
|
||||
return err
|
||||
}
|
||||
cmd, err := cmd(logger, urlIgnoreCertificateErrors)
|
||||
cmd, err := cmd(logger, ignoreCertificateErrors)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -118,7 +118,7 @@ func restart(logger xlog.Logger, proc *os.Process, urlIgnoreCertificateErrors bo
|
||||
// if the process failed to restart correctly,
|
||||
// we have to restart it again.
|
||||
if !isViable(logger) {
|
||||
return restart(logger, cmd.Process, urlIgnoreCertificateErrors)
|
||||
return restart(logger, cmd.Process, ignoreCertificateErrors)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -40,8 +40,9 @@ const (
|
||||
// DefaultGoogleChromeRpccBufferSizeEnvVar contains the name
|
||||
// of the environment variable "DEFAULT_GOOGLE_CHROME_RPCC_BUFFER_SIZE".
|
||||
DefaultGoogleChromeRpccBufferSizeEnvVar string = "DEFAULT_GOOGLE_CHROME_RPCC_BUFFER_SIZE"
|
||||
// Allow self signed certificates when using a remote url
|
||||
URLIgnoreCertificateErrorsEnvVar string = "URL_IGNORE_CERTIFICATE_ERRORS"
|
||||
// GoogleChromeIgnoreCertificateErrorsEnvVar contains the name
|
||||
// of the environment variable "GOOGLE_CHROME_IGNORE_CERTIFICATE_ERRORS".
|
||||
GoogleChromeIgnoreCertificateErrorsEnvVar string = "GOOGLE_CHROME_IGNORE_CERTIFICATE_ERRORS"
|
||||
)
|
||||
|
||||
// Config contains the application
|
||||
@@ -55,7 +56,7 @@ type Config struct {
|
||||
defaultListenPort int64
|
||||
disableGoogleChrome bool
|
||||
disableUnoconv bool
|
||||
urlIgnoreCertificateErrors bool
|
||||
googleChromeIgnoreCertificateErrors bool
|
||||
logLevel xlog.Level
|
||||
rootPath string
|
||||
maximumGoogleChromeRpccBufferSize int64
|
||||
@@ -78,7 +79,7 @@ func DefaultConfig() Config {
|
||||
rootPath: "/",
|
||||
maximumGoogleChromeRpccBufferSize: 104857600, // ~100 MB
|
||||
defaultGoogleChromeRpccBufferSize: 1048576, // 1 MB
|
||||
urlIgnoreCertificateErrors: false,
|
||||
googleChromeIgnoreCertificateErrors: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,11 +193,11 @@ func FromEnv() (Config, error) {
|
||||
if err != nil {
|
||||
return c, err
|
||||
}
|
||||
urlIgnoreCertificateErrors, err := xassert.BoolFromEnv(
|
||||
URLIgnoreCertificateErrorsEnvVar,
|
||||
c.urlIgnoreCertificateErrors,
|
||||
googleChromeIgnoreCertificateErrors, err := xassert.BoolFromEnv(
|
||||
GoogleChromeIgnoreCertificateErrorsEnvVar,
|
||||
c.googleChromeIgnoreCertificateErrors,
|
||||
)
|
||||
c.urlIgnoreCertificateErrors = urlIgnoreCertificateErrors
|
||||
c.googleChromeIgnoreCertificateErrors = googleChromeIgnoreCertificateErrors
|
||||
if err != nil {
|
||||
return c, err
|
||||
}
|
||||
@@ -287,9 +288,6 @@ func (c Config) DefaultGoogleChromeRpccBufferSize() int64 {
|
||||
return c.defaultGoogleChromeRpccBufferSize
|
||||
}
|
||||
|
||||
// IgnoreCertificateErrors returns true if
|
||||
// Google Chrome should ignore certificate errors
|
||||
// in case of self signed certificates for example.
|
||||
func (c Config) IgnoreCertificateErrors() bool {
|
||||
func (c Config) GoogleChromeIgnoreCertificateErrors() bool {
|
||||
return c.urlIgnoreCertificateErrors
|
||||
}
|
||||
|
||||
@@ -380,38 +380,38 @@ func TestDefaultGoogleChromeRpccBufferSizeFromEnv(t *testing.T) {
|
||||
os.Unsetenv(DefaultGoogleChromeRpccBufferSizeEnvVar)
|
||||
}
|
||||
|
||||
func TestIgnoreCertificateErrorsFromEnv(t *testing.T) {
|
||||
func TestGoogleChromeIgnoreCertificateErrorsFromEnv(t *testing.T) {
|
||||
var (
|
||||
expected Config
|
||||
result Config
|
||||
err error
|
||||
)
|
||||
// URL_IGNORE_CERTIFICATE_ERRORS correctly set to true.
|
||||
os.Setenv(URLIgnoreCertificateErrorsEnvVar, "1")
|
||||
// GOOGLE_CHROME_IGNORE_CERTIFICATE_ERRORS correctly set to true.
|
||||
os.Setenv(GoogleChromeIgnoreCertificateErrorsEnvVar, "1")
|
||||
expected = DefaultConfig()
|
||||
expected.urlIgnoreCertificateErrors = true
|
||||
expected.googleChromeIgnoreCertificateErrors = true
|
||||
result, err = FromEnv()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, expected, result)
|
||||
os.Unsetenv(URLIgnoreCertificateErrorsEnvVar)
|
||||
// URL_IGNORE_CERTIFICATE_ERRORS correctly set to false.
|
||||
os.Setenv(URLIgnoreCertificateErrorsEnvVar, "0")
|
||||
os.Unsetenv(GoogleChromeIgnoreCertificateErrorsEnvVar)
|
||||
// GOOGLE_CHROME_IGNORE_CERTIFICATE_ERRORS correctly set to false.
|
||||
os.Setenv(GooleChromeIgnoreCertificateErrorsEnvVar, "0")
|
||||
expected = DefaultConfig()
|
||||
expected.urlIgnoreCertificateErrors = false
|
||||
expected.googleChromeIgnoreCertificateErrors = false
|
||||
result, err = FromEnv()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, expected, result)
|
||||
os.Unsetenv(URLIgnoreCertificateErrorsEnvVar)
|
||||
// URL_IGNORE_CERTIFICATE_ERRORS wrongly set.
|
||||
os.Setenv(URLIgnoreCertificateErrorsEnvVar, "foo")
|
||||
os.Unsetenv(GoogleChromeIgnoreCertificateErrorsEnvVar)
|
||||
// GOOGLE_CHROME_IGNORE_CERTIFICATE_ERRORS wrongly set.
|
||||
os.Setenv(GoogleChromeIgnoreCertificateErrorsEnvVar, "foo")
|
||||
expected = DefaultConfig()
|
||||
result, err = FromEnv()
|
||||
test.AssertError(t, err)
|
||||
assert.Equal(t, expected, result)
|
||||
os.Unsetenv(URLIgnoreCertificateErrorsEnvVar)
|
||||
// URL_IGNORE_CERTIFICATE_ERRORS not set at all.
|
||||
os.Unsetenv(GoogleChromeIgnoreCertificateErrorsEnvVar)
|
||||
// GOOGLE_CHROME_IGNORE_CERTIFICATE_ERRORS not set at all.
|
||||
expected = DefaultConfig()
|
||||
expected.urlIgnoreCertificateErrors = false
|
||||
expected.googleChromeIgnoreCertificateErrors = false
|
||||
result, err = FromEnv()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, expected, result)
|
||||
@@ -431,5 +431,5 @@ func TestGetters(t *testing.T) {
|
||||
assert.Equal(t, result.rootPath, result.RootPath())
|
||||
assert.Equal(t, result.maximumGoogleChromeRpccBufferSize, result.MaximumGoogleChromeRpccBufferSize())
|
||||
assert.Equal(t, result.defaultGoogleChromeRpccBufferSize, result.DefaultGoogleChromeRpccBufferSize())
|
||||
assert.Equal(t, result.urlIgnoreCertificateErrors, result.IgnoreCertificateErrors())
|
||||
assert.Equal(t, result.googleChromeIgnoreCertificateErrors, result.GoogleChromeIgnoreCertificateErrors())
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ func main() {
|
||||
systemLogger.FatalOp(op, err)
|
||||
}
|
||||
// start Google Chrome headless.
|
||||
if err := chrome.Start(systemLogger, config.IgnoreCertificateErrors()); err != nil {
|
||||
if err := chrome.Start(systemLogger, config.GoogleChromeIgnoreCertificateErrors()); err != nil {
|
||||
systemLogger.FatalOp(op, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user