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 @@
b1ebae8ab2cb7e636f04d847e0ac77aba891ff30
19059b1bedc8bbc7a9d293486842a9a4fd264ea3
1 change: 1 addition & 0 deletions libs/api-mocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
export * from './disk'
export * from './image'
export * from './instance'
export * from './ip-pool'
export * from './network-interface'
export * from './physical-disk'
export * from './project'
Expand Down
38 changes: 38 additions & 0 deletions libs/api-mocks/ip-pool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* Copyright Oxide Computer Company
*/

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

import type { Json } from './json-type'
import { defaultSilo } from './silo'

const ipPool1: Json<IpPool> = {
id: '69b5c583-74a9-451a-823d-0741c1ec66e2',
name: 'ip-pool-1',
description: '',
time_created: new Date().toISOString(),
time_modified: new Date().toISOString(),
}

const ipPool2: Json<IpPool> = {
id: 'af2fbe06-b21d-4364-96b7-a58220bc3242',
name: 'ip-pool-2',
description: '',
time_created: new Date().toISOString(),
time_modified: new Date().toISOString(),
}

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

export const ipPoolSilos: Json<IpPoolSilo>[] = [
{
ip_pool_id: ipPool1.id,
silo_id: defaultSilo.id,
is_default: true,
},
]
24 changes: 24 additions & 0 deletions libs/api-mocks/msw/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,28 @@ export const lookup = {
if (!image) throw notFoundErr
return image
},
ipPool({ pool: id }: PP.IpPool): Json<Api.IpPool> {
if (!id) throw notFoundErr

if (isUuid(id)) return lookupById(db.ipPools, id)

const pool = db.ipPools.find((p) => p.name === id)
if (!pool) throw notFoundErr

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> {
const pool = lookup.ipPool({ pool: poolId })
const silo = lookup.silo({ silo: siloId })

const ipPoolSilo = db.ipPoolSilos.find(
(ips) => ips.ip_pool_id === pool.id && ips.silo_id === silo.id
)
if (!ipPoolSilo) throw notFoundErr

return ipPoolSilo
},
samlIdp({
provider: id,
...siloSelector
Expand Down Expand Up @@ -203,6 +225,8 @@ const initDb = {
groupMemberships: [...mock.groupMemberships],
images: [...mock.images],
instances: [...mock.instances],
ipPools: [...mock.ipPools],
ipPoolSilos: [...mock.ipPoolSilos],
networkInterfaces: [mock.networkInterface],
physicalDisks: [...mock.physicalDisks],
projects: [...mock.projects],
Expand Down
66 changes: 62 additions & 4 deletions libs/api-mocks/msw/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,66 @@ export const handlers = makeHandlers({

return json(instance, { status: 202 })
},
ipPoolList: ({ query }) => paginated(query, db.ipPools),
ipPoolView: ({ path }) => lookup.ipPool(path),
ipPoolSiloList({ path /*query*/ }) {
// TODO: paginated wants an id field, but this is a join table, so it has a
// composite pk
// return paginated(query, db.ipPoolResources)

const pool = lookup.ipPool(path)
const assocs = db.ipPoolSilos.filter((ipr) => ipr.ip_pool_id === pool.id)
return { items: assocs }
},
ipPoolSiloLink({ path, body }) {
const pool = lookup.ipPool(path)
const silo_id = lookup.silo({ silo: body.silo }).id

const assoc = {
ip_pool_id: pool.id,
silo_id,
is_default: body.is_default,
}

const alreadyThere = db.ipPoolSilos.find(
(ips) => ips.ip_pool_id === pool.id && ips.silo_id === silo_id
)

// TODO: this matches current API logic but makes no sense because is_default
// could be different. Need to fix that. Should 400 or 409 on conflict.
if (!alreadyThere) db.ipPoolSilos.push(assoc)

return assoc
},
ipPoolSiloUnlink({ path }) {
const pool = lookup.ipPool(path)
const silo = lookup.silo(path)

// ignore is_default when deleting, it's not part of the pk
db.ipPoolSilos = db.ipPoolSilos.filter(
(ips) => !(ips.ip_pool_id === pool.id && ips.silo_id === silo.id)
)

return 204
},
ipPoolSiloUpdate: ({ path, body }) => {
const ipPoolSilo = lookup.ipPoolSilo(path)

// if we're setting default, we need to set is_default false on the existing default
if (body.is_default) {
const silo = lookup.silo(path)
const existingDefault = db.ipPoolSilos.find(
(ips) => ips.silo_id === silo.id && ips.is_default
)
if (existingDefault) {
existingDefault.is_default = false
}
}

ipPoolSilo.is_default = body.is_default

return ipPoolSilo
},
projectPolicyView({ path }) {
const project = lookup.project(path)

Expand Down Expand Up @@ -960,7 +1020,6 @@ export const handlers = makeHandlers({
siloMetric: handleMetrics,

// Misc endpoints we're not using yet in the console
addSledToInitializedRack: NotImplemented,
certificateCreate: NotImplemented,
certificateDelete: NotImplemented,
certificateList: NotImplemented,
Expand All @@ -973,7 +1032,6 @@ export const handlers = makeHandlers({
instanceSerialConsoleStream: NotImplemented,
ipPoolCreate: NotImplemented,
ipPoolDelete: NotImplemented,
ipPoolList: NotImplemented,
ipPoolRangeAdd: NotImplemented,
ipPoolRangeList: NotImplemented,
ipPoolRangeRemove: NotImplemented,
Expand All @@ -982,7 +1040,6 @@ export const handlers = makeHandlers({
ipPoolServiceRangeRemove: NotImplemented,
ipPoolServiceView: NotImplemented,
ipPoolUpdate: NotImplemented,
ipPoolView: NotImplemented,
localIdpUserCreate: NotImplemented,
localIdpUserDelete: NotImplemented,
localIdpUserSetPassword: NotImplemented,
Expand Down Expand Up @@ -1021,12 +1078,13 @@ export const handlers = makeHandlers({
siloQuotasView: NotImplemented,
siloUserList: NotImplemented,
siloUserView: NotImplemented,
sledAdd: NotImplemented,
sledListUninitialized: NotImplemented,
sledSetProvisionState: NotImplemented,
switchList: NotImplemented,
switchView: NotImplemented,
systemPolicyUpdate: NotImplemented,
systemQuotasList: NotImplemented,
uninitializedSledList: NotImplemented,
userBuiltinList: NotImplemented,
userBuiltinView: NotImplemented,
})
Loading