Support uploading config files. #14
@ -19,6 +19,7 @@ export const Config = {
|
|||||||
UNDEPLOYER_STATE:
|
UNDEPLOYER_STATE:
|
||||||
process.env.UNDEPLOYER_STATE || '/srv/deployments/autoundeploy.state',
|
process.env.UNDEPLOYER_STATE || '/srv/deployments/autoundeploy.state',
|
||||||
BUILD_LOGS: process.env.BUILD_LOGS || '/srv/logs',
|
BUILD_LOGS: process.env.BUILD_LOGS || '/srv/logs',
|
||||||
|
UPLOAD_MAX_SIZE: process.env.BUILD_LOGS || '1MB',
|
||||||
OPENPGP_PASSPHRASE: process.env.OPENPGP_PASSPHRASE,
|
OPENPGP_PASSPHRASE: process.env.OPENPGP_PASSPHRASE,
|
||||||
OPENPGP_PRIVATE_KEY_FILE: process.env.OPENPGP_PRIVATE_KEY_FILE,
|
OPENPGP_PRIVATE_KEY_FILE: process.env.OPENPGP_PRIVATE_KEY_FILE,
|
||||||
};
|
};
|
||||||
|
@ -10,7 +10,8 @@ import { Uploader } from './upload.js';
|
|||||||
const app = express();
|
const app = express();
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|
||||||
const uploader = new Uploader(Config.UPLOAD_DIRECTORY);
|
const configUploader = new Uploader(Config.UPLOAD_DIRECTORY);
|
||||||
|
const configUploadParser = bodyParser.raw({limit: Config.UPLOAD_MAX_SIZE, type: "*/*"})
|
||||||
|
|
||||||
app.use(function (_req, res, next) {
|
app.use(function (_req, res, next) {
|
||||||
res.header('Access-Control-Allow-Origin', '*');
|
res.header('Access-Control-Allow-Origin', '*');
|
||||||
@ -99,10 +100,9 @@ app.get('/:id/log', async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const rawParser = bodyParser.raw({limit: "1MB", type: "*/*"})
|
app.post('/upload/config', configUploadParser, async (req, res) => {
|
||||||
app.post('/upload/config', rawParser, async (req, res) => {
|
|
||||||
try {
|
try {
|
||||||
const id = await uploader.upload(req.body);
|
const id = await configUploader.upload(req.body);
|
||||||
res.json({
|
res.json({
|
||||||
id
|
id
|
||||||
});
|
});
|
||||||
|
@ -43,9 +43,6 @@ export const b64ToBytes = (base64): Uint8Array => {
|
|||||||
return bytes;
|
return bytes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const decrypt = async (binaryMessage: Uint8Array): Promise<any> => {
|
const decrypt = async (binaryMessage: Uint8Array): Promise<any> => {
|
||||||
const message = await openpgp.readMessage({
|
const message = await openpgp.readMessage({
|
||||||
binaryMessage,
|
binaryMessage,
|
||||||
@ -74,16 +71,20 @@ export class Uploader {
|
|||||||
} catch {
|
} catch {
|
||||||
raw = body;
|
raw = body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We decrypt only to make sure the content is valid.
|
||||||
|
// Once we know it is good, we want to store the encrypted copy.
|
||||||
const obj = await decrypt(raw);
|
const obj = await decrypt(raw);
|
||||||
validateConfig(obj);
|
validateConfig(obj);
|
||||||
|
|
||||||
let id = randomId();
|
let id: string;
|
||||||
let destination: string;
|
let destination: string;
|
||||||
do {
|
do {
|
||||||
id = randomId();
|
id = randomId();
|
||||||
destination = `${this.directory}/${id}`;
|
destination = `${this.directory}/${id}`;
|
||||||
} while (fs.existsSync(destination));
|
} while (fs.existsSync(destination));
|
||||||
|
|
||||||
|
console.log(`Wrote config to: ${destination}`);
|
||||||
fs.writeFileSync(destination, raw);
|
fs.writeFileSync(destination, raw);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user