Skip to content

Commit

Permalink
fix(Console): Ensure errorneus resolution of url does not break deplo…
Browse files Browse the repository at this point in the history
…yments
  • Loading branch information
medikoo committed Nov 4, 2022
1 parent 294e45e commit 025ab2f
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions 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');
Expand All @@ -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}/${
Expand Down

0 comments on commit 025ab2f

Please sign in to comment.