UNPKG

17.5 kBMarkdownView Raw
1<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
2
3### Table of Contents
4
5- [Config](#config)
6 - [parse](#parse)
7 - [flatten](#flatten)
8- [Kes](#kes)
9 - [updateSingleLambda](#updatesinglelambda)
10 - [compileCF](#compilecf)
11 - [uploadToS3](#uploadtos3)
12 - [uploadCF](#uploadcf)
13 - [waitFor](#waitfor)
14 - [cloudFormation](#cloudformation)
15 - [validateTemplate](#validatetemplate)
16 - [describeCF](#describecf)
17 - [deleteCF](#deletecf)
18 - [opsStack](#opsstack)
19 - [upsertStack](#upsertstack)
20 - [deployStack](#deploystack)
21 - [createStack](#createstack)
22 - [updateStack](#updatestack)
23 - [deleteStack](#deletestack)
24- [Lambda](#lambda)
25 - [buildS3Path](#builds3path)
26 - [getHash](#gethash)
27 - [zipLambda](#ziplambda)
28 - [uploadLambda](#uploadlambda)
29 - [zipAndUploadLambda](#zipanduploadlambda)
30 - [process](#process)
31 - [updateSingleLambda](#updatesinglelambda-1)
32- [localRun](#localrun)
33- [zip](#zip)
34- [exec](#exec)
35- [configureAws](#configureaws)
36- [fileToString](#filetostring)
37- [mergeYamls](#mergeyamls)
38- [determineKesClass](#determinekesclass)
39- [failure](#failure)
40- [success](#success)
41- [getSystemBucket](#getsystembucket)
42
43## Config
44
45This class handles reading and parsing configuration files.
46It primarily reads `config.yml` and `.env` files
47
48**Parameters**
49
50- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** a js object that includes required options.
51 - `options.stack` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** the stack name
52 - `options.deployment` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the deployment name (optional, default `null`)
53 - `options.region` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the aws region (optional, default `'us-east-1'`)
54 - `options.profile` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the profile name (optional, default `null`)
55 - `options.kesFolder` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the path to the kes folder (optional, default `'.kes'`)
56 - `options.configFile` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the path to the config.yml (optional, default `'config.yml'`)
57 - `options.envFile` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the path to the .env file (optional, default `'.env'`)
58 - `options.cfFile` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the path to the CF template (optional, default `'cloudformation.template.yml'`)
59- `stack` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Stack name
60- `deployment` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Deployment name
61- `configFile` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to the config.yml file
62- `envFile` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path to the .env file (optional)
63
64**Examples**
65
66```javascript
67const config = new Config('mystack', 'dev', '.kes/config.yml', '.kes/.env');
68```
69
70### parse
71
72Main method of the class. It parses a configuration and returns it
73as a JS object.
74
75**Examples**
76
77```javascript
78const configInstance = new Config(null, null, 'path/to/config.yml', 'path/to/.env');
79config = configInstance.parse();
80```
81
82Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** the configuration object
83
84### flatten
85
86Return a javascript object (not a class instance) of the
87config class
88
89Returns **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** a javascript object version of the class
90
91## Kes
92
93The main Kes class. This class is used in the command module to create
94the CLI interface for kes. This class can be extended in order to override
95and modify the behavior of kes cli.
96
97**Parameters**
98
99- `config` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** an instance of the Config class (config.js)
100
101**Examples**
102
103```javascript
104const { Kes, Config } = require('kes');
105
106const options = { stack: 'myStack' };
107const config = new Config(options);
108const kes = new Kes(config);
109
110// create a new stack
111kes.deployStack()
112 .then(() => describeCF())
113 .then(() => updateSingleLambda('myLambda'))
114 .catch(e => console.log(e));
115```
116
117### updateSingleLambda
118
119Updates code of a deployed lambda function
120
121**Parameters**
122
123- `name` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the lambda function defined in config.yml
124
125Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object
126
127### compileCF
128
129Compiles a CloudFormation template in Yaml format.
130
131Reads the configuration yaml from `.kes/config.yml`.
132
133Writes the template to `.kes/cloudformation.yml`.
134
135Uses `.kes/cloudformation.template.yml` as the base template
136for generating the final CF template.
137
138Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object
139
140### uploadToS3
141
142This is just a wrapper around AWS s3.upload method.
143It uploads a given string to a S3 object.
144
145**Parameters**
146
147- `bucket` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the s3 bucket name
148- `key` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the path and name of the object
149- `body` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the content of the object
150
151Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object
152
153### uploadCF
154
155Uploads the Cloud Formation template to a given S3 location
156
157Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object
158
159### waitFor
160
161Wait for the current stack and log the current outcome
162
163**Parameters**
164
165- `wait`
166
167Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** undefined
168
169### cloudFormation
170
171Calls CloudFormation's update-stack or create-stack methods
172
173Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object
174
175### validateTemplate
176
177Validates the CF template
178
179Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object
180
181### describeCF
182
183Describes the cloudformation stack deployed
184
185Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object
186
187### deleteCF
188
189Deletes the current stack
190
191Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** undefined
192
193### opsStack
194
195Generic create/update method for CloudFormation
196
197Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object
198
199### upsertStack
200
201[Deprecated] Creates a CloudFormation stack for the class instance
202If exists, will update the existing one
203
204Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object
205
206### deployStack
207
208Creates a CloudFormation stack for the class instance
209If exists, will update the existing one
210
211Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object
212
213### createStack
214
215[Deprecated] Creates a CloudFormation stack for the class instance
216
217Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object
218
219### updateStack
220
221[Deprecated] Updates an existing CloudFormation stack for the class instance
222
223Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object
224
225### deleteStack
226
227Deletes the main stack
228
229Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of an AWS response object
230
231## Lambda
232
233Copy, zip and upload lambda functions to S3
234
235**Parameters**
236
237- `config` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** the configuration object
238- `kesFolder` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the path to the `.kes` folder
239- `bucket` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the S3 bucket name
240- `key` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the main folder to store the data in the bucket (stack)
241
242### buildS3Path
243
244Adds hash value, bucket name, and remote and local paths
245for lambdas that have source value.
246
247If a s3Source is usaed, only add remote and bucket values
248
249**Parameters**
250
251- `lambda` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** the lambda object
252
253Returns **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** the lambda object
254
255### getHash
256
257calculate the hash value for a given path
258
259**Parameters**
260
261- `folderName` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** directory path
262- `method` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** hash type, default to shasum
263
264Returns **[buffer](https://nodejs.org/api/buffer.html)** hash value
265
266### zipLambda
267
268zip a given lambda function source code
269
270**Parameters**
271
272- `lambda` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** the lambda object
273
274Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of the lambda object
275
276### uploadLambda
277
278Uploads the zipped lambda code to a given s3 bucket
279if the zip file already exists on S3 it skips the upload
280
281**Parameters**
282
283- `lambda` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** the lambda object. It must have the following properties
284 - `lambda.bucket` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the s3 buckt name
285 - `lambda.remote` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the lambda code's key (path and filename) on s3
286 - `lambda.local` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the zip files location on local machine
287
288Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of updated lambda object
289
290### zipAndUploadLambda
291
292Zips and Uploads a lambda function. If the source of the function
293is already zipped and uploaded, it skips the step only updates the
294lambda config object.
295
296**Parameters**
297
298- `lambda` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** the lambda object.
299
300Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of updated lambda object
301
302### process
303
304Zips and Uploads lambda functions in the configuration object.
305If the source of the function
306is already zipped and uploaded, it skips the step only updates the
307lambda config object.
308
309If the lambda config includes a link to zip file on S3, it skips
310the whole step.
311
312Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns the promise of updated configuration object
313
314### updateSingleLambda
315
316Uploads the zip code of a single lambda function to AWS Lambda
317
318**Parameters**
319
320- `name` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** name of the lambda function
321
322Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** returns AWS response for lambda code update operation
323
324## localRun
325
326A simple helper for running a function if `local` is passed as argument
327
328**Parameters**
329
330- `func` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** A javascript function
331
332**Examples**
333
334```javascript
335// test.js
336const { localRun } = require('kes');
337localRun(() => {
338 console.log('my function');
339});
340// result
341// $ node test.js local
342// my function
343```
344
345Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** returns the result of the function call
346
347## zip
348
349Zips a list of files or directories
350
351**Parameters**
352
353- `zipFile` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** filename and path where the zip file is stored
354- `srcList` **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** array of files and directories paths
355- `dstPath` **type** for directories whether to put the directories at
356 root of the zip file or relative to your path on the local machine
357
358Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**
359
360## exec
361
362Executes shell commands synchronously and logs the
363stdout to console.
364
365**Parameters**
366
367- `cmd` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Bash command
368- `verbose` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** whether to post stdout to console (optional, default `true`)
369
370Returns **[Buffer](https://nodejs.org/api/buffer.html)** The command's stdout in for of Buffer
371
372## configureAws
373
374Updates region of an AWS configuration and point to the correct
375of profile on ~/.aws/credentials file if necessary
376
377**Parameters**
378
379- `region` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** AWS region (optional, default `'us-east-1'`)
380- `profile` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** aws credentials profile name (optional, default `null`)
381- `role`
382
383## fileToString
384
385Checks if the input is a file, if it is a file,
386it reads it and return the content, otherwise just pass
387the input as an output
388
389**Parameters**
390
391- `file` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** A file path or a string
392
393Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** String content of a given file
394
395## mergeYamls
396
397Merges two yaml files. The merge is done using lodash.merge
398and it happens recursively. Meaning that values of file2 will
399replace values of file 1 if they have the same key.
400
401**Parameters**
402
403- `file1` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Yaml path to file 1 or file 1 string
404- `file2` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Yaml path to file 2 or file 2 string
405
406Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Merged Yaml file in string format
407
408## determineKesClass
409
410Based on the information passed from the CLI by the commander
411module this function determines whether to use the default Kes class
412or use the override class provided by the user
413
414**Parameters**
415
416- `options` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The options passed by the commander library
417- `Kes` **Class** the default kes class
418
419Returns **Class** Kes class
420
421## failure
422
423In case of error logs the error and exit with error 1
424
425**Parameters**
426
427- `e` **[Error](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error)** error object
428
429## success
430
431Exists the process when called
432
433## getSystemBucket
434
435Discover and returns the system bucket used for deployment
436
437**Parameters**
438
439- `config` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** cumulus config object
440
441Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** name of the bucket