-
Notifications
You must be signed in to change notification settings - Fork 50
/
noOrchestration.api.js
221 lines (198 loc) · 6.15 KB
/
noOrchestration.api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*
* Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
*/
/**
* This file contains the functions for the orchestration model when it is is
* set to none
*
*/
var plugins = require('../plugins.api');
var config = process.mainModule.exports['config'];
var commonUtils = require('../../../utils/common.utils');
var messages = require('../../../common/messages');
var configUtils = require('../../../common/configServer.utils');
var roleMap = require('../../../web/core/rolemap.api');
function authenticate (req, res, appData, callback)
{
var urlHash = '';
var post = req.body;
var username = post.username;
var password = post.password;
var userList = config.staticAuth;
if ((null == userList) || (!userList.length)) {
req.session.isAuthenticated = false;
commonUtils.changeFileContentAndSend(res, loginErrFile,
global.CONTRAIL_LOGIN_ERROR,
messages.error.invalid_user_pass,
function() {
});
return;
}
if (post.urlHash != null) {
urlHash = post.urlHash;
}
var loginErrFile = 'webroot/html/login-error.html';
var userListCnt = userList.length;
for (var i = 0; i < userListCnt; i++) {
if (null == userList[i]) {
continue;
}
if ((username == userList[i]['username']) &&
(password == userList[i]['password'])) {
break;
}
}
if (i == userListCnt) {
/* Not matched */
req.session.isAuthenticated = false;
commonUtils.changeFileContentAndSend(res, loginErrFile,
global.CONTRAIL_LOGIN_ERROR,
messages.error.invalid_user_pass,
function() {
});
return;
}
req.session.isAuthenticated = true;
req.session.userRole = userList[i]['roles'];
plugins.setAllCookies(req, res, appData, {'username': username}, function() {
res.redirect('/' + urlHash);
});
}
function getTenantList (req, appData, callback)
{
var projList = {"tenants": []};
callback(null, projList);
}
function getServiceCatalog (req, callback)
{
callback(null);
}
function getAPIServerAuthParamsByReq (req)
{
return null;
}
function getProjectList (req, appData, callback)
{
configUtils.getProjectsFromApiServer(req, appData,
function(error, data) {
callback(error, data);
});
}
function getCookieObjs (req, appData, callback)
{
var cookieObjs = {};
getProjectList(req, appData, function(err, data) {
if ((null != err) || (null == data) || (null == data['projects']) ||
(!data['projects'].length)) {
callback(cookieObjs);
return;
}
var projectList = data['projects'];
cookieObjs['domain'] = projectList[0]['fq_name'][0];
cookieObjs['project'] = projectList[0]['fq_name'][1];
callback(cookieObjs);
});
}
function getImageList (req, callback)
{
var imgList = {"images": []};
callback(null, imgList);
}
function getFlavors (req, callback)
{
var list = {"flavors": []};
callback(null, list);
}
function getUIUserRoleByTenant (userObj, callback)
{
var userRoles = [global.STR_ROLE_USER];
if ((null == userObj) || (null == userObj.req)) {
callback(null, userRoles);
return;
}
userRoles =
commonUtils.getValueByJsonPath(userObj.req,
'session;userRole',
[global.STR_ROLE_USER]);
callback(null, userRoles);
}
function getExtUserRoleByTenant (userObj, callback)
{
getUIUserRoleByTenant(userObj, function(uiRoles) {
if (-1 != uiRoles.indexOf(global.STR_ROLE_ADMIN)) {
callback(null, {'roles': [{'name': 'admin'}]});
return;
}
callback(null, {'roles': [{'name': 'Member'}]});
});
}
function getUIRolesByExtRoles (extRoles)
{
var roles = [];
if ((null == extRoles) || (!extRoles.length)) {
return [global.STR_ROLE_USER];
}
var roleCnt = extRoles.length;
for (var i = 0; i < roleCnt; i++) {
roles.push(extRoles[i]['name']);
}
if (-1 != roles.indexOf('admin')) {
return [global.STR_ROLE_ADMIN];
}
return [global.STR_ROLE_USER];
}
function getOSHostList (req, callback)
{
var list = {"hosts": []};
callback(null, list);
}
function getToken (authObj, callback)
{
callback(null, null);
}
function getAvailabilityZoneList (req, callback)
{
var list = {"availabilityZoneInfo": []};
callback(null, list);
}
function getServiceInstanceVMStatus (req, vmRefs, callback)
{
callback(null, null);
}
function getVMStatsByProject (projUUID, req, callback)
{
callback(null, null);
}
function getSessionExpiryTime (req, appData, callback)
{
var cfgSessTimeout =
((null != config.session) && (null != config.session.timeout)) ?
config.session.timeout : null;
var defSessTimeout = global.MAX_AGE_SESSION_ID;
if (null == cfgSessTimeout) {
return defSessTimeout;
}
return cfgSessTimeout;
}
function getUserAuthDataByConfigAuthObj (authObj, callback)
{
callback(null, null);
}
exports.authenticate = authenticate;
exports.getServiceCatalog = getServiceCatalog;
exports.getAPIServerAuthParamsByReq = getAPIServerAuthParamsByReq;
exports.getTenantList = getTenantList;
exports.getProjectList = getProjectList;
exports.getImageList = getImageList;
exports.getFlavors = getFlavors;
exports.getOSHostList = getOSHostList;
exports.getAvailabilityZoneList = getAvailabilityZoneList;
exports.getServiceInstanceVMStatus = getServiceInstanceVMStatus;
exports.getVMStatsByProject = getVMStatsByProject;
exports.getCookieObjs = getCookieObjs;
exports.getSessionExpiryTime = getSessionExpiryTime;
exports.getToken = getToken;
exports.getUserAuthDataByConfigAuthObj = getUserAuthDataByConfigAuthObj;
exports.getUIUserRoleByTenant = getUIUserRoleByTenant;
exports.getExtUserRoleByTenant = getExtUserRoleByTenant;
exports.getUIRolesByExtRoles = getUIRolesByExtRoles;