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
55 changes: 55 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Node.js CI

on:
push:
branches: [ "master", "develop" ]
pull_request:
branches: [ "master", "develop" ]

jobs:
build:
runs-on: ubuntu-latest

services:
mariadb:
image: mariadb:11
ports:
- 3306:3306
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: licenses
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

strategy:
matrix:
node-version: [20.x, 22.x]

steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install dependencies
run: npm install

- name: Build project
run: npm run build

- name: Run tests
run: npm test
env:
DB_HOST: 127.0.0.1
DB_PORT: 3306
DB_DATABASE: licenses
DB_USERNAME: root
DB_PASSWORD: root
PRIVATE_KEY: "some-dummy-key-for-testing"

- name: Upload coverage to Coveralls
run: npm run coveralls || true
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
16 changes: 15 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
language: node_js

node_js:
- "7"
- "20"
- "22"

services:
- mariadb

before_script:
- mysql -e 'CREATE DATABASE IF NOT EXISTS licenses;'

env:
global:
- DB_HOST=127.0.0.1
- DB_DATABASE=licenses
- DB_USERNAME=root
- PRIVATE_KEY="some-dummy-key-for-testing"

branches:
only:
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ WORKDIR /app/

COPY . /app/

ENV NODE_ENV production
ENV NODE_ENV=production

RUN apk update && apk add --no-cache git bash

Expand All @@ -14,4 +14,4 @@ RUN npm run build
ADD https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh .
RUN chmod +x wait-for-it.sh

ENTRYPOINT /app/entrypoint.sh
ENTRYPOINT ["/app/entrypoint.sh"]
45 changes: 33 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,60 @@ npm run build

### Configuration

The configuration is done using environment variables:
The configuration is done using environment variables and a JSON file:

#### Environment Variables
- `DB_DATABASE ("licenses")`: Name of the database.
- `DB_HOST ("mariadb")`: Hostname where the database is running.
- `DB_PASSWORD ("qwerty")`: Password for the database connection.
- `DB_PORT (3306)`: Port for the connection to the database.
- `DB_USERNAME ("root")`: Username for the connection to the database.
- `LOG_LEVEL ("info")`: Allowed: ["error", "warn", "info", "debug", "trace"].
- `PORT (3000)`: Por to listen for HTTP connections.
- `PRIVATE_KEY ("")`: Private key for signing licenses. Should be on PEM format
and must be separate by '\n' chars. Example:
```
-----BEGIN RSA PRIVATE KEY-----\nMIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp\n...
- `PORT (3000)`: Port to listen for HTTP connections.
- `PRIVATE_KEY ("")`: Private key for signing licenses. Should be in PEM format.

#### Dynamic License Configuration (`config/license.json`)
You can customize the generated licenses by modifying `config/license.json`. This file is loaded at runtime:

- `valid_days`: Duration of the generated license (default: 30 days).
- `sensors`: A dictionary of sensor IDs and their respective counts.

Example `config/license.json`:
```json
{
"valid_days": 30,
"sensors": {
"199": 100,
"191": 100,
"flow": 100,
"vault": 100
}
}
```

### Using Docker

Running with docker compose:
The project is fully modernized for Node.js 22+ and ESM. Running with docker compose:

```yaml
version: '2'
version: '3.8'

services:
server:
image: redborder/license-generator
image: redborder/license-generator:0.5.0
environment:
- DB_PASSWORD=redborder
- PRIVATE_KEY="<your private key here>"
volumes:
- ./config/license.json:/app/config/license.json:ro
ports:
- "80:3000"

mariadb:
image: mariadb
image: mariadb:11
environment:
- MYSQL_DATABASE="licenses"
- MYSQL_ROOT_PASSWORD=qwerty
- MYSQL_DATABASE=licenses
- MYSQL_ROOT_PASSWORD=redborder
```

## Usage
Expand Down
2 changes: 1 addition & 1 deletion api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ info:

The API can be used to request demo licenses valid for 30 days for a
cluster. **Only one license per cluster is allowed**.
version: 0.4.0
version: 0.5.0
contact:
name: redborder
url: https://redborder.com
Expand Down
5 changes: 3 additions & 2 deletions default.yaml → config/default.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
swagger:
fittingsDirs: [ api/fittings ]
fittingsDirs: []
defaultPipe: null
swaggerControllerPipe: swagger_controllers

Expand All @@ -15,9 +15,10 @@ swagger:
validateResponse: true

swagger_controllers:
- onError: json_error_handler
- json_error_handler
- cors
- swagger_security
- swagger_params_parser
- _swagger_validate
- express_compatibility
- _router
Expand Down
26 changes: 26 additions & 0 deletions config/license.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"valid_days": 30,
"sensors": {
"199": 100,
"191": 100,
"999": 100,
"217": 100,
"187": 100,
"227": 100,
"219": 100,
"221": 100,
"223": 100,
"event": 100,
"flow": 100,
"social": 100,
"vault": 100,
"scanner": 100,
"mse": 100,
"meraki": 100,
"ale": 100,
"arubacentral": 100,
"snmp": 100,
"ipmi": 100,
"redfish": 100
}
}
22 changes: 22 additions & 0 deletions docker-compose.yml.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '2'

services:
server:
image: license-generator:0.5.0
depends_on:
- mariadb
ports:
- 80:3000
volumes:
- ./license.json:/app/config/license.json
environment:
- DB_PASSWORD=redborder
- PRIVATE_KEY=your-private-key

mariadb:
image: mariadb
volumes:
- ./mariadb/:/etc/mysql/conf.d
environment:
- MYSQL_DATABASE=licenses
- MYSQL_ROOT_PASSWORD=redborder
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ <h5>Schemes:
<span>http</span>
</h5>
<h5>Version:
<span>0.4.0</span>
<span>0.5.0</span>
</h5>
</section>
</div>
Expand Down
2 changes: 1 addition & 1 deletion docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ info:

The API can be used to request demo licenses valid for 30 days for a
cluster. **Only one license per cluster is allowed**.
version: 0.4.0
version: 0.5.0
contact:
name: redborder
url: https://redborder.com
Expand Down
20 changes: 10 additions & 10 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const gulp = require('gulp');
const ts = require('gulp-typescript');
import gulp from "gulp";
import ts from "gulp-typescript";

const tsProject = ts.createProject('tsconfig.json');
const tsProject = ts.createProject("tsconfig.json");

gulp.task('build', () => {
export function build() {
const tsResult = tsProject.src().pipe(tsProject());
return tsResult.js.pipe(gulp.dest('dist'));
});
return tsResult.js.pipe(gulp.dest("dist"));
}

gulp.task('watch', ['scripts'], () => {
gulp.watch('src/**/*.ts', ['scripts']);
});
export function watch() {
gulp.watch("src/**/*.ts", build);
}

gulp.task('default', ['build']);
export default build;
26 changes: 26 additions & 0 deletions license.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"valid_days": 30,
"sensors": {
"199": 1,
"191": 1,
"999": 1,
"217": 1,
"187": 1,
"227": 1,
"219": 1,
"221": 1,
"223": 1,
"event": 1,
"flow": 10,
"social": 1,
"vault": 10,
"scanner": 10,
"mse": 1,
"meraki": 1,
"ale": 1,
"arubacentral": 1,
"snmp": 1,
"ipmi": 1,
"redfish": 1
}
}
Loading
Loading