mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-16 22:50:10 +03:00
F #5422: reuse variables
Signed-off-by: Jorge Lobo <jlobo@opennebula.io>
This commit is contained in:
parent
87fd9f68db
commit
01b778381f
@ -18,10 +18,9 @@ const qrcode = require('qrcode')
|
||||
const { Map } = require('immutable')
|
||||
const { httpResponse } = require('server/utils/server') // '../../../utils/server'
|
||||
const { getConfig } = require('server/utils/yml') // '../../../utils/yml'
|
||||
const { Actions } = require('server/utils/constants/commands/user')
|
||||
const {
|
||||
httpMethod,
|
||||
defaultMethodUserInfo,
|
||||
defaultMethodUserUpdate,
|
||||
default2FAIssuer,
|
||||
default2FAOpennebulaVar,
|
||||
default2FAOpennebulaTmpVar
|
||||
@ -56,7 +55,7 @@ const getUserInfoAuthenticated = (connect, userId, callback, next) => {
|
||||
typeof connect === 'function' &&
|
||||
typeof callback === 'function' &&
|
||||
typeof next === 'function' &&
|
||||
defaultMethodUserInfo
|
||||
Actions.USER_INFO
|
||||
) {
|
||||
const connectOpennebula = connect()
|
||||
const dataUser = {}
|
||||
@ -66,11 +65,11 @@ const getUserInfoAuthenticated = (connect, userId, callback, next) => {
|
||||
dataUser[fromData.postBody] = {}
|
||||
dataUser[fromData.resource].id = userId
|
||||
const getOpennebulaMethod = checkOpennebulaCommand(
|
||||
defaultMethodUserInfo,
|
||||
Actions.USER_INFO,
|
||||
GET
|
||||
)
|
||||
connectOpennebula(
|
||||
defaultMethodUserInfo,
|
||||
Actions.USER_INFO,
|
||||
getOpennebulaMethod(dataUser),
|
||||
(err, value) => {
|
||||
responseOpennebula(
|
||||
@ -120,11 +119,11 @@ const generateQR = (req, res, next, connect, userId) => {
|
||||
[default2FAOpennebulaVar]
|
||||
)
|
||||
const getOpennebulaMethod = checkOpennebulaCommand(
|
||||
defaultMethodUserUpdate,
|
||||
Actions.USER_UPDATE,
|
||||
POST
|
||||
)
|
||||
connectOpennebula(
|
||||
defaultMethodUserUpdate,
|
||||
Actions.USER_UPDATE,
|
||||
getOpennebulaMethod(dataUser),
|
||||
(error, value) => {
|
||||
responseOpennebula(
|
||||
@ -191,11 +190,11 @@ const twoFactorSetup = (req, res, next, connect, userId) => {
|
||||
[default2FAOpennebulaTmpVar]
|
||||
)
|
||||
const getOpennebulaMethodUpdate = checkOpennebulaCommand(
|
||||
defaultMethodUserUpdate,
|
||||
Actions.USER_UPDATE,
|
||||
POST
|
||||
)
|
||||
connectOpennebula(
|
||||
defaultMethodUserUpdate,
|
||||
Actions.USER_UPDATE,
|
||||
getOpennebulaMethodUpdate(dataUser),
|
||||
(err, value) => {
|
||||
responseOpennebula(
|
||||
@ -244,11 +243,11 @@ const twoFactorDelete = (req, res, next, connect, userId) => {
|
||||
[default2FAOpennebulaTmpVar, default2FAOpennebulaVar]
|
||||
)
|
||||
const getOpennebulaMethodUpdate = checkOpennebulaCommand(
|
||||
defaultMethodUserUpdate,
|
||||
Actions.USER_UPDATE,
|
||||
POST
|
||||
)
|
||||
connectOpennebula(
|
||||
defaultMethodUserUpdate,
|
||||
Actions.USER_UPDATE,
|
||||
getOpennebulaMethodUpdate(dataUser),
|
||||
(err, value) => {
|
||||
responseOpennebula(
|
||||
|
@ -30,10 +30,9 @@ const {
|
||||
updaterResponse
|
||||
} = require('./functions')
|
||||
const { internalServerError } = require('server/utils/constants/http-codes')
|
||||
const { Actions } = require('server/utils/constants/commands/user')
|
||||
const {
|
||||
httpMethod,
|
||||
defaultMethodLogin,
|
||||
defaultMethodUserInfo
|
||||
httpMethod
|
||||
} = require('server/utils/constants/defaults')
|
||||
const {
|
||||
paramsDefaultByCommandOpennebula,
|
||||
@ -51,7 +50,7 @@ const auth = (req, res, next, connect) => {
|
||||
setNext(next)
|
||||
updaterResponse(new Map(internalServerError).toObject())
|
||||
const getOpennebulaMethod = checkOpennebulaCommand(
|
||||
defaultMethodLogin,
|
||||
Actions.USER_LOGIN,
|
||||
POST
|
||||
)
|
||||
if (getOpennebulaMethod) {
|
||||
@ -87,8 +86,8 @@ const auth = (req, res, next, connect) => {
|
||||
if (getUser() && getPass()) {
|
||||
const oneConnect = connectOpennebula()
|
||||
oneConnect(
|
||||
defaultMethodUserInfo,
|
||||
paramsDefaultByCommandOpennebula(defaultMethodUserInfo, GET),
|
||||
Actions.USER_INFO,
|
||||
paramsDefaultByCommandOpennebula(Actions.USER_INFO, GET),
|
||||
(err, value) => {
|
||||
responseOpennebula(updaterResponse, err, value, login, next)
|
||||
},
|
||||
|
@ -17,13 +17,11 @@ const { Map } = require('immutable')
|
||||
// eslint-disable-next-line node/no-deprecated-api
|
||||
const { parse } = require('url')
|
||||
const { global, Array } = require('window-or-global')
|
||||
|
||||
const { Actions: ActionUsers } = require('server/utils/constants/commands/user')
|
||||
const { Actions: ActionZones } = require('server/utils/constants/commands/zone')
|
||||
const {
|
||||
httpMethod,
|
||||
defaultOpennebulaExpiration,
|
||||
defaultMethodLogin,
|
||||
defaultMethodZones,
|
||||
defaultMethodUserInfo,
|
||||
default2FAOpennebulaVar,
|
||||
defaultNamespace
|
||||
} = require('server/utils/constants/defaults')
|
||||
@ -48,7 +46,7 @@ const namespace = appConfig.namespace || defaultNamespace
|
||||
|
||||
const { POST } = httpMethod
|
||||
|
||||
const getOpennebulaMethod = checkOpennebulaCommand(defaultMethodLogin, POST)
|
||||
const getOpennebulaMethod = checkOpennebulaCommand(ActionUsers.USER_LOGIN, POST)
|
||||
|
||||
let user = ''
|
||||
let key = ''
|
||||
@ -209,7 +207,7 @@ const setZones = () => {
|
||||
const oneConnect = connectOpennebula()
|
||||
const dataSource = dataSourceWithExpirateDate()
|
||||
oneConnect(
|
||||
defaultMethodZones,
|
||||
ActionZones.ZONEPOOL_INFO,
|
||||
getOpennebulaMethod(dataSource),
|
||||
(err, value) => {
|
||||
// res, err, value, response, next
|
||||
@ -317,7 +315,7 @@ const getServerAdminAndWrapUser = (userData = {}) => {
|
||||
const tokenWithServerAdmin = createTokenServerAdmin(serverAdminData.username, serverAdminData.username)
|
||||
const oneConnect = connectOpennebula(`${serverAdminData.username}:${serverAdminData.username}`, tokenWithServerAdmin)
|
||||
oneConnect(
|
||||
defaultMethodUserInfo,
|
||||
ActionUsers.USER_INFO,
|
||||
[-1, false],
|
||||
(err, value) => {
|
||||
responseOpennebula(
|
||||
@ -335,7 +333,7 @@ const getServerAdminAndWrapUser = (userData = {}) => {
|
||||
const login = userData => {
|
||||
let rtn = false
|
||||
if (userData) {
|
||||
const findTextError = `[${namespace + defaultMethodUserInfo}]`
|
||||
const findTextError = `[${namespace}${ActionUsers.USER_INFO}]`
|
||||
if (userData.indexOf && userData.indexOf(findTextError) >= 0) {
|
||||
updaterResponse(httpResponse(unauthorized))
|
||||
} else {
|
||||
|
@ -24,7 +24,7 @@ const ZONE_UPDATE = 'zone.update'
|
||||
const ZONE_RENAME = 'zone.rename'
|
||||
const ZONE_INFO = 'zone.info'
|
||||
const ZONE_RAFTSTATUS = 'zone.raftstatus'
|
||||
const ZONE_POOL_INFO = 'zonepool.info'
|
||||
const ZONEPOOL_INFO = 'zonepool.info'
|
||||
|
||||
const Actions = {
|
||||
ZONE_ALLOCATE,
|
||||
@ -33,8 +33,8 @@ const Actions = {
|
||||
ZONE_RENAME,
|
||||
ZONE_INFO,
|
||||
ZONE_RAFTSTATUS,
|
||||
ZONE_POOL_INFO
|
||||
}
|
||||
ZONEPOOL_INFO
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
Actions,
|
||||
|
@ -14,12 +14,13 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const appName = 'fireedge'
|
||||
const appNameSunstone = 'sunstone'
|
||||
const baseUrl = `${appName ? `/${appName}/` : '/'}`
|
||||
const baseUrlWebsockets = 'websockets/'
|
||||
const apps = {
|
||||
sunstone: {
|
||||
name: 'sunstone',
|
||||
theme: 'sunstone',
|
||||
name: appNameSunstone,
|
||||
theme: appNameSunstone,
|
||||
assets: true
|
||||
},
|
||||
provision: {
|
||||
@ -93,6 +94,8 @@ const defaults = {
|
||||
defaultHideCredentialReplacer: '****',
|
||||
defaultOneFlowServer: `${protocol}://${defaultIp}:2474`,
|
||||
defaultConfigFile: `${appName}-server.conf`,
|
||||
defaultSunstoneViews: `${appNameSunstone}-views.conf`,
|
||||
defaultSunstoneConfig: `${appNameSunstone}-server.conf`,
|
||||
defaultTypeLog: 'prod',
|
||||
defaultWebpackMode: 'development',
|
||||
defaultProductionWebpackMode: 'production',
|
||||
@ -115,11 +118,6 @@ const defaults = {
|
||||
default2FAOpennebulaTmpVar: `TMP_${default2FAOpennebulaVar}`,
|
||||
defaultGetMethod: 'info',
|
||||
defaultMessageProblemOpennebula: 'Problem with connection or xml parser',
|
||||
defaultMethodLogin: 'user.login',
|
||||
defaultMethodZones: 'zonepool.info',
|
||||
defaultMethodConfig: 'system.config',
|
||||
defaultMethodUserUpdate: 'user.update',
|
||||
defaultMethodUserInfo: 'user.info',
|
||||
defaultIP: defaultIp,
|
||||
defaultProtocolHotReload: 'http',
|
||||
defaultHost: '0.0.0.0',
|
||||
|
@ -15,6 +15,7 @@
|
||||
const { env } = require('process')
|
||||
const { Map } = require('immutable')
|
||||
const { global } = require('window-or-global')
|
||||
const path = require('path')
|
||||
// eslint-disable-next-line node/no-deprecated-api
|
||||
const { createCipheriv, createCipher, createDecipheriv, createDecipher, createHash } = require('crypto')
|
||||
const { existsSync, readFileSync, createWriteStream } = require('fs-extra')
|
||||
@ -35,7 +36,9 @@ const {
|
||||
defaultOpennebulaZones,
|
||||
defaultEtcPath,
|
||||
defaultTypeCrypto,
|
||||
defaultHash
|
||||
defaultHash,
|
||||
defaultSunstoneViews,
|
||||
defaultSunstoneConfig
|
||||
} = require('./constants/defaults')
|
||||
|
||||
let cert = ''
|
||||
@ -301,6 +304,12 @@ const genPathResources = () => {
|
||||
if (!global.SUNSTONE_AUTH_PATH) {
|
||||
global.SUNSTONE_AUTH_PATH = `${VAR_LOCATION}/.one/${defaultSunstoneAuth}`
|
||||
}
|
||||
if (!global.SUNSTONE_CONFIG) {
|
||||
global.SUNSTONE_CONFIG = `${ETC_LOCATION}/${defaultSunstoneConfig}`
|
||||
}
|
||||
if (!global.SUNSTONE_VIEWS) {
|
||||
global.SUNSTONE_VIEWS = `${ETC_LOCATION}/${defaultSunstoneViews}`
|
||||
}
|
||||
if (!global.FIREEDGE_KEY_PATH) {
|
||||
global.FIREEDGE_KEY_PATH = `${VAR_LOCATION}/.one/${defaultKeyFilename}`
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user