From a5ab0a1c19b5bf5a64bba195d8f4596811dbd695 Mon Sep 17 00:00:00 2001 From: Aitor Algorta Date: Wed, 14 Feb 2024 15:37:07 +0100 Subject: [PATCH] fix issues --- .../schema-registry-manager/src/app.ts | 9 +++--- .../src/providers/karapace.ts | 30 +++++++++---------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/backend/components/schema-registry-manager/src/app.ts b/backend/components/schema-registry-manager/src/app.ts index b78665ca4..305b46173 100644 --- a/backend/components/schema-registry-manager/src/app.ts +++ b/backend/components/schema-registry-manager/src/app.ts @@ -114,7 +114,7 @@ app.post('/schemas.update', (req: Request, res: Response) => { switch (currentProvider) { case SchemaProvider.karapace: - updateSchema(req.query.topicName as string, req.body.schema as string) + updateSchema(req.get('host') as string, req.query.topicName as string, req.body.schema as string) .then((response: any) => { res.status(200).send(response); }) @@ -140,7 +140,7 @@ app.post('/schemas.create', (req: Request, res: Response) => { switch (currentProvider) { case SchemaProvider.karapace: - createSchema(req.query.topicName as string, req.body.schema as string) + createSchema(req.get('host') as string, req.query.topicName as string, req.body.schema as string) .then((response: any) => { res.status(200).send(response); }) @@ -171,6 +171,7 @@ app.post('/schemas.compatibility', (req: Request, res: Response) => { switch (currentProvider) { case SchemaProvider.karapace: checkCompatibilityOfNewSchema( + req.get('host') as string, req.query.topicName as string, req.body.schema as string, req.query.version as string @@ -196,7 +197,7 @@ app.post('/schemas.delete', (req: Request, res: Response) => { switch (currentProvider) { case SchemaProvider.karapace: - deleteSchema(req.query.topicName as string) + deleteSchema(req.get('host') as string, req.query.topicName as string) .then((response: any) => { res.status(200).send(response); }) @@ -218,7 +219,7 @@ app.get('/schemas.lastMessage', (req: Request, res: Response) => { switch (currentProvider) { case SchemaProvider.karapace: - getLastMessage(req.query.topicName as string) + getLastMessage(req.get('host') as string, req.query.topicName as string) .then((response: any) => { res.status(200).send(response); }) diff --git a/backend/components/schema-registry-manager/src/providers/karapace.ts b/backend/components/schema-registry-manager/src/providers/karapace.ts index 08de3bd10..487aa31a8 100644 --- a/backend/components/schema-registry-manager/src/providers/karapace.ts +++ b/backend/components/schema-registry-manager/src/providers/karapace.ts @@ -22,11 +22,11 @@ export async function getSchemaInfo(host: string, topicName: string, version: st }); } -export async function updateSchema(topicName: string, schema: string) { +export async function updateSchema(host: string, topicName: string, schema: string) { const body = { schema: JSON.stringify({...JSON.parse(schema)}), }; - return postData(`subjects/${topicName}/versions`, body).then(response => { + return postData(host, `subjects/${topicName}/versions`, body).then(response => { if (response.error_code && response.error_code.toString().includes('404') && !topicName.includes('-value')) { return Promise.reject('404 Not Found'); } @@ -36,11 +36,11 @@ export async function updateSchema(topicName: string, schema: string) { }); } -export async function createSchema(topicName: string, schema: string) { +export async function createSchema(host: string, topicName: string, schema: string) { const body = { schema: JSON.stringify({...JSON.parse(schema)}), }; - return postData(`subjects/${topicName}/versions`, body) + return postData(host, `subjects/${topicName}/versions`, body) .then(response => { if (response.id) return response; if (response.message) return Promise.reject(response.message); @@ -51,11 +51,12 @@ export async function createSchema(topicName: string, schema: string) { }); } -export async function checkCompatibilityOfNewSchema(topicName: string, schema: string, version: string) { +export async function checkCompatibilityOfNewSchema(host: string, topicName: string, schema: string, version: string) { const body = { schema: JSON.stringify({...JSON.parse(schema)}), }; - return postData(`compatibility/subjects/${topicName}/versions/${version}`, body) + + return postData(host, `compatibility/subjects/${topicName}/versions/${version}`, body) .then(response => { if (response.error_code && response.error_code.toString().includes('404') && !topicName.includes('-value')) { return Promise.reject('404 Not Found'); @@ -74,8 +75,8 @@ export async function checkCompatibilityOfNewSchema(topicName: string, schema: s }); } -export async function deleteSchema(topicName: string) { - return deleteData(`subjects/${topicName}`).then(response => { +export async function deleteSchema(host: string, topicName: string) { + return deleteData(host, `subjects/${topicName}`).then(response => { if (response.error_code && response.error_code.toString().includes('404') && !topicName.includes('-value')) { return Promise.reject('404 Not Found'); } @@ -83,13 +84,12 @@ export async function deleteSchema(topicName: string) { }); } -export async function getLastMessage(topicName: string) { +export async function getLastMessage(host: string, topicName: string) { const body = { ksql: `PRINT '${topicName}' FROM BEGINNING LIMIT 1;`, streamsProperties: {}, }; - return postData('query', body).then(response => { - console.log(response); + return postData(host, 'query', body).then(response => { return response; }); } @@ -101,15 +101,15 @@ async function getData(host: string, url: string) { return response.json(); } -async function deleteData(url: string) { - const response = await fetch(process.env.URL + '/' + url, { +async function deleteData(host: string, url: string) { + const response = await fetch('https://' + host + '/' + url, { method: 'DELETE', }); return response.json(); } -async function postData(url: string, body: any) { - const response = await fetch(process.env.URL + '/' + url, { +async function postData(host: string, url: string, body: any) { + const response = await fetch('https://' + host + '/' + url, { method: 'POST', headers: { 'Content-Type': 'application/vnd.schemaregistry.v1+json',