Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support configurable timeout #62

Merged
merged 5 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Option | Default Value | Valid Options | Environment Variable | Description
--subject | This is an email containing your dashboard report | - | OPENSEARCH_SUBJECT | subject for the email
--note | Hi,\nHere is the latest report! | string or path to text file | OPENSEARCH_EMAIL_NOTE | The email body
--selfsignedcerts | false | true, false | - | enable or disable self-signed certicates for smtp transport
--timeout | 300000 | - | OPENSEARCH_TIMEOUT | timeout for generating report in ms
| - | - | - | CHROMIUM_PATH | path to chromium directory

You can also find this information using help command.
Expand Down
15 changes: 12 additions & 3 deletions src/arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { program, Option } = require('commander');
const { exit } = require('process');
const fs = require('fs');
const ora = require('ora');
const { AUTH, CLI_COMMAND_NAME, DEFAULT_AUTH, DEFAULT_FILENAME, DEFAULT_FORMAT, DEFAULT_MIN_HEIGHT, DEFAULT_TENANT, DEFAULT_WIDTH, ENV_VAR, FORMAT, TRANSPORT_TYPE, DEFAULT_EMAIL_SUBJECT, DEFAULT_EMAIL_NOTE, DEFAULT_MULTI_TENANCY, DEFAULT_SELF_SIGNED_CERTIFICATES } = require('./constants.js');
const { AUTH, CLI_COMMAND_NAME, DEFAULT_AUTH, DEFAULT_FILENAME, DEFAULT_FORMAT, DEFAULT_MIN_HEIGHT, DEFAULT_TENANT, DEFAULT_WIDTH, ENV_VAR, FORMAT, TRANSPORT_TYPE, DEFAULT_EMAIL_SUBJECT, DEFAULT_EMAIL_NOTE, DEFAULT_MULTI_TENANCY, DEFAULT_SELF_SIGNED_CERTIFICATES, DEFAULT_TIMEOUT } = require('./constants.js');
const dotenv = require("dotenv");
dotenv.config();
const spinner = ora('');
Expand Down Expand Up @@ -67,7 +67,10 @@ async function getCommandArguments() {
.env(ENV_VAR.EMAIL_NOTE))
.addOption(new Option('--selfsignedcerts <flag>', 'enable or disable self-signed certicates for smtp transport')
.default(DEFAULT_SELF_SIGNED_CERTIFICATES)
.choices(['true', 'false']));
.choices(['true', 'false']))
.addOption(new Option('--timeout <timeout>', 'timeout for generating report in ms')
.default(DEFAULT_TIMEOUT)
.env(ENV_VAR.TIMEOUT));

program.addHelpText('after', `
Note: The tenant in the url has the higher priority than tenant value provided as command option.`);
Expand Down Expand Up @@ -99,6 +102,8 @@ async function getEventArguments(event) {
event['multitenancy'] = DEFAULT_MULTI_TENANCY;
if (event.selfsignedcerts === undefined)
event['selfsignedcerts'] = DEFAULT_SELF_SIGNED_CERTIFICATES;
if (event.timeout === undefined)
event['timeout'] = DEFAULT_TIMEOUT;

return getOptions(event);
}
Expand Down Expand Up @@ -127,7 +132,8 @@ function getOptions(options) {
time: null,
note: null,
emailbody: null,
selfsignedcerts: null
selfsignedcerts: null,
timeout: null
}

// Set url.
Expand Down Expand Up @@ -222,6 +228,9 @@ function getOptions(options) {
// Set self signed certificate flag.
commandOptions.selfsignedcerts = options.selfsignedcerts;

// Set timeout.
commandOptions.timeout = options.timeout;

spinner.succeed('Fetched argument values');
return commandOptions;
}
Expand Down
6 changes: 4 additions & 2 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const DEFAULT_EMAIL_SUBJECT = 'This is an email containing your opensearch dashb
const DEFAULT_EMAIL_NOTE = 'Hi,\nHere is the latest report!';
const DEFAULT_MULTI_TENANCY = true;
const DEFAULT_SELF_SIGNED_CERTIFICATES = false;
const DEFAULT_TIMEOUT = 300000;

const REPORT_TYPE = {
DASHBOARD: 'Dashboard',
Expand Down Expand Up @@ -65,6 +66,7 @@ const ENV_VAR = {
SMTP_PASSWORD: 'OPENSEARCH_SMTP_PASSWORD',
EMAIL_SUBJECT: 'OPENSEARCH_EMAIL_SUBJECT',
EMAIL_NOTE: 'OPENSEARCH_EMAIL_NOTE',
TIMEOUT: 'OPENSEARCH_TIMEOUT'
}

const TRANSPORT_TYPE = {
Expand All @@ -74,5 +76,5 @@ const TRANSPORT_TYPE = {

module.exports = {
CLI_COMMAND_NAME, DEFAULT_AUTH, DEFAULT_TENANT, DEFAULT_FORMAT, DEFAULT_WIDTH, DEFAULT_MIN_HEIGHT, DEFAULT_FILENAME, DEFAULT_EMAIL_SUBJECT,
DEFAULT_EMAIL_NOTE, REPORT_TYPE, SELECTOR, FORMAT, AUTH, URL_SOURCE, ENV_VAR, TRANSPORT_TYPE, DEFAULT_MULTI_TENANCY, DEFAULT_SELF_SIGNED_CERTIFICATES
};
DEFAULT_EMAIL_NOTE, REPORT_TYPE, SELECTOR, FORMAT, AUTH, URL_SOURCE, ENV_VAR, TRANSPORT_TYPE, DEFAULT_MULTI_TENANCY, DEFAULT_SELF_SIGNED_CERTIFICATES, DEFAULT_TIMEOUT
};
15 changes: 7 additions & 8 deletions src/download-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const exit = require('process');
const ora = require('ora');
const spinner = ora('');

module.exports = async function downloadReport(url, format, width, height, filename, authType, username, password, tenant, multitenancy, time, transport, emailbody) {
module.exports = async function downloadReport(url, format, width, height, filename, authType, username, password, tenant, multitenancy, time, transport, emailbody, timeout) {
spinner.start('Connecting to url ' + url);
try {
const browser = await puppeteer.launch({
Expand All @@ -32,13 +32,12 @@ module.exports = async function downloadReport(url, format, width, height, filen
TZ: process.env.TZ || 'UTC',
},
});

const page = await browser.newPage();
const overridePage = await browser.newPage();
page.setDefaultNavigationTimeout(0);
page.setDefaultTimeout(300000);
page.setDefaultTimeout(timeout);
overridePage.setDefaultNavigationTimeout(0);
overridePage.setDefaultTimeout(300000);
overridePage.setDefaultTimeout(timeout);

// auth
if (authType !== undefined && authType !== AUTH.NONE && username !== undefined && password !== undefined) {
Expand Down Expand Up @@ -95,7 +94,7 @@ module.exports = async function downloadReport(url, format, width, height, filen

// force wait for any resize to load after the above DOM modification.
await new Promise(resolve => setTimeout(resolve, 2000));
await waitForDynamicContent(page);
await waitForDynamicContent(page, timeout);
let buffer;
spinner.text = `Downloading Report...`;

Expand Down Expand Up @@ -155,7 +154,7 @@ module.exports = async function downloadReport(url, format, width, height, filen

const waitForDynamicContent = async (
page,
timeout = 30000,
timeout = timeout,
interval = 1000,
checks = 5
) => {
Expand Down Expand Up @@ -257,7 +256,7 @@ const samlAuthentication = async (page, url, username, password, tenant, multite
await page.type('[name="identifier"]', username);
await page.type('[name="credentials.passcode"]', password);
await page.click('[value="Sign in"]')
await page.waitForTimeout(30000);
await page.waitForTimeout(timeout);
try {
if (multitenancy === true) {
if (tenant === 'global' || tenant === 'private') {
Expand Down Expand Up @@ -291,7 +290,7 @@ const cognitoAuthentication = async (page, overridePage, url, username, password
await page.type('[name="username"]', username);
await page.type('[name="password"]', password);
await page.click('[name="signInSubmitButton"]');
await page.waitForTimeout(30000);
await page.waitForTimeout(timeout);
try {
if (multitenancy === true) {
if (tenant === 'global' || tenant === 'private') {
Expand Down
3 changes: 2 additions & 1 deletion src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ module.exports = async function run(args) {
options.multitenancy,
options.time,
options.transport,
options.emailbody
options.emailbody,
options.timeout
);

await sendEmail(
Expand Down
1 change: 1 addition & 0 deletions test/help.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Options:
--subject <subject> email subject (default: "This is an email containing your opensearch dashboard report", env: OPENSEARCH_EMAIL_SUBJECT)
--note <note> email body (string or path to text file) (default: "Hi,\\nHere is the latest report!", env: OPENSEARCH_EMAIL_NOTE)
--selfsignedcerts <flag> enable or disable self-signed certicates for smtp transport (choices: "true", "false", default: false)
--timeout <timeout> timeout for generating report in ms (default: 300000, env: OPENSEARCH_TIMEOUT)
-h, --help display help for command

Note: The tenant in the url has the higher priority than tenant value provided as command option.
Expand Down
Loading