mirror of
https://github.com/OpenNebula/one.git
synced 2026-12-04 22:21:36 +09:00
M #-: Fix URL support (#3770)
This commit is contained in:
1 parent
b4f2beee97
commit
fe67119e0e
4 files changed
+6
-114
No files matched your search
@@ -51,6 +51,7 @@ const SingleDetailActions = memo(({ selectedRows = [], singleActions }) => {
|
||||
SingleDetailActions.propTypes = {
|
||||
selectedRows: PropTypes.array,
|
||||
actions: PropTypes.array,
|
||||
singleActions: PropTypes.func,
|
||||
}
|
||||
SingleDetailActions.displayName = 'SingleDetailActions'
|
||||
export default SingleDetailActions
|
||||
@@ -14,14 +14,11 @@
|
||||
* 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, defaultComunityRepo } = defaults
|
||||
const { defaultEmptyFunction, httpMethod, defaultEnterpriseRepo } = defaults
|
||||
const { ok, badRequest } = httpCodes
|
||||
const { GET } = httpMethod
|
||||
|
||||
@@ -31,23 +28,6 @@ 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.
|
||||
*
|
||||
@@ -69,7 +49,7 @@ const checkSupport = (res = {}, next = defaultEmptyFunction) => {
|
||||
executeRequest(
|
||||
{
|
||||
params: {
|
||||
url: defaultComunityRepo,
|
||||
url: defaultEnterpriseRepo,
|
||||
method: GET,
|
||||
headers: {
|
||||
Authorization: `Basic ${btoa(appConfig.token_remote_support)}`,
|
||||
@@ -86,88 +66,6 @@ const checkSupport = (res = {}, next = defaultEmptyFunction) => {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 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: defaultComunityRepo,
|
||||
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,
|
||||
}
|
||||
@@ -15,20 +15,13 @@
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
||||
const { Actions, Commands } = require('server/routes/api/support/routes')
|
||||
const {
|
||||
checkSupport,
|
||||
versionSupport,
|
||||
} = require('server/routes/api/support/functions')
|
||||
const { checkSupport } = require('server/routes/api/support/functions')
|
||||
|
||||
const { SUPPORT_CHECK, SUPPORT_VERSION } = Actions
|
||||
const { SUPPORT_CHECK } = Actions
|
||||
|
||||
module.exports = [
|
||||
{
|
||||
...Commands[SUPPORT_CHECK],
|
||||
action: checkSupport,
|
||||
},
|
||||
{
|
||||
...Commands[SUPPORT_VERSION],
|
||||
action: versionSupport,
|
||||
},
|
||||
]
|
||||
@@ -79,7 +79,7 @@ const defaults = {
|
||||
query: 'QUERY',
|
||||
postBody: 'POST_BODY',
|
||||
},
|
||||
defaultComunityRepo: 'https://downloads.opennebula.io/repo/',
|
||||
defaultEnterpriseRepo: 'https://enterprise.opennebula.io/repo/',
|
||||
defaultDownloader: 'remotes/datastore/downloader.sh',
|
||||
defaultOpennebulaZones: [
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user