Module: Azure::Core::Utility

Defined in:
lib/azure/core/utility.rb

Instance Method Summary collapse

Instance Method Details

#enable_winrm?(winrm_transport) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/azure/core/utility.rb', line 79

def enable_winrm?(winrm_transport)
  (!winrm_transport.nil? && (winrm_transport.select { |x| x.downcase == 'http' || x.downcase == 'https' }.size > 0))
end

#export_der(cert, key, pass = nil, name = nil) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/azure/core/utility.rb', line 67

def export_der(cert, key, pass = nil, name = nil)
  pkcs12 = OpenSSL::PKCS12.create(pass, name, key, cert)
  Base64.encode64(pkcs12.to_der)
rescue Exception => e
  puts e.message
  abort
end

#export_fingerprint(certificate) ⇒ Object



75
76
77
# File 'lib/azure/core/utility.rb', line 75

def export_fingerprint(certificate)
  Digest::SHA1.hexdigest(certificate.to_der)
end

#locate_file(name) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/azure/core/utility.rb', line 57

def locate_file(name)
  if File.exist? name
    name
  elsif File.exist?(File.join(ENV['HOME'], name))
    File.join(ENV['HOME'], name)
  else
    Loggerx.error_with_exit "Unable to find #{name} file  "
  end
end

#random_string(str = 'azure', no_of_char = 5) ⇒ Object



46
47
48
# File 'lib/azure/core/utility.rb', line 46

def random_string(str = 'azure', no_of_char = 5)
  str + (0...no_of_char).map { ('a'..'z').to_a[rand(26)] }.join
end

#xml_content(xml, key, default = '') ⇒ Object



50
51
52
53
54
55
# File 'lib/azure/core/utility.rb', line 50

def xml_content(xml, key, default = '')
  content = default
  node = xml.at_css(key)
  content = node.text if node
  content
end