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

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
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,
},
}
);
25 changes: 17 additions & 8 deletions packages/manager/src/mocks/indexedDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,15 @@ export const mswDB = {
const deleteEntity = (state: MockState | undefined) => {
if (state && state[entity]) {
const index = state[entity].findIndex((item) => {
if (!hasId(item)) {
return false;
}
// Some items may be stored as [number, Entity]
const isItemTuple = Array.isArray(item) && item.length >= 2;

return item.id === id;
const itemTupleToFind =
isItemTuple && hasId(item[1]) && item[1].id === id;

const itemToFind = hasId(item) && item.id === id;

return itemTupleToFind || itemToFind;
});
if (index !== -1) {
state[entity].splice(index, 1);
Expand Down Expand Up @@ -327,10 +331,15 @@ export const mswDB = {

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

const itemTupleToFind =
isItemTuple && hasId(item[1]) && item[1].id === id;

const itemToFind = hasId(item) && item.id === id;

return itemTupleToFind || itemToFind;
});
};

Expand Down
2 changes: 2 additions & 0 deletions packages/manager/src/mocks/mockState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export const emptyStore: MockState = {
domainRecords: [],
domains: [],
eventQueue: [],
firewallDevices: [],
firewalls: [],
ipAddresses: [],
linodeConfigs: [],
linodes: [],
notificationQueue: [],
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
32 changes: 32 additions & 0 deletions packages/manager/src/mocks/presets/crud/firewalls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {
createFirewall,
createFirewallDevice,
deleteFirewall,
deleteFirewallDevice,
getFirewallSettings,
getFirewallTemplates,
getFirewalls,
updateFirewall,
updateFirewallRules,
updateFirewallSettings,
} 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,
getFirewallSettings,
getFirewallTemplates,
updateFirewall,
updateFirewallRules,
updateFirewallSettings,
],
id: 'firewalls:crud',
label: 'Firewall CRUD',
};
Loading