-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathlistAliases.js
95 lines (78 loc) · 2.2 KB
/
listAliases.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
'use strict';
/**
* List all deployed aliases
*/
const BbPromise = require('bluebird');
const _ = require('lodash');
const chalk = require('chalk');
/* eslint no-console: "off" */
module.exports = {
listDescribeApiStage(apiId, stageName) {
if (!apiId) {
return BbPromise.resolve(null);
}
return this._provider.request('APIGateway',
'getStage',
{
restApiId: apiId,
stageName: stageName
})
.then(stage => {
return this._provider.request('APIGateway',
'getDeployment',
{
restApiId: apiId,
deploymentId: stage.deploymentId
});
})
.catch(err => {
if (/^Invalid stage/.test(err.message)) {
return BbPromise.resolve(null);
}
return BbPromise.reject(err);
});
},
listGetApiId(stackName) {
return this._provider.request('CloudFormation',
'describeStackResource',
{
LogicalResourceId: 'ApiGatewayRestApi',
StackName: stackName
})
.then(cfData => cfData.StackResourceDetail.PhysicalResourceId)
.catch(() => BbPromise.resolve(null));
},
listAliases() {
console.log(chalk.yellow('aliases:'));
return BbPromise.join(
BbPromise.bind(this).then(() => {
return this.aliasStackGetAliasStackNames()
.mapSeries(stack => this.aliasStackLoadTemplate(stack));
}),
this.listGetApiId(this._provider.naming.getStackName())
)
.spread((aliasStackTemplates, apiId) => {
return BbPromise.mapSeries(aliasStackTemplates, aliasTemplate => {
const aliasName = _.get(aliasTemplate, 'Outputs.ServerlessAliasName.Value');
if (aliasName) {
console.log(chalk.white(` ${aliasName}`));
if (this._options.verbose) {
return BbPromise.join(
this.aliasGetAliasFunctionVersions(aliasName),
this.listDescribeApiStage(apiId, aliasName)
)
.spread((versions /*, apiStage */) => {
console.log(chalk.white(' Functions:'));
_.forEach(versions, version => {
console.log(chalk.yellow(` ${version.functionName} -> ${version.functionVersion}`));
// Print deployed endpoints for the function
// FIXME: Check why APIG getStage and getDeployment do not return the stage API layout.
});
return BbPromise.resolve();
});
}
}
});
});
}
};