Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/node/scripts/add-shebang.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo -e '#!/usr/bin/env node\n'"$(cat app/index.js)" > app/index.js
14 changes: 14 additions & 0 deletions common/node/scripts/generate-database-migration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/bash

sudo service mysql start

sudo mysql -e "DROP DATABASE IF EXISTS database_migration;"
sudo mysql -e "CREATE DATABASE database_migration DEFAULT CHARSET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;"
sudo mysql -e "CREATE USER IF NOT EXISTS 'service'@localhost IDENTIFIED BY 'service';"
sudo mysql -e "GRANT ALL PRIVILEGES ON database_migration.* to 'service'@'localhost';"
sudo mysql -e "FLUSH PRIVILEGES;"

npx env-cmd -e database_migration npx typeorm-ts-node-commonjs migration:run -d ./src/database/dataSource.ts
npx env-cmd -e database_migration npx typeorm-ts-node-commonjs migration:generate ./src/database/migrations/$1 -d ./src/database/dataSource.ts

sudo mysql -e "DROP DATABASE database_migration"
8 changes: 8 additions & 0 deletions common/node/scripts/init-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/bash

sudo service mysql start

sudo mysql -e "CREATE DATABASE IF NOT EXISTS $1 DEFAULT CHARSET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;"
sudo mysql -e "CREATE USER IF NOT EXISTS '$2'@localhost IDENTIFIED BY '$3';"
sudo mysql -e "GRANT ALL PRIVILEGES ON $1.* to '$2'@'localhost';"
sudo mysql -e "FLUSH PRIVILEGES;"
2 changes: 2 additions & 0 deletions integration-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"description": "This project contains test cases for the APIs of the different microservices of the crosslab infrastructure.",
"private": true,
"scripts": {
"pretest": "bash scripts/pre_test.sh",
"test": "mocha --nolazy --require mocha-steps -r ts-node/register -r src/fixtures/debug.ts -r src/fixtures/localServer.ts src/**/*.spec.ts",
"pretest:debug": "bash scripts/pre_test.sh",
"test:debug": "mocha --inspect=9101 --nolazy --require mocha-steps -r ts-node/register -r src/fixtures/debug.ts -r src/fixtures/localServer.ts src/**/*.spec.ts",
"lint": "eslint ."
},
Expand Down
21 changes: 21 additions & 0 deletions integration-test/scripts/pre_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
sudo service mysql start

sudo mysql -e "DROP USER IF EXISTS 'service'@localhost;"
sudo mysql -e "DROP DATABASE IF EXISTS auth_service;"
sudo mysql -e "DROP DATABASE IF EXISTS device_service;"
sudo mysql -e "DROP DATABASE IF EXISTS experiment_service;"
sudo mysql -e "DROP DATABASE IF EXISTS federation_service;"

sudo mysql -e "CREATE DATABASE IF NOT EXISTS auth_service DEFAULT CHARSET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;"
sudo mysql -e "CREATE DATABASE IF NOT EXISTS device_service DEFAULT CHARSET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;"
sudo mysql -e "CREATE DATABASE IF NOT EXISTS experiment_service DEFAULT CHARSET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;"
sudo mysql -e "CREATE DATABASE IF NOT EXISTS federation_service DEFAULT CHARSET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;"

sudo mysql -e "CREATE USER IF NOT EXISTS 'service'@localhost IDENTIFIED BY 'service';"

sudo mysql -e "GRANT ALL PRIVILEGES ON auth_service.* to 'service'@'localhost';"
sudo mysql -e "GRANT ALL PRIVILEGES ON device_service.* to 'service'@'localhost';"
sudo mysql -e "GRANT ALL PRIVILEGES ON experiment_service.* to 'service'@'localhost';"
sudo mysql -e "GRANT ALL PRIVILEGES ON federation_service.* to 'service'@'localhost';"

sudo mysql -e "FLUSH PRIVILEGES;"
15 changes: 15 additions & 0 deletions integration-test/src/fixtures/localServer.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
const DB_COMMON = {
DB_HOST: 'localhost',
DB_PORT: '3306',
DB_USERNAME: 'service',
DB_PASSWORD: 'service',
};

export const ENV = {
common: {
SECURITY_ISSUER: 'http://localhost',
Expand All @@ -15,18 +22,26 @@ export const ENV = {
'federationservice:local:federationservice',
].join(','),
API_TOKEN: 'authservice',
DB_NAME: 'auth_service',
...DB_COMMON,
},
device: {
PORT: '3001',
API_TOKEN: 'deviceservice',
DB_NAME: 'device_service',
...DB_COMMON,
},
experiment: {
PORT: '3002',
API_TOKEN: 'experimentservice',
DB_NAME: 'experiment_service',
...DB_COMMON,
},
federation: {
PORT: '3003',
API_TOKEN: 'federationservice',
DB_NAME: 'federation_service',
...DB_COMMON,
},
gateway: {
AUTH_SERVICE_URL: '127.0.0.1:3000',
Expand Down
18 changes: 18 additions & 0 deletions services/auth/.env-cmdrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
{
"development": {
"DB_HOST": "localhost",
"DB_PORT": "3306",
"DB_USERNAME": "service",
"DB_PASSWORD": "service",
"DB_NAME": "auth_service",
"SECURITY_ISSUER": "http://localhost",
"SECURITY_AUDIENCE": "http://localhost",
"BASE_URL": "http://localhost",
"PORT": "3000",
"ALLOWLIST": "auth-service-dev-token:local:authservice,device-service-dev-token:local:deviceservice,experiment-service-dev-token:local:experimentservice,superadmin-test-token:local:superadmin",
"API_TOKEN": "auth-service-dev-token"
},
"database_migration": {
"DB_HOST": "localhost",
"DB_PORT": "3306",
"DB_USERNAME": "service",
"DB_PASSWORD": "service",
"DB_NAME": "database_migration",
"SECURITY_ISSUER": "http://localhost",
"SECURITY_AUDIENCE": "http://localhost",
"BASE_URL": "http://localhost",
Expand Down
4 changes: 0 additions & 4 deletions services/auth/addShebang.js

This file was deleted.

3 changes: 2 additions & 1 deletion services/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
"build:generate:test": "npx openapi-codegen -i dist/openapi.json -p @cross-lab-project/codegen-typescript-addon:preset:service:test -o test/generated",
"build:generate": "npm-run-all build:generate:*",
"build:compile": "tsc --project tsconfig.build.json",
"build:add-shebang": "node addShebang.js",
"build:add-shebang": "bash scripts/add-shebang.sh",
"build": "npm-run-all build:*",
"start": "node app/index.js",
"predev": "bash scripts/init-db.sh auth_service service service",
"dev": "env-cmd -e development npx nodemon src/index.ts",
"format:src": "npx prettier src --write",
"format:test": "npx prettier test --write",
Expand Down
1 change: 1 addition & 0 deletions services/auth/scripts/add-shebang.sh
1 change: 1 addition & 0 deletions services/auth/scripts/generate-database-migration.sh
1 change: 1 addition & 0 deletions services/auth/scripts/init-db.sh
12 changes: 8 additions & 4 deletions services/auth/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ function initializeAppConfiguration(): AppConfiguration {
export const config: AppConfiguration = initializeAppConfiguration()

export const dataSourceConfig: DataSourceOptions = {
type: 'sqlite',
database: 'db/auth.db',
entities: [ScopeModel, RoleModel, UserModel, KeyModel, ActiveKeyModel, TokenModel],
migrationsRun: true,
type: 'mariadb',
host: process.env.DB_HOST,
port: parseInt(process.env.DB_PORT ?? '3306'),
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
migrations: [...Migrations],
migrationsRun: true,
entities: [ScopeModel, RoleModel, UserModel, KeyModel, ActiveKeyModel, TokenModel],
}
Loading