Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended organization network api #393

Merged
merged 3 commits into from
May 8, 2024
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
12 changes: 10 additions & 2 deletions docs/docs/Rest Api/_schema/NetworkSchema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ NetworkResponse:
UpdateNetworkShema:
type: object
properties:
name:
type: string
description:
type: string
mtu:
type: integer
default: 2800
dns:
type: object
properties:
Expand All @@ -122,8 +129,6 @@ UpdateNetworkShema:
type: string
ipRangeEnd:
type: string
name:
type: string
private:
type: boolean
routes:
Expand All @@ -136,6 +141,9 @@ UpdateNetworkShema:
via:
type: string
nullable: true
flowRules:
type: string
default: "drop not ethertype ipv4 and not ethertype arp and not ethertype ipv6; accept;"
v4AssignMode:
type: object
properties:
Expand Down
20 changes: 17 additions & 3 deletions src/pages/api/v1/org/[orgid]/network/[nwid]/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ export const POST_network = async (req: NextApiRequest, res: NextApiResponse) =>
// structure of the updateableFields object:
const updateableFields = {
name: { type: "string", destinations: ["controller", "database"] },
description: { type: "string", destinations: ["database"] },
flowRule: { type: "string", destinations: ["custom"] },
mtu: { type: "string", destinations: ["controller"] },
private: { type: "boolean", destinations: ["controller"] },
// capabilities: { type: "array", destinations: ["controller"] },
dns: { type: "array", destinations: ["controller"] },
Expand All @@ -122,6 +125,9 @@ export const POST_network = async (req: NextApiRequest, res: NextApiResponse) =>
const databasePayload: Partial<network> = {};
const controllerPayload: Partial<network> = {};

// @ts-expect-error
const caller = appRouter.createCaller(ctx);

// Iterate over keys in the request body
for (const key in requestBody) {
// Check if the key is not in updateableFields
Expand All @@ -131,7 +137,17 @@ export const POST_network = async (req: NextApiRequest, res: NextApiResponse) =>

try {
const parsedValue = parseField(key, requestBody[key], updateableFields[key].type);

// if custom and flowRule call the caller.setFlowRule
if (key === "flowRule") {
// @ts-expect-error
const caller = appRouter.createCaller(ctx);
await caller.network.setFlowRule({
nwid: networkId,
updateParams: {
flowRoute: parsedValue,
},
});
}
if (updateableFields[key].destinations.includes("database")) {
databasePayload[key] = parsedValue;
}
Expand All @@ -143,8 +159,6 @@ export const POST_network = async (req: NextApiRequest, res: NextApiResponse) =>
}
}

// @ts-expect-error
const caller = appRouter.createCaller(ctx);
const network = await caller.network
.getNetworkById({ nwid: networkId })
.then(async (res) => {
Expand Down
Loading