Skip to content

Commit

Permalink
Fix support for Rackspace ServiceNet
Browse files Browse the repository at this point in the history
  • Loading branch information
rossj committed Aug 22, 2014
1 parent 2df4ab9 commit 9407358
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 51 deletions.
6 changes: 4 additions & 2 deletions lib/rackit.js
Expand Up @@ -32,7 +32,8 @@ var Rackit = function (options) {
provider : 'rackspace',
username : this.options.user,
apiKey : this.options.key,
region : this.options.region
region : this.options.region,
useInternal : this.options.useSNET
});

this.config = null;
Expand Down Expand Up @@ -150,6 +151,7 @@ Rackit.prototype._getContainers = function (cb) {
async.whilst(function () {
return next >= 0;
}, function (cb) {
o1._log('Probing for container ' + o1.options.prefix + next);
o1._client.getContainer(o1.options.prefix + next, function (err, container) {
if ( err && err.statusCode && err.statusCode >= 500 ) {
return cb(err);
Expand All @@ -164,7 +166,7 @@ Rackit.prototype._getContainers = function (cb) {
});
}, function (err) {
if ( !err ) {
o1._log('Got ' + aContainers.count + ' containers');
o1._log('Got ' + aContainers.length + ' containers');
o1.aContainers = aContainers;
}
cb(err);
Expand Down
90 changes: 45 additions & 45 deletions test/cloudfiles.mock.js
Expand Up @@ -15,12 +15,6 @@ var
var authResponse = require('./auth-response.json');
var Rackit = require('../lib/main.js').Rackit;

var mockOptions = {
storage : 'https://storage101.dfw1.clouddrive.com/v1/MossoCloudFS_aaaaaaaa-bbbb-cccc-dddd-eeeeeeee',
cdn : 'https://cdn1.clouddrive.com/v1/MossoCloudFS_aaaaaaaa-bbbb-cccc-dddd-eeeeeeee',
token : authResponse.access.token.id
};

var Mock = module.exports = function (rackitOptions, aContainers, aCDNContainers) {
this.rackitOptions = Object.create(Rackit.defaultOptions);

Expand All @@ -31,6 +25,12 @@ var Mock = module.exports = function (rackitOptions, aContainers, aCDNContainers
}
}

this.mockOptions = {
storage : 'https://' + (rackitOptions.useSNET ? 'snet-' : '') + 'storage101.dfw1.clouddrive.com/v1/MossoCloudFS_aaaaaaaa-bbbb-cccc-dddd-eeeeeeee',
cdn : 'https://cdn1.clouddrive.com/v1/MossoCloudFS_aaaaaaaa-bbbb-cccc-dddd-eeeeeeee',
token : authResponse.access.token.id
};

this.aContainers = aContainers;
this.aCDNContainers = aCDNContainers;
this.scopes = [];
Expand Down Expand Up @@ -73,8 +73,8 @@ Mock.prototype = {
return this;
},
tempURL : function (key) {
var path = url.parse(mockOptions.storage).pathname;
var scope = nock(mockOptions.storage)
var path = url.parse(this.mockOptions.storage).pathname;
var scope = nock(this.mockOptions.storage)
.post(path)
.matchHeader('X-Account-Meta-Temp-Url-Key', key)
.reply(204, 'No Content');
Expand All @@ -94,21 +94,21 @@ Mock.prototype = {
return this;
},
storage : function () {
var path = url.parse(mockOptions.storage).pathname + '?format=json';
var scope = nock(mockOptions.storage)
var path = url.parse(this.mockOptions.storage).pathname + '?format=json';
var scope = nock(this.mockOptions.storage)
.get(path)
.matchHeader('X-Auth-Token', mockOptions.token)
.matchHeader('X-Auth-Token', this.mockOptions.token)
.reply(200, JSON.stringify(this.aContainers));

this.scopes.push(scope);
return this;
},
storageHead : function (container) {
var _container = _.find(this.aContainers, { name : container });
var path = url.parse(mockOptions.storage).pathname + '/' + container;
var scope = nock(mockOptions.storage)
var path = url.parse(this.mockOptions.storage).pathname + '/' + container;
var scope = nock(this.mockOptions.storage)
.head(path)
.matchHeader('X-Auth-Token', mockOptions.token);
.matchHeader('X-Auth-Token', this.mockOptions.token);

if ( _container ) {
scope = scope.reply(204, '', {
Expand Down Expand Up @@ -141,21 +141,21 @@ Mock.prototype = {
return containers;
},
CDN : function () {
var path = url.parse(mockOptions.cdn).pathname + '?format=json';
var scope = nock(mockOptions.cdn)
var path = url.parse(this.mockOptions.cdn).pathname + '?format=json';
var scope = nock(this.mockOptions.cdn)
.get(path)
.matchHeader('X-Auth-Token', mockOptions.token)
.matchHeader('X-Auth-Token', this.mockOptions.token)
.reply(200, JSON.stringify(this.aCDNContainers));

this.scopes.push(scope);
return this;
},
CDNHead : function (container) {
var _container = _.find(this.aCDNContainers, { name : container });
var path = url.parse(mockOptions.cdn).pathname + '/' + container;
var scope = nock(mockOptions.cdn)
var path = url.parse(this.mockOptions.cdn).pathname + '/' + container;
var scope = nock(this.mockOptions.cdn)
.head(path)
.matchHeader('X-Auth-Token', mockOptions.token);
.matchHeader('X-Auth-Token', this.mockOptions.token);

if ( _container ) {
scope = scope.reply(204, '', {
Expand All @@ -182,9 +182,9 @@ Mock.prototype = {
});
},
add : function (container, data, type, length, cb) {
var path = url.parse(mockOptions.storage).pathname + '/' + container + '/filename';
var path = url.parse(this.mockOptions.storage).pathname + '/' + container + '/filename';
var lastPath;
var scope = nock(mockOptions.storage)
var scope = nock(this.mockOptions.storage)
.filteringPath(function(path) {
lastPath = path;
var r = new RegExp(container + '/.*', 'g');
Expand All @@ -204,7 +204,7 @@ Mock.prototype = {
}

scope = scope
.matchHeader('X-Auth-Token', mockOptions.token)
.matchHeader('X-Auth-Token', this.mockOptions.token)
.matchHeader('Content-Type', type)
.matchHeader('ETag', undefined);

Expand All @@ -223,16 +223,16 @@ Mock.prototype = {
return this;
},
head : function (cloudpath, response, headers) {
var path = url.parse(mockOptions.storage).pathname + '/' + cloudpath + '?format=json';
var scope = nock(mockOptions.storage)
var path = url.parse(this.mockOptions.storage).pathname + '/' + cloudpath + '?format=json';
var scope = nock(this.mockOptions.storage)
.head(path)
.reply(response, '', headers);
this.scopes.push(scope);
return this;
},
post : function (cloudpath, response, headers) {
var path = url.parse(mockOptions.storage).pathname + '/' + cloudpath;
var scope = nock(mockOptions.storage)
var path = url.parse(this.mockOptions.storage).pathname + '/' + cloudpath;
var scope = nock(this.mockOptions.storage)
.post(path);

for (var key in headers) {
Expand All @@ -244,16 +244,16 @@ Mock.prototype = {
return this;
},
get : function (cloudpath, data) {
var path = url.parse(mockOptions.storage).pathname + '/' + cloudpath;
var scope = nock(mockOptions.storage)
var path = url.parse(this.mockOptions.storage).pathname + '/' + cloudpath;
var scope = nock(this.mockOptions.storage)
.get(path)
.reply(200, data);
this.scopes.push(scope);
return this;
},
remove : function (cloudpath, response) {
var path = url.parse(mockOptions.storage).pathname + '/' + (cloudpath || 'cloudpath');
var scope = nock(mockOptions.storage);
var path = url.parse(this.mockOptions.storage).pathname + '/' + (cloudpath || 'cloudpath');
var scope = nock(this.mockOptions.storage);

if (!cloudpath)
scope = scope.filteringPath(function(path) {
Expand All @@ -266,29 +266,29 @@ Mock.prototype = {
return this;
},
createContainer : function (container) {
var path = url.parse(mockOptions.storage).pathname + '/' + container;
var scope = nock(mockOptions.storage)
var path = url.parse(this.mockOptions.storage).pathname + '/' + container;
var scope = nock(this.mockOptions.storage)
.put(path)
.matchHeader('X-Auth-Token', mockOptions.token)
.matchHeader('X-Auth-Token', this.mockOptions.token)
.reply(201);

this.scopes.push(scope);
return this;
},
enableCDN : function (container) {
var path = url.parse(mockOptions.cdn).pathname + '/' + container;
var scope = nock(mockOptions.cdn)
var path = url.parse(this.mockOptions.cdn).pathname + '/' + container;
var scope = nock(this.mockOptions.cdn)
.put(path)
.matchHeader('X-Auth-Token', mockOptions.token)
.matchHeader('X-Auth-Token', this.mockOptions.token)
.reply(201);

this.scopes.push(scope);

// pkgcloud refreshes container info after CDN enabling
path = url.parse(mockOptions.storage).pathname + '/' + container;
scope = nock(mockOptions.storage)
path = url.parse(this.mockOptions.storage).pathname + '/' + container;
scope = nock(this.mockOptions.storage)
.head(path)
.matchHeader('X-Auth-Token', mockOptions.token)
.matchHeader('X-Auth-Token', this.mockOptions.token)
.reply(204, '', {
'X-Container-Bytes-Used' : 0,
'X-Container-Object-Count' : 0
Expand All @@ -297,10 +297,10 @@ Mock.prototype = {
this.scopes.push(scope);

// pkgcloud refreshes cdn container info after CDN enabling
path = url.parse(mockOptions.cdn).pathname + '/' + container;
scope = nock(mockOptions.cdn)
path = url.parse(this.mockOptions.cdn).pathname + '/' + container;
scope = nock(this.mockOptions.cdn)
.head(path)
.matchHeader('X-Auth-Token', mockOptions.token)
.matchHeader('X-Auth-Token', this.mockOptions.token)
.reply(204, '', {
'X-Cdn-Enabled' : 'True',
'X-Log-Retention' : 'False'
Expand All @@ -314,7 +314,7 @@ Mock.prototype = {
var containers = this.getPrefixedContainers(prefix);
var i = containers.length;
var container, basepath, path, count, j, objects;
var scope = nock(mockOptions.storage);
var scope = nock(this.mockOptions.storage);

// There may be more than one container with this prefix, and the client will be requesting from all
while ( i-- ) {
Expand All @@ -324,7 +324,7 @@ Mock.prototype = {
if ( container.name.indexOf(prefix) !== 0 )
continue;

basepath = url.parse(mockOptions.storage).pathname + '/' + container.name;
basepath = url.parse(this.mockOptions.storage).pathname + '/' + container.name;
basepath += '?format=json&limit=' + limit;

// If the container has no objects, respond with 204.
Expand Down
8 changes: 4 additions & 4 deletions test/rackit.test.js
Expand Up @@ -21,7 +21,8 @@ var rackitOptions = {
region : 'DFW',
user : 'boopity',
key : 'bop',
tempURLKey : '3522d2sa'
tempURLKey : '3522d2sa',
useSNET : true
};


Expand Down Expand Up @@ -226,7 +227,6 @@ describe('Rackit', function () {
});

it('should not return an error with good credentials', function (cb) {
this.timeout(10000);
superNock.typicalResponse().containerHead(['dev0']);

var rackit = new Rackit(rackitOptions);
Expand Down Expand Up @@ -324,7 +324,7 @@ describe('Rackit', function () {
describe('empty existing container', function () {
// Start off each test with a new, initialized rackit
beforeEach(function (cb) {
superNock.typicalResponse().containerHead(['empty0']);
superNock.typicalResponse().containerHead(['empty0', 'empty1']);
rackit = new Rackit(rackitOptions);
rackit.options.prefix = 'empty';
rackit.init(function (err) {
Expand Down Expand Up @@ -612,7 +612,7 @@ describe('Rackit', function () {
describe('with full existing container', function () {
// Start off each test with a new, initialized rackit
beforeEach(function (cb) {
superNock.typicalResponse().containerHead(['full0']);
superNock.typicalResponse().containerHead(['full0', 'full1']);
rackit = new Rackit(rackitOptions);
rackit.options.prefix = 'full';
rackit.init(function (err) {
Expand Down

0 comments on commit 9407358

Please sign in to comment.