Skip to content
This repository was archived by the owner on Apr 2, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ To ensure only valid updates are processed, all requests must provide an authent
The configuration is managed in `config` directory. [The `default.json`](config/default.json) file as the name suggested is used as a base configuration, every entry can
be overwritten in env-specific config files (see [`kovan.json`](config/kovan.json) as an example). Feel free to add your override to that directory.

To load a specific config file run with `NODE_ENV` environment variable set to the name of the config file. E.g. `NODE_ENV="kovan" node server.js`
To load a specific config file run with `NODE_ENV` environment variable set to the name of the config file. E.g. `NODE_ENV="kovan" node index.js`
will run the server using `kovan.json` settings.

Some parameters can also be overridden by environment variables. See [`config/custom-environment-variables.json`](config/custom-environment-variables.json) for all possible options. Notable ones:
Expand Down
2 changes: 1 addition & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"gasPrice": "0x4F9ACA000"
},
"enabledTracks": ["stable", "beta"],
"secretHash": "ffa69b8d6bc6f7466e51ff21931295be5d5234dafc5f3ff034f68d59918744c4",
"secretHash": "9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658",
"repository": "paritytech/parity",
"assetsBaseUrl": "http://d1h4xl4cr1h0mo.cloudfront.net",
"supportedPlatforms": ["x86_64-apple-darwin", "x86_64-pc-windows-msvc", "x86_64-unknown-linux-gnu"]
Expand Down
1 change: 1 addition & 0 deletions config/kovan.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"address": "0x004E9a7d60af10f7A8866b868e36b86D4A9bA450",
"gasPrice": null
},
"secretHash": "ffa69b8d6bc6f7466e51ff21931295be5d5234dafc5f3ff034f68d59918744c4",
"enabledTracks": ["stable", "beta", "nightly", "master", "testing"]
}
3 changes: 3 additions & 0 deletions config/production.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"secretHash": "ffa69b8d6bc6f7466e51ff21931295be5d5234dafc5f3ff034f68d59918744c4"
}
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const config = require('config');
const httpPort = config.get('http.port');
const app = require('./server');

const server = app.listen(httpPort, function () {
const host = server.address().address;
const port = server.address().port;
console.log('push-release service listening at http://%s:%s', host, port);
});
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"version": "0.1.0",
"description": "Web service to push a new release onto the chain",
"author": "Parity Technologies <admin@parity.io>",
"main": "server.js",
"main": "index.js",
"scripts": {
"start": "node server.js",
"test": "npm run lint",
"start": "node index.js",
"test": "npm run lint && npm run test:integration",
"test:integration": "mocha --exit",
"lint": "eslint *.js"
},
"dependencies": {
Expand All @@ -18,12 +19,17 @@
"request": "^2.79.0"
},
"devDependencies": {
"chai": "4.1.2",
"chai-http": "3.0.0",
"eslint": "4.17.0",
"eslint-config-semistandard": "12.0.0",
"eslint-config-standard": "11.0.0-beta.0",
"eslint-plugin-import": "2.8.0",
"eslint-plugin-node": "6.0.0",
"eslint-plugin-promise": "3.6.0",
"eslint-plugin-standard": "3.0.1"
"eslint-plugin-standard": "3.0.1",
"mocha": "5.0.0",
"mock-http-server": "0.2.0",
"sinon": "4.2.2"
}
}
4 changes: 2 additions & 2 deletions push-release.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"name": "push-release",
"script": "server.js",
"script": "index.js",
"log_date_format": "YYYY-MM-DD HH:mm Z",
"merge_logs": false,
"watch": false,
Expand All @@ -15,7 +15,7 @@
},
{
"name": "push-release-kovan",
"script": "server.js",
"script": "index.js",
"log_date_format": "YYYY-MM-DD HH:mm Z",
"merge_logs": false,
"watch": false,
Expand Down
79 changes: 43 additions & 36 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const api = new Parity.Api(transport);

const app = express();
app.use(bodyParser.urlencoded({extended: true}));
module.exports = app;

const reduceObject = (obj, prop) => ({ ...obj, [prop]: true });
const enabledTracks = config.get('enabledTracks').reduce(reduceObject, {});
Expand Down Expand Up @@ -45,7 +46,7 @@ const tracks = {

app.post('/push-release/:tag/:commit', handleAsync(async function (req, res) {
if (keccak256(req.body.secret || '') !== secretHash) {
throw new Error('Bad request');
throw new Error('Invalid secret');
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this bit be a middleware if it's used several times?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had the same idea, realized in #8

}
const { commit, tag } = req.params;

Expand All @@ -61,7 +62,11 @@ app.post('/push-release/:tag/:commit', handleAsync(async function (req, res) {
console.log(`Pushing commit: ${commit} (tag: ${tag}/${goodTag})`);

const miscBody = await fetchFile(commit, '/util/src/misc.rs');
const branch = miscBody.match(`const THIS_TRACK. ..static str = "([a-z]*)";`)[1];
const branch = match(
miscBody,
/const THIS_TRACK. ..static str = "([a-z]*)";/,
'Unable to detect track'
)[1];
const track = tracks[branch] ? branch : 'testing';
console.log(`Track: ${branch} => ${track} (${tracks[track]}) [enabled: ${enabledTracks[track]}]`);

Expand All @@ -71,24 +76,24 @@ app.post('/push-release/:tag/:commit', handleAsync(async function (req, res) {

let ethereumMod = await fetchFile(commit, '/ethcore/src/ethereum/mod.rs');
const network = await getNetwork();
const pattern = `pub const FORK_SUPPORTED_${network.toUpperCase()}: u64 = (\\d+);`;
const m = ethereumMod.match(pattern);
if (m === null) {
throw new Error(`Unable to detect supported fork with pattern: ${pattern}.`);
}

const forkSupported = m[1];

// Return a response already.
res.send(`RELEASE: ${commit}/${track}/${branch}/${forkSupported}`);
const forkSupported = match(
ethereumMod,
`pub const FORK_SUPPORTED_${network.toUpperCase()}: u64 = (\\d+);`,
'Unable to detect supported fork'
)[1];

console.log(`Fork supported: ${forkSupported}`);

let cargoToml = await fetchFile(commit, 'Cargo.toml');
const version = cargoToml.match(/version = "([0-9]+)\.([0-9]+)\.([0-9]+)"/).slice(1);
const semver = +version[0] * 65536 + +version[1] * 256 + +version[2];
const cargoToml = await fetchFile(commit, '/Cargo.toml');
const versionMatch = match(
cargoToml,
/version = "([0-9]+)\.([0-9]+)\.([0-9]+)"/,
'Unable to detect version'
);
const [major, minor, patch] = versionMatch.slice(1).map(x => parseInt(x, 10));
const semver = major * 65536 + minor * 256 + patch;

console.log(`Version: ${version.join('.')} = ${semver}`);
console.log(`Version: ${versionMatch.join('.')} = ${semver}`);

const registryAddress = await api.parity.registryAddress();
console.log(`Registry address: ${registryAddress}`);
Expand All @@ -97,16 +102,16 @@ app.post('/push-release/:tag/:commit', handleAsync(async function (req, res) {
const operationsAddress = await registry.instance.getAddress.call({}, [operationsContract, 'A']);
console.log(`Parity operations address: ${operationsAddress}`);
console.log(`Registering release: 0x000000000000000000000000${commit}, ${forkSupported}, ${tracks[track]}, ${semver}, ${isCritical}`);
// Should be this...
// api.newContract(OperationsABI, a).instance.addRelease.postTransaction({from: account.address}, [`0x000000000000000000000000${commit}`, forkSupported, tracks[track], semver, isCritical])
// ...but will have to be this for now...
const hash = await sendTransaction(OperationsABI, operationsAddress, 'addRelease', [`0x000000000000000000000000${commit}`, forkSupported, tracks[track], semver, isCritical]);
console.log(`Transaction sent with hash: ${hash}`);

// Return the response
res.send(`RELEASE: ${commit}/${track}/${branch}/${forkSupported}`);
}));

app.post('/push-build/:tag/:platform', handleAsync(async function (req, res) {
if (keccak256(req.body.secret || '') !== secretHash) {
throw new Error('Bad request');
throw new Error('Invalid secret');
}

const { tag, platform } = req.params;
Expand All @@ -124,8 +129,12 @@ app.post('/push-build/:tag/:platform', handleAsync(async function (req, res) {
throw new Error(`Invalid sha3 (${sha3}), tag (${tag}) or platform (${platform}).`);
}

let body = await fetchFile(commit, '/util/src/misc.rs');
const branch = body.match(`const THIS_TRACK. ..static str = "([a-z]*)";`)[1];
const body = await fetchFile(commit, '/util/src/misc.rs');
const branch = match(
body,
/const THIS_TRACK. ..static str = "([a-z]*)"/,
'Unable to detect track'
)[1];
const track = tracks[branch] ? branch : 'testing';

console.log(`Track: ${branch} => ${track} (${tracks[track]}) [enabled: ${!!enabledTracks[track]}]`);
Expand All @@ -136,34 +145,32 @@ app.post('/push-build/:tag/:platform', handleAsync(async function (req, res) {

// make sure the node is running
await getNetwork();
// Respond already
res.send(out);

const registryAddress = await api.parity.registryAddress();
const reg = api.newContract(RegistrarABI, registryAddress);
const githubHintAddress = await reg.instance.getAddress.call({}, [githubHint, 'A']);

console.log(`Registering on GithubHint: ${sha3}, ${url}`);
// Should be this...
// api.newContract(GitHubHintABI, g).instance.hintURL.postTransaction({from: account.address}, [`0x${sha3}`, url]).then(() => {
// ...but will have to be this for now...
const hash = await sendTransaction(GitHubHintABI, githubHintAddress, 'hintURL', [`0x${sha3}`, url]);
console.log(`Transaction sent with hash: ${hash}`);

const operationsAddress = reg.instance.getAddress.call({}, [operationsContract, 'A']);
const operationsAddress = await reg.instance.getAddress.call({}, [operationsContract, 'A']);
console.log(`Registering platform binary: ${commit}, ${platform}, ${sha3}`);
// Should be this...
// return api.newContract(OperationsABI, o).instance.addChecksum.postTransaction({from: account.address}, [`0x000000000000000000000000${commit}`, platform, `0x${sha3}`]);
// ...but will have to be this for now...
const hash2 = await sendTransaction(OperationsABI, operationsAddress, 'addChecksum', [`0x000000000000000000000000${commit}`, platform, `0x${sha3}`]);
console.log(`Transaction sent with hash: ${hash2}`);

// Respond already
res.send(out);
}));

const server = app.listen(httpPort, function () {
const host = server.address().address;
const port = server.address().port;
console.log('push-release service listening at http://%s:%s', host, port);
});
function match (string, pattern, comment) {
const match = string.match(pattern);
if (!match) {
throw new Error(`${comment} in ${string}`);
}

return match;
}

function handleAsync (asyncFn) {
return (req, res) => asyncFn(req, res)
Expand Down
Loading