1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-06 12:58:18 +03:00

M #-: Message cluster.info/no admin (#2377)

This commit is contained in:
Jorge Miguel Lobo Escalona 2022-11-24 15:57:29 +01:00 committed by GitHub
parent f77b9365ee
commit 9a02f7d1a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 182 additions and 2 deletions

View File

@ -19,7 +19,7 @@ import { generatePath } from 'react-router-dom'
import { Stack } from '@mui/material'
import { useViews } from 'client/features/Auth'
import { useGetClusterQuery } from 'client/features/OneApi/cluster'
import { useGetClusterAdminQuery } from 'client/features/OneApi/cluster'
import { useRenameVmMutation } from 'client/features/OneApi/vm'
import { StatusCircle, StatusChip } from 'client/components/Status'
@ -75,7 +75,7 @@ const InformationPanel = ({ vm = {}, actions }) => {
CID: clusterId,
} = getLastHistory(vm)
const { data: cluster } = useGetClusterQuery({ id: clusterId })
const { data: cluster } = useGetClusterAdminQuery({ id: clusterId })
const clusterName = +clusterId === -1 ? 'default' : cluster?.NAME ?? '--'
const handleRename = async (_, newName) => {

View File

@ -14,6 +14,11 @@
* limitations under the License. *
* ------------------------------------------------------------------------- */
import { Actions, Commands } from 'server/utils/constants/commands/cluster'
import {
Actions as ExtraActions,
Commands as ExtraCommands,
} from 'server/routes/api/cluster/routes'
import {
oneApi,
ONE_RESOURCES,
@ -86,6 +91,24 @@ const clusterApi = oneApi.injectEndpoints({
} catch {}
},
}),
getClusterAdmin: builder.query({
/**
* Retrieve the information as serveradmin.
*
* @param {object} params - Request params
* @param {string} params.id - Cluster id
* @param {boolean} [params.decrypt] - Optional flag to decrypt contained secrets, valid only for admin
* @returns {Cluster} Get cluster identified by id
* @throws Fails when response isn't code 200
*/
query: (params) => {
const name = ExtraActions.CLUSTER_ADMINSHOW
const command = { name, ...ExtraCommands[name] }
return { params, command }
},
providesTags: (_, __, { id }) => [{ type: CLUSTER, id }],
}),
allocateCluster: builder.mutation({
/**
* Allocates a new cluster in OpenNebula.
@ -281,6 +304,8 @@ export const {
useLazyGetClustersQuery,
useGetClusterQuery,
useLazyGetClusterQuery,
useGetClusterAdminQuery,
useLazyGetClusterAdminQuery,
// Mutations
useAllocateClusterMutation,

View File

@ -0,0 +1,81 @@
/* ------------------------------------------------------------------------- *
* 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 { defaults, httpCodes } = require('server/utils/constants')
const { httpResponse, getSunstoneAuth } = require('server/utils/server')
const { createTokenServerAdmin } = require('server/routes/api/auth/utils')
const {
Actions: clusterActions,
} = require('server/utils/constants/commands/cluster')
const { defaultEmptyFunction } = defaults
const { CLUSTER_INFO } = clusterActions
const { ok, badRequest, unauthorized } = httpCodes
/**
* Show cluster with server admin credentials.
*
* @param {object} res - response http
* @param {Function} next - express stepper
* @param {string} params - data response http
* @param {object} userData - user of http request
* @param {Function} xmlrpc - XML-RPC function
*/
const show = (
res = {},
next = defaultEmptyFunction,
params = {},
userData = {},
xmlrpc = defaultEmptyFunction
) => {
const { id: clusterId } = params
const serverAdmin = getSunstoneAuth() ?? {}
const { token: authToken } = createTokenServerAdmin(serverAdmin) ?? {}
if (!authToken) {
res.locals.httpCode = httpResponse(badRequest, '')
next()
return
}
const { username } = serverAdmin
const oneClientServerAdmin = xmlrpc(`${username}:${username}`, authToken)
// get CLUSTER information by id
oneClientServerAdmin({
action: CLUSTER_INFO,
parameters: [parseInt(clusterId, 10), true],
callback: (clusterInfoErr, data = {}) => {
const { CLUSTER } = data
if (clusterInfoErr || !CLUSTER) {
res.locals.httpCode = httpResponse(unauthorized, clusterInfoErr)
next()
return
}
res.locals.httpCode = httpResponse(ok, CLUSTER)
next()
},
})
}
const functionRoutes = {
show,
}
module.exports = functionRoutes

View File

@ -0,0 +1,27 @@
/* ------------------------------------------------------------------------- *
* 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/cluster/routes')
const { show } = require('server/routes/api/cluster/functions')
const { CLUSTER_ADMINSHOW } = Actions
module.exports = [
{
...Commands[CLUSTER_ADMINSHOW],
action: show,
},
]

View File

@ -0,0 +1,46 @@
/* ------------------------------------------------------------------------- *
* 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 {
from: fromData,
httpMethod,
} = require('../../../utils/constants/defaults')
const { GET } = httpMethod
const basepath = '/cluster'
const { resource } = fromData
const CLUSTER_ADMINSHOW = 'cluster.adminInfo'
const Actions = {
CLUSTER_ADMINSHOW,
}
module.exports = {
Actions,
Commands: {
[CLUSTER_ADMINSHOW]: {
path: `${basepath}/admininfo/:id`,
httpMethod: GET,
auth: true,
params: {
id: {
from: resource,
},
},
},
},
}

View File

@ -35,6 +35,7 @@ const upload = multer(optsMulter)
const routes = [
'2fa',
'auth',
'cluster',
'files',
'image',
'marketapp',