Commit f8cfd2b3 authored by Mohamed, Fawzi Roberto (fawzi)'s avatar Mohamed, Fawzi Roberto (fawzi)
Browse files

local or login

parent 40738b38
...@@ -41,6 +41,15 @@ baseRepl['templatesDir'] = templatesDir ...@@ -41,6 +41,15 @@ baseRepl['templatesDir'] = templatesDir
baseRepl['namespace'] = cconfig.namespace baseRepl['namespace'] = cconfig.namespace
baseRepl['commands'] = templatize(cconfig.commands.path)(baseRepl) baseRepl['commands'] = templatize(cconfig.commands.path)(baseRepl)
const loginPrefix = (config.app.globalLogin ? '' : baseRepl.commands)
//if (cmds.includes('apiserver'))
// loginPrefixes.push('/userapi')
//if (cmds.includes('webserver'))
// loginPrefixes.push(config.k8component.image.imageType)
const loginUri = loginPrefix + '/login'
baseRepl.loginPrefix = loginPrefix
baseRepl.loginUri = loginUri
// Given a path loads it and compiles a template for it, use loadTemplate that has caching // Given a path loads it and compiles a template for it, use loadTemplate that has caching
function loadTemplateInternal(templatePath, next) { function loadTemplateInternal(templatePath, next) {
const templateRealPath = path.join(templatesDir, templatePath || "kube/defaultTemplate.yaml") const templateRealPath = path.join(templatesDir, templatePath || "kube/defaultTemplate.yaml")
......
...@@ -4,6 +4,7 @@ module.exports = function (app, redirect, config, proxyServer, proxyRouter, k8, ...@@ -4,6 +4,7 @@ module.exports = function (app, redirect, config, proxyServer, proxyRouter, k8,
const stringify = require('json-stringify-safe') const stringify = require('json-stringify-safe')
const k8D = require('./k8-data') const k8D = require('./k8-data')
const compactSha = require('./compact-sha') const compactSha = require('./compact-sha')
const loginUri = components.baseRepl.loginUri
function setFrontendHeader() { function setFrontendHeader() {
return function(req, res, next) { return function(req, res, next) {
...@@ -29,7 +30,7 @@ module.exports = function (app, redirect, config, proxyServer, proxyRouter, k8, ...@@ -29,7 +30,7 @@ module.exports = function (app, redirect, config, proxyServer, proxyRouter, k8,
let entryPath = components.templatize(cconf.entryPoint.path)(components.baseRepl) let entryPath = components.templatize(cconf.entryPoint.path)(components.baseRepl)
logger.debug(`entryPoint: ${entryPath}`) logger.debug(`entryPoint: ${entryPath}`)
app.get(entryPath, ensureLoggedIn('/login'), bodyParser.json(), bodyParser.urlencoded({extended:true}), function(req, res){ app.get(entryPath, ensureLoggedIn(loginUri), bodyParser.json(), bodyParser.urlencoded({extended:true}), function(req, res){
function isEmpty(obj) { function isEmpty(obj) {
for (var x in obj) { return false; } for (var x in obj) { return false; }
return true; return true;
...@@ -170,7 +171,7 @@ module.exports = function (app, redirect, config, proxyServer, proxyRouter, k8, ...@@ -170,7 +171,7 @@ module.exports = function (app, redirect, config, proxyServer, proxyRouter, k8,
const commandsBase = components.templatize(cconf.commands.path)(components.baseRepl) const commandsBase = components.templatize(cconf.commands.path)(components.baseRepl)
app.get(commandsBase + "/view-containers", ensureLoggedIn('/login'), bodyParser.urlencoded({extended: true}), function(req, res){ app.get(commandsBase + "/view-containers", ensureLoggedIn(loginUri), bodyParser.urlencoded({extended: true}), function(req, res){
let user = components.selfUserName(req) let user = components.selfUserName(req)
var selectors var selectors
if (req.body) if (req.body)
...@@ -192,7 +193,7 @@ module.exports = function (app, redirect, config, proxyServer, proxyRouter, k8, ...@@ -192,7 +193,7 @@ module.exports = function (app, redirect, config, proxyServer, proxyRouter, k8,
}) })
}) })
app.get(commandsBase + "/container", ensureLoggedIn('/login'), bodyParser.json(), bodyParser.urlencoded({extended: true}), function(req, res){ app.get(commandsBase + "/container", ensureLoggedIn(loginUri), bodyParser.json(), bodyParser.urlencoded({extended: true}), function(req, res){
k8D.jsonApiPods(req.body, function(err, pods) { k8D.jsonApiPods(req.body, function(err, pods) {
if (err) { if (err) {
res.status(400).type('application/vnd.api+json').json({ errors: [{ id: 'ErrorContainer', res.status(400).type('application/vnd.api+json').json({ errors: [{ id: 'ErrorContainer',
...@@ -205,7 +206,7 @@ module.exports = function (app, redirect, config, proxyServer, proxyRouter, k8, ...@@ -205,7 +206,7 @@ module.exports = function (app, redirect, config, proxyServer, proxyRouter, k8,
}) })
}) })
app.get(commandsBase + "/container/:podname", ensureLoggedIn('/login'), bodyParser.json(), function(req, res){ app.get(commandsBase + "/container/:podname", ensureLoggedIn(loginUri), bodyParser.json(), function(req, res){
var loggedUsername = components.selfUserName(req); var loggedUsername = components.selfUserName(req);
var podName = req.params.podname; var podName = req.params.podname;
var podInfo = components.infoForPodName(podName) var podInfo = components.infoForPodName(podName)
...@@ -236,7 +237,7 @@ module.exports = function (app, redirect, config, proxyServer, proxyRouter, k8, ...@@ -236,7 +237,7 @@ module.exports = function (app, redirect, config, proxyServer, proxyRouter, k8,
} }
}) })
app.delete(commandsBase + "/container/:podname", ensureLoggedIn('/login'), bodyParser.json(), function(req, res){ app.delete(commandsBase + "/container/:podname", ensureLoggedIn(loginUri), bodyParser.json(), function(req, res){
var loggedUsername = components.selfUserName(req); var loggedUsername = components.selfUserName(req);
var podName = req.params.podname; var podName = req.params.podname;
var podInfo = components.infoForPodName(podName) var podInfo = components.infoForPodName(podName)
...@@ -277,7 +278,7 @@ module.exports = function (app, redirect, config, proxyServer, proxyRouter, k8, ...@@ -277,7 +278,7 @@ module.exports = function (app, redirect, config, proxyServer, proxyRouter, k8,
} }
}) })
app.all('/*', ensureLoggedIn('/login'), function (req, res) { app.all('/*', ensureLoggedIn(loginUri), function (req, res) {
//logger.debug('Pre redirect, Retrieved session: '+stringify(req.session, null, 2)) //logger.debug('Pre redirect, Retrieved session: '+stringify(req.session, null, 2))
redirect(req, res, req.user.id, false, cconf['imageType'], function(route){ redirect(req, res, req.user.id, false, cconf['imageType'], function(route){
proxyServer.web(req, res,{ proxyServer.web(req, res,{
......
...@@ -19,14 +19,9 @@ module.exports = function(config, models, cmds) { ...@@ -19,14 +19,9 @@ module.exports = function(config, models, cmds) {
const fs = require('fs'); const fs = require('fs');
const ensureLoggedIn = require('connect-ensure-login').ensureLoggedIn; const ensureLoggedIn = require('connect-ensure-login').ensureLoggedIn;
const logger = require('./logger') const logger = require('./logger')
const components = require('./components')
var loginPrefixes = [''] config.passport.saml.path = components.baseRepl.loginPrefix + config.passport.saml.path
//if (cmds.includes('apiserver'))
// loginPrefixes.push('/userapi')
//if (cmds.includes('webserver'))
// loginPrefixes.push(config.k8component.image.imageType)
//
// config.passport.saml.path = loginPrefixes[loginPrefixes.length - 1] + config.passport.saml.path
const strategies = require('./passport-settings')(passport, config); const strategies = require('./passport-settings')(passport, config);
var app = express(); var app = express();
...@@ -71,38 +66,17 @@ module.exports = function(config, models, cmds) { ...@@ -71,38 +66,17 @@ module.exports = function(config, models, cmds) {
httpServer = https.createServer(httpsOptions, app); httpServer = https.createServer(httpsOptions, app);
} }
for (var loginPrefixIndex in loginPrefixes) {
const loginPrefix = loginPrefixes[loginPrefixIndex]
const loginUri = loginPrefix + '/login'
//if (config.passport.strategy === "local") { //if (config.passport.strategy === "local") {
// const flash = require('connect-flash'); // const flash = require('connect-flash');
// app.use(flash()); // app.use(flash());
//} //}
const loginUri = components.baseRepl.loginUri
app.get(loginUri,function(req, res, next) { app.get(loginUri,function(req, res, next) {
if (config.passport.strategy === "local") { if (config.passport.strategy === "local") {
res.send(` components.evalHtmlTemplate('login.html',{}, function (err, template) {
<html> res.send(template)
<head> })
<title>Login</title>
</head>
<body>
<h1>Login</h1>
<form action="${loginUri}/callback" method="post">
<div>
<label>Username:</label>
<input type="text" name="username"/>
</div>
<div>
<label>Password:</label>
<input type="password" name="password"/>
</div>
<div>
<input type="submit" value="Log In"/>
</div>
</form>
</body>
</html>`)
} else { } else {
var target = '/' var target = '/'
if (req.session && req.query.redirectTo) if (req.session && req.query.redirectTo)
...@@ -112,10 +86,9 @@ module.exports = function(config, models, cmds) { ...@@ -112,10 +86,9 @@ module.exports = function(config, models, cmds) {
}, passport.authenticate( }, passport.authenticate(
config.passport.strategy, config.passport.strategy,
{ {
successReturnToOrRedirect: '/', successReturnToOrRedirect: config.k8component.image.prefix + '/',
failureRedirect: loginUri failureRedirect: loginUri
}) }));
);
app.get(loginUri + '/logout', function(req, res){ app.get(loginUri + '/logout', function(req, res){
var user; var user;
...@@ -162,7 +135,7 @@ module.exports = function(config, models, cmds) { ...@@ -162,7 +135,7 @@ module.exports = function(config, models, cmds) {
} }
} }
); );
}
if (cmds.includes('webserver')) { if (cmds.includes('webserver')) {
logger.info('starting webserver') logger.info('starting webserver')
......
...@@ -15,6 +15,7 @@ app: { ...@@ -15,6 +15,7 @@ app: {
nomadRoot: "/nomad/nomadlab" nomadRoot: "/nomad/nomadlab"
} }
debug: false debug: false
globalLogin: true
} }
mongoDb: { mongoDb: {
url: "mongodb://notebook-info-db-mongodb/filedatabase" url: "mongodb://notebook-info-db-mongodb/filedatabase"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment