@saidsef/aws-kinesis-local 1.1.0 → 1.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.
package/README.md CHANGED
@@ -57,7 +57,7 @@ Read the Docs publishes the pages under [`docs/`](docs) with MkDocs Material at
57
57
  | [Kubernetes](docs/kubernetes.md) | Helm, Kustomize and Argo CD installs |
58
58
  | [Supported operations](docs/supported-operations.md) | Implemented operations, differences from AWS and KCL setup |
59
59
  | [Development](docs/development.md) | Builds, tests, CI workflows, releases and image tags |
60
- | [Specifications](docs/specs/architecture.md) | Architecture, request validation, storage, enhanced fan-out, upgrading from kinesalite and testing |
60
+ | [Specifications](docs/specs/architecture.md) | Architecture, request validation, storage, enhanced fan-out and testing |
61
61
  | [Chart values](charts/kinesis/README.md) | Every Helm value, generated by helm-docs |
62
62
 
63
63
  ## Contributing
package/dist/cli.js CHANGED
@@ -5,15 +5,15 @@ const HELP = [
5
5
  '',
6
6
  'Usage: aws-kinesis-local [--port <port>] [--path <path>] [--ssl] [options]',
7
7
  '',
8
- 'Serves the Amazon Kinesis Data Streams API in JSON and CBOR over HTTP/1.1 and HTTP/2, optionally backed by SQLite',
8
+ 'Serves the Amazon Kinesis Data Streams API in JSON and CBOR over HTTP/1.1 and HTTP/2, with or without TLS, optionally backed by SQLite',
9
9
  '',
10
10
  'Options:',
11
11
  '--help Display this help message and exit',
12
12
  '--port <port> The port to listen on (default: 4567)',
13
13
  '--path <path> The directory for the SQLite store (in-memory by default)',
14
- '--ssl Enable SSL for the web server (default: false)',
15
- '--key <file> PEM private key for --ssl (default: a generated self-signed key)',
16
- '--cert <file> PEM certificate for --ssl (default: a generated self-signed certificate)',
14
+ '--ssl Accept TLS connections only (default: TLS and plain HTTP on the same port)',
15
+ '--key <file> PEM private key for TLS connections (default: a generated self-signed key)',
16
+ '--cert <file> PEM certificate for TLS connections (default: a generated self-signed certificate)',
17
17
  '--createStreamMs <ms> Amount of time streams stay in CREATING state (default: 500)',
18
18
  '--deleteStreamMs <ms> Amount of time streams stay in DELETING state (default: 500)',
19
19
  '--updateStreamMs <ms> Amount of time streams stay in UPDATING state (default: 500)',
package/dist/server.js CHANGED
@@ -7,6 +7,7 @@ import { createHandler } from './handler.js';
7
7
  import { registerTransitions } from './operations/index.js';
8
8
  import { Store } from './store/store.js';
9
9
  const HTTP2_PREFACE = Buffer.from('PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n', 'latin1');
10
+ const TLS_HANDSHAKE = 0x16;
10
11
  export function defaultOptions() {
11
12
  return {
12
13
  port: 4567,
@@ -21,22 +22,26 @@ export function defaultOptions() {
21
22
  shutdownMs: 5000,
22
23
  };
23
24
  }
24
- function routeByProtocol(socket, http1, http2) {
25
+ function routeByProtocol(socket, servers) {
25
26
  let buffered = Buffer.alloc(0);
26
27
  const onData = (chunk) => {
27
28
  buffered = Buffer.concat([buffered, chunk]);
29
+ const isTls = buffered[0] === TLS_HANDSHAKE;
28
30
  const length = Math.min(buffered.length, HTTP2_PREFACE.length);
29
- const isHttp2 = buffered.subarray(0, length).equals(HTTP2_PREFACE.subarray(0, length));
31
+ const isHttp2 = !isTls && buffered.subarray(0, length).equals(HTTP2_PREFACE.subarray(0, length));
30
32
  if (isHttp2 && buffered.length < HTTP2_PREFACE.length)
31
33
  return;
32
34
  socket.off('data', onData);
33
35
  socket.pause();
34
36
  socket.unshift(buffered);
35
- if (isHttp2) {
36
- http2.emit('connection', socket);
37
+ if (isTls) {
38
+ servers.tls.emit('connection', socket);
39
+ }
40
+ else if (isHttp2) {
41
+ servers.http2.emit('connection', socket);
37
42
  }
38
43
  else {
39
- http1.emit('connection', socket);
44
+ servers.http1.emit('connection', socket);
40
45
  socket.resume();
41
46
  }
42
47
  };
@@ -49,6 +54,9 @@ function hostname(address) {
49
54
  }
50
55
  export async function start(overrides = {}) {
51
56
  const options = { ...defaultOptions(), ...overrides };
57
+ const credentials = options.keyFile && options.certFile
58
+ ? { key: readFileSync(options.keyFile), cert: readFileSync(options.certFile) }
59
+ : selfSignedCertificate();
52
60
  const store = new Store(options);
53
61
  registerTransitions(store);
54
62
  store.startExpiry();
@@ -74,22 +82,19 @@ export async function start(overrides = {}) {
74
82
  sessions.add(session);
75
83
  session.once('close', () => sessions.delete(session));
76
84
  };
85
+ const secure = createSecureServer({ ...credentials, allowHTTP1: true }, handler);
86
+ secure.on('session', trackSession);
77
87
  let server;
78
88
  if (options.ssl) {
79
- const credentials = options.keyFile && options.certFile
80
- ? { key: readFileSync(options.keyFile), cert: readFileSync(options.certFile) }
81
- : selfSignedCertificate();
82
- const secure = createSecureServer({ ...credentials, allowHTTP1: true }, handler);
83
- secure.on('session', trackSession);
84
89
  server = secure;
85
90
  }
86
91
  else {
87
- const http1 = createHttpServer(handler);
88
92
  const http2 = createHttp2Server(handler);
89
93
  http2.on('session', trackSession);
94
+ const servers = { http1: createHttpServer(handler), http2: http2, tls: secure };
90
95
  server = createNetServer(socket => {
91
96
  socket.on('error', () => socket.destroy());
92
- routeByProtocol(socket, http1, http2);
97
+ routeByProtocol(socket, servers);
93
98
  });
94
99
  }
95
100
  server.on('connection', (socket) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saidsef/aws-kinesis-local",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "Local Amazon Kinesis Data Streams server for development and CI, with all 45 operations, enhanced fan-out, JSON and CBOR over HTTP/1.1 and HTTP/2",
5
5
  "keywords": [
6
6
  "aws",
@@ -10,8 +10,7 @@
10
10
  "mock",
11
11
  "testing",
12
12
  "kcl",
13
- "enhanced-fan-out",
14
- "kinesalite"
13
+ "enhanced-fan-out"
15
14
  ],
16
15
  "author": "Said Sef <saidsef@gmail.com>",
17
16
  "license": "MIT",