gds-operations / vcloud-core

vCloud Core is a gem that supports automated provisioning of VMWare vCloud Director, used by the vCloud Tools gems
http://gds-operations.github.io/vcloud-tools/
MIT License
12 stars 19 forks source link

vcloud_director/compute.rb #139

Closed dougmbaya closed 9 years ago

dougmbaya commented 9 years ago

There seem to be a logic error in the compute file, specifically in the "check_session_matches_credentials(session_org, session_user)" function. vCloud API take credentials in the form of user@domain.com@organization but returns authentication token named user@domain.com.

The "fog_credential_user = @vcloud_director_username.split('@')[0...-1].join" removes both @ symboles witch returns userDomain.com instead of user@domain.com forcing the application to fail for token name mismatch.

Here is the exact error:

FOG_CREDENTIAL specified is for user 'usernameDomain.com' but your current session is for 'username@domain.com'. You should generate a new FOG_VCLOUD_TOKEN.

Any idea?

dcarley commented 9 years ago

Hey,

That looks like a bad assumption on our part. The usernames our team have with most providers don't include an @ symbol. Do you think it makes sense to split the username and organisation on just the last @?

dougmbaya commented 9 years ago

I think we could add an "If" logic as such that the algorithm can detect that the username is an email address and act accordingly by only slicing starting from the 2nd "@" ?

dcarley commented 9 years ago

I've raised a pull request against fog/fog (linked above) which should fix it.

If you'd like to test it out you can do the following:

➜  govuk  git clone git@github.com:fog/fog.git
➜  govuk  cd fog
➜  fog git:(master) git fetch origin pull/3229/head:pr-3229
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (6/6), done.
From github.com:fog/fog
 * [new ref]         refs/pull/3229/head -> pr-3229
➜  fog git:(master) git co pr-3229
Switched to branch 'pr-3229'
➜  fog git:(pr-3229) cd ../vcloud-core
➜  vcloud-core git:(master) ✗ export VCLOUD_TOOLS_DEV_FOG_LOCAL=true
➜  vcloud-core git:(master) ✗ bundle
Resolving dependencies...
…
Using fog (1.24.0) from source at ../fog
Using vcloud-core (0.13.0) from source at .
Using vcloud-tools-tester (0.2.0)
Your bundle is complete!
It was installed into /Users/dcarley/vendor/bundle
➜  vcloud-core git:(master) ✗ eval $(FOG_CREDENTIAL=skyscape b vcloud-login)
/Users/dcarley/vendor/bundle/gems/fog-core-1.24.0/lib/fog/core/version.rb:2: warning: already initialized constant VERSION
vCloud password:
mattbostock commented 9 years ago

This is my fault, I did consider email addresses as usernames but omitted to pass a parameter to join() to add back the '@' (as @dcarley did in fog/fog#3229 - thanks!).

mattbostock commented 9 years ago

@dcarley's pull request (fog/fog#3229) has been merged. Once a new version of Fog is released, I'll release a new version of vCloud Core and the other vCloud Tools which depend on it.

mattbostock commented 9 years ago

fog/fog#3229 was released upstream as Fog version 1.25.0. I've raised a PR to bump our dependency to that version: https://github.com/gds-operations/vcloud-core/pull/142

mattbostock commented 9 years ago

All of the vCloud Tools have now been re-released to depend on vCloud Core 0.16.0, which supports usernames containing email addresses. Thanks for reporting this @dougmbaya.