Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'passwordCredentials' of undefined #521

Open
clsahongraph opened this issue May 19, 2016 · 1 comment
Open

Comments

@clsahongraph
Copy link

clsahongraph commented May 19, 2016

I have configure all credential for upload file and save in Bluemix Object Storage with the help this solution, code here

...
...
 var pkgcloud = require('pkgcloud-bluemix-objectstorage');
 var fs = require('fs');

app.post('/upload', function(req, res) {
    // Create a config object
    var config = {};
    // Specify Openstack as the provider
    config.provider = "openstack";
    // Authentication url
    config.authUrl = 'https://identity.open.softlayer.com/';
    config.region= 'dallas';
    // Use the service catalog
    config.useServiceCatalog = true;
    // true for applications running inside Bluemix, otherwise false
    config.useInternal = false;
    // projectId as provided in your Service Credentials
    config.tenantId = '234567890-0987654';
    // userId as provided in your Service Credentials
    config.userId = '098765434567890';
    // username as provided in your Service Credentials
    config.username = 'admin_34567890-09876543';
    // password as provided in your Service Credentials
    config.password = 'sdfghjklkjhgfds';

  //This is part which is NOT in original pkgcloud. This is how it works with newest version of bluemix and pkgcloud at 22.12.2015. 
    //In reality, anything you put in this config.auth will be send in body to server, so if you need change anything to make it work, you can. PS : Yes, these are the same credentials as you put to config before. 
    //I do not fill this automatically to make it transparent.
    config.auth = {
        forceUri  : "https://identity.open.softlayer.com/v3/auth/tokens", //force uri to v3, usually you take the baseurl for authentication and add this to it /v3/auth/tokens (at least in bluemix)    
        interfaceName : "public", //use public for apps outside bluemix and internal for apps inside bluemix. There is also admin interface, I personally do not know, what it is for.
        "identity": {
            "methods": [
                "password"
            ],
            "password": {
                "user": {
                    "id": "098765434567890", //userId
                    "password": "sdfghjklkjhgfds" //userPassword
                }
            }
        },
        "scope": {
            "project": {
                "id": "234567890-0987654" //projectId
            }
        }
    };

    //console.log("config: " + JSON.stringify(config));

    // Create a pkgcloud storage client
    var storageClient = pkgcloud.storage.createClient(config);


    // Authenticate to OpenStack
    storageClient.auth(function (error) {
        if (error) {
            console.error("storageClient.auth() : error creating storage client: ", error);
        } else {

            //OK
            var new_fname = dir + "__" + file.originalname;
            var readStream = fs.createReadStream('uploads/' + file.filename);
            var writeStream = storageClient.upload({
                container: 'chat-files',
                remote: new_fname
            });

            writeStream.on('error', function(err) {
                // handle your error case
                console.log("concluido o upload com erro!");
                console.log(err);
            });

            writeStream.on('success', function(file) {
                // success, file will be a File model
                console.log("concluido o upload com sucesso!");
            });

            readStream.pipe(writeStream);                
        }
    });

}
...
...

But when i hit this api using postman then it throw an error i.e,

 ERR TypeError: Cannot read property 'passwordCredentials' of undefined
2016-05-19T17:04:28.81+0530 [App/0]      ERR     at Client._getIdentityOptions (/home/vcap/app/node_modules/pkgcloud-bluemix-objectstorage/lib/pkgcloud/openstack/client.js:96:49)
2016-05-19T17:04:28.81+0530 [App/0]      ERR     at exports.Client (/home/vcap/app/node_modules/pkgcloud-bluemix-objectstorage/lib/pkgcloud/openstack/client.js:64:46)
2016-05-19T17:04:28.81+0530 [App/0]      ERR     at new exports.Client (/home/vcap/app/node_modules/pkgcloud-bluemix-objectstorage/lib/pkgcloud/openstack/storage/client/index.js:21:20)
2016-05-19T17:04:28.81+0530 [App/0]      ERR     at new exports.createClient (/home/vcap/app/node_modules/pkgcloud-bluemix-objectstorage/lib/pkgcloud/openstack/storage/index.js:14:10)
2016-05-19T17:04:28.81+0530 [App/0]      ERR     at Object.pkgcloud.(anonymous function).createClient (/home/vcap/app/node_modules/pkgcloud-bluemix-objectstorage/lib/pkgcloud.js:97:12)
2016-05-19T17:04:28.81+0530 [App/0]      ERR     at /home/vcap/app/app.js:55:40
2016-05-19T17:04:28.81+0530 [App/0]      ERR     at Layer.handle [as handle_request] (/home/vcap/app/node_modules/express/lib/router/layer.js:95:5)
2016-05-19T17:04:28.81+0530 [App/0]      ERR     at next (/home/vcap/app/node_modules/express/lib/router/route.js:131:13)
2016-05-19T17:04:28.81+0530 [App/0]      ERR     at Route.dispatch (/home/vcap/app/node_modules/express/lib/router/route.js:112:3)
2016-05-19T17:04:28.81+0530 [App/0]      ERR     at Layer.handle [as handle_request] (/home/vcap/app/node_modules/express/lib/router/layer.js:95:5)
@enkidoo
Copy link

enkidoo commented Oct 11, 2016

I corrected the issue with this package :

It works as per documentation after I used this package.

pkgcloud-bluemix-objectstorage

It fixes the AUTH issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants