Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion OMICRON_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19059b1bedc8bbc7a9d293486842a9a4fd264ea3
e8b6dd1dc4e7abb39276ad347bdf1ac08171862d
4 changes: 2 additions & 2 deletions libs/api-mocks/ip-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Copyright Oxide Computer Company
*/

import { type IpPool, type IpPoolSilo } from '@oxide/api'
import { type IpPool, type IpPoolSiloLink } from '@oxide/api'

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

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

export const ipPoolSilos: Json<IpPoolSilo>[] = [
export const ipPoolSilos: Json<IpPoolSiloLink>[] = [
{
ip_pool_id: ipPool1.id,
silo_id: defaultSilo.id,
Expand Down
25 changes: 24 additions & 1 deletion libs/api-mocks/msw/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ export const lookup = {
return pool
},
// unusual one because it's a sibling relationship. we look up both the pool and the silo first
ipPoolSilo({ pool: poolId, silo: siloId }: PP.IpPool & PP.Silo): Json<Api.IpPoolSilo> {
ipPoolSiloLink({
pool: poolId,
silo: siloId,
}: PP.IpPool & PP.Silo): Json<Api.IpPoolSiloLink> {
const pool = lookup.ipPool({ pool: poolId })
const silo = lookup.silo({ silo: siloId })

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

return ipPoolSilo
},
// unusual because it returns a list, but we need it for multiple endpoints
siloIpPools(path: PP.Silo): Json<Api.SiloIpPool>[] {
const silo = lookup.silo(path)

// effectively join db.ipPools and db.ipPoolSilos on ip_pool_id
return db.ipPoolSilos
.filter((link) => link.silo_id === silo.id)
.map((link) => {
const pool = db.ipPools.find((pool) => pool.id === link.ip_pool_id)

// this should never happen
if (!pool) {
const linkStr = JSON.stringify(link)
const message = `Found IP pool-silo link without corresponding pool: ${linkStr}`
throw json({ message }, { status: 500 })
}

return { ...pool, is_default: link.is_default }
})
},
samlIdp({
provider: id,
...siloSelector
Expand Down
23 changes: 20 additions & 3 deletions libs/api-mocks/msw/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,25 @@ export const handlers = makeHandlers({
return json(instance, { status: 202 })
},
ipPoolList: ({ query }) => paginated(query, db.ipPools),
siloIpPoolList({ path, query }) {
const pools = lookup.siloIpPools(path)
return paginated(query, pools)
},
projectIpPoolList({ query }) {
const pools = lookup.siloIpPools({ silo: defaultSilo.id })
return paginated(query, pools)
},
projectIpPoolView({ path }) {
// this will 404 if it doesn't exist at all...
const pool = lookup.ipPool(path)
// but we also want to 404 if it exists but isn't in the silo
const link = db.ipPoolSilos.find(
(link) => link.ip_pool_id === pool.id && link.silo_id === defaultSilo.id
)
if (!link) throw notFoundErr()

return { ...pool, is_default: link.is_default }
},
ipPoolView: ({ path }) => lookup.ipPool(path),
ipPoolSiloList({ path /*query*/ }) {
// TODO: paginated wants an id field, but this is a join table, so it has a
Expand Down Expand Up @@ -585,7 +604,7 @@ export const handlers = makeHandlers({
return 204
},
ipPoolSiloUpdate: ({ path, body }) => {
const ipPoolSilo = lookup.ipPoolSilo(path)
const ipPoolSilo = lookup.ipPoolSiloLink(path)

// if we're setting default, we need to set is_default false on the existing default
if (body.is_default) {
Expand Down Expand Up @@ -1062,8 +1081,6 @@ export const handlers = makeHandlers({
networkingSwitchPortSettingsDelete: NotImplemented,
networkingSwitchPortSettingsView: NotImplemented,
networkingSwitchPortSettingsList: NotImplemented,
projectIpPoolList: NotImplemented,
projectIpPoolView: NotImplemented,
rackView: NotImplemented,
roleList: NotImplemented,
roleView: NotImplemented,
Expand Down
86 changes: 71 additions & 15 deletions libs/api/__generated__/Api.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion libs/api/__generated__/OMICRON_VERSION

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 18 additions & 7 deletions libs/api/__generated__/msw-handlers.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading