From 025ab2fc32760434ea06d8864aa398b3e3c9d7ed Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Fri, 4 Nov 2022 17:49:23 +0100 Subject: [PATCH] fix(Console): Ensure errorneus resolution of url does not break deployments --- lib/plugins/aws/info/display.js | 58 +++++++++++++++++---------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/lib/plugins/aws/info/display.js b/lib/plugins/aws/info/display.js index 992e91c275af..ac70fcc41a72 100644 --- a/lib/plugins/aws/info/display.js +++ b/lib/plugins/aws/info/display.js @@ -1,6 +1,6 @@ 'use strict'; -const { isVerboseMode, style } = require('@serverless/utils/log'); +const { isVerboseMode, style, log } = require('@serverless/utils/log'); const apiRequest = require('@serverless/utils/api-request'); const resolveAuthMode = require('@serverless/utils/auth/resolve-mode'); const urls = require('@serverless/utils/lib/auth/urls'); @@ -10,37 +10,39 @@ const filesize = require('../../../utils/filesize'); module.exports = { async resolveConsoleUrl() { if (!(await resolveAuthMode())) return null; - const awsAccountId = await (async () => { + const org = await (async () => { try { - return (await this.provider.request('STS', 'getCallerIdentity')).Account; - } catch { + const awsAccountId = (await this.provider.request('STS', 'getCallerIdentity')).Account; + + const { userId } = await apiRequest('/api/identity/me'); + const { orgs } = await apiRequest(`/api/identity/users/${userId}/orgs`); + + return ( + await Promise.all( + orgs.map(async (orgCandidate) => { + const orgData = await (async () => { + try { + return await apiRequest(`/api/integrations/?orgId=${orgCandidate.orgId}`, { + urlName: 'integrationsBackend', + }); + } catch { + return null; + } + })(); + if (!orgData) return null; + return orgData.integrations.some( + ({ vendorAccount }) => vendorAccount === awsAccountId + ) + ? orgCandidate + : null; + }) + ) + ).filter(Boolean)[0]; + } catch (error) { + log.info('Could not retrieve console error due to error:', error.message); return null; } })(); - if (!awsAccountId) return null; - - const { userId } = await apiRequest('/api/identity/me'); - const { orgs } = await apiRequest(`/api/identity/users/${userId}/orgs`); - - const org = ( - await Promise.all( - orgs.map(async (orgCandidate) => { - const orgData = await (async () => { - try { - return await apiRequest(`/api/integrations/?orgId=${orgCandidate.orgId}`, { - urlName: 'integrationsBackend', - }); - } catch { - return null; - } - })(); - if (!orgData) return null; - return orgData.integrations.some(({ vendorAccount }) => vendorAccount === awsAccountId) - ? orgCandidate - : null; - }) - ) - ).filter(Boolean)[0]; if (!org) return false; return `${urls.frontend}/${