Skip to content

Commit

Permalink
fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
AitorAlgorta committed Feb 14, 2024
1 parent badf1a0 commit a5ab0a1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
9 changes: 5 additions & 4 deletions backend/components/schema-registry-manager/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})
Expand All @@ -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);
})
Expand Down Expand Up @@ -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
Expand All @@ -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);
})
Expand All @@ -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);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand All @@ -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);
Expand All @@ -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');
Expand All @@ -74,22 +75,21 @@ 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');
}
return response;
});
}

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;
});
}
Expand All @@ -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',
Expand Down

0 comments on commit a5ab0a1

Please sign in to comment.