cdk-ecr-deployment 2.2.0 → 2.3.0

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.
@@ -0,0 +1,101 @@
1
+ 'use strict'
2
+
3
+ const https = require('https')
4
+ const http = require('http')
5
+ const { URL } = require('url')
6
+
7
+ class HttpProxyAgent extends http.Agent {
8
+ constructor (options) {
9
+ const { proxy, ...opts } = options
10
+ super(opts)
11
+ this.proxy = typeof proxy === 'string'
12
+ ? new URL(proxy)
13
+ : proxy
14
+ }
15
+
16
+ createConnection (options, callback) {
17
+ const requestOptions = {
18
+ method: 'CONNECT',
19
+ host: this.proxy.hostname,
20
+ port: this.proxy.port,
21
+ path: `${options.host}:${options.port}`,
22
+ setHost: false,
23
+ headers: { connection: this.keepAlive ? 'keep-alive' : 'close', host: `${options.host}:${options.port}` },
24
+ agent: false
25
+ }
26
+
27
+ if (this.proxy.username || this.proxy.password) {
28
+ const base64 = Buffer.from(`${this.proxy.username || ''}:${this.proxy.password || ''}`).toString('base64')
29
+ requestOptions.headers['proxy-authorization'] = `Basic ${base64}`
30
+ }
31
+
32
+ const request = (this.proxy.protocol === 'http:' ? http : https).request(requestOptions)
33
+ request.once('connect', (response, socket, head) => {
34
+ request.removeAllListeners()
35
+ socket.removeAllListeners()
36
+ if (response.statusCode === 200) {
37
+ callback(null, socket)
38
+ } else {
39
+ callback(new Error(`Bad response: ${response.statusCode}`), null)
40
+ }
41
+ })
42
+
43
+ request.once('error', err => {
44
+ request.removeAllListeners()
45
+ callback(err, null)
46
+ })
47
+
48
+ request.end()
49
+ }
50
+ }
51
+
52
+ class HttpsProxyAgent extends https.Agent {
53
+ constructor (options) {
54
+ const { proxy, ...opts } = options
55
+ super(opts)
56
+ this.proxy = typeof proxy === 'string'
57
+ ? new URL(proxy)
58
+ : proxy
59
+ }
60
+
61
+ createConnection (options, callback) {
62
+ const requestOptions = {
63
+ method: 'CONNECT',
64
+ host: this.proxy.hostname,
65
+ port: this.proxy.port,
66
+ path: `${options.host}:${options.port}`,
67
+ setHost: false,
68
+ headers: { connection: this.keepAlive ? 'keep-alive' : 'close', host: `${options.host}:${options.port}` },
69
+ agent: false
70
+ }
71
+
72
+ if (this.proxy.username || this.proxy.password) {
73
+ const base64 = Buffer.from(`${this.proxy.username || ''}:${this.proxy.password || ''}`).toString('base64')
74
+ requestOptions.headers['proxy-authorization'] = `Basic ${base64}`
75
+ }
76
+
77
+ const request = (this.proxy.protocol === 'http:' ? http : https).request(requestOptions)
78
+ request.once('connect', (response, socket, head) => {
79
+ request.removeAllListeners()
80
+ socket.removeAllListeners()
81
+ if (response.statusCode === 200) {
82
+ const secureSocket = super.createConnection({ ...options, socket })
83
+ callback(null, secureSocket)
84
+ } else {
85
+ callback(new Error(`Bad response: ${response.statusCode}`), null)
86
+ }
87
+ })
88
+
89
+ request.once('error', err => {
90
+ request.removeAllListeners()
91
+ callback(err, null)
92
+ })
93
+
94
+ request.end()
95
+ }
96
+ }
97
+
98
+ module.exports = {
99
+ HttpProxyAgent,
100
+ HttpsProxyAgent
101
+ }
@@ -0,0 +1,5 @@
1
+ import mod from './index.js'
2
+
3
+ export default mod
4
+ export const HttpProxyAgent = mod.HttpProxyAgent
5
+ export const HttpsProxyAgent = mod.HttpsProxyAgent
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "hpagent",
3
+ "version": "0.1.2",
4
+ "description": "A ready to use http and https agent for working with proxies that keeps connections alive!",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "require": "./index.js",
10
+ "import": "./index.mjs"
11
+ },
12
+ "./": "./"
13
+ },
14
+ "scripts": {
15
+ "test": "standard && ava -v test/*.test.js && tsd"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/delvedor/hpagent.git"
20
+ },
21
+ "keywords": [
22
+ "agent",
23
+ "http",
24
+ "https",
25
+ "secure",
26
+ "proxy",
27
+ "alive",
28
+ "keep-alive"
29
+ ],
30
+ "author": "Tomas Della Vedova",
31
+ "license": "MIT",
32
+ "bugs": {
33
+ "url": "https://github.com/delvedor/hpagent/issues"
34
+ },
35
+ "homepage": "https://github.com/delvedor/hpagent#readme",
36
+ "tsd": {
37
+ "directory": "test"
38
+ },
39
+ "devDependencies": {
40
+ "ava": "^3.10.1",
41
+ "got": "^11.5.1",
42
+ "needle": "^2.5.0",
43
+ "node-fetch": "^2.6.0",
44
+ "proxy": "^1.0.2",
45
+ "simple-get": "^4.0.0",
46
+ "standard": "^16.0.1",
47
+ "tsd": "^0.13.1"
48
+ }
49
+ }
@@ -0,0 +1,111 @@
1
+ 'use strict'
2
+
3
+ const got = require('got')
4
+ const test = require('ava')
5
+ const {
6
+ createServer,
7
+ createSecureServer,
8
+ createProxy,
9
+ createSecureProxy
10
+ } = require('./utils')
11
+ const { HttpProxyAgent, HttpsProxyAgent } = require('../')
12
+
13
+ test('http to http', async t => {
14
+ const server = await createServer()
15
+ const proxy = await createProxy()
16
+ server.on('request', (req, res) => res.end('ok'))
17
+
18
+ const response = await got(`http://${server.address().address}:${server.address().port}`, {
19
+ agent: {
20
+ http: new HttpProxyAgent({
21
+ keepAlive: true,
22
+ keepAliveMsecs: 1000,
23
+ maxSockets: 256,
24
+ maxFreeSockets: 256,
25
+ scheduling: 'lifo',
26
+ proxy: `http://${proxy.address().address}:${proxy.address().port}`
27
+ })
28
+ }
29
+ })
30
+
31
+ t.is(response.body, 'ok')
32
+ t.is(response.statusCode, 200)
33
+
34
+ server.close()
35
+ proxy.close()
36
+ })
37
+
38
+ test('https to http', async t => {
39
+ const server = await createServer()
40
+ const proxy = await createSecureProxy()
41
+ server.on('request', (req, res) => res.end('ok'))
42
+
43
+ const response = await got(`http://${server.address().address}:${server.address().port}`, {
44
+ agent: {
45
+ http: new HttpProxyAgent({
46
+ keepAlive: true,
47
+ keepAliveMsecs: 1000,
48
+ maxSockets: 256,
49
+ maxFreeSockets: 256,
50
+ scheduling: 'lifo',
51
+ proxy: `https://${proxy.address().address}:${proxy.address().port}`
52
+ })
53
+ }
54
+ })
55
+
56
+ t.is(response.body, 'ok')
57
+ t.is(response.statusCode, 200)
58
+
59
+ server.close()
60
+ proxy.close()
61
+ })
62
+
63
+ test('http to https', async t => {
64
+ const server = await createSecureServer()
65
+ const proxy = await createProxy()
66
+ server.on('request', (req, res) => res.end('ok'))
67
+
68
+ const response = await got(`https://${server.address().address}:${server.address().port}`, {
69
+ agent: {
70
+ http: new HttpsProxyAgent({
71
+ keepAlive: true,
72
+ keepAliveMsecs: 1000,
73
+ maxSockets: 256,
74
+ maxFreeSockets: 256,
75
+ scheduling: 'lifo',
76
+ proxy: `http://${proxy.address().address}:${proxy.address().port}`
77
+ })
78
+ }
79
+ })
80
+
81
+ t.is(response.body, 'ok')
82
+ t.is(response.statusCode, 200)
83
+
84
+ server.close()
85
+ proxy.close()
86
+ })
87
+
88
+ test('https to https', async t => {
89
+ const server = await createSecureServer()
90
+ const proxy = await createSecureProxy()
91
+ server.on('request', (req, res) => res.end('ok'))
92
+
93
+ const response = await got(`https://${server.address().address}:${server.address().port}`, {
94
+ agent: {
95
+ http: new HttpsProxyAgent({
96
+ keepAlive: true,
97
+ keepAliveMsecs: 1000,
98
+ maxSockets: 256,
99
+ maxFreeSockets: 256,
100
+ scheduling: 'lifo',
101
+ proxy: `https://${proxy.address().address}:${proxy.address().port}`
102
+ })
103
+ }
104
+ })
105
+
106
+ t.is(response.body, 'ok')
107
+ t.is(response.statusCode, 200)
108
+
109
+ server.close()
110
+ proxy.close()
111
+ })
@@ -0,0 +1,351 @@
1
+ 'use strict'
2
+
3
+ const http = require('http')
4
+ const test = require('ava')
5
+ const { createServer, createProxy } = require('./utils')
6
+ const { HttpProxyAgent } = require('../')
7
+
8
+ function request (opts) {
9
+ return new Promise((resolve, reject) => {
10
+ const req = http.request(opts, resolve)
11
+ req.on('error', reject)
12
+ req.end(opts.body)
13
+ })
14
+ }
15
+
16
+ test('Basic', async t => {
17
+ const server = await createServer()
18
+ const proxy = await createProxy()
19
+ server.on('request', (req, res) => res.end('ok'))
20
+
21
+ const response = await request({
22
+ method: 'GET',
23
+ hostname: server.address().address,
24
+ port: server.address().port,
25
+ path: '/',
26
+ agent: new HttpProxyAgent({
27
+ keepAlive: true,
28
+ keepAliveMsecs: 1000,
29
+ maxSockets: 256,
30
+ maxFreeSockets: 256,
31
+ scheduling: 'lifo',
32
+ proxy: `http://${proxy.address().address}:${proxy.address().port}`
33
+ })
34
+ })
35
+
36
+ let body = ''
37
+ response.setEncoding('utf8')
38
+ for await (const chunk of response) {
39
+ body += chunk
40
+ }
41
+
42
+ t.is(body, 'ok')
43
+ t.is(response.statusCode, 200)
44
+
45
+ server.close()
46
+ proxy.close()
47
+ })
48
+
49
+ test('Connection header (keep-alive)', async t => {
50
+ const server = await createServer()
51
+ const proxy = await createProxy()
52
+ server.on('request', (req, res) => res.end('ok'))
53
+
54
+ proxy.authenticate = function (req, fn) {
55
+ t.is(req.headers.connection, 'keep-alive')
56
+ fn(null, true)
57
+ }
58
+
59
+ const response = await request({
60
+ method: 'GET',
61
+ hostname: server.address().address,
62
+ port: server.address().port,
63
+ path: '/',
64
+ agent: new HttpProxyAgent({
65
+ keepAlive: true,
66
+ keepAliveMsecs: 1000,
67
+ maxSockets: 256,
68
+ maxFreeSockets: 256,
69
+ scheduling: 'lifo',
70
+ proxy: `http://${proxy.address().address}:${proxy.address().port}`
71
+ })
72
+ })
73
+
74
+ let body = ''
75
+ response.setEncoding('utf8')
76
+ for await (const chunk of response) {
77
+ body += chunk
78
+ }
79
+
80
+ t.is(body, 'ok')
81
+ t.is(response.statusCode, 200)
82
+
83
+ server.close()
84
+ proxy.close()
85
+ })
86
+
87
+ test('Connection header (close)', async t => {
88
+ const server = await createServer()
89
+ const proxy = await createProxy()
90
+ server.on('request', (req, res) => res.end('ok'))
91
+
92
+ proxy.authenticate = function (req, fn) {
93
+ t.is(req.headers.connection, 'close')
94
+ fn(null, true)
95
+ }
96
+
97
+ const response = await request({
98
+ method: 'GET',
99
+ hostname: server.address().address,
100
+ port: server.address().port,
101
+ path: '/',
102
+ agent: new HttpProxyAgent({
103
+ keepAlive: false,
104
+ keepAliveMsecs: 1000,
105
+ maxSockets: Infinity,
106
+ maxFreeSockets: 256,
107
+ scheduling: 'lifo',
108
+ proxy: `http://${proxy.address().address}:${proxy.address().port}`
109
+ })
110
+ })
111
+
112
+ let body = ''
113
+ response.setEncoding('utf8')
114
+ for await (const chunk of response) {
115
+ body += chunk
116
+ }
117
+
118
+ t.is(body, 'ok')
119
+ t.is(response.statusCode, 200)
120
+
121
+ server.close()
122
+ proxy.close()
123
+ })
124
+
125
+ test('Proxy authentication (empty)', async t => {
126
+ const server = await createServer()
127
+ const proxy = await createProxy()
128
+ server.on('request', (req, res) => res.end('ok'))
129
+
130
+ proxy.authenticate = function (req, fn) {
131
+ fn(null, req.headers['proxy-authorization'] === undefined)
132
+ }
133
+
134
+ const response = await request({
135
+ method: 'GET',
136
+ hostname: server.address().address,
137
+ port: server.address().port,
138
+ path: '/',
139
+ agent: new HttpProxyAgent({
140
+ keepAlive: true,
141
+ keepAliveMsecs: 1000,
142
+ maxSockets: 256,
143
+ maxFreeSockets: 256,
144
+ scheduling: 'lifo',
145
+ proxy: `http://${proxy.address().address}:${proxy.address().port}`
146
+ })
147
+ })
148
+
149
+ let body = ''
150
+ response.setEncoding('utf8')
151
+ for await (const chunk of response) {
152
+ body += chunk
153
+ }
154
+
155
+ t.is(body, 'ok')
156
+ t.is(response.statusCode, 200)
157
+
158
+ server.close()
159
+ proxy.close()
160
+ })
161
+
162
+ test('Proxy authentication', async t => {
163
+ const server = await createServer()
164
+ const proxy = await createProxy()
165
+ server.on('request', (req, res) => res.end('ok'))
166
+
167
+ proxy.authenticate = function (req, fn) {
168
+ fn(null, req.headers['proxy-authorization'] === `Basic ${Buffer.from('hello:world').toString('base64')}`)
169
+ }
170
+
171
+ const response = await request({
172
+ method: 'GET',
173
+ hostname: server.address().address,
174
+ port: server.address().port,
175
+ path: '/',
176
+ agent: new HttpProxyAgent({
177
+ keepAlive: true,
178
+ keepAliveMsecs: 1000,
179
+ maxSockets: 256,
180
+ maxFreeSockets: 256,
181
+ scheduling: 'lifo',
182
+ proxy: `http://hello:world@${proxy.address().address}:${proxy.address().port}`
183
+ })
184
+ })
185
+
186
+ let body = ''
187
+ response.setEncoding('utf8')
188
+ for await (const chunk of response) {
189
+ body += chunk
190
+ }
191
+
192
+ t.is(body, 'ok')
193
+ t.is(response.statusCode, 200)
194
+
195
+ server.close()
196
+ proxy.close()
197
+ })
198
+
199
+ test('Configure the agent to reuse sockets', async t => {
200
+ const server = await createServer()
201
+ const proxy = await createProxy()
202
+ server.on('request', (req, res) => res.end('ok'))
203
+
204
+ let count = 0
205
+ proxy.on('connection', () => {
206
+ count += 1
207
+ t.is(count, 1)
208
+ })
209
+
210
+ const agent = new HttpProxyAgent({
211
+ keepAlive: true,
212
+ keepAliveMsecs: 1000,
213
+ maxSockets: 256,
214
+ maxFreeSockets: 256,
215
+ scheduling: 'lifo',
216
+ proxy: `http://${proxy.address().address}:${proxy.address().port}`
217
+ })
218
+
219
+ let response = await request({
220
+ method: 'GET',
221
+ hostname: server.address().address,
222
+ port: server.address().port,
223
+ path: '/',
224
+ agent
225
+ })
226
+
227
+ let body = ''
228
+ response.setEncoding('utf8')
229
+ for await (const chunk of response) {
230
+ body += chunk
231
+ }
232
+
233
+ t.is(body, 'ok')
234
+ t.is(response.statusCode, 200)
235
+
236
+ response = await request({
237
+ method: 'GET',
238
+ hostname: server.address().address,
239
+ port: server.address().port,
240
+ path: '/',
241
+ agent
242
+ })
243
+
244
+ body = ''
245
+ response.setEncoding('utf8')
246
+ for await (const chunk of response) {
247
+ body += chunk
248
+ }
249
+
250
+ t.is(body, 'ok')
251
+ t.is(response.statusCode, 200)
252
+
253
+ server.close()
254
+ proxy.close()
255
+ })
256
+
257
+ test('Configure the agent to NOT reuse sockets', async t => {
258
+ const server = await createServer()
259
+ const proxy = await createProxy()
260
+ server.on('request', (req, res) => res.end('ok'))
261
+
262
+ const ports = []
263
+ proxy.on('connection', socket => {
264
+ t.false(ports.includes(socket.remotePort))
265
+ ports.push(socket.remotePort)
266
+ })
267
+
268
+ const agent = new HttpProxyAgent({
269
+ keepAlive: false,
270
+ keepAliveMsecs: 1000,
271
+ maxSockets: Infinity,
272
+ maxFreeSockets: 256,
273
+ scheduling: 'lifo',
274
+ proxy: `http://${proxy.address().address}:${proxy.address().port}`
275
+ })
276
+
277
+ let response = await request({
278
+ method: 'GET',
279
+ hostname: server.address().address,
280
+ port: server.address().port,
281
+ path: '/',
282
+ agent
283
+ })
284
+
285
+ let body = ''
286
+ response.setEncoding('utf8')
287
+ for await (const chunk of response) {
288
+ body += chunk
289
+ }
290
+
291
+ t.is(body, 'ok')
292
+ t.is(response.statusCode, 200)
293
+
294
+ response = await request({
295
+ method: 'GET',
296
+ hostname: server.address().address,
297
+ port: server.address().port,
298
+ path: '/',
299
+ agent
300
+ })
301
+
302
+ body = ''
303
+ response.setEncoding('utf8')
304
+ for await (const chunk of response) {
305
+ body += chunk
306
+ }
307
+
308
+ t.is(body, 'ok')
309
+ t.is(response.statusCode, 200)
310
+
311
+ server.close()
312
+ proxy.close()
313
+ })
314
+
315
+ test('Test Host Header', async t => {
316
+ const server = await createServer()
317
+ const proxy = await createProxy()
318
+ server.on('request', (req, res) => res.end('ok'))
319
+
320
+ proxy.authenticate = function (req, fn) {
321
+ t.is(req.headers.host, `${server.address().address}:${server.address().port}`)
322
+ fn(null, true)
323
+ }
324
+
325
+ const response = await request({
326
+ method: 'GET',
327
+ hostname: server.address().address,
328
+ port: server.address().port,
329
+ path: '/',
330
+ agent: new HttpProxyAgent({
331
+ keepAlive: true,
332
+ keepAliveMsecs: 1000,
333
+ maxSockets: 256,
334
+ maxFreeSockets: 256,
335
+ scheduling: 'lifo',
336
+ proxy: `http://${proxy.address().address}:${proxy.address().port}`
337
+ })
338
+ })
339
+
340
+ let body = ''
341
+ response.setEncoding('utf8')
342
+ for await (const chunk of response) {
343
+ body += chunk
344
+ }
345
+
346
+ t.is(body, 'ok')
347
+ t.is(response.statusCode, 200)
348
+
349
+ server.close()
350
+ proxy.close()
351
+ })