src/config.js   A
last analyzed

Complexity

Total Complexity 3
Complexity/F 0

Size

Lines of Code 96
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 72
mnd 3
bc 3
fnc 0
dl 0
loc 96
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import dotenv from 'dotenv';
2
import cottus, { Assembler } from 'cottus';
3
4
dotenv.config({ path: '.env' });
5
dotenv.config({ path: '.env.defaults' });
6
7
const e = process.env;
8
9
const schema = {
10
    github : {
11
        app : {
12
            privateKey    : { $source: '{GITHUB_APP_PRIVATE_KEY}', $validate: [ 'required', 'encryption_key' ] },
13
            tokenExpire   : { $source: '{GITHUB_APP_TOKEN_EXPIRE}', $validate: [ 'required', 'time_unit' ] },
14
            timeToRefresh : { $source: '{GITHUB_APP_TOKEN_REFRESH}', $validate: [ 'required', 'time_unit' ] },
15
            appID         : { $source: '{GITHUB_APP_ID}', $validate: [ 'required', 'integer' ] }
16
        },
17
        userId   : { $source: '{GITHUB_USER_ID}', $validate: [ 'required', 'integer' ] },
18
        userName : { $source: '{GITHUB_USER_NAME}', $validate: [ 'required', 'string' ] },
19
        analyze  : { $source: '{GITHUB_ANALIZE}', $validate: [ 'required', 'boolean' ] }
20
    },
21
22
    gitea : e.GITEA_URL ? {
23
        url     : { $source: '{GITEA_URL}', $validate: [ 'required', 'url' ] },
24
        token   : { $source: '{GITEA_TOKEN}', $validate: [ 'required', 'string' ] },
25
        analyze : { $source: '{GITEA_ANALIZE}', $validate: [ 'required', 'boolean' ] }
26
    } : null,
27
28
    git : {
29
        tmpFolder : { $source: '{TMP_FOLDER}', $validate: [ 'required', 'path' ] },
30
        name      : { $source: '{GIT_USER}', $validate: [ 'required', 'string' ] },
31
        email     : { $source: '{GIT_EMAIL}', $validate: [ 'required', 'email' ] }
32
    },
33
    queue : {
34
        redis : {
35
            port     : { $source: '{REDIS_PORT}', $validate: [ 'required', 'port' ] },
36
            host     : { $source: '{REDIS_HOST}', $validate: [ 'required', 'hostname' ] },
37
            db       : { $source: '{REDIS_DB}', $validate: [ 'integer' ] },
38
            password : { $source: '{REDIS_PASSWORD}', $validate: [ 'string' ] },
39
            username : { $source: '{REDIS_USER}', $validate: [ 'string' ] }
40
        },
41
        main : {
42
            name        : { $source: '{MAIN_QUEUE_NAME}', $validate: [ 'required', 'string' ] },
43
            ttl         : { $source: '{MAIN_QUEUE_TTL}', $validate: [ 'required', 'time_unit' ] },
44
            attempts    : { $source: '{MAIN_QUEUE_ATTEMPTS}', $validate: [ 'required', 'integer', { 'min': 1 } ] },
45
            concurrency : { $source: '{MAIN_QUEUE_CONCURRENCY}', $validate: [ 'required', 'integer', { 'min': 1 } ] },
46
            logLevel    : {
47
                $source   : '{MAIN_QUEUE_LOG_LEVEL}',
48
                $validate : [ 'required', { 'enum': [ 'error', 'warn', 'info', 'notice', 'verbose', 'debug' ] } ]
49
            },
50
            repeat     : { $source: '{MAIN_QUEUE_REPEAT}', $validate: [ 'cron' ] },
51
            canProcess : { $source: '{MAIN_QUEUE_PROCESS}', $validate: [ 'required', 'boolean' ] },
52
            backoff    : e.REPO_QUEUE_BACKOFF_TYPE ? {
53
                type  : { $source: '{MAIN_QUEUE_BACKOFF_TYPE}', $validate: [ 'string' ] },
54
                delay : { $source: '{MAIN_QUEUE_BACKOFF_DELAY}', $validate: [ 'string' ] }
55
            } : null
56
        },
57
        repo : {
58
            name        : { $source: '{REPO_QUEUE_NAME}', $validate: [ 'required', 'string' ] },
59
            ttl         : { $source: '{REPO_QUEUE_TTL}', $validate: [ 'required', 'time_unit' ] },
60
            attempts    : { $source: '{REPO_QUEUE_ATTEMPTS}', $validate: [ 'required', 'integer', { 'min': 1 } ] },
61
            concurrency : { $source: '{REPO_QUEUE_CONCURRENCY}', $validate: [ 'required', 'integer', { 'min': 1 } ] },
62
            logLevel    : {
63
                $source   : '{REPO_QUEUE_LOG_LEVEL}',
64
                $validate : [ 'required', { 'enum': [ 'error', 'warn', 'info', 'notice', 'verbose', 'debug' ] } ]
65
            },
66
            // repeat     : { $source: '{REPO_QUEUE_REPEAT}', $validate: [ 'cron' ] },
67
            canProcess : { $source: '{REPO_QUEUE_PROCESS}', $validate: [ 'required', 'boolean' ] },
68
            backoff    : e.REPO_QUEUE_BACKOFF_TYPE ? {
69
                type  : { $source: '{REPO_QUEUE_BACKOFF_TYPE}', $validate: [ 'string' ] },
70
                delay : { $source: '{REPO_QUEUE_BACKOFF_DELAY}', $validate: [ 'string' ] }
71
            } : null
72
        }
73
    },
74
    web : {
75
        port  : { $source: '{PORT}', $validate: [ 'required', 'port' ] },
76
        start : { $source: '{WEB_START}', $validate: [ 'required', 'boolean' ] },
77
        admin : {
78
            password : { $source: '{BASIC_ADMIN_PASSWORD}', $validate: [ 'required', 'string' ] }
79
        }
80
    },
81
    verification : {
82
        $source   : { type: 'complex_array', prefix: 'VERIFICATION_' },
83
        $validate : {
84
            'fileName' : { $source: '{_FILE_NAME}', $validate: [ 'required', 'path' ] },
85
            'content'  : { $source: '{_CONTENT}', $validate: [ 'required', 'string' ] }
86
        }
87
    }
88
};
89
90
const assembler = new Assembler(cottus, schema);
91
92
assembler.parse();
93
94
const config = assembler.run(e);
95
96
export default config;
97