Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
container-manager
Commits
f8cfd2b3
Commit
f8cfd2b3
authored
Oct 24, 2018
by
Mohamed, Fawzi Roberto (fawzi)
Browse files
local or login
parent
40738b38
Changes
4
Hide whitespace changes
Inline
Side-by-side
app/components.js
View file @
f8cfd2b3
...
...
@@ -41,6 +41,15 @@ baseRepl['templatesDir'] = templatesDir
baseRepl
[
'
namespace
'
]
=
cconfig
.
namespace
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
function
loadTemplateInternal
(
templatePath
,
next
)
{
const
templateRealPath
=
path
.
join
(
templatesDir
,
templatePath
||
"
kube/defaultTemplate.yaml
"
)
...
...
app/routes.js
View file @
f8cfd2b3
...
...
@@ -4,6 +4,7 @@ module.exports = function (app, redirect, config, proxyServer, proxyRouter, k8,
const
stringify
=
require
(
'
json-stringify-safe
'
)
const
k8D
=
require
(
'
./k8-data
'
)
const
compactSha
=
require
(
'
./compact-sha
'
)
const
loginUri
=
components
.
baseRepl
.
loginUri
function
setFrontendHeader
()
{
return
function
(
req
,
res
,
next
)
{
...
...
@@ -29,7 +30,7 @@ module.exports = function (app, redirect, config, proxyServer, proxyRouter, k8,
let
entryPath
=
components
.
templatize
(
cconf
.
entryPoint
.
path
)(
components
.
baseRepl
)
logger
.
debug
(
`entryPoint:
${
entryPath
}
`
)
app
.
get
(
entryPath
,
ensureLoggedIn
(
'
/
login
'
),
bodyParser
.
json
(),
bodyParser
.
urlencoded
({
extended
:
true
}),
function
(
req
,
res
){
app
.
get
(
entryPath
,
ensureLoggedIn
(
login
Uri
),
bodyParser
.
json
(),
bodyParser
.
urlencoded
({
extended
:
true
}),
function
(
req
,
res
){
function
isEmpty
(
obj
)
{
for
(
var
x
in
obj
)
{
return
false
;
}
return
true
;
...
...
@@ -170,7 +171,7 @@ module.exports = function (app, redirect, config, proxyServer, proxyRouter, k8,
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
(
login
Uri
),
bodyParser
.
urlencoded
({
extended
:
true
}),
function
(
req
,
res
){
let
user
=
components
.
selfUserName
(
req
)
var
selectors
if
(
req
.
body
)
...
...
@@ -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
(
login
Uri
),
bodyParser
.
json
(),
bodyParser
.
urlencoded
({
extended
:
true
}),
function
(
req
,
res
){
k8D
.
jsonApiPods
(
req
.
body
,
function
(
err
,
pods
)
{
if
(
err
)
{
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,
})
})
app
.
get
(
commandsBase
+
"
/container/:podname
"
,
ensureLoggedIn
(
'
/
login
'
),
bodyParser
.
json
(),
function
(
req
,
res
){
app
.
get
(
commandsBase
+
"
/container/:podname
"
,
ensureLoggedIn
(
login
Uri
),
bodyParser
.
json
(),
function
(
req
,
res
){
var
loggedUsername
=
components
.
selfUserName
(
req
);
var
podName
=
req
.
params
.
podname
;
var
podInfo
=
components
.
infoForPodName
(
podName
)
...
...
@@ -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
(
login
Uri
),
bodyParser
.
json
(),
function
(
req
,
res
){
var
loggedUsername
=
components
.
selfUserName
(
req
);
var
podName
=
req
.
params
.
podname
;
var
podInfo
=
components
.
infoForPodName
(
podName
)
...
...
@@ -277,7 +278,7 @@ module.exports = function (app, redirect, config, proxyServer, proxyRouter, k8,
}
})
app
.
all
(
'
/*
'
,
ensureLoggedIn
(
'
/
login
'
),
function
(
req
,
res
)
{
app
.
all
(
'
/*
'
,
ensureLoggedIn
(
login
Uri
),
function
(
req
,
res
)
{
//logger.debug('Pre redirect, Retrieved session: '+stringify(req.session, null, 2))
redirect
(
req
,
res
,
req
.
user
.
id
,
false
,
cconf
[
'
imageType
'
],
function
(
route
){
proxyServer
.
web
(
req
,
res
,{
...
...
app/webserver.js
View file @
f8cfd2b3
...
...
@@ -19,14 +19,9 @@ module.exports = function(config, models, cmds) {
const
fs
=
require
(
'
fs
'
);
const
ensureLoggedIn
=
require
(
'
connect-ensure-login
'
).
ensureLoggedIn
;
const
logger
=
require
(
'
./logger
'
)
const
components
=
require
(
'
./components
'
)
var
loginPrefixes
=
[
''
]
//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
config
.
passport
.
saml
.
path
=
components
.
baseRepl
.
loginPrefix
+
config
.
passport
.
saml
.
path
const
strategies
=
require
(
'
./passport-settings
'
)(
passport
,
config
);
var
app
=
express
();
...
...
@@ -71,38 +66,17 @@ module.exports = function(config, models, cmds) {
httpServer
=
https
.
createServer
(
httpsOptions
,
app
);
}
for
(
var
loginPrefixIndex
in
loginPrefixes
)
{
const
loginPrefix
=
loginPrefixes
[
loginPrefixIndex
]
const
loginUri
=
loginPrefix
+
'
/login
'
//if (config.passport.strategy === "local") {
// const flash = require('connect-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
"
)
{
res
.
send
(
`
<html>
<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>`
)
components
.
evalHtmlTemplate
(
'
login.html
'
,{},
function
(
err
,
template
)
{
res
.
send
(
template
)
})
}
else
{
var
target
=
'
/
'
if
(
req
.
session
&&
req
.
query
.
redirectTo
)
...
...
@@ -112,10 +86,9 @@ module.exports = function(config, models, cmds) {
},
passport
.
authenticate
(
config
.
passport
.
strategy
,
{
successReturnToOrRedirect
:
'
/
'
,
successReturnToOrRedirect
:
config
.
k8component
.
image
.
prefix
+
'
/
'
,
failureRedirect
:
loginUri
})
);
}));
app
.
get
(
loginUri
+
'
/logout
'
,
function
(
req
,
res
){
var
user
;
...
...
@@ -162,7 +135,7 @@ module.exports = function(config, models, cmds) {
}
}
);
}
if
(
cmds
.
includes
(
'
webserver
'
))
{
logger
.
info
(
'
starting webserver
'
)
...
...
config/default.hjson
View file @
f8cfd2b3
...
...
@@ -15,6 +15,7 @@ app: {
nomadRoot: "/nomad/nomadlab"
}
debug: false
globalLogin: true
}
mongoDb: {
url: "mongodb://notebook-info-db-mongodb/filedatabase"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment