Module: Azure::Storage::Common::Core::Utility

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

Instance Method Summary collapse

Instance Method Details

#enable_winrm?(winrm_transport) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/azure/storage/common/core/utility.rb', line 91

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



79
80
81
82
83
84
85
# File 'lib/azure/storage/common/core/utility.rb', line 79

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



87
88
89
# File 'lib/azure/storage/common/core/utility.rb', line 87

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

#get_certificate(private_key_file) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/azure/storage/common/core/utility.rb', line 95

def get_certificate(private_key_file)
  rsa = OpenSSL::PKey.read File.read(private_key_file)
  cert = OpenSSL::X509::Certificate.new
  cert.version = 2
  cert.serial = 0
  name = OpenSSL::X509::Name.new([["CN", "Azure Management Certificate"]])
  cert.subject = cert.issuer = name
  cert.not_before = Time.now
  cert.not_after = cert.not_before + (60 * 60 * 24 * 365)
  cert.public_key = rsa.public_key
  cert.sign(rsa, OpenSSL::Digest::SHA1.new)
  cert
end

#initialize_external_logger(logger) ⇒ Object



109
110
111
# File 'lib/azure/storage/common/core/utility.rb', line 109

def initialize_external_logger(logger)
  Loggerx.initialize_external_logger(logger)
end

#locate_file(name) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'lib/azure/storage/common/core/utility.rb', line 69

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

#parse_charset_from_content_type(content_type) ⇒ Object



113
114
115
116
117
118
# File 'lib/azure/storage/common/core/utility.rb', line 113

def parse_charset_from_content_type(content_type)
  if (content_type && content_type.length > 0)
    charset = content_type.split(";").delete_if { |attribute| !attribute.lstrip.start_with?("charset=") }.map { |x| x.lstrip }[0]
    charset["charset=".length...charset.length] if charset
  end
end

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



58
59
60
# File 'lib/azure/storage/common/core/utility.rb', line 58

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



62
63
64
65
66
67
# File 'lib/azure/storage/common/core/utility.rb', line 62

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