Skip to content

Commit fb9e9ca

Browse files
authored
Bump API for silo IP pools list endpoint and implement endpoints (#1904)
bump API for silo IP pools list endpoint and implement endpoints
1 parent 9ae2949 commit fb9e9ca

File tree

8 files changed

+182
-38
lines changed

8 files changed

+182
-38
lines changed

OMICRON_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
19059b1bedc8bbc7a9d293486842a9a4fd264ea3
1+
e8b6dd1dc4e7abb39276ad347bdf1ac08171862d

libs/api-mocks/ip-pool.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright Oxide Computer Company
77
*/
88

9-
import { type IpPool, type IpPoolSilo } from '@oxide/api'
9+
import { type IpPool, type IpPoolSiloLink } from '@oxide/api'
1010

1111
import type { Json } from './json-type'
1212
import { defaultSilo } from './silo'
@@ -29,7 +29,7 @@ const ipPool2: Json<IpPool> = {
2929

3030
export const ipPools: Json<IpPool>[] = [ipPool1, ipPool2]
3131

32-
export const ipPoolSilos: Json<IpPoolSilo>[] = [
32+
export const ipPoolSilos: Json<IpPoolSiloLink>[] = [
3333
{
3434
ip_pool_id: ipPool1.id,
3535
silo_id: defaultSilo.id,

libs/api-mocks/msw/db.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,10 @@ export const lookup = {
141141
return pool
142142
},
143143
// unusual one because it's a sibling relationship. we look up both the pool and the silo first
144-
ipPoolSilo({ pool: poolId, silo: siloId }: PP.IpPool & PP.Silo): Json<Api.IpPoolSilo> {
144+
ipPoolSiloLink({
145+
pool: poolId,
146+
silo: siloId,
147+
}: PP.IpPool & PP.Silo): Json<Api.IpPoolSiloLink> {
145148
const pool = lookup.ipPool({ pool: poolId })
146149
const silo = lookup.silo({ silo: siloId })
147150

@@ -152,6 +155,26 @@ export const lookup = {
152155

153156
return ipPoolSilo
154157
},
158+
// unusual because it returns a list, but we need it for multiple endpoints
159+
siloIpPools(path: PP.Silo): Json<Api.SiloIpPool>[] {
160+
const silo = lookup.silo(path)
161+
162+
// effectively join db.ipPools and db.ipPoolSilos on ip_pool_id
163+
return db.ipPoolSilos
164+
.filter((link) => link.silo_id === silo.id)
165+
.map((link) => {
166+
const pool = db.ipPools.find((pool) => pool.id === link.ip_pool_id)
167+
168+
// this should never happen
169+
if (!pool) {
170+
const linkStr = JSON.stringify(link)
171+
const message = `Found IP pool-silo link without corresponding pool: ${linkStr}`
172+
throw json({ message }, { status: 500 })
173+
}
174+
175+
return { ...pool, is_default: link.is_default }
176+
})
177+
},
155178
samlIdp({
156179
provider: id,
157180
...siloSelector

libs/api-mocks/msw/handlers.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,25 @@ export const handlers = makeHandlers({
543543
return json(instance, { status: 202 })
544544
},
545545
ipPoolList: ({ query }) => paginated(query, db.ipPools),
546+
siloIpPoolList({ path, query }) {
547+
const pools = lookup.siloIpPools(path)
548+
return paginated(query, pools)
549+
},
550+
projectIpPoolList({ query }) {
551+
const pools = lookup.siloIpPools({ silo: defaultSilo.id })
552+
return paginated(query, pools)
553+
},
554+
projectIpPoolView({ path }) {
555+
// this will 404 if it doesn't exist at all...
556+
const pool = lookup.ipPool(path)
557+
// but we also want to 404 if it exists but isn't in the silo
558+
const link = db.ipPoolSilos.find(
559+
(link) => link.ip_pool_id === pool.id && link.silo_id === defaultSilo.id
560+
)
561+
if (!link) throw notFoundErr()
562+
563+
return { ...pool, is_default: link.is_default }
564+
},
546565
ipPoolView: ({ path }) => lookup.ipPool(path),
547566
ipPoolSiloList({ path /*query*/ }) {
548567
// TODO: paginated wants an id field, but this is a join table, so it has a
@@ -585,7 +604,7 @@ export const handlers = makeHandlers({
585604
return 204
586605
},
587606
ipPoolSiloUpdate: ({ path, body }) => {
588-
const ipPoolSilo = lookup.ipPoolSilo(path)
607+
const ipPoolSilo = lookup.ipPoolSiloLink(path)
589608

590609
// if we're setting default, we need to set is_default false on the existing default
591610
if (body.is_default) {
@@ -1062,8 +1081,6 @@ export const handlers = makeHandlers({
10621081
networkingSwitchPortSettingsDelete: NotImplemented,
10631082
networkingSwitchPortSettingsView: NotImplemented,
10641083
networkingSwitchPortSettingsList: NotImplemented,
1065-
projectIpPoolList: NotImplemented,
1066-
projectIpPoolView: NotImplemented,
10671084
rackView: NotImplemented,
10681085
roleList: NotImplemented,
10691086
roleView: NotImplemented,

libs/api/__generated__/Api.ts

Lines changed: 71 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/api/__generated__/OMICRON_VERSION

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/api/__generated__/msw-handlers.ts

Lines changed: 18 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)