From 4674b3a9641326945d4184fb6eba286e02488dba Mon Sep 17 00:00:00 2001 From: Rupal Mahajan Date: Mon, 26 Feb 2024 15:38:57 -0800 Subject: [PATCH 1/5] Add logs to test Signed-off-by: Rupal Mahajan --- Dockerfile | 56 +++++++++++++++++++++++++++++++++++++++++ src/arguments.js | 8 ++++++ src/download-helpers.js | 2 ++ 3 files changed, 66 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1e6a062 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,56 @@ +# Define function directory + ARG FUNCTION_DIR="/function" + + # Base image of the docker container + FROM node:lts-slim as build-image + + # Include global arg in this stage of the build + ARG FUNCTION_DIR + + # AWS Lambda runtime dependencies + RUN apt-get update && \ + apt-get install -y \ + g++ \ + make \ + unzip \ + libcurl4-openssl-dev \ + autoconf \ + automake \ + libtool \ + cmake \ + python3 \ + libkrb5-dev + + # Copy function code + COPY package.json src/ ${FUNCTION_DIR}/ + WORKDIR ${FUNCTION_DIR} + RUN npm install && npm install aws-lambda-ric + + # Build Stage 2: Copy Build Stage 1 files in to Stage 2. Install chromium dependencies and chromium. + FROM node:lts-slim + + # Include global arg in this stage of the build + ARG FUNCTION_DIR + + # Set working directory to function root directory + WORKDIR ${FUNCTION_DIR} + + # Copy in the build image dependencies + COPY --from=build-image ${FUNCTION_DIR} ${FUNCTION_DIR} + + # Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others) + # Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer installs, work. + RUN apt-get update \ + && apt-get install -y wget gnupg \ + && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \ + && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \ + && apt-get update \ + && apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 \ + --no-install-recommends \ + && apt-get remove -y google-chrome-stable \ + && rm -rf /var/lib/apt/lists/* + + ENTRYPOINT ["/usr/local/bin/npx", "aws-lambda-ric"] + + ENV HOME="/tmp" + CMD [ "/function/index.handler" ] \ No newline at end of file diff --git a/src/arguments.js b/src/arguments.js index d9e4b80..c33bb10 100644 --- a/src/arguments.js +++ b/src/arguments.js @@ -100,6 +100,10 @@ async function getEventArguments(event) { if (event.selfsignedcerts === undefined) event['selfsignedcerts'] = DEFAULT_SELF_SIGNED_CERTIFICATES; + spinner.info('Event Argument'); + spinner.info('auth: '+ event['auth']); + spinner.info('multitenancy: '+ event['multitenancy']); + return getOptions(event); } @@ -164,6 +168,10 @@ function getOptions(options) { spinner.fail('Please specify a valid username or password'); exit(1); } + spinner.info('commandOptions'); + spinner.info('auth: '+ commandOptions.auth); + spinner.info('username: '+ commandOptions.username); + spinner.info('password: '+ commandOptions.password); // If auth type is none and credentials are present, give warning auth type might be missing. if (commandOptions.auth === DEFAULT_AUTH && commandOptions.username !== undefined && commandOptions.password !== undefined) { diff --git a/src/download-helpers.js b/src/download-helpers.js index 4ce6dac..00fa630 100644 --- a/src/download-helpers.js +++ b/src/download-helpers.js @@ -40,6 +40,8 @@ module.exports = async function downloadReport(url, format, width, height, filen overridePage.setDefaultNavigationTimeout(0); overridePage.setDefaultTimeout(300000); + spinner.info('authType: '+authType); + // auth if (authType !== undefined && authType !== AUTH.NONE && username !== undefined && password !== undefined) { if (authType === AUTH.BASIC) { From dfc1c3c82d562d7787a4804c65a3799265c68eb8 Mon Sep 17 00:00:00 2001 From: Rupal Mahajan Date: Wed, 28 Feb 2024 09:30:57 -0800 Subject: [PATCH 2/5] Fix invalid username/password error due to missing tenant selection window Signed-off-by: Rupal Mahajan --- src/download-helpers.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/download-helpers.js b/src/download-helpers.js index 00fa630..8b40389 100644 --- a/src/download-helpers.js +++ b/src/download-helpers.js @@ -211,10 +211,13 @@ const basicAuthentication = async (page, overridePage, url, username, password, await page.type('[data-test-subj="password"]', password); await page.click('button[type=submit]'); await page.waitForTimeout(10000); + const tenantSelection = await page.$("h4::-p-text(Select your tenant)"); try { - if (multitenancy === true) { + if (multitenancy === true && tenantSelection !== null) { + console.log('1'); if (tenant === 'global' || tenant === 'private') { await page.click('label[for=' + tenant + ']'); + console.log('2'); } else { await page.click('label[for="custom"]'); await page.click('button[data-test-subj="comboBoxToggleListButton"]'); @@ -230,7 +233,7 @@ const basicAuthentication = async (page, overridePage, url, username, password, exit(1); } - if (multitenancy === true) { + if (multitenancy === true && tenantSelection !== null) { await page.waitForTimeout(5000); await page.click('button[data-test-subj="confirm"]'); await page.waitForTimeout(25000); @@ -238,7 +241,7 @@ const basicAuthentication = async (page, overridePage, url, username, password, await overridePage.goto(url, { waitUntil: 'networkidle0' }); await overridePage.waitForTimeout(5000); - if (multitenancy === true) { + if (multitenancy === true && tenantSelection !== null) { // Check if tenant was selected successfully. if ((await overridePage.$('button[data-test-subj="confirm"]')) !== null) { spinner.fail('Invalid tenant'); @@ -260,8 +263,9 @@ const samlAuthentication = async (page, url, username, password, tenant, multite await page.type('[name="credentials.passcode"]', password); await page.click('[value="Sign in"]') await page.waitForTimeout(30000); + const tenantSelection = await page.$("h4::-p-text(Select your tenant)"); try { - if (multitenancy === true) { + if (multitenancy === true && tenantSelection !== null) { if (tenant === 'global' || tenant === 'private') { await page.click('label[for=' + tenant + ']'); } else { @@ -278,7 +282,7 @@ const samlAuthentication = async (page, url, username, password, tenant, multite spinner.fail('Invalid username or password'); exit(1); } - if (multitenancy === true) { + if (multitenancy === true && tenantSelection !== null) { await page.waitForTimeout(2000); await page.click('button[data-test-subj="confirm"]'); await page.waitForTimeout(25000); @@ -294,8 +298,9 @@ const cognitoAuthentication = async (page, overridePage, url, username, password await page.type('[name="password"]', password); await page.click('[name="signInSubmitButton"]'); await page.waitForTimeout(30000); + const tenantSelection = await page.$("h4::-p-text(Select your tenant)"); try { - if (multitenancy === true) { + if (multitenancy === true && tenantSelection !== null) { if (tenant === 'global' || tenant === 'private') { await page.click('label[for=' + tenant + ']'); } else { @@ -312,7 +317,7 @@ const cognitoAuthentication = async (page, overridePage, url, username, password spinner.fail('Invalid username or password'); exit(1); } - if (multitenancy === true) { + if (multitenancy === true && tenantSelection !== null) { await page.waitForTimeout(2000); await page.click('button[data-test-subj="confirm"]'); await page.waitForTimeout(25000); @@ -320,7 +325,7 @@ const cognitoAuthentication = async (page, overridePage, url, username, password await overridePage.goto(url, { waitUntil: 'networkidle0' }); await overridePage.waitForTimeout(5000); - if (multitenancy === true) { + if (multitenancy === true && tenantSelection !== null) { // Check if tenant was selected successfully. if ((await overridePage.$('button[data-test-subj="confirm"]')) !== null) { spinner.fail('Invalid tenant'); From b859e350153cb3067dfc6817e1aa1a270a19c552 Mon Sep 17 00:00:00 2001 From: Rupal Mahajan Date: Wed, 28 Feb 2024 09:37:32 -0800 Subject: [PATCH 3/5] Remove debug logs Signed-off-by: Rupal Mahajan --- src/arguments.js | 8 -------- src/download-helpers.js | 4 ---- 2 files changed, 12 deletions(-) diff --git a/src/arguments.js b/src/arguments.js index c33bb10..d9e4b80 100644 --- a/src/arguments.js +++ b/src/arguments.js @@ -100,10 +100,6 @@ async function getEventArguments(event) { if (event.selfsignedcerts === undefined) event['selfsignedcerts'] = DEFAULT_SELF_SIGNED_CERTIFICATES; - spinner.info('Event Argument'); - spinner.info('auth: '+ event['auth']); - spinner.info('multitenancy: '+ event['multitenancy']); - return getOptions(event); } @@ -168,10 +164,6 @@ function getOptions(options) { spinner.fail('Please specify a valid username or password'); exit(1); } - spinner.info('commandOptions'); - spinner.info('auth: '+ commandOptions.auth); - spinner.info('username: '+ commandOptions.username); - spinner.info('password: '+ commandOptions.password); // If auth type is none and credentials are present, give warning auth type might be missing. if (commandOptions.auth === DEFAULT_AUTH && commandOptions.username !== undefined && commandOptions.password !== undefined) { diff --git a/src/download-helpers.js b/src/download-helpers.js index 8b40389..33031df 100644 --- a/src/download-helpers.js +++ b/src/download-helpers.js @@ -40,8 +40,6 @@ module.exports = async function downloadReport(url, format, width, height, filen overridePage.setDefaultNavigationTimeout(0); overridePage.setDefaultTimeout(300000); - spinner.info('authType: '+authType); - // auth if (authType !== undefined && authType !== AUTH.NONE && username !== undefined && password !== undefined) { if (authType === AUTH.BASIC) { @@ -214,10 +212,8 @@ const basicAuthentication = async (page, overridePage, url, username, password, const tenantSelection = await page.$("h4::-p-text(Select your tenant)"); try { if (multitenancy === true && tenantSelection !== null) { - console.log('1'); if (tenant === 'global' || tenant === 'private') { await page.click('label[for=' + tenant + ']'); - console.log('2'); } else { await page.click('label[for="custom"]'); await page.click('button[data-test-subj="comboBoxToggleListButton"]'); From 4131e732ced60bc0e04e3d3bbc09c3db780ad96a Mon Sep 17 00:00:00 2001 From: Rupal Mahajan Date: Wed, 28 Feb 2024 09:38:39 -0800 Subject: [PATCH 4/5] Remove Dockerfile Signed-off-by: Rupal Mahajan --- Dockerfile | 56 ------------------------------------------------------ 1 file changed, 56 deletions(-) delete mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 1e6a062..0000000 --- a/Dockerfile +++ /dev/null @@ -1,56 +0,0 @@ -# Define function directory - ARG FUNCTION_DIR="/function" - - # Base image of the docker container - FROM node:lts-slim as build-image - - # Include global arg in this stage of the build - ARG FUNCTION_DIR - - # AWS Lambda runtime dependencies - RUN apt-get update && \ - apt-get install -y \ - g++ \ - make \ - unzip \ - libcurl4-openssl-dev \ - autoconf \ - automake \ - libtool \ - cmake \ - python3 \ - libkrb5-dev - - # Copy function code - COPY package.json src/ ${FUNCTION_DIR}/ - WORKDIR ${FUNCTION_DIR} - RUN npm install && npm install aws-lambda-ric - - # Build Stage 2: Copy Build Stage 1 files in to Stage 2. Install chromium dependencies and chromium. - FROM node:lts-slim - - # Include global arg in this stage of the build - ARG FUNCTION_DIR - - # Set working directory to function root directory - WORKDIR ${FUNCTION_DIR} - - # Copy in the build image dependencies - COPY --from=build-image ${FUNCTION_DIR} ${FUNCTION_DIR} - - # Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others) - # Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer installs, work. - RUN apt-get update \ - && apt-get install -y wget gnupg \ - && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \ - && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \ - && apt-get update \ - && apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 \ - --no-install-recommends \ - && apt-get remove -y google-chrome-stable \ - && rm -rf /var/lib/apt/lists/* - - ENTRYPOINT ["/usr/local/bin/npx", "aws-lambda-ric"] - - ENV HOME="/tmp" - CMD [ "/function/index.handler" ] \ No newline at end of file From 52b534f6e4b539583ff64563daf88608bdd4ee9e Mon Sep 17 00:00:00 2001 From: Rupal Mahajan Date: Wed, 28 Feb 2024 22:40:01 -0800 Subject: [PATCH 5/5] Fix tenant condition Signed-off-by: Rupal Mahajan --- src/download-helpers.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/download-helpers.js b/src/download-helpers.js index ba44a39..6a1bf0b 100644 --- a/src/download-helpers.js +++ b/src/download-helpers.js @@ -208,7 +208,7 @@ const basicAuthentication = async (page, overridePage, url, username, password, await page.type('[data-test-subj="password"]', password); await page.click('button[type=submit]'); await page.waitForTimeout(10000); - const tenantSelection = await page.$("h4::-p-text(Select your tenant)"); + const tenantSelection = await page.$('Select your tenant'); try { if (multitenancy === true && tenantSelection !== null) { if (tenant === 'global' || tenant === 'private') { @@ -258,7 +258,7 @@ const samlAuthentication = async (page, url, username, password, tenant, multite await page.type('[name="credentials.passcode"]', password); await page.click('[value="Sign in"]') await page.waitForTimeout(timeout); - const tenantSelection = await page.$("h4::-p-text(Select your tenant)"); + const tenantSelection = await page.$('Select your tenant'); try { if (multitenancy === true && tenantSelection !== null) { if (tenant === 'global' || tenant === 'private') { @@ -293,7 +293,7 @@ const cognitoAuthentication = async (page, overridePage, url, username, password await page.type('[name="password"]', password); await page.click('[name="signInSubmitButton"]'); await page.waitForTimeout(timeout); - const tenantSelection = await page.$("h4::-p-text(Select your tenant)"); + const tenantSelection = await page.$('Select your tenant'); try { if (multitenancy === true && tenantSelection !== null) { if (tenant === 'global' || tenant === 'private') {