Matteo Scandolo | bd13aab | 2017-08-08 13:05:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Matteo Scandolo | e3ed016 | 2016-12-01 10:09:12 -0800 | [diff] [blame] | 17 | (function () { |
| 18 | 'use strict'; |
Zack Williams | ea89ebb | 2018-09-07 12:37:36 -0700 | [diff] [blame] | 19 | |
| 20 | // NOTE do we still need CLI args? |
Matteo Scandolo | e3ed016 | 2016-12-01 10:09:12 -0800 | [diff] [blame] | 21 | // Won't be better to use NODE_ENV and the native node-yaml-config feature |
| 22 | |
| 23 | const argv = require('yargs').argv; |
| 24 | const path = require('path'); |
| 25 | const yaml_config = require('node-yaml-config'); |
| 26 | const logger = require('../config/logger.js'); |
| 27 | |
| 28 | // if a config file is specified in as a CLI arguments use that one |
| 29 | const cfgFile = argv.config || 'config.yml'; |
| 30 | |
| 31 | let config; |
| 32 | try { |
Matteo Scandolo | 1116b97 | 2018-12-18 09:33:59 -0800 | [diff] [blame] | 33 | logger.log('debug', `Loading ${path.join(__dirname, cfgFile)}`); |
Matteo Scandolo | e3ed016 | 2016-12-01 10:09:12 -0800 | [diff] [blame] | 34 | config = yaml_config.load(path.join(__dirname, cfgFile)); |
Matteo Scandolo | 1116b97 | 2018-12-18 09:33:59 -0800 | [diff] [blame] | 35 | logger.log('debug', `Parsed config: ${JSON.stringify(config)}`); |
Matteo Scandolo | e3ed016 | 2016-12-01 10:09:12 -0800 | [diff] [blame] | 36 | } |
| 37 | catch(e) { |
| 38 | logger.log('debug', `No ${cfgFile} found, using default params`); |
| 39 | } |
| 40 | |
| 41 | module.exports = { |
Matteo Scandolo | e3ed016 | 2016-12-01 10:09:12 -0800 | [diff] [blame] | 42 | gateway: { |
| 43 | port: (config && config.gateway) ? config.gateway.port : 3000 |
Zack Williams | ea89ebb | 2018-09-07 12:37:36 -0700 | [diff] [blame] | 44 | }, |
| 45 | kafka_bootstrap_servers: ( config && config.kafka_bootstrap_servers ) ? |
| 46 | config.kafka_bootstrap_servers : ['cord-kafka:9092'] |
Matteo Scandolo | e3ed016 | 2016-12-01 10:09:12 -0800 | [diff] [blame] | 47 | }; |
Zack Williams | ea89ebb | 2018-09-07 12:37:36 -0700 | [diff] [blame] | 48 | })(); |