Skip to content

Commit 6bfa827

Browse files
authored
Ignore https errors using environment variable (#59)
Makes it possible to configure puppeteer with ignoreHttpsErrors when launching chrome. Fixes #33
1 parent f74b36b commit 6bfa827

File tree

6 files changed

+58
-9
lines changed

6 files changed

+58
-9
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ for rendering and using remote rendering, see [Remote Rendering Using Docker](#r
3434

3535
If you still want to install the plugin in the Grafana docker image we provide instructions for how to build a custom Grafana image, see [Grafana Docker documentation](https://grafana.com/docs/installation/docker/#custom-image-with-grafana-image-renderer-plugin-pre-installed) for further instructions.
3636

37+
### Environment variables
38+
39+
You can override certain settings by using environment variables and making sure that those are available for the Grafana process.
40+
41+
**Ignore HTTPS errors:**
42+
43+
Instruct headless Chrome Whether to ignore HTTPS errors during navigation. Per default HTTPS errors is not ignored.
44+
Due to the security risk it's not recommended to ignore HTTPS errors.
45+
46+
```bash
47+
export GF_RENDERER_PLUGIN_IGNORE_HTTPS_ERRORS=true
48+
```
49+
3750
## Remote Rendering Using Docker
3851

3952
Instead of installing and running the image renderer as a plugin, you can run it as a remote image rendering service using Docker. Read more about [remote rendering using Docker](https://github.com/grafana/grafana-image-renderer/blob/master/docs/remote_rendering_using_docker.md).

docs/remote_rendering_using_docker.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ As an alternative to installing and running the image renderer as a plugin you c
44

55
The docker image are published at [Docker Hub](https://hub.docker.com/r/grafana/grafana-image-renderer).
66

7+
## Environment variables
8+
9+
You can override certain settings by using environment variables and making sure that those are available for the Grafana process.
10+
11+
**Ignore HTTPS errors:**
12+
13+
Instruct headless Chrome Whether to ignore HTTPS errors during navigation. Per default HTTPS errors is not ignored.
14+
Due to the security risk it's not recommended to ignore HTTPS errors.
15+
16+
```bash
17+
export IGNORE_HTTPS_ERRORS=true
18+
```
19+
720
## Docker Compose example
821

922
The following docker-compose example can also be found in [docker/](https://github.com/grafana/grafana-image-renderer/tree/master/docker).

src/browser.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ import uniqueFilename = require('unique-filename');
66

77
export function newPluginBrowser(log: Logger): Browser {
88
const env = Object.assign({}, process.env);
9-
let chromeBin: any;
9+
let ignoreHttpsErrors = false;
10+
11+
if (env['GF_RENDERER_PLUGIN_IGNORE_HTTPS_ERRORS']) {
12+
ignoreHttpsErrors = env['GF_RENDERER_PLUGIN_IGNORE_HTTPS_ERRORS'] === 'true';
13+
}
1014

15+
let chromeBin: any;
1116
if (env['GF_RENDERER_PLUGIN_CHROME_BIN']) {
1217
chromeBin = env['GF_RENDERER_PLUGIN_CHROME_BIN'];
1318
} else if ((process as any).pkg) {
@@ -19,24 +24,31 @@ export function newPluginBrowser(log: Logger): Browser {
1924
chromeBin = [path.dirname(process.execPath), ...parts].join(path.sep);
2025
}
2126

22-
return new Browser(log, chromeBin);
27+
return new Browser(log, ignoreHttpsErrors, chromeBin);
2328
}
2429

2530
export function newServerBrowser(log: Logger): Browser {
2631
const env = Object.assign({}, process.env);
27-
let chromeBin: any;
32+
let ignoreHttpsErrors = false;
33+
34+
if (env['IGNORE_HTTPS_ERRORS']) {
35+
ignoreHttpsErrors = env['IGNORE_HTTPS_ERRORS'] === 'true';
36+
}
2837

38+
let chromeBin: any;
2939
if (env['CHROME_BIN']) {
3040
chromeBin = env['CHROME_BIN'];
3141
}
3242

33-
return new Browser(log, chromeBin);
43+
return new Browser(log, ignoreHttpsErrors, chromeBin);
3444
}
3545

3646
export class Browser {
3747
chromeBin?: string;
48+
ignoreHttpsErrors: boolean;
3849

39-
constructor(private log: Logger, chromeBin?: string) {
50+
constructor(private log: Logger, ignoreHttpsErrors: boolean, chromeBin?: string) {
51+
this.ignoreHttpsErrors = ignoreHttpsErrors;
4052
this.chromeBin = chromeBin;
4153
}
4254

@@ -67,6 +79,7 @@ export class Browser {
6779

6880
let launcherOptions: any = {
6981
env: env,
82+
ignoreHttpsErrors: this.ignoreHttpsErrors,
7083
args: ['--no-sandbox'],
7184
};
7285

src/grpc-plugin.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,15 @@ export class GrpcPlugin {
2828
console.log(`1|1|tcp|${SERVER_ADDRESS}|grpc`);
2929

3030
if (this.browser.chromeBin) {
31-
this.log.info('Renderer plugin started', 'chromeBin', this.browser.chromeBin);
31+
this.log.info(
32+
'Renderer plugin started',
33+
'chromeBin',
34+
this.browser.chromeBin,
35+
'ignoreHttpsErrors',
36+
this.browser.ignoreHttpsErrors
37+
);
3238
} else {
33-
this.log.info('Renderer plugin started');
39+
this.log.info('Renderer plugin started', 'ignoreHttpsErrors', this.browser.ignoreHttpsErrors);
3440
}
3541
}
3642

src/http-server.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export class HttpServer {
2727
this.log.info(`Using chromeBin ${this.browser.chromeBin}`);
2828
}
2929

30+
if (this.browser.ignoreHttpsErrors) {
31+
this.log.info(`Ignoring HTTPS errors`);
32+
}
33+
3034
this.app.listen(this.options.port);
3135
this.log.info(`HTTP Server started, listening on ${this.options.port}`);
3236
}

src/logger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ export class PluginLogger {
3434
}
3535

3636
if (optionalParams) {
37-
for (let n = 0; n < optionalParams.length; n = n + 2) {
37+
for (let n = 0; n < optionalParams.length; n += 2) {
3838
const key = optionalParams[n];
3939
const value = optionalParams[n + 1];
4040

41-
if (key && value) {
41+
if (key !== null && value !== null) {
4242
logEntry[key] = value;
4343
}
4444
}

0 commit comments

Comments
 (0)