Skip to content
Snippets Groups Projects
Commit d16bfcf2 authored by Lansana DIOMANDE's avatar Lansana DIOMANDE
Browse files

feat: add http server to enable communication between extension and recorder

parent f45c5b92
No related branches found
No related tags found
3 merge requests!14feat: added mounted, .bashrc, .zshrc, added tests, added keycloak tests,!8feat(extension): login, open in devcontainer, automaticly save code, open briefing, publish extension,!4feat: create little container for developer
Showing with 1233 additions and 13 deletions
......@@ -3,3 +3,6 @@ export const KEYCLOAK_DEVICE_AUTH_URL =
export const KEYCLOAK_TOKEN_CREATE_URL = 'https://auth.deadlock.io/auth/realms/Deadlock/protocol/openid-connect/token';
export const KEYCLOAK_USER_INFO_URL = 'https://auth.deadlock.io/auth/realms/Deadlock/protocol/openid-connect/userinfo';
export const REJECT_UNAUTHORIZED = true;
export const ENABLE_HTTP_SERVER = false;
export const HTTP_SERVER_PORT = 8751;
export const HTTP_SERVER_URL = `http://localhost:${HTTP_SERVER_PORT}`;
......@@ -5,3 +5,6 @@ export const KEYCLOAK_TOKEN_CREATE_URL =
export const KEYCLOAK_USER_INFO_URL =
'https://auth.staging.deadlock.io/auth/realms/Deadlock/protocol/openid-connect/userinfo';
export const REJECT_UNAUTHORIZED = true;
export const ENABLE_HTTP_SERVER = false;
export const HTTP_SERVER_PORT = 8751;
export const HTTP_SERVER_URL = `http://localhost:${HTTP_SERVER_PORT}`;
......@@ -5,3 +5,6 @@ export const KEYCLOAK_TOKEN_CREATE_URL =
export const KEYCLOAK_USER_INFO_URL =
'https://auth.dev.deadlock.io/auth/realms/Deadlock/protocol/openid-connect/userinfo';
export const REJECT_UNAUTHORIZED = false;
export const ENABLE_HTTP_SERVER = false;
export const HTTP_SERVER_PORT = 8751;
export const HTTP_SERVER_URL = `http://localhost:${HTTP_SERVER_PORT}`;
......@@ -48,8 +48,6 @@ export default class GitMission {
const remote = await this.readRemote();
//TODO: REMOVE
console.log('After finish readremote..');
if (remote === DEFAULT_REMOTE) {
return Promise.resolve(this);
}
......
......@@ -4,7 +4,8 @@ import UserConfigNode from './userConfigNode';
import { PROJECT_SRC_PATH, PROJECT_DEADLOCK_DESKTOP_PATH } from '../core/config';
import { copyProjectSources, clearFilesExceptGit, log, error, renameTempToUserGitFiles } from './utils';
import UserConfig from '../core/userConfig';
import HttpServer from './services/http-server';
import { ENABLE_HTTP_SERVER } from '../config';
export default class Recorder {
async setupProject(userConfig: UserConfig, gitMission?: GitMission) {
log('Setup user project..');
......@@ -49,6 +50,8 @@ export default class Recorder {
await userConfig.init();
log('Init GitMission');
gitMission = await new GitMission(userConfig).init();
if (ENABLE_HTTP_SERVER) new HttpServer(gitMission);
await this.setupFromRemoteRepo(gitMission);
} catch (e) {
error('Cannot setup user repo.');
......
This diff is collapsed.
......@@ -9,6 +9,9 @@
"author": "",
"license": "MIT",
"dependencies": {
"deadlock-coding": "^0.0.1"
"express": "^4.18.0"
},
"devDependencies": {
"@types/express": "^4.17.13"
}
}
import GitMission from '../../core/gitMission';
import { Express } from 'express';
import { commitAndPushCode, CommitFrom, log } from '../utils';
import { HTTP_SERVER_PORT } from '../../config';
const express = require('express');
export default class HttpServer {
app: Express;
constructor(private gitMission: GitMission) {
this.app = express();
this.setupSaveCodeEndpoints();
this.listen();
}
setupSaveCodeEndpoints() {
this.app.post('/save', async (req, res) => {
try {
await commitAndPushCode(this.gitMission, CommitFrom.HttpServer);
res.status(200).json({
message: 'Commit & push done.',
});
} catch (error) {
res.status(400).json({
error,
});
}
});
}
listen() {
this.app.listen(HTTP_SERVER_PORT, () => {
log(`Http server listen on port ${HTTP_SERVER_PORT}`);
});
}
}
......@@ -110,6 +110,7 @@ function copyGitUserFiles(srcPath: string, destPath: string, userId: string) {
export enum CommitFrom {
Run = 'Run',
Auto = 'Auto',
HttpServer = 'HttpServer',
}
export async function commitAndPushCode(gitMission: GitMission, from: CommitFrom) {
......@@ -133,5 +134,6 @@ export async function commitAndPushCode(gitMission: GitMission, from: CommitFrom
} catch (e) {
error(`[${e.status}] cannot commitAndPush code: ${e.stderr}`);
error(e.message);
throw new Error(e);
}
}
npm install
npm install --prefix ./deadlock-plugins/deadlock-extension
npm install --prefix ./deadlock-plugins/deadlock-extension/src/recorder
\ No newline at end of file
......@@ -25,16 +25,9 @@ su deadlock -c "python setup_trace.py"
rm setup_trace.py
trap "node deadlock/preStop.js" SIGTERM
# start command recorder
node deadlock/recorder.js &
echo "WELCOME TO DEADLOCK CHALLENGE"
child=$!
wait "$child"
node deadlock/recorder.js
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment