-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(3418): fix displaying subnets for namespaces in emerald
- Loading branch information
Chinedu Olebu
committed
Nov 25, 2024
1 parent
21bd6be
commit c7c47c2
Showing
6 changed files
with
79 additions
and
6 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
app/app/api/private-cloud/products/[licencePlate]/namespace-subnet/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Cluster } from '@prisma/client'; | ||
import { z, string } from 'zod'; | ||
import { GlobalRole } from '@/constants'; | ||
import createApiHandler from '@/core/api-handler'; | ||
import { OkResponse, UnauthorizedResponse } from '@/core/responses'; | ||
import { models } from '@/services/db'; | ||
import { getSubnet } from '@/services/k8s'; | ||
import { getPathParamSchema } from '../schema'; | ||
|
||
const queryParamSchema = z.object({ | ||
environment: string(), | ||
}); | ||
|
||
const apiHandler = createApiHandler({ | ||
roles: [GlobalRole.User], | ||
validations: { queryParams: queryParamSchema, pathParams: getPathParamSchema }, | ||
}); | ||
|
||
export const GET = apiHandler(async ({ queryParams, pathParams, session }) => { | ||
const { environment } = queryParams; | ||
const { licencePlate } = pathParams; | ||
const { data: product } = await models.privateCloudProduct.get({ where: { licencePlate } }, session); | ||
|
||
if (!product?._permissions.view) { | ||
return UnauthorizedResponse(); | ||
} | ||
|
||
const subnetInfo = await getSubnet(licencePlate, environment, product.cluster); | ||
return OkResponse(subnetInfo); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './usage-metrics'; | ||
export * from './resource-details'; | ||
export * from './namespace'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Cluster } from '@prisma/client'; | ||
import _get from 'lodash-es/get'; | ||
import { getK8sClients } from './core'; | ||
|
||
export async function getNamespace(namespace: string, cluster: Cluster) { | ||
const { apiClient } = getK8sClients(cluster); | ||
return apiClient.readNamespace(namespace); | ||
} | ||
|
||
export async function getSubnet(licencePlate: string, environment: string, cluster: Cluster) { | ||
const namespaceInfo = await getNamespace(`${licencePlate}-${environment}`, cluster); | ||
return _get(namespaceInfo.body, 'metadata.annotations.ncp/subnet-0'); | ||
} |