While someone has a workspace open, the gateway asks the API for a 15-minute write token for the project's platform repository on behalf of that person (membership and role checked each time) and delivers it to the workspace backend. The backend writes it to a Git config file outside the repository (a memory volume in Kubernetes) that the clone includes, and on the first delivery clones the target branch into a folder named after the project. The workspace cannot mint credentials itself, so access ends with the last session. - People commit and push to the target branch like with any Git server; the platform only accepts fast-forwards, and the next wish starts from that commit (covered end to end in the local loop test). - Commits are authored by whoever opened the latest session, from the name and email in their sign-in; their own git config overrides it. - Only the gateway can reach the delivery endpoint: it needs Theia's connection token, and the gateway refuses the path for browsers. - The provisioner pins the workspace to its repository and lets the pod reach the Git service; the Kubernetes baseline admits that traffic. External repositories are not cloned. - The local shared Theia clones each project into its own folder. - The Theia image installs Git, and its stage is named theia: the default build target of that Dockerfile is the gateway. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
44 lines
1.7 KiB
JavaScript
44 lines
1.7 KiB
JavaScript
'use strict';
|
|
const { decorate, inject, injectable } = require('@theia/core/shared/inversify');
|
|
const express = require('@theia/core/shared/express');
|
|
const { HttpConnectionValidator } = require('@theia/core/lib/node');
|
|
const {
|
|
CREDENTIAL_PATH,
|
|
GitWorkspaceError,
|
|
createGitWorkspace,
|
|
readGitWorkspaceConfig,
|
|
} = require('./git-workspace.cjs');
|
|
|
|
/**
|
|
* Receives the repository credential from the workspace gateway. Theia's connection token,
|
|
* which only the gateway holds, is required; the gateway refuses to forward this path for people.
|
|
*/
|
|
class GitCredentialEndpoint {
|
|
configure(app) {
|
|
const config = readGitWorkspaceConfig(process.env);
|
|
if (!config) return;
|
|
const workspace = createGitWorkspace(config);
|
|
app.post(
|
|
CREDENTIAL_PATH,
|
|
(req, res, next) => this.connectionValidator.validateRequest(req, res, next),
|
|
express.json({ limit: '16kb' }),
|
|
async (req, res) => {
|
|
try {
|
|
const { status, directory } = await workspace.apply(req.body);
|
|
res.status(200).json({ status, directory });
|
|
} catch (error) {
|
|
const known = error instanceof GitWorkspaceError;
|
|
if (!known || error.code !== 'INVALID_GIT_CREDENTIAL')
|
|
console.error(`WishForge Git workspace update failed: ${error.message}`);
|
|
res
|
|
.status(known && error.code === 'INVALID_GIT_CREDENTIAL' ? 400 : 500)
|
|
.json({ error: known ? error.code : 'GIT_WORKSPACE_FAILED' });
|
|
}
|
|
},
|
|
);
|
|
}
|
|
}
|
|
decorate(inject(HttpConnectionValidator), GitCredentialEndpoint.prototype, 'connectionValidator');
|
|
decorate(injectable(), GitCredentialEndpoint);
|
|
module.exports = { GitCredentialEndpoint };
|