@itentialopensource/adapter-aws_lambda 0.1.1

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.
Files changed (77) hide show
  1. package/.eslintignore +6 -0
  2. package/.eslintrc.js +19 -0
  3. package/.gitlab/.gitkeep +0 -0
  4. package/.gitlab/issue_templates/.gitkeep +0 -0
  5. package/.gitlab/issue_templates/Default.md +17 -0
  6. package/.gitlab/issue_templates/bugReportTemplate.md +76 -0
  7. package/.gitlab/issue_templates/featureRequestTemplate.md +14 -0
  8. package/.jshintrc +0 -0
  9. package/AUTH.md +39 -0
  10. package/BROKER.md +211 -0
  11. package/CALLS.md +603 -0
  12. package/CODE_OF_CONDUCT.md +43 -0
  13. package/CONTRIBUTING.md +13 -0
  14. package/ENHANCE.md +69 -0
  15. package/LICENSE +201 -0
  16. package/PROPERTIES.md +661 -0
  17. package/README.md +344 -0
  18. package/SUMMARY.md +9 -0
  19. package/SYSTEMINFO.md +14 -0
  20. package/TROUBLESHOOT.md +56 -0
  21. package/UTILITIES.md +473 -0
  22. package/adapter.js +8845 -0
  23. package/adapterBase.js +1488 -0
  24. package/entities/.generic/action.json +214 -0
  25. package/entities/.generic/schema.json +28 -0
  26. package/entities/.system/action.json +50 -0
  27. package/entities/.system/mockdatafiles/getToken-default.json +3 -0
  28. package/entities/.system/mockdatafiles/healthcheck-default.json +3 -0
  29. package/entities/.system/schema.json +19 -0
  30. package/entities/.system/schemaTokenReq.json +53 -0
  31. package/entities/.system/schemaTokenResp.json +53 -0
  32. package/entities/AccountSettings/action.json +25 -0
  33. package/entities/AccountSettings/schema.json +19 -0
  34. package/entities/CodeSigningConfigs/action.json +127 -0
  35. package/entities/CodeSigningConfigs/schema.json +57 -0
  36. package/entities/EventSourceMappings/action.json +106 -0
  37. package/entities/EventSourceMappings/schema.json +78 -0
  38. package/entities/Functions/action.json +860 -0
  39. package/entities/Functions/schema.json +170 -0
  40. package/entities/Layers/action.json +189 -0
  41. package/entities/Layers/schema.json +126 -0
  42. package/entities/Tags/action.json +65 -0
  43. package/entities/Tags/schema.json +32 -0
  44. package/error.json +190 -0
  45. package/metadata.json +58 -0
  46. package/package.json +77 -0
  47. package/pronghorn.json +4833 -0
  48. package/propertiesDecorators.json +14 -0
  49. package/propertiesSchema.json +1635 -0
  50. package/report/AWS Lambda-swagger.fixed.json +15883 -0
  51. package/report/adapterInfo.json +10 -0
  52. package/report/creationReport.json +615 -0
  53. package/sampleProperties.json +274 -0
  54. package/test/integration/adapterTestBasicGet.js +117 -0
  55. package/test/integration/adapterTestConnectivity.js +117 -0
  56. package/test/integration/adapterTestIntegration.js +2103 -0
  57. package/test/unit/adapterBaseTestUnit.js +1626 -0
  58. package/test/unit/adapterTestUnit.js +3942 -0
  59. package/utils/adapterInfo.js +156 -0
  60. package/utils/argParser.js +44 -0
  61. package/utils/checkMigrate.js +102 -0
  62. package/utils/entitiesToDB.js +190 -0
  63. package/utils/findPath.js +74 -0
  64. package/utils/logger.js +26 -0
  65. package/utils/methodDocumentor.js +273 -0
  66. package/utils/modify.js +153 -0
  67. package/utils/mongoDbConnection.js +79 -0
  68. package/utils/mongoUtils.js +162 -0
  69. package/utils/pre-commit.sh +32 -0
  70. package/utils/removeHooks.js +20 -0
  71. package/utils/setup.js +33 -0
  72. package/utils/taskMover.js +308 -0
  73. package/utils/tbScript.js +103 -0
  74. package/utils/tbUtils.js +347 -0
  75. package/utils/testRunner.js +298 -0
  76. package/utils/troubleshootingAdapter.js +177 -0
  77. package/utils/updateAdapterConfig.js +158 -0
@@ -0,0 +1,274 @@
1
+ {
2
+ "id": "Adapter-aws_lambda",
3
+ "type": "AwsLambda",
4
+ "properties": {
5
+ "host": "lambda.amazonaws.com",
6
+ "region": "us-east-1",
7
+ "port": 80,
8
+ "choosepath": "",
9
+ "base_path": "/",
10
+ "version": "",
11
+ "cache_location": "none",
12
+ "encode_pathvars": true,
13
+ "encode_queryvars": true,
14
+ "save_metric": false,
15
+ "stub": true,
16
+ "protocol": "http",
17
+ "authentication": {
18
+ "auth_method": "aws_authentication",
19
+ "username": "username",
20
+ "password": "password",
21
+ "token": "token",
22
+ "token_timeout": 600000,
23
+ "token_cache": "local",
24
+ "invalid_token_error": 401,
25
+ "auth_field": "header.headers.Authorization",
26
+ "auth_field_format": "Basic {b64}{username}:{password}{/b64}",
27
+ "auth_logging": false,
28
+ "client_id": "",
29
+ "client_secret": "",
30
+ "grant_type": "",
31
+ "sensitive": [],
32
+ "sso": {
33
+ "protocol": "",
34
+ "host": "",
35
+ "port": 0
36
+ },
37
+ "multiStepAuthCalls": [
38
+ {
39
+ "name": "",
40
+ "requestFields": {},
41
+ "responseFields": {},
42
+ "successfullResponseCode": 200
43
+ }
44
+ ],
45
+ "aws_access_key": "aws_access_key",
46
+ "aws_secret_key": "aws_secret_key",
47
+ "aws_session_token": "aws_session_token",
48
+ "aws_iam_role": "",
49
+ "aws_sts": {
50
+ "region": "us-east-1",
51
+ "sslEnable": true,
52
+ "endpoint": "",
53
+ "proxy": "",
54
+ "proxyagent": "",
55
+ "use_proxy_for_initial_auth": false,
56
+ "externalId": ""
57
+ }
58
+ },
59
+ "healthcheck": {
60
+ "type": "none",
61
+ "frequency": 60000,
62
+ "query_object": {},
63
+ "addlHeaders": {}
64
+ },
65
+ "throttle": {
66
+ "throttle_enabled": false,
67
+ "number_pronghorns": 1,
68
+ "sync_async": "sync",
69
+ "max_in_queue": 1000,
70
+ "concurrent_max": 1,
71
+ "expire_timeout": 0,
72
+ "avg_runtime": 200,
73
+ "priorities": [
74
+ {
75
+ "value": 0,
76
+ "percent": 100
77
+ }
78
+ ]
79
+ },
80
+ "request": {
81
+ "number_redirects": 0,
82
+ "number_retries": 3,
83
+ "limit_retry_error": [
84
+ 0
85
+ ],
86
+ "failover_codes": [],
87
+ "attempt_timeout": 5000,
88
+ "global_request": {
89
+ "payload": {},
90
+ "uriOptions": {},
91
+ "addlHeaders": {},
92
+ "authData": {}
93
+ },
94
+ "healthcheck_on_timeout": true,
95
+ "return_raw": false,
96
+ "archiving": false,
97
+ "return_request": false
98
+ },
99
+ "proxy": {
100
+ "enabled": false,
101
+ "host": "",
102
+ "port": 1,
103
+ "protocol": "http",
104
+ "username": "",
105
+ "password": ""
106
+ },
107
+ "ssl": {
108
+ "ecdhCurve": "",
109
+ "enabled": false,
110
+ "accept_invalid_cert": false,
111
+ "ca_file": "",
112
+ "key_file": "",
113
+ "cert_file": "",
114
+ "secure_protocol": "",
115
+ "ciphers": ""
116
+ },
117
+ "mongo": {
118
+ "url": "",
119
+ "host": "",
120
+ "port": 0,
121
+ "database": "",
122
+ "dbAuth": false,
123
+ "username": "",
124
+ "password": "",
125
+ "replSet": "",
126
+ "addSrv": false,
127
+ "db_ssl": {
128
+ "enabled": false,
129
+ "accept_invalid_cert": false,
130
+ "ca_file": "",
131
+ "key_file": "",
132
+ "cert_file": ""
133
+ }
134
+ },
135
+ "devicebroker": {
136
+ "enabled": false,
137
+ "getDevice": [
138
+ {
139
+ "path": "/get/devices/{id}",
140
+ "method": "GET",
141
+ "query": {},
142
+ "body": {},
143
+ "headers": {},
144
+ "handleFailure": "fail",
145
+ "requestFields": {
146
+ "id": "name"
147
+ },
148
+ "responseDatakey": "",
149
+ "responseFields": {
150
+ "name": "host",
151
+ "ostype": "os",
152
+ "ostypePrefix": "system-",
153
+ "ipaddress": "attributes.ipaddr",
154
+ "port": "443"
155
+ }
156
+ }
157
+ ],
158
+ "getDevicesFiltered": [
159
+ {
160
+ "path": "/get/devices",
161
+ "method": "GET",
162
+ "pagination": {
163
+ "offsetVar": "",
164
+ "limitVar": "",
165
+ "incrementBy": "limit",
166
+ "requestLocation": "query"
167
+ },
168
+ "query": {},
169
+ "body": {},
170
+ "headers": {},
171
+ "handleFailure": "fail",
172
+ "requestFields": {},
173
+ "responseDatakey": "",
174
+ "responseFields": {
175
+ "name": "host",
176
+ "ostype": "os",
177
+ "ostypePrefix": "system-",
178
+ "ipaddress": "attributes.ipaddr",
179
+ "port": "443"
180
+ }
181
+ }
182
+ ],
183
+ "isAlive": [
184
+ {
185
+ "path": "/get/devices/{id}/status",
186
+ "method": "GET",
187
+ "query": {},
188
+ "body": {},
189
+ "headers": {},
190
+ "handleFailure": "fail",
191
+ "requestFields": {
192
+ "id": "name"
193
+ },
194
+ "responseDatakey": "",
195
+ "responseFields": {
196
+ "status": "status",
197
+ "statusValue": "online"
198
+ }
199
+ }
200
+ ],
201
+ "getConfig": [
202
+ {
203
+ "path": "/get/devices/{id}/configPart1",
204
+ "method": "GET",
205
+ "query": {},
206
+ "body": {},
207
+ "headers": {},
208
+ "handleFailure": "fail",
209
+ "requestFields": {
210
+ "id": "name"
211
+ },
212
+ "responseDatakey": "",
213
+ "responseFields": {}
214
+ }
215
+ ],
216
+ "getCount": [
217
+ {
218
+ "path": "/get/devices",
219
+ "method": "GET",
220
+ "query": {},
221
+ "body": {},
222
+ "headers": {},
223
+ "handleFailure": "fail",
224
+ "requestFields": {},
225
+ "responseDatakey": "",
226
+ "responseFields": {}
227
+ }
228
+ ]
229
+ },
230
+ "cache": {
231
+ "enabled": false,
232
+ "entities": [
233
+ {
234
+ "entityType": "",
235
+ "frequency": 1440,
236
+ "flushOnFail": false,
237
+ "limit": 1000,
238
+ "retryAttempts": 5,
239
+ "sort": true,
240
+ "populate": [
241
+ {
242
+ "path": "",
243
+ "method": "GET",
244
+ "pagination": {
245
+ "offsetVar": "",
246
+ "limitVar": "",
247
+ "incrementBy": "limit",
248
+ "requestLocation": "query"
249
+ },
250
+ "query": {},
251
+ "body": {},
252
+ "headers": {},
253
+ "handleFailure": "ignore",
254
+ "requestFields": {},
255
+ "responseDatakey": "",
256
+ "responseFields": {}
257
+ }
258
+ ],
259
+ "cachedTasks": [
260
+ {
261
+ "name": "",
262
+ "filterField": "",
263
+ "filterLoc": ""
264
+ }
265
+ ]
266
+ }
267
+ ]
268
+ }
269
+ },
270
+ "groups": [],
271
+ "brokers": [],
272
+ "logLevel": "none",
273
+ "timeout": 120000
274
+ }
@@ -0,0 +1,117 @@
1
+ /* @copyright Itential, LLC 2020 */
2
+
3
+ /* global describe it log before after */
4
+ /* eslint global-require: warn */
5
+ /* eslint no-unused-vars: warn */
6
+ /* eslint import/no-extraneous-dependencies: warn */
7
+ /* eslint import/no-dynamic-require: warn */
8
+ /* eslint import/no-unresolved: warn */
9
+ /* eslint no-loop-func: warn */
10
+
11
+ /* This performs a number of GET calls (defaults to 5 calls) which do not reuire an input, to test connectivity and functionality.
12
+ The number of calls can be modified if running from CLI. */
13
+
14
+ const assert = require('assert');
15
+
16
+ const log = require('../../utils/logger');
17
+ const { id } = require('../../package.json');
18
+ const { methods } = require('../../pronghorn.json');
19
+ const { parseArgs } = require('../../utils/argParser');
20
+
21
+ const {
22
+ properties, maxCalls
23
+ } = parseArgs();
24
+
25
+ // require the adapter that we are going to be using
26
+ const TestAdapter = require('../../adapter');
27
+
28
+ if (!properties) {
29
+ log.warn('No properties provided. Exiting process.');
30
+ process.exit(1);
31
+ }
32
+
33
+ let successCount = 0;
34
+ let calls = 0;
35
+ let attemptTimeout = 60000;
36
+ if (properties.request && properties.request.attempt_timeout) {
37
+ attemptTimeout = properties.request.attempt_timeout;
38
+ }
39
+
40
+ // turn off stub mode - basic get should not be run in stub mode
41
+ properties.stub = false;
42
+
43
+ describe('[integration] Adapter BasicGET Test', () => {
44
+ describe('Class Tests', () => {
45
+ const testAdapter = new TestAdapter(
46
+ id,
47
+ properties
48
+ );
49
+
50
+ after((done) => {
51
+ if (successCount === calls) {
52
+ log.info('\x1b[32m%s\x1b[0m', `\n\nSUCCESS: ${successCount} test(s) passed of ${calls} executed!`);
53
+ } else if (successCount > 0) {
54
+ log.error('\x1b[32m%s\x1b[0m', `\n\nPARTIAL SUCCESS: ${successCount} test(s) passed of ${calls} executed!`);
55
+ } else {
56
+ log.error('\x1b[31m%s\x1b[0m', '\n\nFAILURE: All tests failed.');
57
+ }
58
+ done();
59
+ });
60
+
61
+ const basicGets = methods.filter((method) => {
62
+ // ignore iapMetadata as the input since its optional and all functions will have it
63
+ const inputKeys = (method.input || [])
64
+ .map((param) => param.name)
65
+ .filter((name) => name !== 'iapMetadata');
66
+ return method.route.verb === 'GET' && inputKeys.length === 0 && !method.name.startsWith('iap');
67
+ });
68
+
69
+ if (basicGets.length === 0) {
70
+ log.warn('No non-parameter GET calls found.');
71
+ process.exitCode = 0;
72
+ return;
73
+ }
74
+
75
+ const functionNames = basicGets.map((g) => g.name);
76
+ calls = functionNames.length;
77
+ if (calls > maxCalls) {
78
+ calls = maxCalls;
79
+ }
80
+
81
+ // test up to the first 5 get calls without parameters
82
+ for (let f = 0; f < calls; f += 1) {
83
+ const fnName = functionNames[f];
84
+ const method = basicGets.find((m) => m.name === fnName);
85
+ const hasIapMetadata = Array.isArray(method.input) && method.input.some((param) => param.name === 'iapMetadata');
86
+ describe(`#${functionNames[f]}`, () => {
87
+ it('should return valid response without error', (done) => {
88
+ const callback = (data, error) => {
89
+ try {
90
+ assert.equal(undefined, error);
91
+ assert.notEqual(undefined, data);
92
+ assert.notEqual(null, data);
93
+ assert.notEqual(undefined, data.response);
94
+ assert.notEqual(null, data.response);
95
+ successCount += 1;
96
+ done();
97
+ } catch (err) {
98
+ log.error(`Test Failure in ${fnName}: ${err}`);
99
+ done(err);
100
+ }
101
+ };
102
+
103
+ try {
104
+ if (hasIapMetadata) {
105
+ testAdapter[fnName](null, callback);
106
+ } else {
107
+ testAdapter[fnName](callback);
108
+ }
109
+ } catch (err) {
110
+ log.error(`Unexpected error in test for ${fnName}: ${err}`);
111
+ done(err);
112
+ }
113
+ }).timeout(attemptTimeout);
114
+ });
115
+ }
116
+ });
117
+ });
@@ -0,0 +1,117 @@
1
+ /* @copyright Itential, LLC 2020 */
2
+
3
+ /* global describe it context before after */
4
+ /* eslint no-unused-vars: warn */
5
+
6
+ const assert = require('assert');
7
+ const https = require('https');
8
+ const mocha = require('mocha');
9
+ const ping = require('ping');
10
+ const dns = require('dns');
11
+ const { parseArgs } = require('../../utils/argParser');
12
+
13
+ const dnsPromises = dns.promises;
14
+ const { host } = parseArgs();
15
+
16
+ describe('[integration] Adapter Test', () => {
17
+ context(`Testing network connection on ${host}`, () => {
18
+ after((done) => {
19
+ done();
20
+ });
21
+
22
+ it('DNS resolve', (done) => {
23
+ dnsPromises.lookup(host, { all: true })
24
+ .then((result) => {
25
+ try {
26
+ assert.ok(result.length > 0);
27
+ done();
28
+ } catch (error) {
29
+ done(error);
30
+ }
31
+ })
32
+ .catch((err) => {
33
+ done(err);
34
+ });
35
+ });
36
+
37
+ it('Responds to ping', (done) => {
38
+ ping.promise.probe(host)
39
+ .then((result) => {
40
+ try {
41
+ assert.ok(result.alive);
42
+ done();
43
+ } catch (error) {
44
+ done(error);
45
+ }
46
+ })
47
+ .catch((err) => {
48
+ done(err);
49
+ });
50
+ });
51
+
52
+ it('Support HTTPS on port 443', (done) => {
53
+ const requestOptions = {
54
+ host,
55
+ port: 443,
56
+ method: 'HEAD'
57
+ };
58
+
59
+ const req = https.request(requestOptions, (res) => {
60
+ try {
61
+ assert.ok(res.statusCode >= 200 && res.statusCode < 400);
62
+ done();
63
+ } catch (error) {
64
+ done(error);
65
+ }
66
+ });
67
+
68
+ req.on('error', (err) => {
69
+ done(err);
70
+ });
71
+
72
+ req.end();
73
+ });
74
+
75
+ it('Support IPv4', (done) => {
76
+ const options = {
77
+ family: 4,
78
+ hints: dns.ADDRCONFIG
79
+ };
80
+
81
+ dnsPromises.lookup(host, options)
82
+ .then((result) => {
83
+ try {
84
+ const { address, family } = result;
85
+ assert.ok(address !== null && family === 4);
86
+ done();
87
+ } catch (error) {
88
+ done(error);
89
+ }
90
+ })
91
+ .catch((err) => {
92
+ done(err);
93
+ });
94
+ });
95
+
96
+ it('Support IPv6', (done) => {
97
+ const options = {
98
+ family: 6,
99
+ hints: dns.ADDRCONFIG
100
+ };
101
+
102
+ dnsPromises.lookup(host, options)
103
+ .then((result) => {
104
+ try {
105
+ const { address, family } = result;
106
+ assert.ok(address !== null && family === 6);
107
+ done();
108
+ } catch (error) {
109
+ done(error);
110
+ }
111
+ })
112
+ .catch((err) => {
113
+ done(err);
114
+ });
115
+ });
116
+ });
117
+ });