diff --git a/deadlock-plugins/deadlock-extension/dev/README.md b/deadlock-plugins/deadlock-extension/dev/README.md index ea985e86635cbee7062c285600c9bbc7456a44d6..b2fb4782cd70d06ce2ca9fe91c679f9dc6ab2e7c 100644 --- a/deadlock-plugins/deadlock-extension/dev/README.md +++ b/deadlock-plugins/deadlock-extension/dev/README.md @@ -38,7 +38,7 @@ Pour le moment, la marketplace de Vscode ne supporte pas totalement le `semver`( 2. Pousser le code source et le tag : ```shell -git tag [X.Y.Z] [hash du commit] +git tag [X.Y.Z] git push origin [taBranch] --tags ``` diff --git a/deadlock-plugins/deadlock-extension/src/core/api.service.ts b/deadlock-plugins/deadlock-extension/src/core/api.service.ts index be281fc060267e91132510eebcb4b6da7f23e3be..b41170e7c48a64d0db59446afbc8ecdf47cc216f 100644 --- a/deadlock-plugins/deadlock-extension/src/core/api.service.ts +++ b/deadlock-plugins/deadlock-extension/src/core/api.service.ts @@ -92,10 +92,8 @@ export default class ApiService { } catch (_error) { if (_error.response && _error.response.data) { return Promise.reject(_error.response.data); - } else { - return await this.onInvalidRefreshToken(originalConfig); } - return Promise.reject(_error); + return await this.onInvalidRefreshToken(originalConfig); } } diff --git a/deadlock-plugins/deadlock-extension/src/core/controller.ts b/deadlock-plugins/deadlock-extension/src/core/controller.ts index 9ae124a6b08f87b48e0c1a2c4bbe2b44f985fa45..a50e93fc5d12c0acd8b0881784578546743f8d42 100644 --- a/deadlock-plugins/deadlock-extension/src/core/controller.ts +++ b/deadlock-plugins/deadlock-extension/src/core/controller.ts @@ -7,7 +7,7 @@ import { CHOOSE_MISSION_WORKDIR_COMMAND, CommandHandler, OPEN_URL_IN_BROWSER_COM import ExtensionStore from './extensionStore'; import KeycloakOAuth2DeviceFlowConnection from './keycloakOAuth2DeviceFlowConnection'; import ApiService from './api.service'; -import SshKeyManager from './sshKeyManager'; +import { createSshKeyFiles, isSshKeyPairExist } from './sshKeyManager'; import { GiteaPublicProperties } from '../model/giteaPublicProperties.model'; import { User } from '../model/user.model'; import { Mission } from './mission/mission'; @@ -19,8 +19,7 @@ export default class Controller { private briefingView: BriefingView; private quickSetupView: QuickSetupView; private extensionStore: ExtensionStore; - private callApiService: ApiService; - private sshKeyManager: SshKeyManager; + private apiService: ApiService; constructor(private context: vscode.ExtensionContext) { this.extensionStore = ExtensionStore.getInstance(context); @@ -33,8 +32,7 @@ export default class Controller { KEYCLOAK_USER_INFO_URL, ); - this.callApiService = new ApiService(this.connection, this.extensionStore, this); - this.sshKeyManager = new SshKeyManager(); + this.apiService = new ApiService(this.connection, this.extensionStore, this); this.init(); } @@ -95,9 +93,9 @@ export default class Controller { } public async createSshKeyPairIfNotExist() { - if (this.sshKeyManager.isSshKeyPairExist()) return; - const { publicKey, privateKey } = await this.callApiService.getUserSshKey(); - await this.sshKeyManager.createSshKeyFiles(publicKey, privateKey); + if (isSshKeyPairExist()) return; + const { publicKey, privateKey } = await this.apiService.getUserSshKey(); + await createSshKeyFiles(publicKey, privateKey); } public async authenticate() { @@ -127,16 +125,13 @@ export default class Controller { vscode.window.showInformationMessage('Connexion validée'); } - const mission = new Mission( - `${ExtensionStore.getInstance().getMissionWorkdir()}/${missionId}`, - missionId, - missionVersion, - ); + const mission = new Mission(missionId, missionVersion); - const user: User = await this.callApiService.getUser(); - const giteaPublicProperties: GiteaPublicProperties = await this.callApiService.getGiteaPublicProperties(); + const missionsWorkdir = this.extensionStore.getMissionWorkdir(); + const user: User = await this.apiService.getUser(); + const giteaPublicProperties: GiteaPublicProperties = await this.apiService.getGiteaPublicProperties(); - const missionDevcontainer = new MissionDevContainer(user, mission, giteaPublicProperties); + const missionDevcontainer = new MissionDevContainer(missionsWorkdir, user, mission, giteaPublicProperties); vscode.window.showInformationMessage( 'opening inside folder ' + this.extensionStore.getMissionWorkdir()! + '/' + missionId, diff --git a/deadlock-plugins/deadlock-extension/src/core/mission/mission.ts b/deadlock-plugins/deadlock-extension/src/core/mission/mission.ts index 641b8112e3ab1f9be44ca2fa593568ae72b5f831..ba27109c96a09ddd2633e3ff21045b3b8f192da9 100644 --- a/deadlock-plugins/deadlock-extension/src/core/mission/mission.ts +++ b/deadlock-plugins/deadlock-extension/src/core/mission/mission.ts @@ -1,10 +1,8 @@ export class Mission { - readonly directory: string; readonly id: string; readonly version: string; - constructor(directory: string, id: string, version: string) { - this.directory = directory; + constructor(id: string, version: string) { this.id = id; this.version = version; } diff --git a/deadlock-plugins/deadlock-extension/src/core/mission/missionDevContainer.ts b/deadlock-plugins/deadlock-extension/src/core/mission/missionDevContainer.ts index 363c60ca47c183f6b150bac48c8f954c42072d0e..bbfc04498b68360ea6bac0a91092f3f9578fea8b 100644 --- a/deadlock-plugins/deadlock-extension/src/core/mission/missionDevContainer.ts +++ b/deadlock-plugins/deadlock-extension/src/core/mission/missionDevContainer.ts @@ -14,12 +14,14 @@ export class MissionDevContainer { private isInit = false; private readonly dirs = { - config: `${this.mission.directory}/.config`, - devcontainer: `${this.mission.directory}/.devcontainer`, - mounted: `${this.mission.directory}/mounted`, + missionWorkdir: `${this.missionsWorkdir}/${this.mission.id}`, + config: `${this.missionsWorkdir}/${this.mission.id}/.config`, + devcontainer: `${this.missionsWorkdir}/${this.mission.id}/.devcontainer`, + mounted: `${this.missionsWorkdir}/${this.mission.id}/mounted`, }; constructor( + private readonly missionsWorkdir: string | undefined, private readonly user: User, private readonly mission: Mission, private readonly giteaProperties: GiteaPublicProperties, @@ -29,33 +31,33 @@ export class MissionDevContainer { if (!this.isInit) { await this.init(); } - assert(existsSync(this.mission.directory)); - await commands.executeCommand('remote-containers.openFolder', Uri.file(this.mission.directory)); + assert(existsSync(this.dirs.missionWorkdir)); + await commands.executeCommand('remote-containers.openFolder', Uri.file(this.dirs.missionWorkdir)); } + private async init() { if (this.isInit) { throw new Error(`${MissionDevContainer.constructor.name} Already initialized`); } - this.isInit = true; await this.createDirectories(...Object.values(this.dirs)); await this.createDevContainerFile(); - await this.createUserChallengeJsonFile(this.user, this.giteaProperties); + await this.createUserChallengeJsonFile(); } - private createUserChallengeJsonFile(user: User, giteaPublicProperties: GiteaPublicProperties) { + private createUserChallengeJsonFile() { return writeFile( `${this.dirs.config}/user-challenge.json`, (() => { const userChallengeJson: UserChallengeJson = { - giteaHost: giteaPublicProperties.sshHost, - giteaSshPort: giteaPublicProperties.sshPort, - username: user.id.split('-').join(''), - email: `${user.id.split('-').join('')}@deadlock.io`, + giteaHost: this.giteaProperties.sshHost, + giteaSshPort: this.giteaProperties.sshPort, + username: this.user.id.split('-').join(''), + email: `${this.user.id.split('-').join('')}@deadlock.io`, missionId: this.mission.id, - remoteGitUsername: user.id.split('-').join(''), - currentUserDetails: user.details, - remoteUserDetails: user.details, + remoteGitUsername: this.user.id.split('-').join(''), + currentUserDetails: this.user.details, + remoteUserDetails: this.user.details, }; return JSON.stringify(userChallengeJson, null, 2); })(), diff --git a/deadlock-plugins/deadlock-extension/src/core/sshKeyManager.ts b/deadlock-plugins/deadlock-extension/src/core/sshKeyManager.ts index e00cb1a01e74ec4ff4c7c66562602ddd1505e46f..94d37e732cb725b21a9faf2c0213c25584e769ba 100644 --- a/deadlock-plugins/deadlock-extension/src/core/sshKeyManager.ts +++ b/deadlock-plugins/deadlock-extension/src/core/sshKeyManager.ts @@ -1,32 +1,31 @@ import * as fs from 'fs'; import { userSshKeyFolderPath } from './config'; -export default class SshKeyManager { - public isSshKeyPairExist(): boolean { - return this.isPrivateKeyExist() && this.isPublicKeyExist(); - } +export function isSshKeyPairExist(): boolean { + return isPrivateKeyExist() && isPublicKeyExist(); +} - private isPublicKeyExist(): boolean { - return fs.existsSync(`${userSshKeyFolderPath}/id_rsa.pub`); - } +function isPublicKeyExist(): boolean { + return fs.existsSync(`${userSshKeyFolderPath}/id_rsa.pub`); +} - private isPrivateKeyExist(): boolean { - return fs.existsSync(`${userSshKeyFolderPath}/id_rsa`); - } +function isPrivateKeyExist(): boolean { + return fs.existsSync(`${userSshKeyFolderPath}/id_rsa`); +} - public async createSshKeyFiles(publicKey: string, privateKey: string) { - await this.createSshKeyFolderIfNotExist(userSshKeyFolderPath); - await fs.promises.writeFile(`${userSshKeyFolderPath}/id_rsa.pub`, publicKey); +export async function createSshKeyFiles(publicKey: string, privateKey: string) { + await createSshKeyFolderIfNotExist(userSshKeyFolderPath); + await fs.promises.writeFile(`${userSshKeyFolderPath}/id_rsa.pub`, publicKey); - await fs.promises.writeFile(`${userSshKeyFolderPath}/id_rsa`, privateKey, { mode: 0o600 }); - } - private async createSshKeyFolderIfNotExist(sshKeyFolderPath) { - if (!this.isSshKeyFolderExist(sshKeyFolderPath)) { - await fs.promises.mkdir(sshKeyFolderPath, { recursive: true }); - } - } + await fs.promises.writeFile(`${userSshKeyFolderPath}/id_rsa`, privateKey, { mode: 0o600 }); +} - private isSshKeyFolderExist(sshKeyFolderPath: string) { - return fs.existsSync(sshKeyFolderPath); +async function createSshKeyFolderIfNotExist(sshKeyFolderPath) { + if (!isSshKeyFolderExist(sshKeyFolderPath)) { + await fs.promises.mkdir(sshKeyFolderPath, { recursive: true }); } } + +export function isSshKeyFolderExist(sshKeyFolderPath: string) { + return fs.existsSync(sshKeyFolderPath); +} diff --git a/deadlock-plugins/deadlock-extension/src/recorder/utils.ts b/deadlock-plugins/deadlock-extension/src/recorder/utils.ts index aad779a410064e9e17955cc4d9694af067592a22..1aa9fbb58d299f4e3bc0b2da0fa3b4e23ee5ce03 100644 --- a/deadlock-plugins/deadlock-extension/src/recorder/utils.ts +++ b/deadlock-plugins/deadlock-extension/src/recorder/utils.ts @@ -12,7 +12,7 @@ const fs = require('fs'); const readdirSync = require('fs').readdirSync; const Path = require('path'); -const PREFIX = '[DEADLOCK-RECORDER]'; +const PREFIX = '[55-RECORDER]'; export const log = (message: any, ...args: any[]) => { if (args) {