Skip to content

Commit

Permalink
fix(Console): Ensure errorneus resolution of url to not break deploys
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Nov 4, 2022
1 parent 294e45e commit f72c595
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions lib/plugins/aws/info/display.js
Original file line number Diff line number Diff line change
@@ -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 f72c595

Please sign in to comment.