Skip to content

Commit a8a9d49

Browse files
committed
msw endpoint for get rules
1 parent 62e6e65 commit a8a9d49

File tree

4 files changed

+91
-4
lines changed

4 files changed

+91
-4
lines changed

app/pages/project/networking/VpcPage/modals/firewall-rules.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const CommonForm = ({ id, error }: FormProps) => (
3333
<SideModal.Section>
3434
<div className="space-y-0.5">
3535
<FieldTitle htmlFor="priority">Priority</FieldTitle>
36-
<TextFieldHint id="priority-hint">Must be 0&ndash;35535</TextFieldHint>
36+
<TextFieldHint id="priority-hint">Must be 0&ndash;65535</TextFieldHint>
3737
<NumberTextField
3838
id="priority"
3939
name="priority"
@@ -297,7 +297,7 @@ export function CreateFirewallRuleModal({
297297
priority: Yup.number()
298298
.integer()
299299
.min(0)
300-
.max(35535)
300+
.max(65535)
301301
.required('Required'),
302302
})}
303303
validateOnBlur

libs/api-mocks/msw/db.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ const initDb = {
131131
disks: [mock.disk],
132132
vpcs: [mock.vpc],
133133
vpcSubnets: [mock.vpcSubnet],
134+
vpcFirewallRules: [...mock.defaultFirewallRules],
134135
}
135136

136137
const clone = (o: unknown) => JSON.parse(JSON.stringify(o))

libs/api-mocks/msw/handlers.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,4 +311,15 @@ export const handlers = [
311311
return res(ctx.status(204))
312312
}
313313
),
314+
315+
rest.get<never, VpcParams, Json<Api.VpcFirewallRuleResultsPage> | GetErr>(
316+
'/api/organizations/:orgName/projects/:projectName/vpcs/:vpcName/firewall/rules',
317+
(req, res, ctx) => {
318+
const vpc = lookupVpc(req, res, ctx)
319+
if (vpc.err) return vpc.err
320+
// TODO: uncomment once omicron PR lands
321+
const items = db.vpcFirewallRules //.filter((r) => r.vpc_id === vpc.ok.id)
322+
return res(json({ items }))
323+
}
324+
),
314325
]

libs/api-mocks/vpc.ts

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@ import type { Json } from './json-type'
22
import { project } from './project'
33
import type {
44
Vpc,
5+
VpcFirewallRule,
56
VpcResultsPage,
67
VpcSubnet,
78
VpcSubnetResultsPage,
89
} from '@oxide/api'
910

11+
const time_created = new Date(2021, 0, 1).toISOString()
12+
const time_modified = new Date(2021, 0, 2).toISOString()
13+
1014
export const vpc: Json<Vpc> = {
1115
id: 'vpc-id',
1216
name: 'mock-vpc',
1317
description: 'a fake vpc',
1418
dns_name: 'mock-vpc',
15-
time_created: new Date(2021, 0, 1).toISOString(),
16-
time_modified: new Date(2021, 0, 2).toISOString(),
1719
project_id: project.id,
1820
system_router_id: 'router-id', // ???
21+
time_created,
22+
time_modified,
1923
}
2024

2125
export const vpcs: Json<VpcResultsPage> = { items: [vpc] }
@@ -43,3 +47,74 @@ export const vpcSubnet2: Json<VpcSubnet> = {
4347
export const vpcSubnets: Json<VpcSubnetResultsPage> = {
4448
items: [vpcSubnet],
4549
}
50+
51+
// TODO: uncomment vpc_ids once omicron PR lands
52+
export const defaultFirewallRules: Json<VpcFirewallRule>[] = [
53+
{
54+
id: 'firewall-rule-id-1',
55+
name: 'allow-internal-inbound',
56+
status: 'enabled',
57+
direction: 'inbound',
58+
targets: [{ type: 'vpc', value: 'default' }],
59+
action: 'allow',
60+
description:
61+
'allow inbound traffic to all instances within the VPC if originated within the VPC',
62+
filters: {
63+
hosts: [{ type: 'vpc', value: 'default' }],
64+
},
65+
priority: 65534,
66+
time_created,
67+
time_modified,
68+
// vpc_id: vpc.id,
69+
},
70+
{
71+
id: 'firewall-rule-id-2',
72+
name: 'allow-ssh',
73+
status: 'enabled',
74+
direction: 'inbound',
75+
targets: [{ type: 'vpc', value: 'default' }],
76+
description: 'allow inbound TCP connections on port 22 from anywhere',
77+
filters: {
78+
ports: ['22'],
79+
protocols: ['TCP'],
80+
},
81+
action: 'allow',
82+
priority: 65534,
83+
time_created,
84+
time_modified,
85+
// vpc_id: vpc.id,
86+
},
87+
{
88+
id: 'firewall-rule-id-3',
89+
name: 'allow-icmp',
90+
status: 'enabled',
91+
direction: 'inbound',
92+
targets: [{ type: 'vpc', value: 'default' }],
93+
description: 'allow inbound ICMP traffic from anywhere',
94+
filters: {
95+
protocols: ['ICMP'],
96+
},
97+
action: 'allow',
98+
priority: 65534,
99+
time_created,
100+
time_modified,
101+
// vpc_id: vpc.id,
102+
},
103+
{
104+
id: 'firewall-rule-id-4',
105+
name: 'allow-rdp',
106+
status: 'enabled',
107+
direction: 'inbound',
108+
targets: [{ type: 'vpc', value: 'default' }],
109+
description: 'allow inbound TCP connections on port 3389 from anywhere',
110+
filters: {
111+
ports: ['3389'],
112+
protocols: ['TCP'],
113+
},
114+
action: 'allow',
115+
priority: 65534,
116+
time_created,
117+
time_modified,
118+
// vpc_id: vpc.id,
119+
},
120+
]

0 commit comments

Comments
 (0)