"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.clusterVersions = clusterVersions;
exports.clusterAuthStatus = clusterAuthStatus;
const utils_1 = require("../utils");
const cluster_queries_1 = require("../components/cluster-queries");
const utils_2 = require("../components/utils");
function clusterVersions(req, res) {
    const clusters = (0, utils_2.getClustersFromConfig)();
    (0, cluster_queries_1.getVersions)(req, clusters)
        .then((data) => (0, utils_1.sendResponse)(res, data))
        .catch((error) => (0, utils_1.sendError)(res, error));
}
function clusterAuthStatus(req, res) {
    const allowPasswordAuth = req.ctx.config.allowPasswordAuth;
    let data = {};
    if (allowPasswordAuth) {
        const clusters = (0, utils_2.getClustersFromConfig)();
        data = Object.keys(clusters).reduce((ret, cluster) => {
            ret[cluster] = {
                authorized: Boolean(req.cookies[(0, utils_1.makeAuthClusterCookieName)(cluster)]),
            };
            return ret;
        }, {});
    }
    else {
        const clusters = (0, utils_2.getClustersFromConfig)();
        data = Object.keys(clusters).reduce((ret, clusterName) => {
            ret[clusterName] = { authorized: true };
            return ret;
        }, {});
    }
    (0, utils_1.sendResponse)(res, data);
}
