{"size": 917, "ext": "js", "max_stars_repo_path": "src/config/api-config-source-util.js", "max_stars_repo_name": "airicyu/airic-api-gateway-stat-server", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/config/api-config-source-util.js", "max_issues_repo_name": "airicyu/airic-api-gateway-stat-server", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/config/api-config-source-util.js", "max_forks_repo_name": "airicyu/airic-api-gateway-stat-server", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 28.65625, "max_line_length": 79, "alphanum_fraction": 0.4743729553}
'use strict';

const YAML = require('yamljs');
const request = require('request');

const configSource = {
    pull: null,
    getAppOpenApiSpec: null
};

configSource.pull = async function (serverConfig) {
    let configUrl = `${serverConfig['config-server-base-url']}/config/export`;
    return new Promise((resolve, reject) => {
        request(configUrl, {
                json: true,
                headers: {
                    'id-key' : serverConfig['admin-token'] || ''
                }
            },
            function (error, response, body) {
                if (error) {
                    reject(error);
                } else if (response.statusCode === 200) {
                    resolve(body);
                } else {
                    resolve(null);
                }
            });
    });
}.bind(configSource);

module.exports.configSource = configSource;