mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-30 22:34:10 -05:00
publishing package to all relevant uplinks
This commit is contained in:
parent
57b34a7637
commit
0173c55ead
3 changed files with 57 additions and 15 deletions
|
@ -27,15 +27,27 @@ function Storage(config) {
|
|||
}
|
||||
|
||||
//
|
||||
// TODO: badly documented
|
||||
// Add a {name} package to a system
|
||||
//
|
||||
// Function checks if package with the same name is available from uplinks.
|
||||
// If it isn't, we create package metadata locally and send requests to do
|
||||
// the same to all uplinks with write access. If all actions succeeded, we
|
||||
// report success, if just one uplink fails, we abort.
|
||||
//
|
||||
// TODO: if a package is uploaded to uplink1, but upload to uplink2 fails,
|
||||
// we report failure, but package is not removed from uplink1. This might
|
||||
// require manual intervention.
|
||||
//
|
||||
// Used storages: local (write) && uplinks (proxy_access, r/o) &&
|
||||
// uplinks (proxy_publish, write)
|
||||
//
|
||||
Storage.prototype.add_package = function(name, metadata, callback) {
|
||||
var self = this;
|
||||
|
||||
var uplinks = [];
|
||||
for (var i in this.uplinks) {
|
||||
if (this.config.proxy_access(name, i)) {
|
||||
uplinks.push(this.uplinks[i]);
|
||||
for (var i in self.uplinks) {
|
||||
if (self.config.proxy_access(name, i)) {
|
||||
uplinks.push(self.uplinks[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,8 +77,24 @@ Storage.prototype.add_package = function(name, metadata, callback) {
|
|||
}
|
||||
}
|
||||
|
||||
uplinks = [];
|
||||
for (var i in self.uplinks) {
|
||||
if (self.config.proxy_publish(name, i)) {
|
||||
uplinks.push(self.uplinks[i]);
|
||||
}
|
||||
}
|
||||
async.map(uplinks, function(up, cb) {
|
||||
up.add_package(name, metadata, cb);
|
||||
}, function(err, results) {
|
||||
if (err) {
|
||||
return callback(new UError({
|
||||
status: 503,
|
||||
msg: 'can\'t upload to one of the uplinks, refuse to publish'
|
||||
}));
|
||||
}
|
||||
self.local.add_package(name, metadata, callback);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -38,7 +38,21 @@ Storage.prototype.can_fetch_url = function(url) {
|
|||
}
|
||||
|
||||
Storage.prototype.add_package = function(name, metadata, callback) {
|
||||
throw new Error('unimplemented');
|
||||
request({
|
||||
url: this.config.url + '/' + name,
|
||||
headers: {
|
||||
'User-Agent': this.ua,
|
||||
},
|
||||
method: 'PUT',
|
||||
ca: this.ca,
|
||||
json: metadata,
|
||||
}, function(err, res, body) {
|
||||
if (err) return callback(err);
|
||||
if (!(res.statusCode >= 200 && res.statusCode < 300)) {
|
||||
return callback(new Error('bad status code: ' + res.statusCode));
|
||||
}
|
||||
callback(null, body);
|
||||
});
|
||||
}
|
||||
|
||||
Storage.prototype.add_version = function(name, version, metadata, tag, callback) {
|
||||
|
|
|
@ -3,7 +3,7 @@ var readfile = require('fs').readFileSync;
|
|||
var ex = module.exports;
|
||||
var server = process.server;
|
||||
var server2 = process.server2;
|
||||
/*
|
||||
|
||||
ex['creating new package'] = function(cb) {
|
||||
server.put_package('testfwd', readfile('fixtures/fwd-package.json'), function(res, body) {
|
||||
assert(res.statusCode === 201);
|
||||
|
@ -21,16 +21,16 @@ ex['uploading new package version'] = function(cb) {
|
|||
};
|
||||
|
||||
ex['downloading package via server2'] = function(cb) {
|
||||
server2.get_package('testpkg', function(res, body) {
|
||||
assert(res.statusCode === 200);
|
||||
assert(body.name === 'testfwd');
|
||||
assert(body.versions['0.1.1'].name === 'testfwd');
|
||||
assert(body.versions['0.1.1'].dist.tarball === 'http://localhost:55552/testpkg/-/blahblah');
|
||||
server2.get_package('testfwd', function(res, body) {
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert.equal(body.name, 'testfwd');
|
||||
assert.equal(body.versions['0.1.1'].name, 'testfwd');
|
||||
assert.equal(body.versions['0.1.1'].dist.tarball, 'http://localhost:55552/testpkg/-/blahblah');
|
||||
cb();
|
||||
});
|
||||
};
|
||||
*/
|
||||
|
||||
/*
|
||||
ex['creating - srv1 (remove it)'] = function(cb) {
|
||||
server.put_package('testfwd', readfile('fixtures/fwd-package.json'), function(res, body) {
|
||||
assert(res.statusCode === 201);
|
||||
|
@ -68,4 +68,4 @@ ex['downloading tarball from server2'] = function(cb) {
|
|||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue