mirror of
https://github.com/OpenNebula/one.git
synced 2026-12-03 21:52:31 +09:00
1 parent
b0dc6e94e4
commit
0cd98ddb89
21 files changed
+1303
-263
No files matched your search
@@ -28,3 +28,12 @@ session_remember_expiration: 3600
|
||||
|
||||
# minimum life expiration time (minutes)
|
||||
minimun_opennebula_expiration: 30
|
||||
|
||||
# :subscriber_endpoint to subscribe for OpenNebula events must match those in
|
||||
# oned.conf
|
||||
subscriber_endpoint: tcp://localhost:2101
|
||||
|
||||
# Log debug level: https://github.com/winstonjs/winston#using-logging-levels
|
||||
# 0 = ERROR, 1 = WARNING, 2 = INFO, 5 = DEBUG
|
||||
#
|
||||
debug_level: 2
|
||||
@@ -13,7 +13,26 @@ vcenter_prepend_command: ''
|
||||
sunstone_prepend: ''
|
||||
|
||||
# Directory to store temporal files when uploading images
|
||||
tmpdir: /var/tmp
|
||||
tmpdir: '/var/tmp'
|
||||
|
||||
# Size upload file
|
||||
max_upload_file_size: 20000
|
||||
|
||||
|
||||
################################################################################
|
||||
# Proxy
|
||||
################################################################################
|
||||
|
||||
#Enable an http proxy for the support portal and to download MarketPlaceApps
|
||||
# from the MarketPlace to the user's desktop.
|
||||
|
||||
#proxy: ""
|
||||
|
||||
################################################################################
|
||||
# Check Official support
|
||||
################################################################################
|
||||
|
||||
#token_remote_support: ""
|
||||
|
||||
################################################################################
|
||||
# UI Settings
|
||||
@@ -94,7 +113,3 @@ langs:
|
||||
vi: 'Vietnamese'
|
||||
zh_CN: 'Chinese (China)'
|
||||
zh_TW: 'Chinese (Taiwan)'
|
||||
|
||||
################################################################################
|
||||
# Unused Settings for future features (added in 6.4 LTS)
|
||||
################################################################################
|
||||
Generated
+866
-173
File diff suppressed because it is too large.
Load diff
@@ -89,6 +89,7 @@
|
||||
"iconoir-react": "4.7.1",
|
||||
"immutable": "4.0.0-rc.12",
|
||||
"intersection-observer": "0.11.0",
|
||||
"jsdom": "19.0.0",
|
||||
"jsonschema": "1.2.7",
|
||||
"jsonwebtoken": "8.5.1",
|
||||
"jwt-simple": "0.5.6",
|
||||
@@ -97,7 +98,7 @@
|
||||
"marked": "4.0.10",
|
||||
"morgan": "1.10.0",
|
||||
"multer": "1.4.3",
|
||||
"node-zendesk": "2.1.0",
|
||||
"node-zendesk": "2.2.0",
|
||||
"notistack": "2.0.3",
|
||||
"opennebula-guacamole": "1.0.0",
|
||||
"opennebula-wmks": "2.1.4",
|
||||
|
||||
@@ -51,6 +51,8 @@ import {
|
||||
validateServerIsSecure,
|
||||
} from './utils/server'
|
||||
|
||||
const appConfig = getFireedgeConfig()
|
||||
|
||||
// set paths
|
||||
genPathResources()
|
||||
|
||||
@@ -58,7 +60,7 @@ genPathResources()
|
||||
genFireedgeKey()
|
||||
|
||||
// set logger
|
||||
initLogger()
|
||||
initLogger(appConfig.debug_level)
|
||||
|
||||
// destructure imports
|
||||
const unsecureServer = http.createServer
|
||||
@@ -70,7 +72,6 @@ const basename = defaultAppName ? `/${defaultAppName}` : ''
|
||||
let frontPath = 'client'
|
||||
|
||||
// settings
|
||||
const appConfig = getFireedgeConfig()
|
||||
const host = appConfig.host || defaultHost
|
||||
const port = appConfig.port || defaultPort
|
||||
|
||||
|
||||
@@ -22,8 +22,15 @@ const {
|
||||
defaultTmpPath,
|
||||
} = require('server/utils/constants/defaults')
|
||||
const { writeInLogger } = require('server/utils/logger')
|
||||
const { getSunstoneConfig } = require('server/utils/yml')
|
||||
|
||||
const upload = multer({ dest: defaultTmpPath })
|
||||
const appConfig = getSunstoneConfig()
|
||||
const optsMulter = { dest: appConfig.tmpdir || defaultTmpPath }
|
||||
if (appConfig && appConfig.max_upload_file_size) {
|
||||
optsMulter.limits = { fileSize: appConfig.max_upload_file_size }
|
||||
}
|
||||
|
||||
const upload = multer(optsMulter)
|
||||
|
||||
const routes = [
|
||||
'2fa',
|
||||
@@ -37,6 +44,7 @@ const routes = [
|
||||
'oneprovision',
|
||||
'sunstone',
|
||||
'system',
|
||||
'support',
|
||||
]
|
||||
|
||||
const serverRoutes = []
|
||||
|
||||
@@ -268,7 +268,7 @@ const getEndpoint = () => {
|
||||
const getSpecificConfig = (key) => {
|
||||
if (!key) return ''
|
||||
|
||||
const provisionConfig = getProvisionConfig({ includeProtectedConfig: true })
|
||||
const provisionConfig = getProvisionConfig()
|
||||
if (Object.hasOwnProperty.call(provisionConfig, key)) {
|
||||
return provisionConfig[key]
|
||||
}
|
||||
|
||||
@@ -165,6 +165,7 @@ const getConfig = (
|
||||
let error
|
||||
|
||||
const config = getSunstoneConfig({
|
||||
includeProtectedConfig: false,
|
||||
onError: (err) => (error = err),
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
/* ------------------------------------------------------------------------- *
|
||||
* Copyright 2002-2022, OpenNebula Project, OpenNebula Systems *
|
||||
* *
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may *
|
||||
* not use this file except in compliance with the License. You may obtain *
|
||||
* a copy of the License at *
|
||||
* *
|
||||
* http://www.apache.org/licenses/LICENSE-2.0 *
|
||||
* *
|
||||
* Unless required by applicable law or agreed to in writing, software *
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, *
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
|
||||
* See the License for the specific language governing permissions and *
|
||||
* limitations under the License. *
|
||||
* ------------------------------------------------------------------------- */
|
||||
const btoa = require('btoa')
|
||||
const { JSDOM } = require('jsdom')
|
||||
// eslint-disable-next-line node/no-deprecated-api
|
||||
const { parse } = require('url')
|
||||
const { defaults, httpCodes } = require('server/utils/constants')
|
||||
const { httpResponse, executeRequest } = require('server/utils/server')
|
||||
const { getSunstoneConfig } = require('server/utils/yml')
|
||||
|
||||
const {
|
||||
defaultEmptyFunction,
|
||||
httpMethod,
|
||||
defaultEnterpriseRepo,
|
||||
defaultComunityRepo,
|
||||
} = defaults
|
||||
const { ok, badRequest } = httpCodes
|
||||
const { GET } = httpMethod
|
||||
|
||||
const appConfig = getSunstoneConfig()
|
||||
|
||||
const headerUserAgent = {
|
||||
'User-Agent': 'OpenNebula Subscription Validation',
|
||||
}
|
||||
|
||||
/**
|
||||
* Get element by xpath.
|
||||
*
|
||||
* @param {string} path - xpath
|
||||
* @param {object} document - document
|
||||
* @returns {Array} result
|
||||
*/
|
||||
const getElementByXpath = (path = '', document = {}) => {
|
||||
const results = []
|
||||
const query = document?.evaluate(path, document, null, 7, null)
|
||||
for (let i = 0, length = query?.snapshotLength; i < length; ++i) {
|
||||
results.push(query?.snapshotItem?.(i))
|
||||
}
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the instance has enterprise support.
|
||||
*
|
||||
* @param {object} res - http response
|
||||
* @param {Function} next - express stepper
|
||||
*/
|
||||
const checkSupport = (res = {}, next = defaultEmptyFunction) => {
|
||||
const responser = (data = '', code = badRequest) => {
|
||||
res.locals.httpCode = httpResponse(code, data, '')
|
||||
next()
|
||||
}
|
||||
|
||||
if (!(appConfig && appConfig.token_remote_support)) {
|
||||
responser('empty/null token')
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
executeRequest(
|
||||
{
|
||||
params: {
|
||||
url: defaultEnterpriseRepo,
|
||||
method: GET,
|
||||
headers: {
|
||||
Authorization: `Basic ${btoa(appConfig.token_remote_support)}`,
|
||||
...headerUserAgent,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
success: (data) => {
|
||||
data ? responser('', ok) : responser('')
|
||||
},
|
||||
error: (error) => responser(error && error.message),
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return latest available version.
|
||||
*
|
||||
* @param {object} res - http response
|
||||
* @param {Function} next - express stepper
|
||||
*/
|
||||
const versionSupport = (res = {}, next = defaultEmptyFunction) => {
|
||||
const responser = (data = '', code = badRequest) => {
|
||||
res.locals.httpCode = httpResponse(code, data, '')
|
||||
next()
|
||||
}
|
||||
|
||||
let params = {
|
||||
url: defaultComunityRepo,
|
||||
headers: headerUserAgent,
|
||||
}
|
||||
|
||||
if (appConfig && appConfig.token_remote_support) {
|
||||
params = {
|
||||
url: defaultEnterpriseRepo,
|
||||
headers: {
|
||||
Authorization: `Basic ${btoa(appConfig.token_remote_support)}`,
|
||||
...headerUserAgent,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if (appConfig && appConfig.proxy) {
|
||||
const parseUrl = parse(appConfig.proxy)
|
||||
params.proxy = {}
|
||||
parseUrl.protocol && (params.proxy.protocol = parseUrl.protocol)
|
||||
parseUrl.host && (params.proxy.host = parseUrl.host)
|
||||
parseUrl.port && (params.proxy.port = parseUrl.port)
|
||||
}
|
||||
|
||||
executeRequest(
|
||||
{
|
||||
params: {
|
||||
method: GET,
|
||||
...params,
|
||||
},
|
||||
},
|
||||
{
|
||||
success: (data) => {
|
||||
if (!data) {
|
||||
responser('')
|
||||
|
||||
return
|
||||
}
|
||||
const dataDom = new JSDOM(data)
|
||||
const versions = getElementByXpath(
|
||||
'//table/tbody/tr/td/a/text()',
|
||||
dataDom?.window?.document
|
||||
)
|
||||
|
||||
const parsedVersions = versions
|
||||
.map((element) => element?.textContent?.replace('/', ''))
|
||||
.filter((element) => {
|
||||
if (!element?.match?.(/^(\d+\.)?(\d+\.)?(\*|\d+\.)?(\*|\d+)$/gm)) {
|
||||
return false
|
||||
}
|
||||
const splitVersion = element.split('.')
|
||||
|
||||
return splitVersion && splitVersion[1] && !(splitVersion[1] % 2)
|
||||
})
|
||||
.reduce((a, b) =>
|
||||
a.localeCompare(b, undefined, {
|
||||
numeric: true,
|
||||
sensitivity: 'base',
|
||||
}) > 0
|
||||
? a
|
||||
: b
|
||||
)
|
||||
|
||||
responser(parsedVersions, ok)
|
||||
},
|
||||
error: (error) => responser(error && error.message),
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
checkSupport,
|
||||
versionSupport,
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/* ------------------------------------------------------------------------- *
|
||||
* Copyright 2002-2022, OpenNebula Project, OpenNebula Systems *
|
||||
* *
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may *
|
||||
* not use this file except in compliance with the License. You may obtain *
|
||||
* a copy of the License at *
|
||||
* *
|
||||
* http://www.apache.org/licenses/LICENSE-2.0 *
|
||||
* *
|
||||
* Unless required by applicable law or agreed to in writing, software *
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, *
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
|
||||
* See the License for the specific language governing permissions and *
|
||||
* limitations under the License. *
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
||||
const { Actions, Commands } = require('server/routes/api/support/routes')
|
||||
const {
|
||||
checkSupport,
|
||||
versionSupport,
|
||||
} = require('server/routes/api/support/functions')
|
||||
|
||||
const { SUPPORT_CHECK, SUPPORT_VERSION } = Actions
|
||||
|
||||
module.exports = [
|
||||
{
|
||||
...Commands[SUPPORT_CHECK],
|
||||
action: checkSupport,
|
||||
},
|
||||
{
|
||||
...Commands[SUPPORT_VERSION],
|
||||
action: versionSupport,
|
||||
},
|
||||
]
|
||||
@@ -0,0 +1,43 @@
|
||||
/* ------------------------------------------------------------------------- *
|
||||
* Copyright 2002-2022, OpenNebula Project, OpenNebula Systems *
|
||||
* *
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may *
|
||||
* not use this file except in compliance with the License. You may obtain *
|
||||
* a copy of the License at *
|
||||
* *
|
||||
* http://www.apache.org/licenses/LICENSE-2.0 *
|
||||
* *
|
||||
* Unless required by applicable law or agreed to in writing, software *
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, *
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
|
||||
* See the License for the specific language governing permissions and *
|
||||
* limitations under the License. *
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
||||
const { httpMethod } = require('server/utils/constants/defaults')
|
||||
|
||||
const basepath = '/support'
|
||||
const { GET } = httpMethod
|
||||
|
||||
const SUPPORT_CHECK = 'support.check'
|
||||
const SUPPORT_VERSION = 'support.version'
|
||||
const Actions = {
|
||||
SUPPORT_CHECK,
|
||||
SUPPORT_VERSION,
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
Actions,
|
||||
Commands: {
|
||||
[SUPPORT_VERSION]: {
|
||||
path: `${basepath}/check/version`,
|
||||
httpMethod: GET,
|
||||
auth: true,
|
||||
},
|
||||
[SUPPORT_CHECK]: {
|
||||
path: `${basepath}/check`,
|
||||
httpMethod: GET,
|
||||
auth: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -14,10 +14,8 @@
|
||||
* limitations under the License. *
|
||||
* ------------------------------------------------------------------------- */
|
||||
const btoa = require('btoa')
|
||||
const https = require('https')
|
||||
// eslint-disable-next-line node/no-deprecated-api
|
||||
const { parse } = require('url')
|
||||
const { request: axios } = require('axios')
|
||||
|
||||
const { defaults, httpCodes } = require('server/utils/constants')
|
||||
const {
|
||||
@@ -26,6 +24,7 @@ const {
|
||||
executeCommandAsync,
|
||||
publish,
|
||||
getSunstoneAuth,
|
||||
executeRequest,
|
||||
} = require('server/utils/server')
|
||||
const {
|
||||
consoleParseToString,
|
||||
@@ -47,7 +46,6 @@ const {
|
||||
} = require('server/utils/constants/commands/cluster')
|
||||
|
||||
const {
|
||||
httpMethod,
|
||||
defaultEmptyFunction,
|
||||
defaultCommandVcenter,
|
||||
defaultRegexpStartJSON,
|
||||
@@ -55,7 +53,6 @@ const {
|
||||
defaultRegexpSplitLine,
|
||||
defaultRegexID,
|
||||
} = defaults
|
||||
const { POST } = httpMethod
|
||||
const { ok, unauthorized, internalServerError, badRequest, accepted } =
|
||||
httpCodes
|
||||
const { LIST, IMPORT } = resourceFromData
|
||||
@@ -503,29 +500,6 @@ const importVobject = (
|
||||
httpReturn(accepted)
|
||||
}
|
||||
|
||||
/**
|
||||
* Axios request.
|
||||
*
|
||||
* @param {object} params - Axios params
|
||||
* @param {Function} callback - Success Axios callback
|
||||
* @param {Function} error - Error Axios callback
|
||||
*/
|
||||
const request = (
|
||||
params = {},
|
||||
callback = defaultEmptyFunction,
|
||||
error = defaultEmptyFunction
|
||||
) => {
|
||||
const defaultsProperties = {
|
||||
method: POST,
|
||||
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
|
||||
validateStatus: (status) => status >= 200 && status < 400,
|
||||
}
|
||||
|
||||
axios({ ...defaultsProperties, ...params })
|
||||
.then(({ data } = {}) => callback(data))
|
||||
.catch(error)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get system config.
|
||||
*
|
||||
@@ -606,44 +580,56 @@ const getToken = (
|
||||
responser(hostInfoError, unauthorized)
|
||||
}
|
||||
|
||||
request(
|
||||
executeRequest(
|
||||
{
|
||||
url: `https://${VCENTER_HOST}/api/session`,
|
||||
headers: {
|
||||
Authorization: `Basic ${btoa(
|
||||
`${VCENTER_USER}:${VCENTER_PASSWORD}`
|
||||
)}`,
|
||||
params: {
|
||||
url: `https://${VCENTER_HOST}/api/session`,
|
||||
headers: {
|
||||
Authorization: `Basic ${btoa(
|
||||
`${VCENTER_USER}:${VCENTER_PASSWORD}`
|
||||
)}`,
|
||||
},
|
||||
},
|
||||
agent: 'https',
|
||||
},
|
||||
(sessionId) => {
|
||||
const vmIdFromDeployId =
|
||||
VM.DEPLOY_ID.match(regexGetVcenterId).groups.id
|
||||
{
|
||||
success: (sessionId) => {
|
||||
const vmIdFromDeployId =
|
||||
VM.DEPLOY_ID.match(regexGetVcenterId).groups.id
|
||||
|
||||
request(
|
||||
{
|
||||
url: `https://${VCENTER_HOST}/api/vcenter/vm/vm-${vmIdFromDeployId}/console/tickets`,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'vmware-api-session-id': sessionId,
|
||||
executeRequest(
|
||||
{
|
||||
params: {
|
||||
url: `https://${VCENTER_HOST}/api/vcenter/vm/vm-${vmIdFromDeployId}/console/tickets`,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'vmware-api-session-id': sessionId,
|
||||
},
|
||||
data: JSON.stringify({ type: 'WEBMKS' }),
|
||||
},
|
||||
agent: 'https',
|
||||
},
|
||||
data: JSON.stringify({ type: 'WEBMKS' }),
|
||||
},
|
||||
(ticketData) => {
|
||||
const { ticket } = ticketData
|
||||
const { protocol, hostname, port, path } = parse(ticket)
|
||||
{
|
||||
success: (ticketData) => {
|
||||
const { ticket } = ticketData
|
||||
const { protocol, hostname, port, path } = parse(ticket)
|
||||
|
||||
const httpProtocol = protocol === 'wss:' ? 'https' : 'http'
|
||||
const esxUrl = `${httpProtocol}://${hostname}:${port}`
|
||||
const token = path.replace('/ticket/', '')
|
||||
global.vcenterToken = { [token]: esxUrl }
|
||||
const httpProtocol =
|
||||
protocol === 'wss:' ? 'https' : 'http'
|
||||
const esxUrl = `${httpProtocol}://${hostname}:${port}`
|
||||
const token = path.replace('/ticket/', '')
|
||||
global.vcenterToken = { [token]: esxUrl }
|
||||
|
||||
responser(token, ok)
|
||||
},
|
||||
(error) =>
|
||||
responser(error && error.message, internalServerError)
|
||||
)
|
||||
},
|
||||
(error) => responser(error && error.message, internalServerError)
|
||||
responser(token, ok)
|
||||
},
|
||||
error: (error) =>
|
||||
responser(error && error.message, internalServerError),
|
||||
}
|
||||
)
|
||||
},
|
||||
error: (error) =>
|
||||
responser(error && error.message, internalServerError),
|
||||
}
|
||||
)
|
||||
},
|
||||
})
|
||||
|
||||
@@ -149,6 +149,9 @@ const getZone = (zone = '0') => {
|
||||
defaultOpennebulaZones[0].rpc
|
||||
) {
|
||||
defaultOpennebulaZones[0].rpc = appConfig.one_xmlrpc
|
||||
if (appConfig.subscriber_endpoint) {
|
||||
defaultOpennebulaZones[0].zeromq = appConfig.subscriber_endpoint
|
||||
}
|
||||
}
|
||||
|
||||
return getDataZone(zone, defaultOpennebulaZones)
|
||||
|
||||
@@ -65,7 +65,10 @@ const executeWorker = ({
|
||||
worker.terminate()
|
||||
const err = result && result.data && result.data.err
|
||||
const value = result && result.data && result.data.value
|
||||
writeInLogger([command, JSON.stringify(value)], 'worker: %s : %s')
|
||||
writeInLogger([command, paramsCommand, JSON.stringify(value)], {
|
||||
format: 'worker: %s, [%s]: %s',
|
||||
level: 2,
|
||||
})
|
||||
if (!err) {
|
||||
fillResourceforHookConnection(user, command, paramsCommand)
|
||||
res.locals.httpCode = parseReturnWorker(value)
|
||||
|
||||
@@ -35,7 +35,8 @@ const APP_NAMES = Object.keys(defaultApps)
|
||||
|
||||
const APP_CONFIG = {
|
||||
[defaultApps.provision.name]: getProvisionConfig() || {},
|
||||
[defaultApps.sunstone.name]: getSunstoneConfig() || {},
|
||||
[defaultApps.sunstone.name]:
|
||||
getSunstoneConfig({ includeProtectedConfig: false }) || {},
|
||||
}
|
||||
|
||||
const ensuredScriptValue = (value) =>
|
||||
|
||||
@@ -98,7 +98,9 @@ const guacamole = (appServer) => {
|
||||
clientCallbacks
|
||||
)
|
||||
guacamoleServer.on('error', (clientConnection, error) => {
|
||||
writeInLogger(error, formatError)
|
||||
writeInLogger(error, {
|
||||
format: formatError,
|
||||
})
|
||||
messageTerminal(configError(error))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -53,11 +53,17 @@ const vmrcProxy = createProxyMiddleware(endpointVmrc, {
|
||||
const parseURL = parse(req.url)
|
||||
if (parseURL && parseURL.pathname) {
|
||||
const ticket = parseURL.pathname.split('/')[3]
|
||||
writeInLogger(ticket, 'path to vmrc token: %s')
|
||||
writeInLogger(ticket, {
|
||||
format: 'path to vmrc token: %s',
|
||||
level: 2,
|
||||
})
|
||||
if (global && global.vcenterToken && global.vcenterToken[ticket]) {
|
||||
return global.vcenterToken[ticket]
|
||||
} else {
|
||||
writeInLogger(ticket, 'Non-existent token: %s')
|
||||
writeInLogger(ticket, {
|
||||
format: 'Non-existent token: %s',
|
||||
level: 2,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,13 +93,14 @@ const defaults = {
|
||||
query: 'QUERY',
|
||||
postBody: 'POST_BODY',
|
||||
},
|
||||
defaultEnterpriseRepo: 'https://enterprise.opennebula.io/repo/',
|
||||
defaultComunityRepo: 'https://downloads.opennebula.io/repo/',
|
||||
defaultDownloader: 'remotes/datastore/downloader.sh',
|
||||
defaultOpennebulaZones: [
|
||||
{
|
||||
id: '0',
|
||||
name: 'OpenNebula',
|
||||
rpc: `${protocol}://${defaultIp}:2633/RPC2`,
|
||||
zeromq: `tcp://${defaultIp}:2101`,
|
||||
},
|
||||
],
|
||||
defaultConfigParseXML: {
|
||||
@@ -125,6 +126,7 @@ const defaults = {
|
||||
defaultSunstonePath: internalSunstonePath,
|
||||
defaultProvisionPath: internalProvisionPath,
|
||||
defaultProvidersConfigPath: 'providers.d',
|
||||
defaultLogsLevels: ['error', 'warm', 'info', 'http', 'verbose', 'debug'],
|
||||
defaultTypeLog: 'prod',
|
||||
defaultWebpackMode: 'development',
|
||||
defaultProductionWebpackMode: 'production',
|
||||
|
||||
@@ -20,15 +20,20 @@ const { transports, format, createLogger } = require('winston')
|
||||
const { sprintf } = require('sprintf-js')
|
||||
const morgan = require('morgan')
|
||||
const { defaults } = require('server/utils/constants')
|
||||
const { defaultWebpackMode } = defaults
|
||||
const { defaultWebpackMode, defaultLogsLevels } = defaults
|
||||
|
||||
let logger = null
|
||||
|
||||
/**
|
||||
* Initialize logger.
|
||||
*
|
||||
* @param {number} logLevel - log level
|
||||
*/
|
||||
const initLogger = () => {
|
||||
const initLogger = (logLevel = 0) => {
|
||||
if (global && global.paths && global.paths.FIREEDGE_LOG) {
|
||||
const levelString = parseInt(logLevel, 10)
|
||||
const logString = defaultLogsLevels && defaultLogsLevels[levelString]
|
||||
|
||||
const trans = []
|
||||
|
||||
if (env && env.NODE_ENV && env.NODE_ENV === defaultWebpackMode) {
|
||||
@@ -41,7 +46,7 @@ const initLogger = () => {
|
||||
trans.push(
|
||||
new transports.File({
|
||||
silent: false,
|
||||
level: 'info',
|
||||
level: logString,
|
||||
filename: global.paths.FIREEDGE_LOG,
|
||||
handleExceptions: true,
|
||||
format: format.simple(),
|
||||
@@ -86,7 +91,12 @@ const getLogger = () => logger
|
||||
const getLoggerMiddleware = () => {
|
||||
const log = getLogger()
|
||||
if (log && log.stream) {
|
||||
return morgan('combined', { stream: log.stream })
|
||||
return morgan('combined', {
|
||||
stream: log.stream,
|
||||
skip: function (req, res) {
|
||||
return res.statusCode < 400
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,13 +104,17 @@ const getLoggerMiddleware = () => {
|
||||
* Write in logger.
|
||||
*
|
||||
* @param {string} message - message for logger file
|
||||
* @param {string } formatLog - message format
|
||||
* @param {object} optLog - message format
|
||||
* @param {string} optLog.format - Message format. By default is '%s'
|
||||
* @param {number} optLog.level - Log debug level. By default is 0
|
||||
*/
|
||||
const writeInLogger = (message = '', formatLog = '%s') => {
|
||||
const writeInLogger = (message = '', optLog = {}) => {
|
||||
const { format: formatLogger = '%s', level = 0 } = optLog
|
||||
const logString = defaultLogsLevels && defaultLogsLevels[level]
|
||||
const log = getLogger()
|
||||
if (log) {
|
||||
const parseMessage = Array.isArray(message) ? message : [message]
|
||||
log.info(sprintf(formatLog, ...parseMessage))
|
||||
log[logString](sprintf(formatLogger, ...parseMessage))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
* limitations under the License. *
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
||||
const https = require('https')
|
||||
const http = require('http')
|
||||
const { env } = require('process')
|
||||
const { Map } = require('immutable')
|
||||
const { global } = require('window-or-global')
|
||||
@@ -41,6 +43,7 @@ const { defaults, httpCodes } = require('server/utils/constants')
|
||||
const { messageTerminal } = require('server/utils/general')
|
||||
const { validateAuth } = require('server/utils/jwt')
|
||||
const { writeInLogger } = require('server/utils/logger')
|
||||
const { request: axios } = require('axios')
|
||||
|
||||
const eventsEmitter = new events.EventEmitter()
|
||||
const {
|
||||
@@ -58,7 +61,6 @@ const {
|
||||
defaultKeyFilename,
|
||||
defaultSunstoneAuth,
|
||||
defaultWebpackMode,
|
||||
defaultOpennebulaZones,
|
||||
defaultEtcPath,
|
||||
defaultTypeCrypto,
|
||||
defaultHash,
|
||||
@@ -71,6 +73,7 @@ const {
|
||||
defaultEmptyFunction,
|
||||
} = defaults
|
||||
const { internalServerError } = httpCodes
|
||||
const { POST } = httpMethod
|
||||
|
||||
let cert = ''
|
||||
let key = ''
|
||||
@@ -392,10 +395,14 @@ const genFireedgeKey = () => {
|
||||
global.paths.FIREEDGE_KEY_PATH,
|
||||
uuidv4.replace(/-/g, ''),
|
||||
() => {
|
||||
writeInLogger(`file ${global.paths.FIREEDGE_KEY_PATH} created`)
|
||||
const formatError = 'file %s created'
|
||||
writeInLogger(global.paths.FIREEDGE_KEY_PATH, {
|
||||
format: formatError,
|
||||
level: 2,
|
||||
})
|
||||
messageTerminal({
|
||||
color: 'green',
|
||||
message: 'File %s created',
|
||||
message: formatError,
|
||||
error: global.paths.FIREEDGE_KEY_PATH,
|
||||
})
|
||||
},
|
||||
@@ -482,8 +489,7 @@ const getSunstoneAuth = () => {
|
||||
*/
|
||||
const getDataZone = (zone = '0', configuredZones) => {
|
||||
let rtn
|
||||
const zones =
|
||||
(global && global.zones) || configuredZones || defaultOpennebulaZones
|
||||
const zones = (global && global.zones) || configuredZones
|
||||
if (zones && Array.isArray(zones)) {
|
||||
rtn = zones[0]
|
||||
if (Number.isInteger(parseInt(zone, 10))) {
|
||||
@@ -527,6 +533,9 @@ const genPathResources = () => {
|
||||
if (!global.paths.FIREEDGE_LOG) {
|
||||
global.paths.FIREEDGE_LOG = `${LOG_LOCATION}/${defaultLogFilename}`
|
||||
}
|
||||
if (!global.paths.FIREEDGE_LOG_LEVEL) {
|
||||
global.paths.FIREEDGE_LOG = `${LOG_LOCATION}/${defaultLogFilename}`
|
||||
}
|
||||
if (!global.paths.DOWNLOADER) {
|
||||
global.paths.DOWNLOADER = `${VAR_LOCATION}/${defaultDownloader}`
|
||||
}
|
||||
@@ -931,6 +940,37 @@ const subscriber = (eventName = '', callback = () => undefined) => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Axios request.
|
||||
*
|
||||
* @param {object} data - data for request
|
||||
* @param {object} data.params - params for request
|
||||
* @param {string} data.method - request method
|
||||
* @param {string} data.agent - request agent
|
||||
* @param {object} callbacks - callbacks
|
||||
* @param {Function} callbacks.success - success callback
|
||||
* @param {Function} callbacks.error - error callback
|
||||
*/
|
||||
const executeRequest = (data = {}, callbacks = {}) => {
|
||||
const { params = {}, method = POST, agent } = data
|
||||
const { success = defaultEmptyFunction, error = defaultEmptyFunction } =
|
||||
callbacks
|
||||
const defaultsProperties = agent
|
||||
? {
|
||||
method,
|
||||
httpsAgent:
|
||||
agent === 'https'
|
||||
? new https.Agent({ rejectUnauthorized: false })
|
||||
: new http.Agent({ rejectUnauthorized: false }),
|
||||
validateStatus: (status) => status >= 200 && status < 400,
|
||||
}
|
||||
: {}
|
||||
|
||||
axios({ ...defaultsProperties, ...params })
|
||||
.then(({ data: dataRequest } = {}) => success(dataRequest))
|
||||
.catch(error)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
encrypt,
|
||||
decrypt,
|
||||
@@ -963,4 +1003,5 @@ module.exports = {
|
||||
validateHttpMethod,
|
||||
publish,
|
||||
subscriber,
|
||||
executeRequest,
|
||||
}
|
||||
@@ -94,7 +94,7 @@ const filterByProtectedKeys = (config = {}, keys = []) =>
|
||||
/**
|
||||
* @typedef GetConfigurationOptions
|
||||
* @property {function(string)} [onError] - Function to be called when an error
|
||||
* @property {boolean} [includeProtectedConfig] - Include protected config
|
||||
* @property {boolean} [includeProtectedConfig] - Include protected config. By default is true.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -106,7 +106,7 @@ const filterByProtectedKeys = (config = {}, keys = []) =>
|
||||
*/
|
||||
const getConfiguration = (
|
||||
app = defaultAppName,
|
||||
{ onError = defaultEmptyFunction, includeProtectedConfig = false } = {}
|
||||
{ onError = defaultEmptyFunction, includeProtectedConfig = true } = {}
|
||||
) => {
|
||||
const config = readYAMLFile(getConfigPathByApp(app), onError)
|
||||
|
||||
@@ -123,8 +123,7 @@ const getConfiguration = (
|
||||
* @param {GetConfigurationOptions} [options] - Options
|
||||
* @returns {object} FireEdge configuration
|
||||
*/
|
||||
const getFireedgeConfig = (options) =>
|
||||
getConfiguration(defaultAppName, { includeProtectedConfig: true, ...options })
|
||||
const getFireedgeConfig = (options) => getConfiguration(defaultAppName, options)
|
||||
|
||||
/**
|
||||
* Get Sunstone configuration.
|
||||
|
||||
Reference in new issue
Block a user