Fixed filtering for vNet prefixes, completed all filter methods for Arrays, fixed IPv6 address space crash, and removed all unnecessary console logs

This commit is contained in:
Matthew Garrett 2022-12-04 12:30:44 -08:00
Родитель 872ad72a93
Коммит a5eee9510d
8 изменённых файлов: 77 добавлений и 39 удалений

Просмотреть файл

@ -31,20 +31,7 @@ resources
| project name, id, resource_group = resourceGroup, subscription_id = subscriptionId, tenant_id = tenantId, prefixes = properties.addressSpace.addressPrefixes
"""
# VNET = """
# resources
# | where type =~ 'Microsoft.Network/virtualNetworks'
# | project name, id, resource_group = resourceGroup, subscription_id = subscriptionId, tenant_id = tenantId, prefixes = properties.addressSpace.addressPrefixes
# | join kind = leftouter(
# resources
# | where type =~ 'Microsoft.Network/virtualNetworks'
# | mv-expand subnet = todynamic(properties.subnets)
# | summarize subnets = make_list(subnet.properties.addressPrefix) by id
# ) on id
# | project-away id1
# | project name, id, prefixes, subnets, resource_group, subscription_id, tenant_id
# """
# This version gets both IPv4 and IPv6 vNET/Subnet address spaces
# VNET = """
# resources
# | where type =~ 'Microsoft.Network/virtualNetworks'
@ -54,25 +41,31 @@ resources
# resources
# | where type =~ 'Microsoft.Network/virtualNetworks'
# | mv-expand subnet = todynamic(properties.subnets)
# | extend subnet_details = pack("name", subnet.name, "prefix", tostring(subnet.properties.addressPrefix), "used", coalesce(array_length(subnet.properties.ipConfigurations), 0) + 5)
# | extend nameMap = dynamic({{'AzureFirewallSubnet': 'AFW', 'GatewaySubnet': 'VGW', 'AzureBastionSubnet': 'BAS'}})
# | extend nameResult = nameMap[tostring(subnet.name)]
# | extend appGwConfig = subnet.properties.applicationGatewayIPConfigurations
# | extend appGwResult = iff(isnotnull(appGwConfig), "AGW", appGwConfig)
# | extend subnetType = coalesce(nameResult, appGwResult)
# | extend subnet_details = pack("name", subnet.name, "prefix", tostring(subnet.properties.addressPrefix), "used", coalesce(array_length(subnet.properties.ipConfigurations), 0) + 5, "type", todynamic(subnetType))
# | summarize subnet_bag = make_bag(subnet_details) by tostring(subnet.id), id
# ) on id
# | join kind = leftouter(
# resources
# | where type =~ 'Microsoft.Network/virtualNetworks'
# | mv-expand peering = properties.virtualNetworkPeerings
# | mv-expand peering = todynamic(properties.virtualNetworkPeerings)
# | extend peering_details = pack("name", peering.name, "remote_network", peering.properties.remoteVirtualNetwork.id, "state", peering.properties.peeringState)
# | summarize peering_bag = make_bag(peering_details) by tostring(peering.id), id
# ) on id
# | summarize subnets = make_list(subnet_bag), peerings = make_list(peering_bag) by id, name, tostring(prefixes), resource_group, subscription_id, tenant_id, resv
# | project name, id, todynamic(prefixes), subnets, peerings, resource_group, subscription_id, tenant_id, todynamic(resv)
# | summarize subnets = make_list(subnet_bag) by id, tostring(peering_bag), name, tostring(prefixes), resource_group, subscription_id, tenant_id, resv
# | summarize peerings = make_list(todynamic(peering_bag)) by id, name, tostring(subnets), tostring(prefixes), resource_group, subscription_id, tenant_id, resv
# | project name, id, todynamic(prefixes), todynamic(subnets), peerings, resource_group, subscription_id, tenant_id, todynamic(resv)
# """
VNET = """
resources
| where type =~ 'Microsoft.Network/virtualNetworks'
| where subscriptionId !in~ {}
| project name, id, resource_group = resourceGroup, subscription_id = subscriptionId, tenant_id = tenantId, prefixes = properties.addressSpace.addressPrefixes, resv = tostring(coalesce(tags['X-IPAM-RES-ID'], tags['ipam-res-id']))
| project name, id, resource_group = resourceGroup, subscription_id = subscriptionId, tenant_id = tenantId, prefixes = array_slice(properties.addressSpace.addressPrefixes, 0, 0), resv = tostring(coalesce(tags['X-IPAM-RES-ID'], tags['ipam-res-id']))
| join kind = leftouter(
resources
| where type =~ 'Microsoft.Network/virtualNetworks'
@ -82,7 +75,9 @@ resources
| extend appGwConfig = subnet.properties.applicationGatewayIPConfigurations
| extend appGwResult = iff(isnotnull(appGwConfig), "AGW", appGwConfig)
| extend subnetType = coalesce(nameResult, appGwResult)
| extend subnet_details = pack("name", subnet.name, "prefix", tostring(subnet.properties.addressPrefix), "used", coalesce(array_length(subnet.properties.ipConfigurations), 0) + 5, "type", todynamic(subnetType))
| extend subnetPrefix = todynamic(subnet.properties.addressPrefix)
| extend subnetPrefixes = todynamic(subnet.properties.addressPrefixes)
| extend subnet_details = pack("name", subnet.name, "prefix", tostring(iff(isnotnull(subnetPrefixes), subnetPrefixes[0], subnetPrefix)), "used", coalesce(array_length(subnet.properties.ipConfigurations), 0) + 5, "type", todynamic(subnetType))
| summarize subnet_bag = make_bag(subnet_details) by tostring(subnet.id), id
) on id
| join kind = leftouter(
@ -97,13 +92,19 @@ resources
| project name, id, todynamic(prefixes), todynamic(subnets), peerings, resource_group, subscription_id, tenant_id, todynamic(resv)
"""
# This version gets both the IPv4 and IPv6 Subnet address space
# SUBNET = """
# resources
# | where type =~ 'Microsoft.Network/virtualNetworks'
# | where subscriptionId !in~ {}
# | mv-expand subnet = todynamic(properties.subnets)
# | extend subnet_size = array_length(subnet.properties.ipConfigurations)
# | project name = subnet.name, id = subnet.id, prefix = subnet.properties.addressPrefix, resource_group = resourceGroup, subscription_id = subscriptionId, tenant_id = tenantId,vnet_name = name, vnet_id = id, used = (iif(isnull(subnet_size), 0, subnet_size) + 5), appgw_config = subnet.properties.applicationGatewayIPConfigurations
# | extend nameMap = dynamic({{'AzureFirewallSubnet': 'AFW', 'GatewaySubnet': 'VGW', 'AzureBastionSubnet': 'BAS'}})
# | extend nameResult = nameMap[tostring(subnet.name)]
# | extend appGwConfig = subnet.properties.applicationGatewayIPConfigurations
# | extend appGwResult = iff(isnotnull(appGwConfig), "AGW", appGwConfig)
# | extend subnetType = coalesce(nameResult, appGwResult)
# | project name = subnet.name, id = subnet.id, prefix = subnet.properties.addressPrefix, resource_group = resourceGroup, subscription_id = subscriptionId, tenant_id = tenantId,vnet_name = name, vnet_id = id, used = (iif(isnull(subnet_size), 0, subnet_size) + 5), type = todynamic(subnetType)
# """
SUBNET = """
@ -117,7 +118,9 @@ resources
| extend appGwConfig = subnet.properties.applicationGatewayIPConfigurations
| extend appGwResult = iff(isnotnull(appGwConfig), "AGW", appGwConfig)
| extend subnetType = coalesce(nameResult, appGwResult)
| project name = subnet.name, id = subnet.id, prefix = subnet.properties.addressPrefix, resource_group = resourceGroup, subscription_id = subscriptionId, tenant_id = tenantId,vnet_name = name, vnet_id = id, used = (iif(isnull(subnet_size), 0, subnet_size) + 5), type = todynamic(subnetType)
| extend subnetPrefix = todynamic(subnet.properties.addressPrefix)
| extend subnetPrefixes = todynamic(subnet.properties.addressPrefixes)
| project name = subnet.name, id = subnet.id, prefix = tostring(iff(isnotnull(subnetPrefixes), subnetPrefixes[0], subnetPrefix)), resource_group = resourceGroup, subscription_id = subscriptionId, tenant_id = tenantId,vnet_name = name, vnet_id = id, used = (iif(isnull(subnet_size), 0, subnet_size) + 5), type = todynamic(subnetType)
"""
PRIVATE_ENDPOINT = """

Просмотреть файл

@ -25,6 +25,39 @@ import Shrug from "../../img/pam/Shrug";
import { TableContext } from "./TableContext";
import ItemDetails from "./Utils/Details";
const filterTypes = Object.assign({}, ReactDataGrid.defaultProps.filterTypes, {
array: {
name: 'array',
emptyValue: null,
operators: [
{
name: 'contains',
fn: ({ value, filterValue, data }) => {
return filterValue !== (null || '') ? value.join(",").includes(filterValue) : true;
}
},
{
name: 'notContains',
fn: ({ value, filterValue, data }) => {
return filterValue !== (null || '') ? !value.join(",").includes(filterValue) : true;
}
},
{
name: 'eq',
fn: ({ value, filterValue, data }) => {
return filterValue !== (null || '') ? value.includes(filterValue) : true;
}
},
{
name: 'neq',
fn: ({ value, filterValue, data }) => {
return filterValue !== (null || '') ? !value.includes(filterValue) : true;
}
}
]
}
});
const openStyle = {
right: 0,
transition: "all 0.5s ease-in-out",
@ -117,7 +150,7 @@ export default function DiscoverTable(props) {
},[location, filterSettings]);
React.useEffect(() => {
stateData && setGridData(filter(stateData, filterData));
stateData && setGridData(filter(stateData, filterData, filterTypes));
},[stateData, filterData]);
React.useEffect(() => {
@ -178,6 +211,7 @@ export default function DiscoverTable(props) {
enableColumnAutosize={false}
showColumnMenuGroupOptions={false}
enableColumnFilterContextMenu={true}
filterTypes={filterTypes}
columns={columnData}
loading={loading}
dataSource={gridData || []}
@ -191,3 +225,5 @@ export default function DiscoverTable(props) {
</TableContext.Provider>
);
}
// data.map((item) => Object.entries(item).reduce((obj, [k, v]) => { Array.isArray(v) ? obj[k] = v.join(", ") : obj[k] = v; return obj; }, {}));

Просмотреть файл

@ -568,11 +568,6 @@ const Visualize = () => {
function setDataFocus(target) {
if(eChartsRef && !isEmpty(options.series)) {
console.log("SET DATA FOCUS");
console.log(options);
console.log("TARGET");
console.log(target);
let newOptions = cloneDeep(options);
newOptions.title.show = target ? false : true;
@ -580,11 +575,7 @@ const Visualize = () => {
eChartsRef.getEchartsInstance().setOption(newOptions);
console.log("NEW OPTIONS");
console.log(newOptions);
if(!target) {
console.log("CLEARING LEGEND SELECT");
eChartsRef.getEchartsInstance().dispatchAction({
type: 'legendAllSelect'
});
@ -593,7 +584,6 @@ const Visualize = () => {
type: 'legendInverseSelect'
});
} else {
console.log("SELECTING LEGEND TARGET");
eChartsRef.getEchartsInstance().dispatchAction({
type: 'legendSelect',
name: target

Просмотреть файл

@ -71,7 +71,7 @@ export default function EditVnets(props) {
React.useEffect(() => {
if(space && block) {
!refreshingState && setSelectionModel(block['vnets'].map(vnet => vnet.id));
!refreshingState && setSelectionModel(block['vnets'].reduce((obj, vnet) => (obj[vnet.id] = vnet, obj) ,{}));
}
}, [space, block, refreshingState]);
@ -232,7 +232,7 @@ export default function EditVnets(props) {
enableColumnAutosize={false}
showColumnMenuGroupOptions={false}
columns={columns}
loading={refreshing}
loading={refreshing || refreshingState}
dataSource={vNets}
selected={selectionModel}
onSelectionChange={({selected}) => setSelectionModel(selected)}

Просмотреть файл

@ -79,7 +79,6 @@ export default function ConfigureIPAM() {
const dispatch = useDispatch();
const refresh = React.useCallback(() => {
console.log("REFRESH SPACES");
const request = {
scopes: apiRequest.scopes,
account: accounts[0],

Просмотреть файл

@ -296,6 +296,16 @@ export default function NavDrawer() {
return titleCase;
}
function GetInstanceType(target) {
var instanceType = typeof target;
if(instanceType === 'object') {
instanceType = Array.isArray(target) ? 'array': 'object';
}
return instanceType;
}
function objToFilter(data, header, path, exclusions) {
const searchObj = data.reduce((prev, curr) => {
@ -310,6 +320,7 @@ export default function NavDrawer() {
searchKey: key,
noun: keyNoun,
comparator: Array.isArray(value) ? 'contains' : 'like',
type: GetInstanceType(value),
values: []
};
}
@ -339,7 +350,7 @@ export default function NavDrawer() {
filter: {
name: props.searchKey,
operator: 'contains',
type: 'string',
type: props.type,
value: value
}
};

Просмотреть файл

@ -60,7 +60,6 @@ function Refresh() {
(async() => {
try {
console.log("REFRESH ME...");
const response = await instance.acquireTokenSilent(request)
dispatch(getMeAsync(response.accessToken))
} catch (e) {

Просмотреть файл

@ -120,7 +120,7 @@ export const vnets = {
{ name: 'parentBlock', operator: 'contains', type: 'string', value: '' },
{ name: 'size', operator: 'gte', type: 'number', value: 0 },
{ name: 'used', operator: 'gte', type: 'number', value: 0 },
{ name: 'prefixes', operator: 'contains', type: 'string', value: '' }
{ name: 'prefixes', operator: 'contains', type: 'array', value: '' }
],
detailsMap: {
showProgress: true,