diff --git a/src/fireedge/src/client/components/Tables/index.js b/src/fireedge/src/client/components/Tables/index.js
index ee7d73549f..822261925a 100644
--- a/src/fireedge/src/client/components/Tables/index.js
+++ b/src/fireedge/src/client/components/Tables/index.js
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
* ------------------------------------------------------------------------- */
+import ACLsTable from 'client/components/Tables/ACLs'
import AllImagesTable from 'client/components/Tables/AllImages'
import BackupJobsTable from 'client/components/Tables/BackupJobs'
import BackupsTable from 'client/components/Tables/Backups'
@@ -46,6 +47,7 @@ import ZonesTable from 'client/components/Tables/Zones'
export * from 'client/components/Tables/Enhanced/Utils'
export {
+ ACLsTable,
AllImagesTable,
BackupJobsTable,
BackupsTable,
diff --git a/src/fireedge/src/client/constants/acl.js b/src/fireedge/src/client/constants/acl.js
index 0eefafe9cf..815e1694d9 100644
--- a/src/fireedge/src/client/constants/acl.js
+++ b/src/fireedge/src/client/constants/acl.js
@@ -14,7 +14,14 @@
* limitations under the License. *
* ------------------------------------------------------------------------- */
-// File with constants about ACLs
+import { T } from 'client/constants'
+
+// ACL actions
+export const ACL_ACTIONS = {
+ CREATE_DIALOG: 'create_dialog',
+ CREATE_DIALOG_STRING: 'create_dialog_string',
+ DELETE: 'delete',
+}
// Types of id definition
export const ACL_TYPE_ID = {
@@ -32,6 +39,13 @@ export const ACL_ID = {
'%': 0x800000000,
}
+export const ACL_USERS = {
+ INDIVIDUAL: { type: 'INDIVIDUAL', id: '#', value: 0x100000000 },
+ GROUP: { type: 'GROUP', id: '@', value: 0x200000000 },
+ ALL: { type: 'ALL', id: '*', value: 0x400000000 },
+ CLUSTER: { type: 'CLUSTER', id: '%', value: 0x800000000 },
+}
+
// Hex values for different resource types
export const ACL_RESOURCES = {
VM: { name: 'VM', value: 0x1000000000n },
@@ -62,3 +76,31 @@ export const ACL_RIGHTS = {
ADMIN: { name: 'ADMIN', value: 0x4 },
CREATE: { name: 'CREATE', value: 0x8 },
}
+
+// type of table views
+export const ACL_TABLE_VIEWS = {
+ ICONS: {
+ type: 'ICONS',
+ name: T['acls.table.types.icons'],
+ },
+ NAMES: {
+ type: 'NAMES',
+ name: T['acls.table.types.names'],
+ },
+ CLI: {
+ type: 'CLI',
+ name: T['acls.table.types.cli'],
+ },
+ RESOURCES: {
+ type: 'RESOURCES',
+ name: T['acls.table.types.resources'],
+ },
+ RULE: {
+ type: 'RULE',
+ name: T['acls.table.types.rule'],
+ },
+ READABLERULE: {
+ type: 'READABLERULE',
+ name: T['acls.table.types.readablerule'],
+ },
+}
diff --git a/src/fireedge/src/client/constants/index.js b/src/fireedge/src/client/constants/index.js
index 970d6221af..48fc1e7cc6 100644
--- a/src/fireedge/src/client/constants/index.js
+++ b/src/fireedge/src/client/constants/index.js
@@ -141,6 +141,7 @@ export const INPUT_TYPES = {
TOGGLE: 'toggle',
DOCKERFILE: 'dockerfile',
UNITS: 'units',
+ LABEL: 'label',
}
export const DEBUG_LEVEL = {
@@ -162,6 +163,7 @@ export const SOCKETS = {
/** @enum {string} Names of resource */
export const RESOURCE_NAMES = {
APP: 'marketplace-app',
+ ACL: 'acl',
BACKUP: 'backup',
CLUSTER: 'cluster',
DATASTORE: 'datastore',
diff --git a/src/fireedge/src/client/constants/system.js b/src/fireedge/src/client/constants/system.js
index 88a5290e49..d87e653846 100644
--- a/src/fireedge/src/client/constants/system.js
+++ b/src/fireedge/src/client/constants/system.js
@@ -21,3 +21,9 @@ export const RESTRICTED_ATTRIBUTES_TYPE = {
IMAGE: 'IMAGE_RESTRICTED_ATTR',
VNET: 'VNET_RESTRICTED_ATTR',
}
+
+export const FEDERATION_TYPE = {
+ STANDALONE: 'STANDALONE',
+ MASTER: 'MASTER',
+ SLAVE: 'SLAVE',
+}
diff --git a/src/fireedge/src/client/constants/translates.js b/src/fireedge/src/client/constants/translates.js
index 7cfaf4d096..535e8113d0 100644
--- a/src/fireedge/src/client/constants/translates.js
+++ b/src/fireedge/src/client/constants/translates.js
@@ -396,8 +396,8 @@ module.exports = {
/* sections - network */
Network: 'Network',
Networks: 'Networks',
- VirtualNetwork: 'Virtual network',
- VirtualNetworks: 'Virtual networks',
+ VirtualNetwork: 'Virtual Network',
+ VirtualNetworks: 'Virtual Networks',
NetworkTemplate: 'Network Template',
NetworkTemplates: 'Network Templates',
NetworkTopology: 'Network topology',
@@ -1563,4 +1563,115 @@ module.exports = {
'showback.button.calculateShowback': 'Calculate showback',
'showback.button.help.paragraph.1':
'Generate showback data to the interval selected in start and end date. After generate the showback data, you can access to the reports on the user or group Showback details. ',
+
+ /* system - acls */
+ 'acls.table.actions.create.string': 'Create from string',
+
+ 'acls.table.types.icons': 'Icons',
+ 'acls.table.types.names': 'Names',
+ 'acls.table.types.cli': 'CLI',
+ 'acls.table.types.resources': 'Resources',
+ 'acls.table.types.rule': 'Rule',
+ 'acls.table.types.readablerule': 'Readable Rule',
+ 'acls.table.types.button': 'Table view',
+ 'acls.table.types.title': 'Change to view:',
+
+ 'acls.table.card.rule.user.tooltip': 'Rule applies to user: %1$s',
+ 'acls.table.card.rule.group.tooltip': 'Rule applies to group: %1$s',
+ 'acls.table.card.rule.cluster.tooltip': 'Rule applies to cluster: %1$s',
+ 'acls.table.card.rule.all.tooltip': 'Rule applies to all',
+ 'acls.table.card.rule.zone.tooltip': 'Rule applies to zone: %1$s',
+ 'acls.table.card.rule.zone.tooltip.all': 'Rule applies to all zones',
+ 'acls.table.card.resources.individual.tooltip':
+ 'Resources with identifier: %1$s',
+ 'acls.table.card.resources.group.tooltip': 'Resources owned by group: %1$s',
+ 'acls.table.card.resources.cluster.tooltip':
+ 'Resources owned by cluster: %1$s',
+ 'acls.table.card.resources.all.tooltip': 'Resources owned by all',
+
+ 'acls.table.filter.string': 'String rule',
+ 'acls.table.filter.resources.user.id': 'Resource identifier id',
+ 'acls.table.filter.resources.user.name': 'Resource identifier name',
+ 'acls.table.filter.resources.user.type': 'Resource identifier type',
+ 'acls.table.filter.user.id': 'User identifier id',
+ 'acls.table.filter.user.name': 'User identifier name',
+ 'acls.table.filter.user.type': 'User identifier type',
+ 'acls.table.filter.zone.id': 'Zone identifier id',
+ 'acls.table.filter.zone.name': 'Zone identifier name',
+ 'acls.table.filter.zone.type': 'Zone identifier type',
+
+ 'acls.form.create.user.title': 'Users',
+ 'acls.form.create.user.info':
+ 'Select whom the rule will apply. Could be an individual user, a group of users or all users.',
+ 'acls.form.create.user.individual': 'Select which user to apply the rule to',
+ 'acls.form.create.user.group': 'Select which group to apply the rule to',
+
+ 'acls.form.create.resources.title': 'Resources',
+ 'acls.form.create.resources.info': 'Select affected resources by the rule.',
+ 'acls.form.create.resources.vm': 'Virtual Machine',
+ 'acls.form.create.resources.vmtemplate': 'Virtual Machine Template',
+ 'acls.form.create.resources.vnettemplate': 'Virtual Network Template',
+
+ 'acls.form.create.resourcesUser.title': 'Resource identifier',
+ 'acls.form.create.resourcesUser.info':
+ 'Select resource owners. Could be an individual user, a group of users, a cluster or all users.',
+ 'acls.form.create.resourcesUser.individual':
+ 'Enter the number of the identifier',
+ 'acls.form.create.resourcesUser.group':
+ 'Select which group is the owner of the resources',
+ 'acls.form.create.resourcesUser.cluster':
+ 'Select which cluster is the owner of the resources',
+ 'acls.form.create.resourcesUser.identifier': 'Identifier',
+
+ 'acls.form.create.rights.title': 'Rights',
+ 'acls.form.create.rights.info':
+ 'Select the allowed operations that this rule will enable.',
+
+ 'acls.form.create.zone.title': 'Zone',
+ 'acls.form.create.zone.info':
+ 'Select the zone where the rule will apply. Optional unless OpenNebula is configured in a federation.',
+ 'acls.form.create.zone.zone': 'Select which zone the rule will apply.',
+
+ 'acls.form.create.summary.title': 'Summary',
+ 'acls.form.create.summary.info.rule': 'Rule that will be created: ',
+ 'acls.form.create.summary.info.translation': 'That means: ',
+
+ 'acls.form.create.stringEditor.title': 'String ACL rule',
+ 'acls.form.create.stringEditor.info':
+ 'Enter the string rule that will be created. Remember that a rule it is composed by four different components:',
+ 'acls.form.create.stringEditor.info.user.title': 'User: ',
+ 'acls.form.create.stringEditor.info.user.info':
+ 'Composed by an ID definition (#
for individual user, @ for groups and * for all).',
+ 'acls.form.create.stringEditor.info.resource.title': 'Resources: ',
+ 'acls.form.create.stringEditor.info.resource.info':
+ "Composed by a list of '+' separated resource types, '/' and an ID definition (# for individual resource, @ for groups, % for clusters and * for all).",
+ 'acls.form.create.stringEditor.info.rights.title': 'Rights: ',
+ 'acls.form.create.stringEditor.info.rights.info':
+ "Is a list of operations (USE, MANAGE, ADMIN and CREATE) separated by the '+' character.",
+ 'acls.form.create.stringEditor.info.zone.title': 'Zone: ',
+ 'acls.form.create.stringEditor.info.zone.info':
+ 'is an ID definition (# for a zone and * for all) of the zones where the rule applies. This last part is optional, and can be ignored unless OpenNebula is configured in a federation.',
+ 'acls.form.create.stringEditor.info.more':
+ 'See OpenNebula documentation to get more details ',
+ 'acls.form.create.stringEditor.info.more.link': 'about ACL rules.',
+
+ 'acls.translate.rule': 'Rule',
+ 'acls.translate.user.id': 'allow user with id',
+ 'acls.translate.user.group': 'allows users in the group',
+ 'acls.translate.user.all': 'allows all users',
+ 'acls.translate.rights': 'the right to perform',
+ 'acls.translate.and': 'and',
+ 'acls.translate.operation': 'operation',
+ 'acls.translate.operations': 'operations',
+ 'acls.translate.over': 'over',
+ 'acls.translate.overall': 'over all',
+ 'acls.translate.resource.id': 'with identifier',
+ 'acls.translate.resource.group': 'in the group',
+ 'acls.translate.resource.cluster': 'in the cluster',
+ 'acls.translate.zone.id': 'in the zone',
+ 'acls.translate.zone.all': 'in all zones',
+ 'acls.translate.error': 'ACL rule is NOT valid',
+
+ Identifier: 'Identifier',
+ Rights: 'Rights',
}
diff --git a/src/fireedge/src/client/containers/ACLs/Create.js b/src/fireedge/src/client/containers/ACLs/Create.js
new file mode 100644
index 0000000000..c31a7fcba4
--- /dev/null
+++ b/src/fireedge/src/client/containers/ACLs/Create.js
@@ -0,0 +1,128 @@
+/* ------------------------------------------------------------------------- *
+ * Copyright 2002-2023, 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. *
+ * ------------------------------------------------------------------------- */
+import { ReactElement } from 'react'
+import PropTypes from 'prop-types'
+import {
+ DefaultFormStepper,
+ SkeletonStepsForm,
+} from 'client/components/FormStepper'
+import { CreateForm } from 'client/components/Forms/ACLs'
+import { createAclObjectFromString } from 'client/models/ACL'
+
+import systemApi from 'client/features/OneApi/system'
+import { useAllocateAclMutation } from 'client/features/OneApi/acl'
+import { useGeneralApi } from 'client/features/General'
+import { PATH } from 'client/apps/sunstone/routesOne'
+import { useHistory, useLocation } from 'react-router'
+
+import { useGetUsersQuery } from 'client/features/OneApi/user'
+import { useGetGroupsQuery } from 'client/features/OneApi/group'
+import { useGetClustersQuery } from 'client/features/OneApi/cluster'
+import { useGetZonesQuery } from 'client/features/OneApi/zone'
+
+import { useSystemData } from 'client/features/Auth'
+
+const _ = require('lodash')
+
+/**
+ * Displays the creation form for a ACL rule.
+ *
+ * @returns {ReactElement} - The ACL form component
+ */
+function CreateACLs() {
+ const { state: fromString } = useLocation()
+
+ // General api for enqueue
+ const { enqueueSuccess, enqueueError } = useGeneralApi()
+
+ // Get ONE config
+ const { oneConfig } = useSystemData()
+
+ // Get views
+ const { data: views } = systemApi.useGetSunstoneAvalaibleViewsQuery()
+
+ // Get version to show links to documentation
+ const { data: version } = systemApi.useGetOneVersionQuery()
+
+ // Get list of all users to add in the acl info the name of the user
+ const { data: users } = useGetUsersQuery()
+
+ // Get list of all groups to add in the acl info the name of the group
+ const { data: groups } = useGetGroupsQuery()
+
+ // Get list of all clusters to add in the acl info the name of the cluster
+ const { data: clusters } = useGetClustersQuery()
+
+ // Get list of all zones to add in the acl info the name of the zone
+ const { data: zones } = useGetZonesQuery()
+
+ // Operation to create ACL
+ const [createAcl] = useAllocateAclMutation()
+
+ const history = useHistory()
+
+ const onSubmit = async (props) => {
+ try {
+ // Create acl rule
+ const idAcl = await createAcl(
+ createAclObjectFromString(props?.string)
+ ).unwrap()
+
+ if (idAcl) {
+ // Success message
+ enqueueSuccess(`ACL rule created - #${idAcl}`)
+
+ // Go to ACL list
+ history.push(PATH.SYSTEM.ACLS.LIST)
+ }
+ } catch (error) {
+ enqueueError('Error creating ACL rule')
+ }
+ }
+
+ return views &&
+ version &&
+ users &&
+ groups &&
+ clusters &&
+ zones &&
+ !_.isEmpty(oneConfig) ? (
+ }
+ >
+ {(config) => }
+
+ ) : (
+
+ )
+}
+
+CreateACLs.propTypes = {
+ string: PropTypes.string,
+}
+
+export default CreateACLs
diff --git a/src/fireedge/src/client/containers/ACLs/index.js b/src/fireedge/src/client/containers/ACLs/index.js
new file mode 100644
index 0000000000..abf1290002
--- /dev/null
+++ b/src/fireedge/src/client/containers/ACLs/index.js
@@ -0,0 +1,83 @@
+/* ------------------------------------------------------------------------- *
+ * Copyright 2002-2023, 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. *
+ * ------------------------------------------------------------------------- */
+import { ReactElement, useState, memo } from 'react'
+import PropTypes from 'prop-types'
+import { Box, Stack, Chip } from '@mui/material'
+import { Row } from 'react-table'
+import SplitPane from 'client/components/SplitPane'
+import MultipleTags from 'client/components/MultipleTags'
+import ACLActions from 'client/components/Tables/ACLs/actions'
+import { ACLsTable } from 'client/components/Tables'
+
+/**
+ * Displays a list of Groups with a split pane between the list and selected row(s).
+ *
+ * @returns {ReactElement} Groups list and selected row(s)
+ */
+function ACLs() {
+ const [selectedRows, onSelectedRowsChange] = useState(() => [])
+
+ const hasSelectedRows = selectedRows?.length > 0
+
+ const actions = ACLActions()
+
+ return (
+
+ {({ getGridProps, GutterComponent }) => (
+
+
+
+ {hasSelectedRows && (
+ <>
+
+
+ >
+ )}
+
+ )}
+
+ )
+}
+
+/**
+ * Displays a list of tags that represent the selected rows.
+ *
+ * @param {Row[]} tags - Row(s) to display as tags
+ * @returns {ReactElement} List of tags
+ */
+const GroupedTags = memo(({ tags = [] }) => (
+
+ (
+ toggleRowSelected(false)}
+ />
+ ))}
+ />
+
+))
+
+GroupedTags.propTypes = { tags: PropTypes.array }
+GroupedTags.displayName = 'GroupedTags'
+
+export default ACLs
diff --git a/src/fireedge/src/client/containers/Groups/Create.js b/src/fireedge/src/client/containers/Groups/Create.js
index 69a28ffce1..eac6627536 100644
--- a/src/fireedge/src/client/containers/Groups/Create.js
+++ b/src/fireedge/src/client/containers/Groups/Create.js
@@ -36,7 +36,7 @@ import {
import { CreateForm, UpdateForm } from 'client/components/Forms/Group'
import { PATH } from 'client/apps/sunstone/routesOne'
-import { createStringACL, createAclObjectFromString } from 'client/models/acl'
+import { createStringACL, createAclObjectFromString } from 'client/models/ACL'
import { ACL_RIGHTS, ACL_TYPE_ID } from 'client/constants'
import systemApi from 'client/features/OneApi/system'
@@ -159,7 +159,7 @@ function CreateGroup() {
// Go to groups list
history.push(PATH.SYSTEM.GROUPS.LIST)
} catch (error) {
- enqueueError('Error creating group: ' + error.message)
+ enqueueError('Error creating group')
}
}
diff --git a/src/fireedge/src/client/features/OneApi/acl.js b/src/fireedge/src/client/features/OneApi/acl.js
index fd780ab59b..731e3ee157 100644
--- a/src/fireedge/src/client/features/OneApi/acl.js
+++ b/src/fireedge/src/client/features/OneApi/acl.js
@@ -15,76 +15,152 @@
* ------------------------------------------------------------------------- */
import { Actions, Commands } from 'server/utils/constants/commands/acl'
import { oneApi, ONE_RESOURCES_POOL } from 'client/features/OneApi'
+import userApi from 'client/features/OneApi/user'
+import groupApi from 'client/features/OneApi/group'
+import clusterApi from 'client/features/OneApi/cluster'
+import zoneApi from 'client/features/OneApi/zone'
+
import { Acl } from 'client/constants'
+import { aclFromString } from 'client/models/ACL'
+const _ = require('lodash')
const { ACL_POOL } = ONE_RESOURCES_POOL
+const basicEndpoints = (builder) => ({
+ getAcls: builder.query({
+ /**
+ * Retrieves information for all the acls in the pool.
+ *
+ * @returns {Acl[]} Get list of acls
+ * @throws Fails when response isn't code 200
+ */
+ query: () => {
+ const name = Actions.ACL_INFO
+ const command = { name, ...Commands[name] }
+
+ return { command }
+ },
+ transformResponse: (data) => [data?.ACL_POOL?.ACL ?? []].flat(),
+ providesTags: (acls) =>
+ acls
+ ? [...acls.map(({ ID }) => ({ type: ACL_POOL, id: `${ID}` })), ACL_POOL]
+ : [ACL_POOL],
+ }),
+ allocateAcl: builder.mutation({
+ /**
+ * Allocates a new acl in OpenNebula.
+ *
+ * @param {object} params - Request parameters
+ * @param {string} params.user - User for the new acl
+ * @param {string} params.resource - Resources for the new acl
+ * @param {string} params.right - Rights for the new acl
+ * @returns {number} The allocated Acl id
+ * @throws Fails when response isn't code 200
+ */
+ query: (params) => {
+ const name = Actions.ACL_ADDRULE
+ const command = { name, ...Commands[name] }
+
+ return { params, command }
+ },
+ invalidatesTags: [ACL_POOL],
+ }),
+ removeAcl: builder.mutation({
+ /**
+ * Deletes the given acl from the pool.
+ *
+ * @param {object} params - Request parameters
+ * @param {string|number} params.id - Acl id
+ * @returns {number} Acl id
+ * @throws Fails when response isn't code 200
+ */
+ query: (params) => {
+ const name = Actions.ACL_DELRULE
+ const command = { name, ...Commands[name] }
+
+ return { params, command }
+ },
+ invalidatesTags: [ACL_POOL],
+ }),
+})
+
+const extendedEnpoints = (builder) => ({
+ getAclsExtended: builder.query({
+ /**
+ * Retrieves information for all the acls in the pool adding the names of users, groups, clusters and zones.
+ *
+ * @param {object} params - Request parameters
+ * @param {object} props - Utils to use on queryFn function
+ * @param {Function} props.dispatch - Function to dispatch queries
+ * @returns {Acl[]} Get list of acls
+ * @throws Fails when response isn't code 200
+ */
+ queryFn: async (params = {}, { dispatch }) => {
+ try {
+ // Get users
+ const users = await dispatch(
+ userApi.endpoints.getUsers.initiate(undefined, { forceRefetch: true })
+ ).unwrap()
+
+ // Get groups
+ const groups = await dispatch(
+ groupApi.endpoints.getGroups.initiate(undefined, {
+ forceRefetch: true,
+ })
+ ).unwrap()
+
+ // Get clusters
+ const clusters = await dispatch(
+ clusterApi.endpoints.getClusters.initiate(undefined, {
+ forceRefetch: true,
+ })
+ ).unwrap()
+
+ // Get zones
+ const zones = await dispatch(
+ zoneApi.endpoints.getZones.initiate(undefined, { forceRefetch: true })
+ ).unwrap()
+
+ // Get acls
+ const acls = await dispatch(
+ aclApi.endpoints.getAcls.initiate(undefined, { forceRefetch: true })
+ ).unwrap()
+
+ const data = _.orderBy(
+ acls,
+ [(item) => parseInt(item.ID)],
+ ['desc']
+ ).map((acl) => ({
+ ID: acl.ID,
+ ...aclFromString(acl.STRING, users, groups, clusters, zones),
+ }))
+
+ // Return data
+ return {
+ data,
+ }
+ } catch (error) {
+ return { error }
+ }
+ },
+ providesTags: (acls) =>
+ acls
+ ? [...acls.map(({ ID }) => ({ type: ACL_POOL, id: `${ID}` })), ACL_POOL]
+ : [ACL_POOL],
+ }),
+})
+
const aclApi = oneApi.injectEndpoints({
endpoints: (builder) => ({
- getAcls: builder.query({
- /**
- * Retrieves information for all the acls in the pool.
- *
- * @returns {Acl[]} Get list of acls
- * @throws Fails when response isn't code 200
- */
- query: () => {
- const name = Actions.ACL_INFO
- const command = { name, ...Commands[name] }
-
- return { command }
- },
- transformResponse: (data) => [data?.ACL_POOL?.ACL ?? []].flat(),
- providesTags: (groups) =>
- groups
- ? [
- ...groups.map(({ ID }) => ({ type: ACL_POOL, id: `${ID}` })),
- ACL_POOL,
- ]
- : [ACL_POOL],
- }),
- allocateAcl: builder.mutation({
- /**
- * Allocates a new acl in OpenNebula.
- *
- * @param {object} params - Request parameters
- * @param {string} params.user - User for the new acl
- * @param {string} params.resource - Resources for the new acl
- * @param {string} params.right - Rights for the new acl
- * @returns {number} The allocated Acl id
- * @throws Fails when response isn't code 200
- */
- query: (params) => {
- const name = Actions.ACL_ADDRULE
- const command = { name, ...Commands[name] }
-
- return { params, command }
- },
- invalidatesTags: [ACL_POOL],
- }),
- removeAcl: builder.mutation({
- /**
- * Deletes the given acl from the pool.
- *
- * @param {object} params - Request parameters
- * @param {string|number} params.id - Acl id
- * @returns {number} Acl id
- * @throws Fails when response isn't code 200
- */
- query: (params) => {
- const name = Actions.ACL_DELRULE
- const command = { name, ...Commands[name] }
-
- return { params, command }
- },
- invalidatesTags: [ACL_POOL],
- }),
+ ...basicEndpoints(builder),
+ ...extendedEnpoints(builder),
}),
})
export const {
// Queries
- useGetAclQuery,
+ useGetAclsQuery,
+ useGetAclsExtendedQuery,
// Mutations
useAllocateAclMutation,
diff --git a/src/fireedge/src/client/models/ACL.js b/src/fireedge/src/client/models/ACL.js
new file mode 100644
index 0000000000..8453a24e21
--- /dev/null
+++ b/src/fireedge/src/client/models/ACL.js
@@ -0,0 +1,453 @@
+/* ------------------------------------------------------------------------- *
+ * Copyright 2002-2023, 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. *
+ * ------------------------------------------------------------------------- */
+
+// File to functions about ACL
+
+import { ACL_TYPE_ID, ACL_RIGHTS, T, ACL_USERS } from 'client/constants'
+import { parseAcl } from 'client/utils'
+
+import { Tr } from 'client/components/HOC'
+const _ = require('lodash')
+
+/**
+ * Create an ACL object to send to the API.
+ *
+ * @param {string} user - The user value in hex value
+ * @param {string} resource - The resource value in hex value
+ * @param {string} rights - The rights value in hex value
+ * @param {string} zone - The zone value in hex value
+ * @returns {object} - The object to send to the API
+ */
+export const createAclObject = (user, resource, rights, zone) => {
+ // Create response
+ const response = {
+ user: user,
+ resource: resource,
+ right: rights,
+ }
+
+ // Add zone if exists
+ if (zone) {
+ response.zone = zone
+ }
+
+ // Return response
+ return response
+}
+
+/**
+ * Create an ACL object to sent to the API from a string rule like #5 HOST+VM/@12 INFO+CREATE+DELETE *.
+ *
+ * @param {string} rule - String rule
+ * @returns {object} - The object to send to the API
+ */
+export const createAclObjectFromString = (rule) => {
+ // Parse the rule to get values
+ const ret = parseAcl(rule)
+
+ // Create response
+ const response = {
+ user: ret[0],
+ resource: ret[1],
+ right: ret[2],
+ }
+
+ // Add zone if exists
+ if (ret.length === 4) {
+ response.zone = ret[3]
+ }
+
+ // Return response
+ return response
+}
+
+/**
+ * Create a string rule using the values from a form.
+ *
+ * @param {string} userType - Type of user, e.g. "#"
+ * @param {number} userId - The id of the user, e.g. 4
+ * @param {Array} resources - List of resources, e.g. ["VM,"TEMPLATE",IMAGE"]
+ * @param {string} resourcesIdType - The type of the resources identifier, e.g. "#"
+ * @param {number} resourcesId - The id user of the resources, e.g. 4
+ * @param {Array} rights - List of rights, e.g. ["CREATE","USE"]
+ * @param {string} zoneType - Type of the zone, e.g. "#"
+ * @param {number} zoneId - The id of the user zone, e.g. 3
+ * @returns {string} - ACL string rule
+ */
+export const createStringACL = (
+ userType,
+ userId,
+ resources,
+ resourcesIdType,
+ resourcesId,
+ rights,
+ zoneType,
+ zoneId
+) => {
+ // Define the string as empty string
+
+ let userString = ''
+ let resourcesString = ''
+ const resourcesIdentifierString = ''
+ let rightsString = ''
+ let zoneString
+
+ // User: Type of user identifier plus the user identifier, e.g. @105
+ if (userType) {
+ if (userType === ACL_TYPE_ID.ALL) {
+ userString += userType
+ } else if (
+ userType === ACL_TYPE_ID.INDIVIDUAL ||
+ userType === ACL_TYPE_ID.GROUP
+ )
+ userString += userType + (userId ?? '')
+ }
+
+ // Resources: List of resources separated by '+' plus the resources ID definition, e.g. VM+NET+IMAGE+TEMPLATE/#104
+ resources?.forEach((resource, index) => {
+ if (index < resources.length - 1) resourcesString += resource.name + '+'
+ else resourcesString += resource.name + '/'
+ })
+
+ if (resourcesIdType) {
+ if (resourcesIdType === ACL_TYPE_ID.ALL) {
+ resourcesString += resourcesIdType
+ } else if (
+ resourcesIdType === ACL_TYPE_ID.INDIVIDUAL ||
+ resourcesIdType === ACL_TYPE_ID.GROUP ||
+ resourcesIdType === ACL_TYPE_ID.CLUSTER
+ ) {
+ resourcesString += resourcesIdType + (resourcesId ?? '')
+ }
+ }
+
+ // Rights: List of rights separated by '+', e.g. CREATE+USE
+ rights?.forEach((right, index) => {
+ if (index < rights.length - 1) rightsString += ACL_RIGHTS[right].name + '+'
+ else rightsString += ACL_RIGHTS[right].name
+ })
+
+ // Zone: Type of zone identifier plus the zone identifier, e.g. #44
+ if (zoneType) {
+ zoneString = zoneType + (zoneId ?? '')
+ }
+
+ // Return the ACL string
+ return (
+ userString +
+ ' ' +
+ resourcesString +
+ resourcesIdentifierString +
+ ' ' +
+ rightsString +
+ (zoneString ? ' ' + zoneString : '')
+ )
+}
+
+/**
+ * Check if a ACL string has the correct format.
+ *
+ * @param {string} rule - ACL rule
+ * @returns {boolean} - If the rule it's ok or not
+ */
+export const validACL = (rule) => {
+ // Regular expression for user component
+ const userRegex = /([#@]\d+|[*])/
+
+ // Regular expression for resources component
+ const resourceTypePattern =
+ /(VM|HOST|NET|IMAGE|USER|TEMPLATE|GROUP|DATASTORE|CLUSTER|DOCUMENT|ZONE|SECGROUP|VDC|VROUTER|MARKETPLACE|MARKETPLACEAPP|VMGROUP|VNTEMPLATE|BACKUPJOB)/
+ const otherResourcesTypePattern = new RegExp(
+ `(\\+${resourceTypePattern.source})*`
+ )
+ const resourcesUserRegex = /([#@%]\d+|[*])/
+ const resourcesRegex = new RegExp(
+ `${resourceTypePattern.source}${otherResourcesTypePattern.source}\\/${resourcesUserRegex.source}`
+ )
+
+ // Regular expression for rights component
+ const rightsTypePattern = /(USE|MANAGE|ADMIN|CREATE)/
+ const otherRightsTypePattern = new RegExp(`(\\+${rightsTypePattern.source})*`)
+ const rightsRegex = new RegExp(
+ `${rightsTypePattern.source}${otherRightsTypePattern.source}`
+ )
+
+ // Regular expression for zone component
+ const zoneRegex = /(\*|#\d+)/
+
+ // ACL regular expression
+ const aclRuleRegex = new RegExp(
+ `^${userRegex.source}\\s${resourcesRegex.source}\\s${rightsRegex.source}(\\s${zoneRegex.source})?$`
+ )
+
+ // Check rule
+ return aclRuleRegex.test(rule)
+}
+
+/**
+ * Create a human readable message with the meaning of the rule.
+ *
+ * @param {string} rule - The ACL sring rule
+ * @param {Array} users - List of users
+ * @param {Array} groups - List of groups
+ * @param {Array} clusters - List of clusters
+ * @param {Array} zones - List of zones
+ * @returns {string} - The meaning of the rule
+ */
+export const translateACL = (rule, users, groups, clusters, zones) => {
+ // Create a readable object from the string rule
+ const acl = aclFromString(rule, users, groups, clusters, zones)
+
+ // Define the message
+ let message = Tr(T['acls.translate.rule']) + ' '
+
+ // User info
+ if (
+ acl.USER?.type &&
+ acl.USER.type === ACL_USERS.INDIVIDUAL.type &&
+ acl.USER?.id
+ ) {
+ message += Tr(T['acls.translate.user.id']) + ' '
+ if (acl.USER.id) {
+ message += acl.USER.id + ' '
+ }
+ if (acl.USER.name) {
+ message += ' (' + acl.USER.name + ') '
+ }
+ } else if (
+ acl.USER?.type &&
+ acl.USER.type === ACL_USERS.GROUP.type &&
+ acl.USER?.id
+ ) {
+ message += Tr(T['acls.translate.user.group']) + ' ' + acl.USER.id + ' '
+ if (acl.USER.name) {
+ message += ' (' + acl.USER.name + ') '
+ }
+ } else if (acl.USER?.type && acl.USER.type === ACL_USERS.ALL.type) {
+ message += Tr(T['acls.translate.user.all']) + ' '
+ }
+
+ // Rights info
+ message += Tr(T['acls.translate.rights']) + ' '
+
+ const rights = acl.RIGHTS?.rights
+
+ rights?.forEach((right, index) => {
+ if (index === rights.length - 1) {
+ message += right
+ } else {
+ message += right + ' ' + Tr(T['acls.translate.and']) + ' '
+ }
+ })
+
+ if (rights?.length > 1) {
+ message += ' ' + Tr(T['acls.translate.operations']) + ' '
+ } else {
+ message += ' ' + Tr(T['acls.translate.operation']) + ' '
+ }
+
+ // Resources info
+ if (
+ acl.RESOURCE?.identifier.type &&
+ acl.RESOURCE.identifier.type === ACL_USERS.INDIVIDUAL.type
+ ) {
+ message += Tr(T['acls.translate.overall']) + ' '
+ } else {
+ message += Tr(T['acls.translate.over']) + ' '
+ }
+
+ acl.RESOURCE?.resources.forEach((resource, index) => {
+ if (index === acl.RESOURCE.resources.length - 1) {
+ message += resource
+ } else {
+ message += resource + ' ' + Tr(T['acls.translate.and']) + ' '
+ }
+ })
+
+ // Resources identifier info
+ if (
+ acl.RESOURCE?.identifier.type &&
+ acl.RESOURCE.identifier.type === ACL_USERS.INDIVIDUAL.type &&
+ acl.RESOURCE?.identifier.id
+ ) {
+ message +=
+ ' ' +
+ Tr(T['acls.translate.resource.id']) +
+ ' ' +
+ acl.RESOURCE.identifier.id
+ } else if (
+ acl.RESOURCE?.identifier.type &&
+ acl.RESOURCE.identifier.type === ACL_USERS.GROUP.type &&
+ acl.RESOURCE?.identifier.id
+ ) {
+ message +=
+ ' ' +
+ Tr(T['acls.translate.resource.group']) +
+ ' ' +
+ acl.RESOURCE.identifier.id
+ if (acl.RESOURCE.identifier.name) {
+ message += ' (' + acl.RESOURCE.identifier.name + ')'
+ }
+ } else if (
+ acl.RESOURCE?.identifier.type &&
+ acl.RESOURCE.identifier.type === ACL_USERS.CLUSTER.type &&
+ acl.RESOURCE?.identifier.id
+ ) {
+ message +=
+ ' ' +
+ Tr(T['acls.translate.resource.cluster']) +
+ ' ' +
+ acl.RESOURCE.identifier.id
+ if (acl.RESOURCE.identifier.name) {
+ message += ' (' + acl.RESOURCE.identifier.name + ')'
+ }
+ }
+
+ // Zone info
+ if (acl.ZONE?.type && acl.ZONE?.type === ACL_USERS.INDIVIDUAL.type) {
+ message += ' ' + Tr(T['acls.translate.zone.id']) + ' ' + acl.ZONE.id
+ if (acl.ZONE.name) {
+ message += ' (' + acl.ZONE.name + ')'
+ }
+ } else if (acl.ZONE?.type === ACL_USERS.ALL.type) {
+ message += ' ' + Tr(T['acls.translate.zone.all'])
+ }
+
+ // Return message
+ return message
+}
+
+/**
+ * Create a readable object from an acl rule.
+ *
+ * @param {string} rule - ACL rule
+ * @param {Array} users - List of users
+ * @param {Array} groups - List of groups
+ * @param {Array} clusters - List of clusters
+ * @param {Array} zones - List of zones
+ * @returns {object} The ACL rule in a readable object
+ */
+export const aclFromString = (rule, users, groups, clusters, zones) => {
+ // Create object
+ const acl = {
+ STRING: rule,
+ }
+
+ // Split rule
+ const aclComponents = acl.STRING.split(' ')
+
+ // User
+ if (aclComponents[0]) {
+ // Get user info
+ const user = aclComponents[0]
+
+ // Set user values
+ const userType = _.find(ACL_USERS, { id: user.charAt(0) })?.type
+ const userId = user.length > 1 ? user.substring(1) : undefined
+ let username
+ if (userType === ACL_USERS.INDIVIDUAL.type && users) {
+ username = _.find(users, { ID: userId })?.NAME
+ } else if (userType === ACL_USERS.GROUP.type && groups) {
+ username = _.find(groups, { ID: userId })?.NAME
+ }
+
+ // Create user object
+ acl.USER = {
+ type: userType,
+ id: userId,
+ string: aclComponents[0],
+ name: username,
+ }
+ }
+
+ // Resources
+ if (aclComponents[1]) {
+ // Get resources info
+ const resourcesComponents = aclComponents[1].split('/')
+ const resources = resourcesComponents[0].split('+')
+ const resourcesIdentifier = resourcesComponents[1]
+
+ // Set resource user values
+ const resourceUserType = _.find(ACL_USERS, {
+ id: resourcesIdentifier.charAt(0),
+ })?.type
+ const resourceId =
+ resourcesIdentifier.length > 1
+ ? resourcesIdentifier.substring(1)
+ : undefined
+ let resourceUsername
+ if (resourceUserType === ACL_USERS.GROUP.type && groups) {
+ resourceUsername = _.find(groups, {
+ ID: resourceId,
+ })?.NAME
+ } else if (resourceUserType === ACL_USERS.CLUSTER.type && clusters) {
+ resourceUsername = _.find(clusters, {
+ ID: resourceId,
+ })?.NAME
+ }
+
+ // Create resource object
+ acl.RESOURCE = {
+ resources: resources,
+ identifier: {
+ type: resourceUserType,
+ id: resourceId,
+ string: resourcesIdentifier,
+ name: resourceUsername,
+ },
+ string: resourcesComponents,
+ }
+ }
+
+ // Rights
+ if (aclComponents[2]) {
+ // Get rights info
+ const rights = aclComponents[2].split('+')
+ acl.RIGHTS = {
+ rights: rights,
+ string: aclComponents[2],
+ }
+ }
+
+ // Zone
+ if (aclComponents[3]) {
+ // Create rights object
+ const zone = aclComponents[3]
+
+ if (zone) {
+ // Set zone values
+ const zoneType = _.find(ACL_USERS, { id: zone.charAt(0) }).type
+ const zoneId = zone.length > 1 ? zone.substring(1) : undefined
+
+ let zonename
+ if (zoneType === ACL_USERS.INDIVIDUAL.type && zones) {
+ zonename = _.find(zones, { ID: zoneId })?.NAME
+ }
+
+ if (zone) {
+ acl.ZONE = {
+ type: zoneType,
+ id: zoneId,
+ string: zone,
+ name: zonename,
+ }
+ }
+ }
+ }
+
+ // Return acl
+ return acl
+}
diff --git a/src/fireedge/src/client/models/acl.js b/src/fireedge/src/client/models/acl.js
deleted file mode 100644
index 0f95080a08..0000000000
--- a/src/fireedge/src/client/models/acl.js
+++ /dev/null
@@ -1,131 +0,0 @@
-/* ------------------------------------------------------------------------- *
- * Copyright 2002-2023, 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. *
- * ------------------------------------------------------------------------- */
-
-// File to functions about ACL
-
-import { ACL_TYPE_ID, ACL_RIGHTS } from 'client/constants'
-import { parseAcl } from 'client/utils'
-
-/**
- * Create an ACL object to send to the API.
- *
- * @param {string} user - The user value in hex value
- * @param {string} resource - The resource value in hex value
- * @param {string} rights - The rights value in hex value
- * @param {string} zone - The zone value in hex value
- * @returns {object} - The object to send to the API
- */
-export const createAclObject = (user, resource, rights, zone) => {
- // Create response
- const response = {
- user: user,
- resource: resource,
- right: rights,
- }
-
- // Add zone if exists
- if (zone) {
- response.zone = zone
- }
-
- // Return response
- return response
-}
-
-/**
- * Create an ACL object to sent to the API from a string rule like #5 HOST+VM/@12 INFO+CREATE+DELETE *.
- *
- * @param {string} rule - String rule
- * @returns {object} - The object to send to the API
- */
-export const createAclObjectFromString = (rule) => {
- // Parse the rule to get values
- const ret = parseAcl(rule)
-
- // Create response
- const response = {
- user: ret[0],
- resource: ret[1],
- right: ret[2],
- }
-
- // Add zone if exists
- if (ret.length === 4) {
- response.zone = ret[3]
- }
-
- // Return response
- return response
-}
-
-/**
- * Create a string rule using the values from a form.
- *
- * @param {string} userType - Type of user, e.g. "#"
- * @param {number} userId - The id of the user, e.g. 4
- * @param {Array} resources - List of resources, e.g. ["VM,"TEMPLATE",IMAGE"]
- * @param {string} resourcesIdType - The type of the resources identifier, e.g. "#"
- * @param {number} resourcesId - The id user of the resources, e.g. 4
- * @param {Array} rights - List of rights, e.g. ["CREATE","USE"]
- * @param {string} zoneType - Type of the zone, e.g. "#"
- * @param {number} zoneId - The id of the user zone, e.g. 3
- * @returns {string} - ACL string rule
- */
-export const createStringACL = (
- userType,
- userId,
- resources,
- resourcesIdType,
- resourcesId,
- rights,
- zoneType,
- zoneId
-) => {
- // Define the string as empty string
- let acl = ''
-
- // User: Type of user identifier plus the user identifier, e.g. @105
- acl += userType === ACL_TYPE_ID.ALL ? userType + ' ' : userType + userId + ' '
-
- // Resources: List of resources separated by '+' plus the resources ID definition, e.g. VM+NET+IMAGE+TEMPLATE/#104
- resources.forEach((resource, index) => {
- if (index < resources.length - 1) acl += resource.name + '+'
- else acl += resource.name + '/'
- })
-
- acl +=
- resourcesIdType === ACL_TYPE_ID.ALL
- ? resourcesIdType + ' '
- : resourcesIdType + resourcesId + ' '
-
- // Rights: List of rights separated by '+', e.g. CREATE+USE
- rights.forEach((right, index) => {
- if (index < rights.length - 1) acl += ACL_RIGHTS[right].name + '+'
- else
- acl +=
- zoneType && zoneId
- ? ACL_RIGHTS[right].name + ' '
- : ACL_RIGHTS[right].name
- })
-
- // Zone: Type of zone identifier plus the zone identifier, e.g. #44
- if (zoneType && zoneId) {
- acl += zoneType + zoneId
- }
-
- // Return the ACL string
- return acl
-}
diff --git a/src/fireedge/src/client/utils/parser/index.js b/src/fireedge/src/client/utils/parser/index.js
index 902679f22b..02870984af 100644
--- a/src/fireedge/src/client/utils/parser/index.js
+++ b/src/fireedge/src/client/utils/parser/index.js
@@ -17,7 +17,7 @@ import templateToObject from 'client/utils/parser/templateToObject'
import parseApplicationToForm from 'client/utils/parser/parseApplicationToForm'
import parseFormToApplication from 'client/utils/parser/parseFormToApplication'
import parseFormToDeployApplication from 'client/utils/parser/parseFormToDeployApplication'
-import parseAcl from 'client/utils/parser/parseACL'
+import { parseAcl } from 'client/utils/parser/parseACL'
export {
templateToObject,
diff --git a/src/fireedge/src/client/utils/parser/parseACL.js b/src/fireedge/src/client/utils/parser/parseACL.js
index 88b7c249d0..8c3fd4f048 100644
--- a/src/fireedge/src/client/utils/parser/parseACL.js
+++ b/src/fireedge/src/client/utils/parser/parseACL.js
@@ -25,7 +25,7 @@ import { ACL_ID, ACL_RESOURCES, ACL_RIGHTS } from 'client/constants'
* @param {string} rule - The ACL rule
* @returns {number} - The hex value for the four components of a rule (user, resources, rights and zone)
*/
-const parseAcl = (rule) => {
+export const parseAcl = (rule) => {
// Get each component
const ruleComponents = rule.split(' ')
@@ -140,6 +140,3 @@ const calculateIds = (id) => {
// Return the integer id value
return idValue
}
-
-// Export parseRule function
-export default parseAcl
diff --git a/src/fireedge/src/server/utils/constants/commands/acl.js b/src/fireedge/src/server/utils/constants/commands/acl.js
index e3720c66fc..e0c8f97f59 100644
--- a/src/fireedge/src/server/utils/constants/commands/acl.js
+++ b/src/fireedge/src/server/utils/constants/commands/acl.js
@@ -47,6 +47,10 @@ module.exports = {
from: postBody,
default: '0x1',
},
+ zone: {
+ from: postBody,
+ default: '0x100000000',
+ },
},
},
[ACL_DELRULE]: {