Class: Knife::KnifeArt::KnifeArtUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/knife-art/knife_art_utils.rb

Class Method Summary collapse

Class Method Details

.auth_header_from(uri) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/knife-art/knife_art_utils.rb', line 8

def self.auth_header_from(uri)
  Chef::Log.debug("[KNIFE-ART] in util, got url: #{uri}")
  begin
  url = URI.parse(uri.gsub(%r{/+$}, ""))
  Chef::Log.debug("[KNIFE-ART] in util, parsed url: #{uri}")
  if url.user and url.password
    user = CGI.unescape(url.user)
    password = CGI.unescape(url.password)
    return {"Authorization" => "Basic " + Base64.strict_encode64("#{user}:#{password}")}
  end
  {}
  end
rescue Exception => e
  Chef::Log.warn("[KNIFE-ART] Unable to parse url: #{uri} --> #{e.message}")
  {}
end