Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: created plugins api * fix: lint * feat: updated plugins sync * feat: updated plugin id and secret * fix: option pluginRepo * Rename camelcase field --------- Co-authored-by: Romaric Mourgues <rmourgues@linagora.com>
- Loading branch information
1 parent
f375d46
commit 89b5368
Showing
17 changed files
with
233 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "api", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"build": "tsc", | ||
"start:dev": "node dist/index.js", | ||
"start": "ts-node src/index.ts", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@types/express": "^4.17.17", | ||
"express": "^4.18.2", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.9.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Request, Response } from "express"; | ||
import { runCommand } from "./utils/runCommand"; | ||
|
||
export const addPluginHandler = async (req: Request, res: Response) => { | ||
const { gitRepo, pluginId, pluginSecret, envVar } = req.body; | ||
|
||
if (!gitRepo || !pluginId || !pluginSecret) { | ||
return res.status(400).send("Missing required parameters"); | ||
} | ||
|
||
try { | ||
await runCommand("add", [gitRepo, pluginId, pluginSecret, envVar]); | ||
res.send("Plugin added successfully"); | ||
} catch (err:any) { | ||
console.error(err); | ||
res.status(500).send("Error adding plugin"); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Request, Response } from "express"; | ||
import { runCommand } from "./utils/runCommand"; | ||
|
||
export const buildPluginHandler = async (req: Request, res: Response) => { | ||
const { gitRepo } = req.body; | ||
|
||
if (!gitRepo) { | ||
return res.status(400).send("Missing required parameters"); | ||
} | ||
|
||
try { | ||
await runCommand("build", [gitRepo]); | ||
res.send("Plugin built successfully"); | ||
} catch (err:any) { | ||
res.status(500).send(`Error building plugin: ${err.message}`); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Request, Response } from "express"; | ||
import { runCommand } from "./utils/runCommand"; | ||
|
||
export const deletePluginHandler = async (req: Request, res: Response) => { | ||
const pluginName = req.params.pluginName; | ||
|
||
try { | ||
await runCommand("delete", [pluginName]); | ||
res.send(`Plugin ${pluginName} deleted successfully`); | ||
} catch (err:any) { | ||
res.status(500).send(`Error deleting plugin ${pluginName}: ${err.message}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export { addPluginHandler } from './addHandler'; | ||
export { startPluginHandler } from './startHandler'; | ||
export { buildPluginHandler } from './buildHandler'; | ||
export { updatePluginHandler } from './updateHandler'; | ||
export { deletePluginHandler } from './deleteHandler'; | ||
export { listPluginHandler } from './listHandler'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Request, Response } from "express"; | ||
import { runCommand } from "./utils/runCommand"; | ||
|
||
export const listPluginHandler = async (req: Request, res: Response) => { | ||
try { | ||
const output = await runCommand("list", []); | ||
res.send(output); | ||
} catch (err:any) { | ||
res.status(500).send(`Error listing plugins: ${err.message}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Request, Response } from "express"; | ||
import { runCommand } from "./utils/runCommand"; | ||
|
||
export const startPluginHandler = async (req: Request, res: Response) => { | ||
try { | ||
await runCommand("start", []); | ||
res.send("Plugins started successfully"); | ||
} catch (err:any) { | ||
res.status(500).send(`Error starting plugins: ${err.message}`); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Request, Response } from "express"; | ||
import { runCommand } from "./utils/runCommand"; | ||
|
||
export const updatePluginHandler = async (req: Request, res: Response) => { | ||
const pluginName = req.params.pluginName; | ||
|
||
try { | ||
await runCommand("update", [pluginName]); | ||
res.send(`Plugin ${pluginName} updated successfully`); | ||
} catch (err:any) { | ||
res.status(500).send(`Error updating plugin ${pluginName}: ${err.message}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { spawn } from "child_process"; | ||
|
||
export const runCommand = ( | ||
command: string, | ||
args: string[] | ||
): Promise<string> => { | ||
return new Promise((resolve, reject) => { | ||
const cmd = spawn(command, args); | ||
|
||
let output = ""; | ||
|
||
cmd.stdout.on("data", (data) => { | ||
output += data; | ||
}); | ||
|
||
cmd.stderr.on("data", (data) => { | ||
console.error(`stderr: ${data}`); | ||
}); | ||
|
||
cmd.on("close", (code) => { | ||
if (code === 0) { | ||
resolve(output); | ||
} else { | ||
reject(new Error(`Command ${command} failed with code ${code}`)); | ||
} | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import express from "express"; | ||
import bodyParser from "body-parser"; | ||
import pluginRoutes from "./routes"; | ||
|
||
const app = express(); | ||
|
||
app.use(bodyParser.json()); | ||
|
||
app.use("/api", pluginRoutes); | ||
|
||
const port = process.env.PORT || 6000; | ||
|
||
app.listen(port, () => { | ||
console.log(`Listening on port ${port} 馃殌`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import express from "express"; | ||
import { | ||
addPluginHandler, | ||
startPluginHandler, | ||
buildPluginHandler, | ||
updatePluginHandler, | ||
deletePluginHandler, | ||
listPluginHandler, | ||
} from "./handlers/"; | ||
|
||
const router = express.Router(); | ||
|
||
router.post("/add", addPluginHandler); | ||
|
||
router.post("/start", startPluginHandler); | ||
|
||
router.post("/build", buildPluginHandler); | ||
|
||
router.post("/update/:pluginName", updatePluginHandler); | ||
|
||
router.post("/delete/:pluginName", deletePluginHandler); | ||
|
||
router.get("/list", listPluginHandler); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2018", | ||
"module": "CommonJS", | ||
"esModuleInterop": true, | ||
"strict": true, | ||
"moduleResolution": "node", | ||
"outDir": "dist", | ||
"sourceMap": true | ||
}, | ||
"include": ["src/**/*"] | ||
} | ||
|