Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tech-story: [M3-9098] - Add MSW crud support for firewalls and some IP functionality for Linode Interfaces project #11586

Merged
merged 13 commits into from
Feb 4, 2025
4 changes: 2 additions & 2 deletions packages/api-v4/src/firewalls/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ export interface FirewallDevicePayload {
}

export interface DefaultFirewallIDs {
interface_public: number;
interface_vpc: number;
public_interface: number;
vpc_interface: number;
Comment on lines +94 to +95
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updating this - it'd been a typo in the spec, see [M3-9210] for details

linode: number;
nodebalancer: number;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tech Stories
---

Add MSW crud operations for firewalls and get operations for IP addresses ([#11586](https://github.com/linode/manager/pull/11586))
12 changes: 12 additions & 0 deletions packages/manager/src/factories/firewalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
FirewallDeviceEntityType,
FirewallRuleType,
FirewallRules,
FirewallSettings,
FirewallTemplate,
FirewallTemplateRules,
} from '@linode/api-v4/lib/firewalls/types';
Expand Down Expand Up @@ -76,3 +77,14 @@ export const firewallTemplateFactory = Factory.Sync.makeFactory<FirewallTemplate
slug: 'akamai-non-prod',
}
);

export const firewallSettingsFactory = Factory.Sync.makeFactory<FirewallSettings>(
{
default_firewall_ids: {
linode: 1,
nodebalancer: 1,
public_interface: 1,
vpc_interface: 1,
},
}
);
15 changes: 11 additions & 4 deletions packages/manager/src/mocks/indexedDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,14 @@ export const mswDB = {
const deleteEntity = (state: MockState | undefined) => {
if (state && state[entity]) {
const index = state[entity].findIndex((item) => {
if (!hasId(item)) {
// Some items may be stored as [number, Entity]
const isItemTuple = Array.isArray(item) && item.length >= 2;

if (!hasId(item) || (isItemTuple && !hasId(item[1]))) {
return false;
}

return item.id === id;
return isItemTuple ? item[1].id === id : item.id === id;
});
if (index !== -1) {
state[entity].splice(index, 1);
Expand Down Expand Up @@ -327,10 +330,14 @@ export const mswDB = {

const findEntity = (state: MockState | undefined) => {
return state?.[entity]?.find((item) => {
if (!hasId(item)) {
// Some items may be stored as [number, Entity]
const isItemTuple = Array.isArray(item) && item.length >= 2;

if (!hasId(item) || (isItemTuple && !hasId(item[1]))) {
return false;
}
return item.id === id;

return isItemTuple ? item[1].id === id : item.id === id;
});
};

Expand Down
1 change: 1 addition & 0 deletions packages/manager/src/mocks/mockState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const emptyStore: MockState = {
domainRecords: [],
domains: [],
eventQueue: [],
firewallDevices: [],
firewalls: [],
linodeConfigs: [],
linodes: [],
Expand Down
2 changes: 2 additions & 0 deletions packages/manager/src/mocks/presets/baseline/crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
import { linodeCrudPreset } from 'src/mocks/presets/crud/linodes';

import { domainCrudPreset } from '../crud/domains';
import { firewallCrudPreset } from '../crud/firewalls';
import { placementGroupsCrudPreset } from '../crud/placementGroups';
import { quotasCrudPreset } from '../crud/quotas';
import { supportTicketCrudPreset } from '../crud/supportTickets';
Expand All @@ -21,6 +22,7 @@ export const baselineCrudPreset: MockPresetBaseline = {
...supportTicketCrudPreset.handlers,
...volumeCrudPreset.handlers,
...domainCrudPreset.handlers,
...firewallCrudPreset.handlers,

// Events.
getEvents,
Expand Down
26 changes: 26 additions & 0 deletions packages/manager/src/mocks/presets/crud/firewalls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {
createFirewall,
createFirewallDevice,
deleteFirewall,
deleteFirewallDevice,
getFirewalls,
updateFirewall,
updateFirewallRules,
} from 'src/mocks/presets/crud/handlers/firewalls';

import type { MockPresetCrud } from 'src/mocks/types';

export const firewallCrudPreset: MockPresetCrud = {
group: { id: 'Firewalls' },
handlers: [
createFirewall,
createFirewallDevice,
deleteFirewall,
deleteFirewallDevice,
getFirewalls,
updateFirewall,
updateFirewallRules,
],
id: 'firewalls:crud',
label: 'Firewall CRUD',
};
Loading