Skip to content

Commit

Permalink
Allow more generic searches of ACLs (#9566)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaanHoogland authored Sep 10, 2024
1 parent 501d8c1 commit b1f683d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ public Pair<List<? extends NetworkACLItem>, Integer> listNetworkACLItems(final L
final String trafficType = cmd.getTrafficType();
final String protocol = cmd.getProtocol();
final String action = cmd.getAction();
final String keyword = cmd.getKeyword();
final Map<String, String> tags = cmd.getTags();
final Account caller = CallContext.current().getCallingAccount();

Expand All @@ -708,6 +709,7 @@ public Pair<List<? extends NetworkACLItem>, Integer> listNetworkACLItems(final L
sb.and("trafficType", sb.entity().getTrafficType(), Op.EQ);
sb.and("protocol", sb.entity().getProtocol(), Op.EQ);
sb.and("action", sb.entity().getAction(), Op.EQ);
sb.and("reason", sb.entity().getReason(), Op.EQ);

if (tags != null && !tags.isEmpty()) {
final SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
Expand All @@ -730,6 +732,12 @@ public Pair<List<? extends NetworkACLItem>, Integer> listNetworkACLItems(final L

final SearchCriteria<NetworkACLItemVO> sc = sb.create();

if (StringUtils.isNotBlank(keyword)) {
final SearchCriteria<NetworkACLItemVO> ssc = _networkACLItemDao.createSearchCriteria();
ssc.addOr("protocol", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("reason", SearchCriteria.Op.LIKE, "%" + keyword + "%");
sc.addAnd("acl_id", SearchCriteria.Op.SC, ssc);
}
if (id != null) {
sc.setParameters("id", id);
}
Expand All @@ -747,7 +755,6 @@ public Pair<List<? extends NetworkACLItem>, Integer> listNetworkACLItems(final L
if (trafficType != null) {
sc.setParameters("trafficType", trafficType);
}

if (aclId != null) {
// Get VPC and check access
final NetworkACL acl = _networkACLDao.findById(aclId);
Expand All @@ -764,7 +771,7 @@ public Pair<List<? extends NetworkACLItem>, Integer> listNetworkACLItems(final L

// aclId is not specified
// List permitted VPCs and filter aclItems
final List<Long> permittedAccounts = new ArrayList<Long>();
final List<Long> permittedAccounts = new ArrayList<>();
Long domainId = cmd.getDomainId();
boolean isRecursive = cmd.isRecursive();
final String accountName = cmd.getAccountName();
Expand All @@ -780,7 +787,7 @@ public Pair<List<? extends NetworkACLItem>, Integer> listNetworkACLItems(final L
final SearchCriteria<VpcVO> scVpc = sbVpc.create();
_accountMgr.buildACLSearchCriteria(scVpc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
final List<VpcVO> vpcs = _vpcDao.search(scVpc, null);
final List<Long> vpcIds = new ArrayList<Long>();
final List<Long> vpcIds = new ArrayList<>();
for (final VpcVO vpc : vpcs) {
vpcIds.add(vpc.getId());
}
Expand Down
18 changes: 16 additions & 2 deletions ui/src/views/network/AclListRulesTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

<template>
<a-spin :spinning="fetchLoading">
<div style="width: 100%; display: flex">

<div style="width: 100%; display: flex">
<a-button
type="dashed"
style="width: 100%; margin-right: 10px"
Expand All @@ -31,6 +32,14 @@
<template #icon><download-outlined /></template>
{{ $t('label.acl.export') }}
</a-button>
<div class="search-bar">
<a-input-search
style="width: 25vw;float: right;margin-left: 10px; z-index: 8"
:placeholder="$t('label.search')"
v-model:value="searchQuery"
@search="fetchData"
/>
</div>
</div>

<div class="list">
Expand Down Expand Up @@ -324,6 +333,7 @@ export default {
},
data () {
return {
searchQuery: '', // Bind this to the search input
acls: [],
fetchLoading: false,
protocolNumbers: [],
Expand Down Expand Up @@ -433,7 +443,11 @@ export default {
},
fetchData () {
this.fetchLoading = true
api('listNetworkACLs', { aclid: this.resource.id }).then(json => {
const params = {
aclid: this.resource.id,
keyword: this.searchQuery
}
api('listNetworkACLs', params).then(json => {
this.acls = json.listnetworkaclsresponse.networkacl || []
if (this.acls.length > 0) {
this.acls.sort((a, b) => a.number - b.number)
Expand Down

0 comments on commit b1f683d

Please sign in to comment.