winterhazel commented on code in PR #13225: URL: https://github.com/apache/cloudstack/pull/13225#discussion_r3391335853
########## ui/public/locales/en.json: ########## @@ -409,6 +412,11 @@ "label.api.docs.count": "APIs available for your account", "label.api.version": "API version", "label.apikey": "API key", +"label.apikeypairs": "API Key Pairs", +"label.apikeypair.description": "Description of the API key pair", +"label.apikeypair.name": "Name of the API key pair", +"label.apikeypair.startdate": "API key pair starting validation date", Review Comment: ```suggestion "label.apikeypair.startdate": "API key pair starting valid date", ``` Maybe something like this instead? ########## ui/public/locales/pt_BR.json: ########## @@ -379,6 +382,11 @@ "label.api.docs.count": "APIs dispon\u00edveis para sua conta", "label.api.version": "Vers\u00e3o da API", "label.apikey": "Chave da API", +"label.apikeypairs": "Par de chaves de API", +"label.apikeypair.description": "Descri\u00e7\u00e3o do par de chaves de API", +"label.apikeypair.name": "Nome do par de chaves de API", +"label.apikeypair.startdate": "Data de in\u00edcio de valida\u00e7\u00e3o par de chaves de API", Review Comment: ```suggestion "label.apikeypair.startdate": "Data de in\u00edcio da validade do par de chaves de API", ``` ########## ui/src/views/iam/ApiKeyPairPermissionTable.vue: ########## @@ -0,0 +1,518 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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. + +<template> + <loading-outlined v-if="loadingTable" class="main-loading-spinner" /> + <div v-else> + <div v-if="!disabled" class="rules-list ant-list ant-list-bordered"> + <div class="rules-table-item ant-list-item"> + <div class="rules-table__col rules-table__col--grab" /> + <div class="rules-table__col rules-table__col--rule rules-table__col--new"> + <a-auto-complete + :key="autocompleteKey" + v-focus="true" + :filterOption="filterOption" + :options="apis" + v-model:value="newRule" + :placeholder="$t('label.rule')" /> + </div> + <div class="rules-table__col rules-table__col--permission"> + <permission-editable + :default-value="newRulePermission" + :value="newRulePermission" + @onChange="updateNewPermission()" /> + </div> + <div class="rules-table__col rules-table__col--description"> + <a-input v-model:value="newRuleDescription" :placeholder="$t('label.description')" /> + </div> + <div class="rules-table__col rules-table__col--actions"> + <tooltip-button + tooltipPlacement="bottom" + :tooltip="$t('label.save.new.rule')" + icon="plus-outlined" + type="primary" + @onClick="onRuleSave" /> + </div> + </div> + + <draggable + v-model="rules" + @change="updateRules" + handle=".drag-handle" + ghostClass="drag-ghost" + :component-data="{type: 'transition'}" + item-key="rule"> + <template #item="{element, index}"> + <div class="rules-table-item ant-list-item"> + <div class="rules-table__col rules-table__col--grab drag-handle"> + <drag-outlined /> + </div> + <div class="rules-table__col rules-table__col--rule"> + {{ element.rule }} + </div> + <div class="rules-table__col rules-table__col--permission"> + <permission-editable + :default-value="element.permission" + @onChange="onPermissionChange(element, $event, index)" /> + </div> + <div class="rules-table__col rules-table__col--description"> + <div v-if="element.description"> + {{ element.description }} + </div> + <div v-else class="no-description"> + {{ $t('message.no.description') }} + </div> + </div> + <div class="rules-table__col rules-table__col--actions"> + <tooltip-button + :tooltip="$t('label.delete.rule')" + tooltipPlacement="bottom" + type="primary" + :danger="true" + icon="delete-outlined" + :disabled="false" + @onClick="onRuleDelete(element.rule, index)" /> + </div> + </div> + </template> + </draggable> + </div> + + <div :style="{width: '100%', display: 'flex', marginTop: this.rules.length > 0 ? '12px' : '0'}" v-if="this.rules.length > 0 && !disabled"> + <a-button + style="width: 100%;" + danger + @click="deleteAllRules()"> + <template #icon><delete-outlined /></template> + {{ $t('label.delete.all.rules') }} + </a-button> + </div> + + <a-table + v-else-if="disabled" + :columns="columns" + :dataSource="rules" + rowKey="rule" + size="large" + :pagination="pagination" + @change="handlePaginationChange"> + <template #customFilterDropdown="{ setSelectedKeys, selectedKeys, confirm, clearFilters, column }"> + <div style="padding: 8px"> + <a-input + ref="searchInput" + :placeholder="$t('label.search')" + :value="selectedKeys[0]" + style="width: 100%; margin-bottom: 8px; display: block" + @change="e => setSelectedKeys(e.target.value ? [e.target.value] : [])" + @pressEnter="handleSearch(selectedKeys, confirm, column.dataIndex)" + /> + <div style="display: flex; gap: 8px"> + <a-button + type="primary" + size="small" + style="width: 112px;" + @click="handleSearch(selectedKeys, confirm, column.dataIndex)"> + <template #icon> + <search-outlined /> + </template> + {{ $t('label.search') }} + </a-button> + + <a-button + size="small" + style="width: 112px;" + @click="handleReset(clearFilters)"> + {{ $t('label.reset') }} + </a-button> + </div> + </div> + </template> + + <template #customFilterIcon="{ filtered }"> + <search-outlined :style="{ color: filtered ? '#1890ff' : '', fontSize: '14px' }" /> + </template> + + <template #bodyCell="{ column, record }"> + <template v-if="column.key === 'permission'"> + <a-tag + class="permission-tag" + :style="{ + backgroundColor: record.permission === 'allow' ? '#d9f7be' : '#fff2f0', + color: record.permission === 'allow' ? '#135200' : '#cf1322' + }"> + <check-outlined v-if="record.permission === 'allow'" /> + <close-outlined v-else /> + {{ record.permission === 'allow' ? $t('label.allow') : $t('label.deny') }} + </a-tag> + </template> + + <template v-else-if="column.key === 'description' && record.description"> + {{ record.description }} + </template> + </template> + </a-table> + </div> +</template> + +<script> +import { getAPI } from '@/api' +import draggable from 'vuedraggable' +import PermissionEditable from './PermissionEditable' +import TooltipButton from '@/components/widgets/TooltipButton' +import { genericCompare } from '@/utils/sort' + +export default { + name: 'ApiKeyPairPermissionTable', + components: { + PermissionEditable, + draggable, + TooltipButton + }, + props: { + resource: { + type: Object, + required: true + } + }, + data () { + return { + loadingTable: true, + disabled: false, + rules: [], + newRule: '', + newRulePermission: 'allow', + newRuleDescription: '', + drag: false, + apis: [], + currRules: new Set(), + searchText: '', + searchedColumn: '', + columns: [ + { + title: this.$t('label.rule'), + dataIndex: 'rule', + key: 'rule', + ellipsis: true, + customFilterDropdown: true, + onFilter: (value, record) => { + return record.rule.toString().toLowerCase().includes(value.toLowerCase()) + }, + sorter: (a, b) => { return genericCompare(a.rule || '', b.rule || '') }, + width: 480 + }, + { + title: this.$t('label.permission'), + dataIndex: 'permission', + key: 'permission', + width: 160, + align: 'center', + sorter: (a, b) => { return genericCompare(a.permission || '', b.permission || '') } + }, + { + title: this.$t('label.description'), + dataIndex: 'description', + key: 'description' + } + ], + pagination: { + pageSize: 20, Review Comment: You could use `default.ui.page.size` as a default value ########## ui/src/views/iam/ApiKeyPairPermissionTable.vue: ########## @@ -0,0 +1,518 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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. + +<template> + <loading-outlined v-if="loadingTable" class="main-loading-spinner" /> + <div v-else> + <div v-if="!disabled" class="rules-list ant-list ant-list-bordered"> + <div class="rules-table-item ant-list-item"> + <div class="rules-table__col rules-table__col--grab" /> + <div class="rules-table__col rules-table__col--rule rules-table__col--new"> + <a-auto-complete + :key="autocompleteKey" + v-focus="true" + :filterOption="filterOption" + :options="apis" + v-model:value="newRule" + :placeholder="$t('label.rule')" /> + </div> + <div class="rules-table__col rules-table__col--permission"> + <permission-editable + :default-value="newRulePermission" + :value="newRulePermission" + @onChange="updateNewPermission()" /> + </div> + <div class="rules-table__col rules-table__col--description"> + <a-input v-model:value="newRuleDescription" :placeholder="$t('label.description')" /> + </div> + <div class="rules-table__col rules-table__col--actions"> + <tooltip-button + tooltipPlacement="bottom" + :tooltip="$t('label.save.new.rule')" + icon="plus-outlined" + type="primary" + @onClick="onRuleSave" /> + </div> + </div> + + <draggable + v-model="rules" + @change="updateRules" + handle=".drag-handle" + ghostClass="drag-ghost" + :component-data="{type: 'transition'}" + item-key="rule"> + <template #item="{element, index}"> + <div class="rules-table-item ant-list-item"> + <div class="rules-table__col rules-table__col--grab drag-handle"> + <drag-outlined /> + </div> + <div class="rules-table__col rules-table__col--rule"> + {{ element.rule }} + </div> + <div class="rules-table__col rules-table__col--permission"> + <permission-editable + :default-value="element.permission" + @onChange="onPermissionChange(element, $event, index)" /> + </div> + <div class="rules-table__col rules-table__col--description"> + <div v-if="element.description"> + {{ element.description }} + </div> + <div v-else class="no-description"> + {{ $t('message.no.description') }} + </div> + </div> + <div class="rules-table__col rules-table__col--actions"> + <tooltip-button + :tooltip="$t('label.delete.rule')" + tooltipPlacement="bottom" + type="primary" + :danger="true" + icon="delete-outlined" + :disabled="false" + @onClick="onRuleDelete(element.rule, index)" /> + </div> + </div> + </template> + </draggable> + </div> + + <div :style="{width: '100%', display: 'flex', marginTop: this.rules.length > 0 ? '12px' : '0'}" v-if="this.rules.length > 0 && !disabled"> + <a-button + style="width: 100%;" + danger + @click="deleteAllRules()"> + <template #icon><delete-outlined /></template> + {{ $t('label.delete.all.rules') }} + </a-button> + </div> + + <a-table + v-else-if="disabled" + :columns="columns" + :dataSource="rules" + rowKey="rule" + size="large" + :pagination="pagination" + @change="handlePaginationChange"> + <template #customFilterDropdown="{ setSelectedKeys, selectedKeys, confirm, clearFilters, column }"> + <div style="padding: 8px"> + <a-input + ref="searchInput" + :placeholder="$t('label.search')" + :value="selectedKeys[0]" + style="width: 100%; margin-bottom: 8px; display: block" + @change="e => setSelectedKeys(e.target.value ? [e.target.value] : [])" + @pressEnter="handleSearch(selectedKeys, confirm, column.dataIndex)" + /> + <div style="display: flex; gap: 8px"> + <a-button + type="primary" + size="small" + style="width: 112px;" + @click="handleSearch(selectedKeys, confirm, column.dataIndex)"> + <template #icon> + <search-outlined /> + </template> + {{ $t('label.search') }} + </a-button> + + <a-button + size="small" + style="width: 112px;" + @click="handleReset(clearFilters)"> + {{ $t('label.reset') }} + </a-button> + </div> + </div> + </template> + + <template #customFilterIcon="{ filtered }"> + <search-outlined :style="{ color: filtered ? '#1890ff' : '', fontSize: '14px' }" /> + </template> + + <template #bodyCell="{ column, record }"> + <template v-if="column.key === 'permission'"> + <a-tag + class="permission-tag" + :style="{ + backgroundColor: record.permission === 'allow' ? '#d9f7be' : '#fff2f0', + color: record.permission === 'allow' ? '#135200' : '#cf1322' + }"> + <check-outlined v-if="record.permission === 'allow'" /> + <close-outlined v-else /> + {{ record.permission === 'allow' ? $t('label.allow') : $t('label.deny') }} + </a-tag> + </template> + + <template v-else-if="column.key === 'description' && record.description"> + {{ record.description }} + </template> + </template> + </a-table> + </div> +</template> + +<script> +import { getAPI } from '@/api' +import draggable from 'vuedraggable' +import PermissionEditable from './PermissionEditable' +import TooltipButton from '@/components/widgets/TooltipButton' +import { genericCompare } from '@/utils/sort' + +export default { + name: 'ApiKeyPairPermissionTable', + components: { + PermissionEditable, + draggable, + TooltipButton + }, + props: { + resource: { + type: Object, + required: true + } + }, + data () { + return { + loadingTable: true, + disabled: false, + rules: [], + newRule: '', + newRulePermission: 'allow', + newRuleDescription: '', + drag: false, + apis: [], + currRules: new Set(), + searchText: '', + searchedColumn: '', + columns: [ + { + title: this.$t('label.rule'), + dataIndex: 'rule', + key: 'rule', + ellipsis: true, + customFilterDropdown: true, + onFilter: (value, record) => { + return record.rule.toString().toLowerCase().includes(value.toLowerCase()) + }, + sorter: (a, b) => { return genericCompare(a.rule || '', b.rule || '') }, + width: 480 + }, + { + title: this.$t('label.permission'), + dataIndex: 'permission', + key: 'permission', + width: 160, + align: 'center', + sorter: (a, b) => { return genericCompare(a.permission || '', b.permission || '') } + }, + { + title: this.$t('label.description'), + dataIndex: 'description', + key: 'description' + } + ], + pagination: { + pageSize: 20, + pageSizeOptions: ['10', '20', '40', '80', '100', '200'], + showSizeChanger: true + }, + autocompleteKey: 0 + } + }, + async created () { + if (this.$route.path.startsWith('/keypair')) { + await this.fetchKeyData() + this.disabled = true + } else { + this.getApis() + } + this.loadingTable = false + }, + methods: { + handleSearch (selectedKeys, confirm, dataIndex) { + confirm() + this.searchText = selectedKeys[0] + this.searchedColumn = dataIndex + }, + handleReset (clearFilters) { + clearFilters() + this.searchText = '' + }, + handlePaginationChange (pagination) { + this.pagination.pageSize = pagination.pageSize + this.pagination.current = pagination.current + }, + filterOption (input, option) { + return option.value.toUpperCase().indexOf(input.toUpperCase()) >= 0 + }, + async fetchKeyData () { + try { + const response = await getAPI('listUserKeyRules', { keypairid: this.resource.id }) + this.rules = response?.listuserkeyrulesresponse?.keypermission ?? [] + } catch (e) { + this.$notifyError(e) + } + }, + getApis () { + this.apis = Object.keys(this.$store.getters.apis).sort((a, b) => a.localeCompare(b)).map(value => { return { value: value } }) Review Comment: It would be nice to filter only the APIs which the account receiving the keypairs has access to here ########## ui/src/components/view/ApiKeyPairsTab.vue: ########## @@ -0,0 +1,451 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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. + +<template> + <div> + <a-spin :spinning="fetchLoading"> + <a-button + v-if="'registerUserKeys' in $store.getters.apis" + type="dashed" + style="width: 100%; margin-bottom: 15px" + @click="onShowAddKeyPair()"> + <template #icon><plus-outlined /></template> + {{ $t('label.register.api.key') }} + </a-button> + <a-button + v-if="this.selectedRowKeys.length > 0 && ('deleteUserKeys' in $store.getters.apis)" + type="primary" + danger + style="width: 100%; margin-bottom: 15px" + @click="bulkActionConfirmation()"> + <template #icon><delete-outlined /></template> + {{ $t('label.action.bulk.delete.api.keys') }} + </a-button> + <a-table + size="small" + style="overflow-y: auto" + :columns="columns" + :dataSource="keypairs" + :rowKey="item => item.id" + :rowSelection="rowSelection()" + :pagination="false" > + <template #name="{ record }"> + <div> + <router-link :to="{ path: '/keypair/' + record.id }" > + {{ record.name }} + </router-link> + </div> + </template> + <template #apikey="{ record }"> + <strong> + <tooltip-button + tooltipPlacement="right" + :tooltip="$t('label.copy')" + icon="CopyOutlined" + type="dashed" + size="small" + @onClick="$message.success($t('label.copied.clipboard'))" + :copyResource="record.apikey" /> + </strong> + <div> + {{ record.apikey.substring(0, 20) }}... + </div> + </template> + + <template #secretkey="{ record }"> + <strong> + <tooltip-button + tooltipPlacement="right" + :tooltip="$t('label.copy')" + icon="CopyOutlined" + type="dashed" + size="small" + @onClick="$message.success($t('label.copied.clipboard'))" + :copyResource="record.secretkey" /> + </strong> + <div> + {{ record.secretkey.substring(0, 20) }}... + </div> + </template> + + <template #startdate="{ record }"> + <div> {{ $toLocaleDate(record.startdate) }} </div> + </template> + + <template #enddate="{ record }"> + <div> {{ $toLocaleDate(record.enddate)}} </div> + </template> + + <template #created="{ record }"> + <div> {{ $toLocaleDate(record.created) }} </div> + </template> + + </a-table> + <a-divider/> + <a-pagination + class="row-element pagination" + size="small" + :current="page" + :pageSize="pageSize" + :total="totalKeypairs" + :showTotal="total => `${$t('label.total')} ${total} ${$t('label.items')}`" + :pageSizeOptions="['10', '20', '40', '80', '100']" + @change="changePage" + @showSizeChange="changePageSize" + showSizeChanger> + <template #buildOptionText="props"> + <span>{{ props.value }} / {{ $t('label.page') }}</span> + </template> + </a-pagination> + </a-spin> + <bulk-action-view + v-if="(showConfirmationAction || showGroupActionModal)" + :showConfirmationAction="showConfirmationAction" + :showGroupActionModal="showGroupActionModal" + :items="keypairs" + :selectedRowKeys="selectedRowKeys" + :selectedItems="selectedItems" + :columns="columns" + :selectedColumns="selectedColumns" + action="eraseKeypairs" + :loading="loading" + :message="bulkDeleteMessage" + @group-action="eraseKeypairs" + @handle-cancel="handleCancelBulk" + @close-modal="closeModalBulk" /> + <generate-api-key-pair + :showAddKeyPair="showAddKeyPair" + :resource="resource" + @fetch-data="fetchData" + @refresh-data="handleRefreshData" + @close-modal="closeModalAddKeyPair" /> + </div> +</template> +<script> +import { getAPI, postAPI } from '@/api' +import TooltipButton from '@/components/widgets/TooltipButton' +import BulkActionView from '@/components/view/BulkActionView.vue' +import eventBus from '@/config/eventBus' +import GenerateApiKeyPair from '@/views/iam/GenerateApiKeyPair.vue' + +export default { + name: 'ApiKeyPairsTab', + components: { + TooltipButton, + BulkActionView, + GenerateApiKeyPair + }, + props: { + resource: { + type: Object, + required: true + }, + loading: { + type: Boolean, + default: false + } + }, + data () { + return { + fetchLoading: false, + keypairs: [], + page: 1, + pageSize: 10, + totalKeypairs: 0, + selectedRowKeys: [], + selectedItems: [], + selectedColumns: [], + filterColumns: ['Action'], + showConfirmationAction: false, + showAddKeyPair: false, + showGroupActionModal: false, + bulkDeleteMessage: { + title: this.$t('label.action.bulk.delete.api.keys'), + confirmMessage: this.$t('label.confirm.delete.api.keys') + }, + columns: [ + { + title: this.$t('label.name'), + dataIndex: 'name', + slots: { customRender: 'name' } + }, + { + title: this.$t('label.apikey'), + dataIndex: 'apikey', + slots: { customRender: 'apikey' } + }, + { + title: this.$t('label.secretkey'), + dataIndex: 'secretkey', + slots: { customRender: 'secretkey' } + }, + { + title: this.$t('label.start.date'), + dataIndex: 'startdate', + slots: { customRender: 'startdate' } + }, + { + title: this.$t('label.end.date'), + dataIndex: 'enddate', + slots: { customRender: 'enddate' } + }, + { + title: this.$t('label.created'), + dataIndex: 'created', + slots: { customRender: 'created' } + } + ] + } + }, + created () { + this.fetchData() + }, + watch: { + resource: { + deep: true, + handler (newItem) { + if (!newItem || !newItem.id) { + return + } + this.fetchData() + } + } + }, + inject: ['parentFetchData'], + methods: { + fetchData () { + const params = { + listall: true, + page: this.page, + pagesize: this.pageSize, + userid: this.resource.id + } + this.fetchLoading = true + getAPI('listUserKeys', params).then(json => { + this.totalKeypairs = json.listuserkeysresponse.count || 0 + this.keypairs = json.listuserkeysresponse.userapikey || [] + }).finally(() => { + this.fetchLoading = false + }) + }, + setSelection (selection) { + this.selectedRowKeys = selection + this.$emit('selection-change', this.selectedRowKeys) + this.selectedItems = (this.keypairs.filter(function (item) { + return selection.indexOf(item.id) !== -1 + })) + }, + changePage (page, pageSize) { + this.page = page + this.pageSize = pageSize + this.fetchData() + }, + changePageSize (currentPage, pageSize) { + this.page = currentPage + this.pageSize = pageSize + this.fetchData() + }, + onShowAddKeyPair () { + this.showAddKeyPair = true + }, + eraseKeypairs () { + this.selectedColumns.splice(0, 0, { + dataIndex: 'status', + title: this.$t('label.operation.status'), + slots: { customRender: 'status' }, + filters: [ + { text: 'In Progress', value: 'InProgress' }, + { text: 'Success', value: 'success' }, + { text: 'Failed', value: 'failed' } Review Comment: Could you use text from the localization files here? <img width="1268" height="616" alt="Image" src="https://github.com/user-attachments/assets/0dd8f690-2a40-4845-9360-06e205ada6c9" /> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
