From 49d22024de8bfdf276d5d27de54bf41f700031a6 Mon Sep 17 00:00:00 2001 From: Alexander Hadik Date: Sat, 21 May 2016 23:45:55 -0500 Subject: [PATCH] Use OpenStack API V1 SoftLayer Object Storage still uses the OpenStack API V1, so we need to indicate in the call to pkgcloud. API Version now passed as a parameter and API specific client info generated as a result Credential key type for V2 fixed Reverting back to custom pkgcloud dependency --- index.js | 30 +++++++++++++++++++++--------- package.json | 2 +- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 821a1e8..39dd6e0 100644 --- a/index.js +++ b/index.js @@ -2,16 +2,28 @@ var pkgcloud = require("pkgcloud"), Writable = require("stream").Writable, _ = require("underscore"); -function getClient(credentials) { - return pkgcloud.storage.createClient({ - provider: 'openstack', +function getClient(credentials, version) { + if (version == 1){ + var clientInfo = { + provider: 'openstack', + username: credentials.userId, + password: credentials.password, + authUrl: credentials.auth_url, + version: 1, + useServiceCatalog: false + } + }else{ + var clientInfo = { + provider: 'openstack', username: credentials.userId, password: credentials.password, authUrl: credentials.auth_url, tenantId: credentials.projectId, region: credentials.region, version: "2" - }); + } + } + return pkgcloud.storage.createClient(clientInfo); } module.exports = function SwiftStore(globalOpts) { @@ -20,7 +32,7 @@ module.exports = function SwiftStore(globalOpts) { var adapter = { read: function(options, file, response) { - var client = getClient(options.credentials); + var client = getClient(options.credentials, options.version); client.download({ container: options.container, remote: file, @@ -31,7 +43,7 @@ module.exports = function SwiftStore(globalOpts) { rm: function(fd, cb) { return cb(new Error('TODO')); }, ls: function(options, callback) { - var client = getClient(options.credentials); + var client = getClient(options.credentials, options.version); client.getFiles(options.container, function (error, files) { return callback(error, files); @@ -44,7 +56,7 @@ module.exports = function SwiftStore(globalOpts) { }); receiver._write = function onFile(__newFile, encoding, done) { - var client = getClient(options.credentials); + var client = getClient(options.credentials, options.version); console.log("Uploading file with name", __newFile.filename); __newFile.pipe(client.upload({ container: options.container, @@ -70,8 +82,8 @@ module.exports = function SwiftStore(globalOpts) { return receiver; }, - ensureContainerExists: function(credentials, containerName, callback) { - var client = getClient(credentials); + ensureContainerExists: function(credentials, containerName, version, callback) { + var client = getClient(credentials, version); client.getContainers(function (error, containers) { if (error) { diff --git a/package.json b/package.json index 54ba75e..35ca5e9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "skipper-openstack", - "version": "0.0.1", + "version": "0.0.2", "dependencies": { "pkgcloud": "git+https://github.com/IBM-Bluemix/pkgcloud.git#fix-openstack-auth", "stream": "0.0.2",