Skip to content

Commit e7b243b

Browse files
authored
Don't pass project on floating IP attach from instance networking (#2203)
don't pass project on floating IP attach
1 parent 43f325d commit e7b243b

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

app/pages/project/floating-ips/AttachFloatingIpModal.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,10 @@ function FloatingIpLabel({ fip }: { fip: FloatingIp }) {
3636
export const AttachFloatingIpModal = ({
3737
floatingIps,
3838
instance,
39-
project,
4039
onDismiss,
4140
}: {
4241
floatingIps: Array<FloatingIp>
4342
instance: Instance
44-
project: string
4543
onDismiss: () => void
4644
}) => {
4745
const queryClient = useApiQueryClient()
@@ -88,8 +86,7 @@ export const AttachFloatingIpModal = ({
8886
disabled={!floatingIp}
8987
onAction={() =>
9088
floatingIpAttach.mutate({
91-
path: { floatingIp },
92-
query: { project },
89+
path: { floatingIp }, // note that this is an ID!
9390
body: { kind: 'instance', parent: instance.id },
9491
})
9592
}

app/pages/project/instances/instance/tabs/NetworkingTab.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@ export function NetworkingTab() {
335335
floatingIps={availableIps}
336336
instance={instance}
337337
onDismiss={() => setAttachModalOpen(false)}
338-
project={project}
339338
/>
340339
)}
341340
</TableControls>

mock-api/msw/db.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import * as mock from '@oxide/api-mocks'
1414

1515
import { json } from '~/api/__generated__/msw-handlers'
1616
import { pick } from '~/util/object'
17+
import { commaSeries } from '~/util/str'
1718

1819
import type { Json } from '../json-type'
1920
import { internalError } from './util'
@@ -25,6 +26,11 @@ export const notFoundErr = (msg?: string) => {
2526
return json({ error_code: 'ObjectNotFound', message } as const, { status: 404 })
2627
}
2728

29+
export const badSelectorErr = (resource: string, parents: string[]) => {
30+
const message = `when ${resource} is specified by ID, ${commaSeries(parents, 'and')} should not be specified`
31+
return json({ error_code: 'InvalidRequest', message }, { status: 400 })
32+
}
33+
2834
export const lookupById = <T extends { id: string }>(table: T[], id: string) => {
2935
const item = table.find((i) => i.id === id)
3036
if (!item) throw notFoundErr
@@ -85,7 +91,10 @@ export const lookup = {
8591
floatingIp({ floatingIp: id, ...projectSelector }: PP.FloatingIp): Json<Api.FloatingIp> {
8692
if (!id) throw notFoundErr
8793

88-
if (isUuid(id)) return lookupById(db.floatingIps, id)
94+
if (isUuid(id)) {
95+
if (projectSelector.project) throw badSelectorErr('floating IP', ['project'])
96+
return lookupById(db.floatingIps, id)
97+
}
8998

9099
const project = lookup.project(projectSelector)
91100
const floatingIp = db.floatingIps.find(

0 commit comments

Comments
 (0)