Class: Aspera::Fasp::Installation

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/aspera/fasp/installation.rb

Overview

Singleton that tells where to find ascp and other local resources (keys..) , using the “path(symb)” method. It is used by object : Fasp::Local to find necessary resources By default it takes the first Aspera product found specified in product_locations but the user can specify ascp location by calling: Installation.instance.use_ascp_from_product(product_name) or Installation.instance.ascp_path=“”

Constant Summary collapse

PRODUCT_CONNECT =
'Aspera Connect'
PRODUCT_CLI_V1 =
'Aspera CLI'
PRODUCT_DRIVE =
'Aspera Drive'
PRODUCT_ENTSRV =
'Enterprise Server'
FILES =
[:ascp,:ascp4,:ssh_bypass_key_dsa,:ssh_bypass_key_rsa,:aspera_license,:aspera_conf,:fallback_cert,:fallback_key]

Instance Method Summary collapse

Instance Method Details

#ascp_path=(v) ⇒ Object

currently used ascp executable



26
27
28
# File 'lib/aspera/fasp/installation.rb', line 26

def ascp_path=(v)
  @path_to_ascp=v
end

#bypass_keysObject



175
176
177
# File 'lib/aspera/fasp/installation.rb', line 175

def bypass_keys
  return [:ssh_bypass_key_dsa,:ssh_bypass_key_rsa].map{|i|Installation.instance.path(i)}
end

#bypass_passObject

default bypass key phrase



171
172
173
# File 'lib/aspera/fasp/installation.rb', line 171

def bypass_pass
  return "%08x-%04x-%04x-%04x-%04x%08x" % DataRepository.instance.get_bin(3).unpack("NnnnnN")
end

#cli_conf_fileObject

@ return path to configuration file of aspera CLI



165
166
167
168
# File 'lib/aspera/fasp/installation.rb', line 165

def cli_conf_file
  connect=get_product_folders(PRODUCT_CLI_V1)
  return File.join(connect[:app_root],BIN_SUBFOLDER,'.aspera_cli_conf')
end

#connect_uriObject



151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/aspera/fasp/installation.rb', line 151

def connect_uri
  connect=get_product_folders(PRODUCT_CONNECT)
  folder=File.join(connect[:run_root],VARRUN_SUBFOLDER)
  ['','s'].each do |ext|
    uri_file=File.join(folder,"http#{ext}.uri")
    Log.log.debug("checking connect port file: #{uri_file}")
    if File.exist?(uri_file)
      return File.open(uri_file){|f|f.gets}.strip
    end
  end
  raise "no connect uri file found in #{folder}"
end

#folder=(v) ⇒ Object

location of SDK files



31
32
33
34
# File 'lib/aspera/fasp/installation.rb', line 31

def folder=(v)
  @sdk_folder=v
  folder_path
end

#install_sdkObject



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/aspera/fasp/installation.rb', line 179

def install_sdk
  require 'zip'
  sdk_zip_path=File.join(Dir.tmpdir,'sdk.zip')
  Aspera::Rest.new(base_url: SDK_URL).call(operation: 'GET',save_to_file: sdk_zip_path)
  filter="/#{Environment.architecture}/"
  ascp_path=nil
  # first ensure license file is here so that ascp invokation for version works
  self.path(:aspera_license)
  self.path(:aspera_conf)
  Zip::File.open(sdk_zip_path) do |zip_file|
    zip_file.each do |entry|
      if entry.name.include?(filter) and !entry.name.end_with?('/')
        archive_file=File.join(folder_path,File.basename(entry.name))
        File.open(archive_file, 'wb') do |output_stream|
          IO.copy_stream(entry.get_input_stream, output_stream)
        end
        if entry.name.include?('ascp')
          FileUtils.chmod(0755,archive_file)
          ascp_path=archive_file
        end
      end
    end
  end
  File.unlink(sdk_zip_path) rescue nil # Windows may give error
  ascp_version='n/a'
  raise "error in sdk: no ascp included" if ascp_path.nil?
  cmd_out=%x{#{ascp_path} -A}
  raise "An error occured when testing ascp: #{cmd_out}" unless $? == 0
  # get version from ascp, only after full extract, as windows requires DLLs (SSL/TLS/etc...)
  m=cmd_out.match(/ascp version (.*)/)
  ascp_version=m[1] unless m.nil?
  File.write(File.join(folder_path,PRODUCT_INFO),"<product><name>IBM Aspera SDK</name><version>#{ascp_version}</version></product>")
  return ascp_version
end

#installed_productsObject

Returns the list of installed products in format of product_locations.

Returns:

  • the list of installed products in format of product_locations



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/aspera/fasp/installation.rb', line 51

def installed_products
  if @found_products.nil?
    @found_products=product_locations
    # add sdk as first search path
    @found_products.unshift({# SDK
      :expected =>'SDK',
      :app_root =>folder_path,
      :sub_bin =>''
    })
    @found_products.select! do |pl|
      next false unless Dir.exist?(pl[:app_root])
      Log.log.debug("found #{pl[:app_root]}")
      sub_bin = pl[:sub_bin] || BIN_SUBFOLDER
      pl[:ascp_path]=File.join(pl[:app_root],sub_bin,'ascp'+Environment.exe_extension)
      next false unless File.exist?(pl[:ascp_path])
      product_info_file="#{pl[:app_root]}/#{PRODUCT_INFO}"
      if File.exist?(product_info_file)
        res_s=XmlSimple.xml_in(File.read(product_info_file),{"ForceArray"=>false})
        pl[:name]=res_s['name']
        pl[:version]=res_s['version']
      else
        pl[:name]=pl[:expected]
      end
      true # select this version
    end
  end
  return @found_products
end

#path(k) ⇒ Object

get path of one resource file of currently activated product keys and certs are generated locally… (they are well known values, arch. independant)



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/aspera/fasp/installation.rb', line 84

def path(k)
  case k
  when :ascp,:ascp4
    use_ascp_from_product(FIRST_FOUND) if @path_to_ascp.nil?
    file=@path_to_ascp
    # note that there might be a .exe at the end
    file=file.gsub('ascp','ascp4') if k.eql?(:ascp4)
  when :ssh_bypass_key_dsa
    file=File.join(folder_path,'aspera_bypass_dsa.pem')
    File.write(file,get_key('dsa',1)) unless File.exist?(file)
    File.chmod(0400,file)
  when :ssh_bypass_key_rsa
    file=File.join(folder_path,'aspera_bypass_rsa.pem')
    File.write(file,get_key('rsa',2)) unless File.exist?(file)
    File.chmod(0400,file)
  when :aspera_license
    file=File.join(folder_path,'aspera-license')
    File.write(file,Base64.strict_encode64("#{Zlib::Inflate.inflate(DataRepository.instance.get_bin(6))}==SIGNATURE==\n#{Base64.strict_encode64(DataRepository.instance.get_bin(7))}")) unless File.exist?(file)
    File.chmod(0400,file)
  when :aspera_conf
    file=File.join(folder_path,'aspera.conf')
    File.write(file,%Q{<?xml version='1.0' encoding='UTF-8'?>
<CONF version="2">
<default>
    <file_system>
  <storage_rc>
      <adaptive>
          true
      </adaptive>
  </storage_rc>
  <resume_suffix>.aspera-ckpt</resume_suffix>
  <partial_file_suffix>.partial</partial_file_suffix>
  <replace_illegal_chars>_</replace_illegal_chars>
    </file_system>
</default>
</CONF>
}) unless File.exist?(file)
    File.chmod(0400,file)
  when :fallback_cert,:fallback_key
    file_key=File.join(folder_path,'aspera_fallback_key.pem')
    file_cert=File.join(folder_path,'aspera_fallback_cert.pem')
    if !File.exist?(file_key) or !File.exist?(file_cert)
      require 'openssl'
      # create new self signed certificate for http fallback
      private_key = OpenSSL::PKey::RSA.new(1024)
      cert = OpenSSL::X509::Certificate.new
      cert.subject = cert.issuer = OpenSSL::X509::Name.parse("/C=US/ST=California/L=Emeryville/O=Aspera Inc./OU=Corporate/CN=Aspera Inc./[email protected]")
      cert.not_before = Time.now
      cert.not_after = Time.now + 365 * 24 * 60 * 60
      cert.public_key = private_key.public_key
      cert.serial = 0x0
      cert.version = 2
      cert.sign(private_key, OpenSSL::Digest::SHA1.new)
      File.write(file_key,private_key.to_pem)
      File.write(file_cert,cert.to_pem)
      File.chmod(0400,file_key)
      File.chmod(0400,file_cert)
    end
    file = k.eql?(:fallback_cert) ? file_cert : file_key
  else
    raise "INTERNAL ERROR: #{k}"
  end
  raise "no such file: #{file}" unless File.exist?(file)
  return file
end

#use_ascp_from_product(product_name) ⇒ Object

find ascp in named product (use value : FIRST_FOUND=‘FIRST’ to just use first one) or select one from installed_products()



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/aspera/fasp/installation.rb', line 38

def use_ascp_from_product(product_name)
  if product_name.eql?(FIRST_FOUND)
    pl=installed_products.first
    raise "no FASP installation found\nPlease check manual on how to install FASP." if pl.nil?
  else
    pl=installed_products.select{|i|i[:name].eql?(product_name)}.first
    raise "no such product installed: #{product_name}" if pl.nil?
  end
  self.ascp_path=pl[:ascp_path]
  Log.log.debug("ascp_path=#{@path_to_ascp}")
end