Skip to content

Commit

Permalink
add test route
Browse files Browse the repository at this point in the history
  • Loading branch information
semd committed Jun 13, 2024
1 parent 939a908 commit 5cb9265
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
* 2.0.
*/

import { schema } from '@kbn/config-schema';
import type { IRouter } from '@kbn/core/server';
import fs from 'fs';
import nunjucks from 'nunjucks';
import { resolve as resolvePath } from 'path';
import { registerEcsRoutes } from './ecs_routes';
import { registerIntegrationBuilderRoutes } from './build_integration_routes';
import { registerCategorizationRoutes } from './categorization_routes';
Expand All @@ -19,4 +23,46 @@ export function registerRoutes(router: IRouter<IntegrationAssistantRouteHandlerC
registerCategorizationRoutes(router);
registerRelatedRoutes(router);
registerPipelineRoutes(router);

router.versioned
.get({
path: '/api/integration_assistant/test',
access: 'internal',
})
.addVersion(
{
version: '1',
validate: {
request: {
query: schema.any(),
},
},
},
async (context, req, res) => {
let body: Record<string, unknown> = {};
try {
const templateDir = resolvePath(__dirname, '../templates');
const templateFile = resolvePath(templateDir, 'readme.md.njk');
body = {
templateDir: { path: templateFile, content: fs.readFileSync(templateFile).toString() },
};

nunjucks.configure([templateDir], {
autoescape: false,
});

const readmeTemplate = nunjucks.render('readme.md.njk', {
package_name: 'testPackageName',
data_streams: ['testDataStreamName'],
});

body.readme = readmeTemplate;

return res.ok({ body });
} catch (error) {
body.error = error.toString();
return res.customError({ statusCode: 400, body: JSON.stringify(body) });
}
}
);
}

0 comments on commit 5cb9265

Please sign in to comment.