Skip to content

Commit

Permalink
add rest of endpoints from Karapace
Browse files Browse the repository at this point in the history
  • Loading branch information
AitorAlgorta committed Feb 8, 2024
1 parent 4ac866c commit 0be3ca1
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 22 deletions.
45 changes: 43 additions & 2 deletions backend/components/schema-registry-manager/backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import dotenv from "dotenv";
import express, { Express, Request, Response } from "express";
import { SchemaProvider } from "./types";
import { createSchema, getSchemaInfo, getSchemaVersions, getSchemas, updateSchema } from "./providers/karapace";
import { checkCompatibilityOfNewSchema, createSchema, deleteSchema, getLastMessage, getSchemaInfo, getSchemaVersions, getSchemas, updateSchema } from "./providers/karapace";

dotenv.config();

Expand Down Expand Up @@ -142,7 +142,48 @@ app.post('/schemas.compatibility', (req: Request, res: Response) => {

switch (currentProvider) {
case SchemaProvider.karapace:
createSchema(req.query.topicName as string, req.body.schema as string).then((response: any) => {
checkCompatibilityOfNewSchema(req.query.topicName as string, req.body.schema as string, req.query.version as string).then((response: any) => {
res.status(200).send(response);
}).catch((e: any) => {
res.status(500).send(e);
});
break;
default:
res.status(404).send('Provider Not Found');
break;
}
});

app.post('/schemas.delete', (req: Request, res: Response) => {
if (!req.query.topicName) {
res.status(400).send('Missing topicName');
return;
}

switch (currentProvider) {
case SchemaProvider.karapace:
deleteSchema(req.query.topicName as string).then((response: any) => {
res.status(200).send(response);
}).catch((e: any) => {
res.status(500).send(e);
});
break;
default:
res.status(404).send('Provider Not Found');
break;
}
});

app.get('/schemas.lastMessage', (req: Request, res: Response) => {
if (!req.query.topicName) {
res.status(400).send('Missing topicName');
return;
}

switch (currentProvider) {
case SchemaProvider.karapace:
getLastMessage(req.query.topicName as string).then((response: any) => {
console.log(response);
res.status(200).send(response);
}).catch((e: any) => {
res.status(500).send(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function createSchema(topicName: string, schema: string) {
});
};

export async function checkCompatibilityOfNewSchema(topicName: string, schema: string, version: number) {
export async function checkCompatibilityOfNewSchema(topicName: string, schema: string, version: string) {
const body = {
schema: JSON.stringify({...JSON.parse(schema)}),
};
Expand All @@ -62,7 +62,7 @@ export async function checkCompatibilityOfNewSchema(topicName: string, schema: s
}
if (response.is_compatible !== undefined) {
if (response.is_compatible === true) {
return Promise.resolve(true);
return response;
}
return Promise.reject('Schema Not Compatible');
}
Expand All @@ -74,25 +74,25 @@ export async function checkCompatibilityOfNewSchema(topicName: string, schema: s
});
};

// export const deleteSchema = (topicName: string) => async () => {
// return deleteData(`subjects/${topicName}`).then(response => {
// if (response.error_code && response.error_code.toString().includes('404') && !topicName.includes('-value')) {
// return Promise.reject('404 Not Found');
// }
// return Promise.resolve(true);
// });
// };
export async function deleteSchema(topicName: string) {
return deleteData(`subjects/${topicName}`).then(response => {
if (response.error_code && response.error_code.toString().includes('404') && !topicName.includes('-value')) {
return Promise.reject('404 Not Found');
}
return response;
});
};

// export const getLastMessage = (topicName: string) => async (dispatch: Dispatch<any>) => {
// const body = {
// ksql: `PRINT '${topicName}' FROM BEGINNING LIMIT 1;`,
// streamsProperties: {},
// };
// return postData('query', body).then(response => {
// dispatch(setLastMessage(response));
// return Promise.resolve(true);
// });
// };
export async function getLastMessage(topicName: string) {
const body = {
ksql: `PRINT '${topicName}' FROM BEGINNING LIMIT 1;`,
streamsProperties: {},
};
return postData('query', body).then(response => {
console.log(response);
return response;
});
};

async function getData(url: string) {
const response = await fetch(process.env.URL + '/' + url, {
Expand Down

0 comments on commit 0be3ca1

Please sign in to comment.