forked from serverless/serverless
/
display.js
158 lines (134 loc) · 5 KB
/
display.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
'use strict';
const chalk = require('chalk');
module.exports = {
displayServiceInfo() {
const info = this.gatheredData.info;
let message = '';
message += `${chalk.yellow.underline('Service Information')}\n`;
message += `${chalk.yellow('service:')} ${info.service}\n`;
message += `${chalk.yellow('stage:')} ${info.stage}\n`;
message += `${chalk.yellow('region:')} ${info.region}\n`;
message += `${chalk.yellow('stack:')} ${info.stack}\n`;
message += `${chalk.yellow('resources:')} ${info.resourceCount}`;
if (info.resourceCount >= 150) {
message += `\n${chalk.red('WARNING:')}\n`;
message += ` You have ${info.resourceCount} resources in your service.\n`;
message += ' CloudFormation has a hard limit of 200 resources in a service.\n';
message += ' For advice on avoiding this limit, check out this link: http://bit.ly/2IiYB38.';
}
this.serverless.cli.consoleLog(message);
return message;
},
displayApiKeys() {
const conceal = this.options.conceal;
const info = this.gatheredData.info;
let apiKeysMessage = `${chalk.yellow('api keys:')}`;
if (info.apiKeys && info.apiKeys.length > 0) {
info.apiKeys.forEach(apiKeyInfo => {
const description = apiKeyInfo.description ? ` - ${apiKeyInfo.description}` : '';
if (conceal) {
apiKeysMessage += `\n ${apiKeyInfo.name}${description}`;
} else {
apiKeysMessage += `\n ${apiKeyInfo.name}: ${apiKeyInfo.value}${description}`;
}
});
} else {
apiKeysMessage += '\n None';
}
this.serverless.cli.consoleLog(apiKeysMessage);
return apiKeysMessage;
},
displayEndpoints() {
const info = this.gatheredData.info;
let endpointsMessage = `${chalk.yellow('endpoints:')}`;
if (info.endpoints && info.endpoints.length) {
info.endpoints.forEach(endpoint => {
// if the endpoint is of type http(s)
if (endpoint.startsWith('https://')) {
Object.values(this.serverless.service.functions).forEach(functionObject => {
functionObject.events.forEach(event => {
if (event.http) {
let method;
let path;
if (typeof event.http === 'object') {
method = event.http.method.toUpperCase();
path = event.http.path;
} else {
method = event.http.split(' ')[0].toUpperCase();
path = event.http.split(' ')[1];
}
path =
path !== '/'
? `/${path
.split('/')
.filter(p => p !== '')
.join('/')}`
: '';
endpointsMessage += `\n ${method} - ${endpoint}${path}`;
}
});
});
} else if (endpoint.startsWith('httpApi: ')) {
endpoint = endpoint.slice('httpApi: '.length);
const { httpApiEventsPlugin } = this.serverless;
httpApiEventsPlugin.resolveConfiguration();
for (const functionData of Object.values(this.serverless.service.functions)) {
for (const event of functionData.events) {
if (!event.httpApi) continue;
endpointsMessage += `\n ${event.resolvedMethod} - ${endpoint}${event.resolvedPath ||
''}`;
}
}
} else {
// if the endpoint is not of type http(s) (e.g. wss) we just display
endpointsMessage += `\n ${endpoint}`;
}
});
}
if (info.cloudFront) {
endpointsMessage += `\n CloudFront - ${info.cloudFront}`;
}
if (!info.endpoints.length && !info.cloudFront) {
endpointsMessage += '\n None';
}
this.serverless.cli.consoleLog(endpointsMessage);
return endpointsMessage;
},
displayFunctions() {
const info = this.gatheredData.info;
let functionsMessage = `${chalk.yellow('functions:')}`;
if (info.functions && info.functions.length > 0) {
info.functions.forEach(f => {
functionsMessage += `\n ${f.name}: ${f.deployedName}`;
});
} else {
functionsMessage += '\n None';
}
this.serverless.cli.consoleLog(functionsMessage);
return functionsMessage;
},
displayLayers() {
const info = this.gatheredData.info;
let layersMessage = `${chalk.yellow('layers:')}`;
if (info.layers && info.layers.length > 0) {
info.layers.forEach(l => {
layersMessage += `\n ${l.name}: ${l.arn}`;
});
} else {
layersMessage += '\n None';
}
this.serverless.cli.consoleLog(layersMessage);
return layersMessage;
},
displayStackOutputs() {
let message = '';
if (this.options.verbose) {
message = `${chalk.yellow.underline('\nStack Outputs\n')}`;
this.gatheredData.outputs.forEach(output => {
message += `${chalk.yellow(output.OutputKey)}: ${output.OutputValue}\n`;
});
this.serverless.cli.consoleLog(message);
}
return message;
},
};