Skip to content

Commit

Permalink
Support new ssh key formats
Browse files Browse the repository at this point in the history
  • Loading branch information
maxcnunes committed Mar 24, 2021
1 parent 0369c8a commit bad0a2a
Show file tree
Hide file tree
Showing 18 changed files with 333 additions and 43 deletions.
24 changes: 13 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:
strategy:
matrix:
include:
- node-version: 10.x
mysql-version: 5.7
maraidb-version: 10.1
cassandra-version: 2.1
postgres-version: 9
sqlserver-collation: Latin1_General_CI_AS
# - node-version: 10.x
# mysql-version: 5.7
# maraidb-version: 10.1
# cassandra-version: 2.1
# postgres-version: 9
# sqlserver-collation: Latin1_General_CI_AS
- node-version: 12.x
mysql-version: 5.7
maraidb-version: 10.1
Expand Down Expand Up @@ -56,17 +56,16 @@ jobs:
- name: Create SQLServer Container
run: docker run --rm -d --name sqlserver -p 1433:1433 -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=Password12!" -e "MSSQL_COLLATION=${{ matrix.sqlserver-collation }}" -v ${GITHUB_WORKSPACE}/spec/databases/sqlserver/schema:/docker-entrypoint-initdb.d mcr.microsoft.com/mssql/server:2017-latest

- name: Create OpenSSH-Server Container
run: docker run --rm -d --name openssh-server -p 2222:2222 -e "DOCKER_MODS=linuxserver/mods:openssh-server-ssh-tunnel" -e "PASSWORD_ACCESS=true" -e "USER_NAME=sqlectron" -e "USER_PASSWORD=password" -e "PUBLIC_KEY_DIR=/ssh_files/pub" -v ${GITHUB_WORKSPACE}/spec/ssh_files:/ssh_files ghcr.io/linuxserver/openssh-server

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install -g npm

- run: npm ci
if: matrix.node-version != '12.x'

- run: npm ci --build-from-source
if: matrix.node-version == '12.x'

- run: npm run lint
- run: npm run compile
Expand All @@ -80,4 +79,7 @@ jobs:
- name: Initialize SQLServer Schema
run: docker exec -i sqlserver /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U sa -P Password12! -i /docker-entrypoint-initdb.d/schema.sql -d "sqlectron"

- run: npm run test:coverage
- name: test
run: |
source ./scripts/env-docker-hosts.sh
npm run test:coverage
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ It will bring up some databases such as MySQL and PostgreSQL and run all the tes
docker-compose run --rm test
```

Or to start the container and run the test command manually from there:

```shell
docker-compose run --rm test bash
npm install
npm test
```

#### Without Docker

You will need to bring up all the databases then run the tests through:
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

The common code used by all sqlectron clients.

> Requires node 10 or higher.
> Requires node v10 or higher.
> For ed25519 ssh support it requires node v12.
## How to pronounce

Expand Down Expand Up @@ -34,8 +35,8 @@ npm install sqlectron-db-core
## Example Usage

```javascript
serverSession = db.createServer(serverInfo);
dbConn = serverSession.createConnection(serverInfo.database);
const serverSession = db.createServer(serverInfo);
const dbConn = serverSession.createConnection(serverInfo.database);
dbConn.connect().then(() => {
console.log(dbConn.executeQuery('SELECT 1'));
})
Expand Down
39 changes: 34 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ version: '3'

services:
mysql:
container_name: mysql
image: mysql:5.7
ports:
- 3306:3306
Expand Down Expand Up @@ -48,18 +49,46 @@ services:
ports:
- 7000 # cluster
- 9042 # native
ports:
- 9042:9042

test:
image: node:10.15.0
image: node:12.21.0
command: npm test
working_dir: /usr/src/app
environment:
DB_ADAPTERS: mysql,postgresql,cassandra
MYSQL_ENV_MYSQL_USER: root
MYSQL_ENV_MYSQL_PASSWORD: password
MYSQL_HOST: mysql
MARIADB_HOST: mariadb
POSTGRES_HOST: postgres
CASSANDRA_HOST: cassandra
REDSHIFT_HOST: redshift
SSH_HOST: openssh-server
volumes:
- .:/usr/src/app
links:
- mysql:mysql
- postgres:postgres
- cassandra:cassandra
- /usr/src/app/node_modules
depends_on:
- mysql
- postgres
- cassandra
- openssh-server

openssh-server:
container_name: openssh-server
image: ghcr.io/linuxserver/openssh-server
environment:
DOCKER_MODS: linuxserver/mods:openssh-server-ssh-tunnel
PASSWORD_ACCESS: 'true'
USER_NAME: sqlectron
USER_PASSWORD: password
PUBLIC_KEY_DIR: /ssh_files/pub
ports:
- 2222:2222
restart: unless-stopped
depends_on:
- mysql
- mariadb
volumes:
- ./spec/ssh_files:/ssh_files
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"portfinder": "^1.0.28",
"sql-query-identifier": "^2.0.0",
"sqlite3": "^5.0.2",
"ssh2": "^0.5.0"
"ssh2": "^0.8.9"
},
"devDependencies": {
"@masterodin/publisher": "^0.7.0",
Expand Down
28 changes: 28 additions & 0 deletions scripts/env-docker-hosts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
# Script to resolve container hosts when running the tests from the the host machine
# but the rest of the depdencies in docker containers.
# Usually we could just use localhost to access those dependencies since their port are
# exposed to the host. But, because of ssh tunnel tests we need to have their real IP/hostname
# to properly forward the connection through the ssh tunnel.
# And because it is using the container direct IP, the port used to connect must be the container internal port.

export MYSQL_HOST=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mysql)
export MYSQL_PORT=3306

export MARIADB_HOST=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mariadb)
export MARIADB_PORT=3306

export POSTGRES_HOST=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' postgres)
export POSTGRES_PORT=5432

export REDSHIFT_HOST=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' redshift)
export REDSHIFT_PORT=5432

export CASSANDRA_HOST=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' cassandra)
export CASSANDRA_PORT=9042

export SQLSERVER_HOST=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' sqlserver)
export SQLSERVER_PORT=1433

# On running from host the SSH_HOST must be localhost, using the real IP address won't work
export SSH_HOST=localhost
35 changes: 29 additions & 6 deletions spec/databases/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,62 @@ const postgres = new ConnectionString(process.env.POSTGRES_DSN, {
user: 'postgres',
password: 'Password12!',
path: ['sqlectron'],
hosts: [{ name: '127.0.0.1', port: 5432 }],
hosts: [{
name: process.env.POSTGRES_HOST || '127.0.0.1',
port: parseInt(process.env.POSTGRES_PORT as string, 10)
}],
});

const redshift = new ConnectionString(process.env.REDSHIFT_DSN, {
protocol: 'postgres',
user: 'postgres',
password: 'Password12!',
path: ['sqlectron'],
hosts: [{ name: '127.0.0.1', port: 5433 }],
hosts: [{
name: process.env.REDSHIFT_HOST || '127.0.0.1',
port: parseInt(process.env.REDSHIFT_PORT as string, 10)
}],
});

const mysql = new ConnectionString(process.env.MYSQL_DSN, {
protocol: 'mysql',
user: 'root',
password: 'Password12!',
path: ['sqlectron'],
hosts: [{ name: 'localhost', port: 3306 }],
hosts: [{
name: process.env.MYSQL_HOST || 'localhost',
port: parseInt(process.env.MYSQL_PORT as string, 10)
}],
});

const mariadb = new ConnectionString(process.env.MARIADB_DSN, {
user: 'root',
password: 'Password12!',
path: ['sqlectron'],
hosts: [{ name: 'localhost', port: 3307 }],
hosts: [{
name: process.env.MARIADB_HOST || 'localhost',
port: parseInt(process.env.MARIADB_PORT as string, 10)
}],
});

const sqlserver = new ConnectionString(process.env.SQLSERVER_DSN, {
protocol: 'mssql',
user: 'sa',
password: 'Password12!',
path: ['sqlectron'],
hosts: [{ name: 'localhost', port: 1433 }],
hosts: [{
name: process.env.SQLSERVER_HOST || 'localhost',
port: parseInt(process.env.SQLSERVER_PORT as string, 10)
}],
});

const cassandra = new ConnectionString(process.env.CASSANDRA_DSN, {
protocol: 'cassandra',
path: ['sqlectron'],
hosts: [{ name: 'localhost', port: 9042 }],
hosts: [{
name: process.env.CASSANDRA_HOST || 'localhost',
port: parseInt(process.env.CASSANDRA_PORT as string, 10)
}],
});

const dbs = {
Expand Down
Loading

0 comments on commit bad0a2a

Please sign in to comment.