@tremho/mist-lift 1.0.2-pre-release.4 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/build/commands/actions/initQuestions.js +24 -22
- package/build/commands/actions/initQuestions.js.map +1 -1
- package/build/commands/actions/setupPackageJson.js +4 -4
- package/build/commands/actions/setupPackageJson.js.map +1 -1
- package/build/commands/build.js +31 -25
- package/build/commands/build.js.map +1 -1
- package/build/commands/builtin/ApiDocMaker.js +60 -23
- package/build/commands/builtin/ApiDocMaker.js.map +1 -1
- package/build/commands/builtin/BuiltInHandler.js +6 -6
- package/build/commands/builtin/BuiltInHandler.js.map +1 -1
- package/build/commands/builtin/DeployBuiltInZip.js +4 -4
- package/build/commands/builtin/DeployBuiltInZip.js.map +1 -1
- package/build/commands/builtin/StageWebrootZip.js +1 -0
- package/build/commands/builtin/StageWebrootZip.js.map +1 -1
- package/build/commands/create.js +10 -11
- package/build/commands/create.js.map +1 -1
- package/build/commands/deploy.js +38 -42
- package/build/commands/deploy.js.map +1 -1
- package/build/commands/doctor.js +38 -37
- package/build/commands/doctor.js.map +1 -1
- package/build/commands/help.js +93 -93
- package/build/commands/help.js.map +1 -1
- package/build/commands/init.js +7 -7
- package/build/commands/init.js.map +1 -1
- package/build/commands/package.js +50 -51
- package/build/commands/package.js.map +1 -1
- package/build/commands/publish.js +98 -102
- package/build/commands/publish.js.map +1 -1
- package/build/commands/settings.js +19 -18
- package/build/commands/settings.js.map +1 -1
- package/build/commands/start.js +4 -4
- package/build/commands/start.js.map +1 -1
- package/build/commands/test.js +3 -3
- package/build/commands/test.js.map +1 -1
- package/build/commands/user.js +1 -1
- package/build/commands/user.js.map +1 -1
- package/build/expressRoutes/all.js +27 -26
- package/build/expressRoutes/all.js.map +1 -1
- package/build/expressRoutes/api.js +9 -7
- package/build/expressRoutes/api.js.map +1 -1
- package/build/expressRoutes/functionBinder.js +38 -36
- package/build/expressRoutes/functionBinder.js.map +1 -1
- package/build/lib/CaseUtils.js +2 -2
- package/build/lib/CaseUtils.js.map +1 -1
- package/build/lib/DirectoryUtils.js +4 -3
- package/build/lib/DirectoryUtils.js.map +1 -1
- package/build/lib/LiftConfig.js +18 -20
- package/build/lib/LiftConfig.js.map +1 -1
- package/build/lib/LiftVersion.js +17 -12
- package/build/lib/LiftVersion.js.map +1 -1
- package/build/lib/Tests/fileCompare.test.js +11 -10
- package/build/lib/Tests/fileCompare.test.js.map +1 -1
- package/build/lib/askQuestion.js +3 -2
- package/build/lib/askQuestion.js.map +1 -1
- package/build/lib/executeCommand.js +46 -33
- package/build/lib/executeCommand.js.map +1 -1
- package/build/lib/fileCompare.js +9 -8
- package/build/lib/fileCompare.js.map +1 -1
- package/build/lib/openAPI/ApiBuildCollector.js +9 -8
- package/build/lib/openAPI/ApiBuildCollector.js.map +1 -1
- package/build/lib/openAPI/WebrootFileSupport.js +4 -3
- package/build/lib/openAPI/WebrootFileSupport.js.map +1 -1
- package/build/lib/openAPI/openApiConstruction.js +62 -61
- package/build/lib/openAPI/openApiConstruction.js.map +1 -1
- package/build/lib/pathResolve.js +4 -4
- package/build/lib/pathResolve.js.map +1 -1
- package/build/lib/utils.js +5 -4
- package/build/lib/utils.js.map +1 -1
- package/build/lift.js +14 -15
- package/build/lift.js.map +1 -1
- package/package.json +2 -1
- package/src/commands/actions/initQuestions.ts +112 -112
- package/src/commands/actions/setupPackageJson.ts +21 -25
- package/src/commands/build.ts +143 -146
- package/src/commands/builtin/ApiDocMaker.ts +86 -54
- package/src/commands/builtin/BuiltInHandler.ts +31 -35
- package/src/commands/builtin/DeployBuiltInZip.ts +15 -17
- package/src/commands/builtin/StageWebrootZip.ts +29 -32
- package/src/commands/create.ts +40 -47
- package/src/commands/deploy.ts +139 -152
- package/src/commands/doctor.ts +86 -82
- package/src/commands/help.ts +152 -153
- package/src/commands/init.ts +37 -39
- package/src/commands/package.ts +201 -204
- package/src/commands/publish.ts +277 -312
- package/src/commands/settings.ts +67 -70
- package/src/commands/start.ts +32 -37
- package/src/commands/test.ts +15 -16
- package/src/commands/user.ts +1 -1
- package/src/expressRoutes/all.ts +73 -78
- package/src/expressRoutes/api.ts +14 -16
- package/src/expressRoutes/functionBinder.ts +144 -151
- package/src/lib/CaseUtils.ts +49 -54
- package/src/lib/DirectoryUtils.ts +25 -27
- package/src/lib/LiftConfig.ts +46 -54
- package/src/lib/LiftVersion.ts +69 -77
- package/src/lib/Tests/fileCompare.test.ts +27 -26
- package/src/lib/askQuestion.ts +12 -13
- package/src/lib/executeCommand.ts +40 -33
- package/src/lib/fileCompare.ts +46 -37
- package/src/lib/openAPI/ApiBuildCollector.ts +36 -36
- package/src/lib/openAPI/WebrootFileSupport.ts +15 -17
- package/src/lib/openAPI/openApiConstruction.ts +169 -175
- package/src/lib/pathResolve.ts +22 -28
- package/src/lib/utils.ts +31 -33
- package/src/lift.ts +68 -67
package/src/commands/publish.ts
CHANGED
|
@@ -1,350 +1,315 @@
|
|
|
1
1
|
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from
|
|
3
|
+
LambdaClient,
|
|
4
|
+
ListFunctionsCommand
|
|
5
|
+
} from '@aws-sdk/client-lambda'
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
import {
|
|
23
|
-
import
|
|
24
|
-
|
|
25
|
-
import {
|
|
26
|
-
|
|
27
|
-
import
|
|
28
|
-
import
|
|
29
|
-
import {
|
|
30
|
-
import
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
let retCode = 0;
|
|
45
|
-
|
|
46
|
-
projectPaths = resolvePaths()
|
|
47
|
-
|
|
48
|
-
await publishApi(stageName ?? "Dev")
|
|
49
|
-
|
|
50
|
-
return retCode;
|
|
7
|
+
APIGatewayClient,
|
|
8
|
+
ImportRestApiCommand,
|
|
9
|
+
GetRestApisCommand,
|
|
10
|
+
GetResourcesCommand, GetResourcesCommandOutput,
|
|
11
|
+
DeleteRestApiCommand,
|
|
12
|
+
PutIntegrationRequest,
|
|
13
|
+
PutIntegrationCommand,
|
|
14
|
+
CreateDeploymentCommand
|
|
15
|
+
} from '@aws-sdk/client-api-gateway'
|
|
16
|
+
|
|
17
|
+
import { getAWSCredentials, getSettings } from '../lib/LiftConfig'
|
|
18
|
+
|
|
19
|
+
import * as ac from 'ansi-colors'
|
|
20
|
+
|
|
21
|
+
import path from 'path'
|
|
22
|
+
import fs, { mkdirSync } from 'fs'
|
|
23
|
+
import os from 'os'
|
|
24
|
+
import { resolvePaths } from '../lib/pathResolve'
|
|
25
|
+
import { gatherFunctionDefinitions } from '../lib/openAPI/ApiBuildCollector'
|
|
26
|
+
import { delay } from '../lib/utils'
|
|
27
|
+
import { addBuiltInDefinitions, MakeBuiltinApiDoc } from './builtin/ApiDocMaker'
|
|
28
|
+
import { DeployApiBuiltin, DeployRootFileserves, DeployWebrootBuiltIn } from './builtin/BuiltInHandler'
|
|
29
|
+
import { getProjectName, getProjectVersion } from '../lib/LiftVersion'
|
|
30
|
+
import md5 from 'md5'
|
|
31
|
+
|
|
32
|
+
let projectPaths: any
|
|
33
|
+
|
|
34
|
+
export async function doPublishAsync (stageName?: string): Promise<number> {
|
|
35
|
+
// let retCode = await doDeployAsync([])
|
|
36
|
+
// if(retCode) return retCode
|
|
37
|
+
const retCode = 0
|
|
38
|
+
|
|
39
|
+
projectPaths = resolvePaths()
|
|
40
|
+
|
|
41
|
+
await publishApi(stageName ?? 'Dev')
|
|
42
|
+
|
|
43
|
+
return retCode
|
|
51
44
|
}
|
|
52
45
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
{
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
46
|
+
async function publishApi (
|
|
47
|
+
stageName?: string
|
|
48
|
+
): Promise<void> {
|
|
49
|
+
if (stageName === undefined) stageName = 'Dev'
|
|
50
|
+
console.log(ac.green.bold(`Publishing Api to ${stageName}`))
|
|
51
|
+
|
|
52
|
+
// do the built-in deploys
|
|
53
|
+
await DeployWebrootBuiltIn()
|
|
54
|
+
await DeployRootFileserves()
|
|
55
|
+
await DeployApiBuiltin()
|
|
56
|
+
|
|
57
|
+
// make a private api
|
|
58
|
+
// const fs = require('fs')
|
|
59
|
+
// const os = require('os')
|
|
60
|
+
// const path = require('path')
|
|
61
|
+
|
|
62
|
+
let tmpDir
|
|
63
|
+
let apiBytes
|
|
64
|
+
const appPrefix = 'MistLift'
|
|
65
|
+
try {
|
|
66
|
+
tmpDir = path.join(os.tmpdir(), appPrefix)
|
|
67
|
+
// console.log("making "+tmpDir)
|
|
68
|
+
mkdirSync(tmpDir, { recursive: true })
|
|
69
|
+
|
|
70
|
+
const yamlFile = path.join(tmpDir, 'papi.yaml')
|
|
71
|
+
await MakeBuiltinApiDoc(yamlFile)
|
|
72
|
+
// console.log("reading "+yamlFile)
|
|
73
|
+
apiBytes = fs.readFileSync(yamlFile)
|
|
74
|
+
} catch (e: any) {
|
|
75
|
+
console.error(ac.red.bold('Error creating temp staging folder ') + (e.message as string))
|
|
76
|
+
throw Error()
|
|
77
|
+
} finally {
|
|
74
78
|
try {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
await MakeBuiltinApiDoc(yamlFile);
|
|
81
|
-
// console.log("reading "+yamlFile)
|
|
82
|
-
apiBytes = fs.readFileSync(yamlFile)
|
|
83
|
-
}
|
|
84
|
-
catch (e:any) {
|
|
85
|
-
console.error(ac.red.bold("Error creating temp staging folder ")+e.message);
|
|
86
|
-
throw Error();
|
|
79
|
+
if (tmpDir !== undefined) {
|
|
80
|
+
fs.rmSync(tmpDir, { recursive: true })
|
|
81
|
+
}
|
|
82
|
+
} catch (e: any) {
|
|
83
|
+
console.error(`An error has occurred while removing the temp folder at ${tmpDir ?? ''}. Please remove it manually. Error: ${(e.message as string)}`)
|
|
87
84
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
try {
|
|
110
|
-
const response = await client.send(command)
|
|
111
|
-
const {name, id, rootResourceId, version, warnings} = response
|
|
112
|
-
console.log(ac.grey(`\n\nAPI ${name} version ${version} [${id}] schema created`))
|
|
113
|
-
apiId = id;
|
|
114
|
-
if (warnings?.length) {
|
|
115
|
-
console.log(ac.magenta(` with ${warnings.length} warnings`))
|
|
116
|
-
for (let warning of warnings) {
|
|
117
|
-
console.log(ac.grey.italic(` ${warning}`))
|
|
118
|
-
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const client = new APIGatewayClient(getAWSCredentials())
|
|
88
|
+
|
|
89
|
+
await RemoveExistingVersions(client)
|
|
90
|
+
|
|
91
|
+
const command = new ImportRestApiCommand({
|
|
92
|
+
failOnWarnings: false,
|
|
93
|
+
body: apiBytes
|
|
94
|
+
})
|
|
95
|
+
let apiId
|
|
96
|
+
try {
|
|
97
|
+
const response = await client.send(command)
|
|
98
|
+
const { name, id, version, warnings } = response
|
|
99
|
+
console.log(ac.grey(`\n\nAPI ${name ?? ''} version ${version ?? ''} [${id ?? ''}] schema created`))
|
|
100
|
+
apiId = id ?? ''
|
|
101
|
+
if (warnings?.length !== 0) {
|
|
102
|
+
console.log(ac.magenta(` with ${warnings?.length ?? 0} warnings`))
|
|
103
|
+
if (warnings !== undefined) {
|
|
104
|
+
for (const warning of warnings) {
|
|
105
|
+
console.log(ac.grey.italic(` ${warning}`))
|
|
119
106
|
}
|
|
107
|
+
}
|
|
120
108
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
109
|
+
} catch (e: any) {
|
|
110
|
+
console.error(ac.bold.red(e.message))
|
|
111
|
+
}
|
|
112
|
+
// const apidoc = new TextDecoder().decode(apiBytes)
|
|
113
|
+
// console.log(apidoc)
|
|
114
|
+
if (apiId === '') return
|
|
115
|
+
|
|
116
|
+
console.log(ac.grey('Continuing with binding...'))
|
|
117
|
+
const prereq = await PrequisiteValues(apiId ?? '')
|
|
118
|
+
const intRequests = prereq.MakeRequests()
|
|
119
|
+
await PutIntegrations(intRequests)
|
|
120
|
+
await DeployApi(apiId ?? '', stageName)
|
|
121
|
+
const region = getSettings()?.awsPreferredRegion ?? ''
|
|
122
|
+
console.log(ac.green.bold(`\n Successfully deployed to https://${apiId ?? ''}.execute-api.${region}.amazonaws.com/${stageName}`))
|
|
135
123
|
}
|
|
136
|
-
function findApiName()
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return info.title ?? pkg.name ?? "API";
|
|
124
|
+
function findApiName (): string {
|
|
125
|
+
const infoFile = path.join(projectPaths.functionPath, 'apiService.info.json')
|
|
126
|
+
const pkgFile = projectPaths.packagePath
|
|
127
|
+
let pkg: any = {}
|
|
128
|
+
if (fs.existsSync(pkgFile)) { pkg = JSON.parse(fs.readFileSync(pkgFile).toString()) }
|
|
129
|
+
let info: any = {}
|
|
130
|
+
if (fs.existsSync(infoFile)) { info = JSON.parse(fs.readFileSync(infoFile).toString()) }
|
|
131
|
+
|
|
132
|
+
return info.title ?? pkg.name ?? 'API'
|
|
146
133
|
}
|
|
147
134
|
|
|
148
|
-
function RemoveExistingVersions(client:APIGatewayClient)
|
|
149
|
-
{
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
DeleteMatchingApis();
|
|
181
|
-
});
|
|
182
|
-
})
|
|
135
|
+
async function RemoveExistingVersions (client: APIGatewayClient): Promise<void> {
|
|
136
|
+
await new Promise(resolve => {
|
|
137
|
+
const ourName = findApiName()
|
|
138
|
+
// ClogDebug("looking for name "+ ourName)
|
|
139
|
+
const listCommand = new GetRestApisCommand({})
|
|
140
|
+
client.send(listCommand).then((response: any) => {
|
|
141
|
+
// ClogInfo(`There are ${response.items.length} other APIs`)
|
|
142
|
+
|
|
143
|
+
const DeleteMatchingApis = async (i: number = 0): Promise<any> => {
|
|
144
|
+
if (i >= response.items.length) {
|
|
145
|
+
resolve(undefined)
|
|
146
|
+
return await Promise.resolve(undefined)
|
|
147
|
+
}
|
|
148
|
+
const item: { name: string, id: string } = response.items[i]
|
|
149
|
+
if (item.name === ourName) {
|
|
150
|
+
// ClogInfo(`Found previous ${ourName}, [${item.id}] -- deleting...`)
|
|
151
|
+
const deleteCommand = new DeleteRestApiCommand({
|
|
152
|
+
restApiId: item.id
|
|
153
|
+
})
|
|
154
|
+
return await client.send(deleteCommand).then(() => {
|
|
155
|
+
delay(5000).then(async () => {
|
|
156
|
+
console.log(ac.magenta.bold(`Removed previous id ${item.id}`))
|
|
157
|
+
return await DeleteMatchingApis(++i)
|
|
158
|
+
}).catch<any>((reason: any) => undefined)
|
|
159
|
+
}).catch<any>((reason: any) => undefined)
|
|
160
|
+
} else {
|
|
161
|
+
return await DeleteMatchingApis(++i)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
DeleteMatchingApis().catch<any>((reason: any) => undefined)
|
|
165
|
+
}).catch<any>((reason: any) => undefined)
|
|
166
|
+
}).catch<any>((reason: any) => undefined)
|
|
183
167
|
}
|
|
184
168
|
|
|
185
|
-
|
|
186
169
|
class FunctionInfo {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
class APIInfo {
|
|
191
|
-
id: string = ""
|
|
192
|
-
parentId: string = ""
|
|
193
|
-
path:string = ""
|
|
194
|
-
pathPart: string = "";
|
|
195
|
-
resourceMethods: object = {}
|
|
170
|
+
name: string = ''
|
|
171
|
+
arn: string = ''
|
|
196
172
|
}
|
|
197
173
|
|
|
198
|
-
|
|
199
174
|
class PrereqInfo {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
return api;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
175
|
+
requestApiId: string = ''
|
|
176
|
+
functions: FunctionInfo[] = []
|
|
177
|
+
apis: any[] = [] // Resource + method
|
|
178
|
+
defs: any[] = []
|
|
179
|
+
|
|
180
|
+
public constructor () {
|
|
181
|
+
this.functions = []
|
|
182
|
+
this.apis = []
|
|
183
|
+
this.defs = []
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
public findApi (pathMap: string, allowedMethods: string): any {
|
|
187
|
+
// find the pathmap in the apis list
|
|
188
|
+
// console.log("findApi "+pathMap, allowedMethods)
|
|
189
|
+
// see that this method exists in method map
|
|
190
|
+
for (const api of this.apis) {
|
|
191
|
+
if (api?.path === pathMap) {
|
|
192
|
+
// console.log("resourceMethods", api.resourceMethods)
|
|
193
|
+
const methodList = Object.getOwnPropertyNames(api.resourceMethods)
|
|
194
|
+
// ClogTrace("methodList", methodList)
|
|
195
|
+
for (const meth of allowedMethods.toUpperCase().split(',')) {
|
|
196
|
+
// console.log("meth", meth)
|
|
197
|
+
if (methodList.includes(meth)) {
|
|
198
|
+
(api).method = meth
|
|
199
|
+
return api
|
|
200
|
+
}
|
|
230
201
|
}
|
|
231
|
-
|
|
202
|
+
}
|
|
232
203
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
console.log("$$$ Couldn't find "+name+" in ", this.functions)
|
|
242
|
-
return "";
|
|
204
|
+
return null
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
public findARN (name: string): string {
|
|
208
|
+
for (const f of this.functions ?? []) {
|
|
209
|
+
const lastus = f.name.lastIndexOf('_')
|
|
210
|
+
const fname = f.name.substring(0, lastus)
|
|
211
|
+
if (fname.toLowerCase() === name.toLowerCase()) return f.arn
|
|
243
212
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
return out;
|
|
213
|
+
console.log("$$$ Couldn't find " + name + ' in ', this.functions)
|
|
214
|
+
return ''
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
public MakeRequests (): PutIntegrationRequest[] {
|
|
218
|
+
const region = getSettings()?.awsPreferredRegion ?? ''
|
|
219
|
+
const out: PutIntegrationRequest[] = []
|
|
220
|
+
for (const d of this.defs) {
|
|
221
|
+
const def = (d)
|
|
222
|
+
const api = this.findApi(def.pathMap, def.allowedMethods)
|
|
223
|
+
const arn = this.findARN(def.name) ?? ''
|
|
224
|
+
if (arn === '') {
|
|
225
|
+
console.log(`>>> No ARN for ${(def.name as string)} ${(def.pathMap as string)}, ${(api.id as string)}`)
|
|
226
|
+
}
|
|
227
|
+
if (api !== undefined) {
|
|
228
|
+
out.push({
|
|
229
|
+
restApiId: this.requestApiId,
|
|
230
|
+
resourceId: api.id, // api.parentId
|
|
231
|
+
httpMethod: api.method,
|
|
232
|
+
integrationHttpMethod: 'POST', // api.method,
|
|
233
|
+
type: 'AWS_PROXY',
|
|
234
|
+
uri: `arn:aws:apigateway:${region}:lambda:path/2015-03-31/functions/${arn}/invocations`,
|
|
235
|
+
credentials: 'arn:aws:iam::545650260286:role/TBDLambdaExecution2'
|
|
236
|
+
})
|
|
237
|
+
}
|
|
270
238
|
}
|
|
239
|
+
return out
|
|
240
|
+
}
|
|
271
241
|
}
|
|
272
242
|
|
|
243
|
+
async function PrequisiteValues (id: string): Promise<PrereqInfo> {
|
|
244
|
+
const pri = new PrereqInfo()
|
|
245
|
+
const out = await GetFunctionInfo(pri)
|
|
246
|
+
out.defs = gatherFunctionDefinitions()
|
|
247
|
+
addBuiltInDefinitions(out.defs)
|
|
248
|
+
out.requestApiId = id
|
|
249
|
+
await GetMethodResources(id, out)
|
|
273
250
|
|
|
274
|
-
|
|
275
|
-
{
|
|
276
|
-
const pri = new PrereqInfo()
|
|
277
|
-
const out = await GetFunctionInfo(pri)
|
|
278
|
-
out.defs = gatherFunctionDefinitions()
|
|
279
|
-
addBuiltInDefinitions(out.defs)
|
|
280
|
-
out.requestApiId = id;
|
|
281
|
-
await GetMethodResources(id, out);
|
|
282
|
-
|
|
283
|
-
return out;
|
|
251
|
+
return out
|
|
284
252
|
}
|
|
285
253
|
|
|
286
|
-
async function GetFunctionInfo(info:PrereqInfo):Promise<PrereqInfo>
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
const response:any = await client.send(listCommand);
|
|
254
|
+
async function GetFunctionInfo (info: PrereqInfo): Promise<PrereqInfo> {
|
|
255
|
+
const client = new LambdaClient(getAWSCredentials())
|
|
256
|
+
const listCommand: any = new ListFunctionsCommand({})
|
|
257
|
+
const response: any = await client.send(listCommand)
|
|
291
258
|
|
|
292
|
-
|
|
259
|
+
const sfx = '_' + md5((getProjectName() ?? '') + (getProjectVersion()?.toString() ?? ''))
|
|
293
260
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
261
|
+
for (const func of response.Functions ?? []) {
|
|
262
|
+
const fName: string = func?.FunctionName ?? ''
|
|
263
|
+
if (fName.endsWith(sfx)) {
|
|
264
|
+
info.functions.push({
|
|
265
|
+
name: func.FunctionName ?? '',
|
|
266
|
+
arn: func.FunctionArn ?? ''
|
|
267
|
+
})
|
|
301
268
|
}
|
|
302
|
-
|
|
303
|
-
|
|
269
|
+
}
|
|
270
|
+
return info
|
|
304
271
|
}
|
|
305
272
|
|
|
306
|
-
async function GetMethodResources(
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
273
|
+
async function GetMethodResources (
|
|
274
|
+
id: string,
|
|
275
|
+
info: PrereqInfo
|
|
276
|
+
): Promise<PrereqInfo> {
|
|
277
|
+
const client = new APIGatewayClient(getAWSCredentials())
|
|
278
|
+
const listCommand = new GetResourcesCommand({
|
|
279
|
+
restApiId: id
|
|
280
|
+
})
|
|
281
|
+
const response: GetResourcesCommandOutput = await client.send(listCommand)
|
|
282
|
+
// ClogInfo("Resources response", response)
|
|
283
|
+
if ((response?.items) != null) info.apis = response.items
|
|
284
|
+
|
|
285
|
+
return info
|
|
317
286
|
}
|
|
318
287
|
|
|
319
|
-
async function PutIntegrations(integrations:PutIntegrationRequest[])
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
console.error("Problem with integration for "+input.uri, {input});
|
|
331
|
-
throw e
|
|
332
|
-
}
|
|
288
|
+
async function PutIntegrations (integrations: PutIntegrationRequest[]): Promise<void> {
|
|
289
|
+
const client = new APIGatewayClient(getAWSCredentials())
|
|
290
|
+
for (const input of integrations) {
|
|
291
|
+
try {
|
|
292
|
+
const command = new PutIntegrationCommand(input)
|
|
293
|
+
/* const intResp = */ await client.send(command)
|
|
294
|
+
// ClogDebug("integration response", intResp);
|
|
295
|
+
await delay(5000)
|
|
296
|
+
} catch (e: any) {
|
|
297
|
+
console.error('Problem with integration for ' + (input.uri as string), { input })
|
|
298
|
+
throw e
|
|
333
299
|
}
|
|
300
|
+
}
|
|
334
301
|
}
|
|
335
302
|
|
|
336
|
-
async function DeployApi(restApiId:string, stageName:string)
|
|
337
|
-
{
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
throw e;
|
|
349
|
-
}
|
|
303
|
+
async function DeployApi (restApiId: string, stageName: string): Promise<void> {
|
|
304
|
+
try {
|
|
305
|
+
const client = new APIGatewayClient(getAWSCredentials())
|
|
306
|
+
const command = new CreateDeploymentCommand({
|
|
307
|
+
restApiId,
|
|
308
|
+
stageName
|
|
309
|
+
})
|
|
310
|
+
await client.send(command)
|
|
311
|
+
} catch (e: any) {
|
|
312
|
+
console.error(ac.red.bold(`Error with deployApi: ${e.message as string}`))
|
|
313
|
+
throw e
|
|
314
|
+
}
|
|
350
315
|
}
|