Skip to content

Commit f72c595

Browse files
committed
fix(Console): Ensure errorneus resolution of url to not break deploys
1 parent 294e45e commit f72c595

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

lib/plugins/aws/info/display.js

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const { isVerboseMode, style } = require('@serverless/utils/log');
3+
const { isVerboseMode, style, log } = require('@serverless/utils/log');
44
const apiRequest = require('@serverless/utils/api-request');
55
const resolveAuthMode = require('@serverless/utils/auth/resolve-mode');
66
const urls = require('@serverless/utils/lib/auth/urls');
@@ -10,37 +10,39 @@ const filesize = require('../../../utils/filesize');
1010
module.exports = {
1111
async resolveConsoleUrl() {
1212
if (!(await resolveAuthMode())) return null;
13-
const awsAccountId = await (async () => {
13+
const org = await (async () => {
1414
try {
15-
return (await this.provider.request('STS', 'getCallerIdentity')).Account;
16-
} catch {
15+
const awsAccountId = (await this.provider.request('STS', 'getCallerIdentity')).Account;
16+
17+
const { userId } = await apiRequest('/api/identity/me');
18+
const { orgs } = await apiRequest(`/api/identity/users/${userId}/orgs`);
19+
20+
return (
21+
await Promise.all(
22+
orgs.map(async (orgCandidate) => {
23+
const orgData = await (async () => {
24+
try {
25+
return await apiRequest(`/api/integrations/?orgId=${orgCandidate.orgId}`, {
26+
urlName: 'integrationsBackend',
27+
});
28+
} catch {
29+
return null;
30+
}
31+
})();
32+
if (!orgData) return null;
33+
return orgData.integrations.some(
34+
({ vendorAccount }) => vendorAccount === awsAccountId
35+
)
36+
? orgCandidate
37+
: null;
38+
})
39+
)
40+
).filter(Boolean)[0];
41+
} catch (error) {
42+
log.info('Could not retrieve console error due to error:', error.message);
1743
return null;
1844
}
1945
})();
20-
if (!awsAccountId) return null;
21-
22-
const { userId } = await apiRequest('/api/identity/me');
23-
const { orgs } = await apiRequest(`/api/identity/users/${userId}/orgs`);
24-
25-
const org = (
26-
await Promise.all(
27-
orgs.map(async (orgCandidate) => {
28-
const orgData = await (async () => {
29-
try {
30-
return await apiRequest(`/api/integrations/?orgId=${orgCandidate.orgId}`, {
31-
urlName: 'integrationsBackend',
32-
});
33-
} catch {
34-
return null;
35-
}
36-
})();
37-
if (!orgData) return null;
38-
return orgData.integrations.some(({ vendorAccount }) => vendorAccount === awsAccountId)
39-
? orgCandidate
40-
: null;
41-
})
42-
)
43-
).filter(Boolean)[0];
4446

4547
if (!org) return false;
4648
return `${urls.frontend}/${

0 commit comments

Comments
 (0)