Skip to content
Permalink
Browse files

[repo] s3 repository support, protocol:s3,url:path/file,auth:{secret:…

…,key:,bucket:}
  • Loading branch information...
bmeck committed Jul 25, 2012
1 parent 942689c commit a1fbe4f64fac68c8e9a07bf802dbcf22b3c93544
Showing with 35 additions and 2 deletions.
  1. +33 −0 lib/haibu/repositories/remote-file.js
  2. +2 −2 package.json
@@ -12,6 +12,7 @@ var util = require('util'),
request = require('request'),
cloudfiles = require('cloudfiles'),
haibu = require('../../haibu'),
knox = require('knox'),
Repository = require('./repository').Repository;

//
@@ -75,6 +76,9 @@ RemoteFile.prototype.fetch = function (callback) {

this.fetchCloudfiles(options, callback);
}
else if (protocol === 's3') {
this.fetchS3(this.app.repository.url, callback);
}
else {
var err = new Error('Cannot fetch app with unknown protocol: ' + this.app.repository.protocol);
err.blame = {
@@ -112,6 +116,35 @@ RemoteFile.prototype.fetchCloudfiles = function (options, callback) {
});
};

//
// ### function fetchCloudfiles (options, callback)
// #### @options {Object} Options for the Cloudfiles remote
// #### @callback {function} Continuation to pass control back to when complete.
// Fetches the file specified by `options.filename` from the Rackspace Cloudfiles
// container specified by `options.container` then saves it to the local packages cache.
//
RemoteFile.prototype.fetchS3 = function (filename, callback) {
var self = this,
localFile = path.join(this.packageDir, filename),
localStream = fs.createWriteStream(localFile),
done = false,
client = knox.createClient(this.app.repository.auth);

client.get(filename).on('response', function (res) {
if (done) return;
done = true;
localStream.once('close', function () {
callback(null, localFile);
});
res.pipe(localStream);
}).on('error', function (e) {
if (done) return;
done = true;
localStream.end();
callback(e);
}).end();
};

//
// ### function fetchHttp (remotePath, callback)
// #### @remotePath {string} Location of the remote HTTP/HTTPS file
@@ -30,7 +30,8 @@
"semver": "1.0.13",
"tar": "0.1.13",
"winston": "0.6.2",
"union": "0.3.3"
"union": "0.3.3",
"knox": "0.0.11"
},
"devDependencies": {
"winston-loggly": "0.6.0",
@@ -47,4 +48,3 @@
"node": ">= 0.8.0"
}
}

0 comments on commit a1fbe4f

Please sign in to comment.
You can’t perform that action at this time.