@knapsack/app
Version:
Build Design Systems on top of knapsack, by Basalt
47 lines (38 loc) • 1.92 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getUserInfo = getUserInfo;
var _core = require("@knapsack/core");
/**
* Copyright (C) 2018 Basalt
This file is part of Knapsack.
Knapsack is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.
Knapsack is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along
with Knapsack; if not, see <https://www.gnu.org/licenses>.
*/
function getUserInfo(req) {
var _req$headers$xKsClo, _req$headers$xKsClo2, _req$headers$xKsClo2$, _req$headers$xKsClo3;
const Authorization = req.headers.authorization;
const roleId = (_req$headers$xKsClo = req.headers['x-ks-cloud-role-id']) === null || _req$headers$xKsClo === void 0 ? void 0 : _req$headers$xKsClo.toString();
const ksRepoAccess = ((_req$headers$xKsClo2 = req.headers['x-ks-cloud-repo-access']) === null || _req$headers$xKsClo2 === void 0 ? void 0 : (_req$headers$xKsClo2$ = _req$headers$xKsClo2.toString()) === null || _req$headers$xKsClo2$ === void 0 ? void 0 : _req$headers$xKsClo2$.split(',')) || [];
const username = (_req$headers$xKsClo3 = req.headers['x-ks-cloud-username']) === null || _req$headers$xKsClo3 === void 0 ? void 0 : _req$headers$xKsClo3.toString();
let role = _core.KS_USER_ROLES.anonymous;
if (roleId && roleId in _core.KS_USER_ROLE_IDS) {
role = _core.KS_USER_ROLES[roleId];
}
const userInfo = {
username,
role,
ksRepoAccess,
Authorization
}; // console.log('getUserInfo', userInfo);
return userInfo;
}