You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by Francesco Vollero <fv...@redhat.com> on 2011/06/06 14:44:15 UTC

[PATCH core] Fix long username for RHEVM driver

This patch is to fix a problem with Base64.b64encode for credentials in RHEVM driver, due to a wrong way in pack to add \n every 60 chars i had to use this hack.
The issue is not present in Ruby 1.9.x in fact they use a method called strict_encode64() that is the same as my hack.


Signed-off-by: Francesco Vollero <fv...@redhat.com>
---
 .../lib/deltacloud/drivers/rhevm/rhevm_client.rb   |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb b/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb
index 5d28b3d..80f5a91 100644
--- a/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb
+++ b/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb
@@ -150,7 +150,9 @@ module RHEVM
     end

     def auth_header
-      { :authorization => "Basic " + Base64.encode64("#{@credentials[:username]}:#{@credentials[:password]}"), }
+      # As RDOC says this is the function for strict_encode64:
+      encoded_credentials = ["#{@credentials[:username]}:#{@credentials[:password]}"].pack("m0").gsub(/\n/,'')
+      { :authorization => "Basic " + encoded_credentials }
     end

     def base_url
--
1.7.4.1


Re: [PATCH core] Fix long username for RHEVM driver

Posted by Michal Fojtik <mf...@redhat.com>.
On Jun 6, 2011, at 2:44 PM, Francesco Vollero wrote:

ACK.

(Tested using RHEV-M 2.2)

  -- Michal

> This patch is to fix a problem with Base64.b64encode for credentials in RHEVM driver, due to a wrong way in pack to add \n every 60 chars i had to use this hack.
> The issue is not present in Ruby 1.9.x in fact they use a method called strict_encode64() that is the same as my hack.
> 
> 
> Signed-off-by: Francesco Vollero <fv...@redhat.com>
> ---
> .../lib/deltacloud/drivers/rhevm/rhevm_client.rb   |    4 +++-
> 1 files changed, 3 insertions(+), 1 deletions(-)
> 
> diff --git a/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb b/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb
> index 5d28b3d..80f5a91 100644
> --- a/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb
> +++ b/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb
> @@ -150,7 +150,9 @@ module RHEVM
>     end
> 
>     def auth_header
> -      { :authorization => "Basic " + Base64.encode64("#{@credentials[:username]}:#{@credentials[:password]}"), }
> +      # As RDOC says this is the function for strict_encode64:
> +      encoded_credentials = ["#{@credentials[:username]}:#{@credentials[:password]}"].pack("m0").gsub(/\n/,'')
> +      { :authorization => "Basic " + encoded_credentials }
>     end
> 
>     def base_url
> --
> 1.7.4.1
> 

------------------------------------------------------
Michal Fojtik, mfojtik@redhat.com
Deltacloud API: http://deltacloud.org


Re: [PATCH core] Fix long username for RHEVM driver

Posted by Francesco Vollero <fv...@redhat.com>.
On Mon, Jun 06, 2011 at 08:59:09AM -0400, Chris Lalancette wrote:
> On 06/06/11 - 02:44:15PM, Francesco Vollero wrote:
> > This patch is to fix a problem with Base64.b64encode for credentials in RHEVM driver, due to a wrong way in pack to add \n every 60 chars i had to use this hack.

[snip]

> ACK to the code, it looks fine.  I would suggest adding a better comment to the
> code, though, so the next person reading the code isn't confused.  Something
> like:
> 
> # in ruby 1.8, the Base64.encode64 method automatically adds \n after every
> # 60 characters.  Strip that out here.  Ruby 1.9 has Base64.strict_encode64()
> # which does not have this problem.
>

Thanks for the suggestion Chris. I wrote it in hurry, but next time i will try to be more clear.

Cheers,
Francesco Vollero

> -- 
> Chris Lalancette

Re: [PATCH core] Fix long username for RHEVM driver

Posted by Chris Lalancette <cl...@redhat.com>.
On 06/06/11 - 02:44:15PM, Francesco Vollero wrote:
> This patch is to fix a problem with Base64.b64encode for credentials in RHEVM driver, due to a wrong way in pack to add \n every 60 chars i had to use this hack.
> The issue is not present in Ruby 1.9.x in fact they use a method called strict_encode64() that is the same as my hack.
> 
> 
> Signed-off-by: Francesco Vollero <fv...@redhat.com>
> ---
>  .../lib/deltacloud/drivers/rhevm/rhevm_client.rb   |    4 +++-
>  1 files changed, 3 insertions(+), 1 deletions(-)
> 
> diff --git a/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb b/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb
> index 5d28b3d..80f5a91 100644
> --- a/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb
> +++ b/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb
> @@ -150,7 +150,9 @@ module RHEVM
>      end
> 
>      def auth_header
> -      { :authorization => "Basic " + Base64.encode64("#{@credentials[:username]}:#{@credentials[:password]}"), }
> +      # As RDOC says this is the function for strict_encode64:
> +      encoded_credentials = ["#{@credentials[:username]}:#{@credentials[:password]}"].pack("m0").gsub(/\n/,'')
> +      { :authorization => "Basic " + encoded_credentials }
>      end

ACK to the code, it looks fine.  I would suggest adding a better comment to the
code, though, so the next person reading the code isn't confused.  Something
like:

# in ruby 1.8, the Base64.encode64 method automatically adds \n after every
# 60 characters.  Strip that out here.  Ruby 1.9 has Base64.strict_encode64()
# which does not have this problem.

-- 
Chris Lalancette