Class: Aspera::Fasp::Parameters

Inherits:
Object
  • Object
show all
Defined in:
lib/aspera/fasp/parameters.rb

Overview

translate transfer specification to ascp parameter list

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.file_list_folderObject



227
# File 'lib/aspera/fasp/parameters.rb', line 227

def file_list_folder; @@file_list_folder;end

.file_list_folder=(v) ⇒ Object

temp file list files are created here



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/aspera/fasp/parameters.rb', line 208

def self.file_list_folder=(v)
  @@file_list_folder=v
  unless @@file_list_folder.nil?
    FileUtils.mkdir_p(@@file_list_folder)
    # garbage collect undeleted files
    Dir.entries(@@file_list_folder).each do |name|
      file_path=File.join(@@file_list_folder,name)
      age_sec=(Time.now - File.stat(file_path).mtime).to_i
      # check age of file, delete too old
      if File.file?(file_path) and age_sec > FILE_LIST_AGE_MAX_SEC
        Log.log.debug("garbage collecting #{name}")
        File.delete(file_path)
      end
    end
  end
end

.ts_to_env_args(transfer_spec, options) ⇒ Object



229
230
231
# File 'lib/aspera/fasp/parameters.rb', line 229

def ts_to_env_args(transfer_spec,options)
  return Parameters.new(transfer_spec,options).ascp_args()
end

Instance Method Details

#ascp_argsObject

translate transfer spec to env vars and command line arguments for ascp NOTE: parameters starting with “EX_” (extended) are not standard



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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
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
# File 'lib/aspera/fasp/parameters.rb', line 115

def ascp_args()
  env_args={
    :args=>[],
    :env=>{},
    :ascp_version=>:ascp
  }
  # some ssh credentials are required to avoid interactive password input
  if !@job_spec.has_key?('remote_password') and
  !@job_spec.has_key?('ssh_private_key') and
  !@job_spec.has_key?('EX_ssh_key_paths') then
    raise Fasp::Error.new('required: password or ssh key (value or path)')
  end

  # special cases
  @job_spec.delete('source_root') if @job_spec.has_key?('source_root') and @job_spec['source_root'].empty?

  # use web socket initiation ?
  if @builder.process_param('wss_enabled',:get_value) and @options[:wss]
    # by default use web socket session if available, unless removed by user
    @builder.add_command_line_options(['--ws-connect'])
    # TODO: option to give order ssh,ws (legacy http is implied bu ssh)
    # quel bordel:
    @job_spec['ssh_port']=@builder.process_param('wss_port',:get_value)
    @job_spec.delete('fasp_port')
    @job_spec.delete('EX_ssh_key_paths')
    @job_spec.delete('sshfp')
  else
    # remove unused parameter (avoid warning)
    @job_spec.delete('wss_port')
  end

  # process parameters as specified in table
  @builder.process_params

  # symbol must be index of Installation.paths
  if @builder.process_param('use_ascp4',:get_value)
    env_args[:ascp_version] = :ascp4
  else
    env_args[:ascp_version] = :ascp
    # destination will be base64 encoded, put before path arguments
    @builder.add_command_line_options(['--dest64'])
  end

  PARAM_DEFINITION['paths'][:mandatory]=!@job_spec.has_key?('keepalive')
  paths_array=@builder.process_param('paths',:get_value)
  unless paths_array.nil?
    # use file list if there is storage defined for it.
    if @@file_list_folder.nil?
      # not safe for special characters ? (maybe not, depends on OS)
      Log.log.debug("placing source file list on command line (no file list file)")
      @builder.add_command_line_options(paths_array.map{|i|i['source']})
    else
      file_list_file=@builder.process_param('EX_file_list',:get_value)
      if !file_list_file.nil?
        option='--file-list'
      else
        file_list_file=@builder.process_param('EX_file_pair_list',:get_value)
        if !file_list_file.nil?
          option='--file-pair-list'
        else
          # safer option: file list
          # if there is destination in paths, then use filepairlist
          # TODO: well, we test only the first one, but anyway it shall be consistent
          if paths_array.first.has_key?('destination')
            option='--file-pair-list'
            lines=paths_array.inject([]){|m,e|m.push(e['source'],e['destination']);m}
          else
            option='--file-list'
            lines=paths_array.map{|i|i['source']}
          end
          file_list_file=Aspera::TempFileManager.instance.new_file_path_in_folder(@@file_list_folder)
          File.open(file_list_file, 'w+'){|f|f.puts(lines)}
          Log.log.debug("#{option}=\n#{File.read(file_list_file)}".red)
        end
      end
      @builder.add_command_line_options(["#{option}=#{file_list_file}"])
    end
  end
  # optional args, at the end to override previous ones (to allow override)
  @builder.add_command_line_options(@builder.process_param('EX_ascp_args',:get_value))
  # process destination folder
  destination_folder = @builder.process_param('destination_root',:get_value) || '/'
  # ascp4 does not support base64 encoding of destination
  destination_folder = Base64.strict_encode64(destination_folder) unless env_args[:ascp_version].eql?(:ascp4)
  # destination MUST be last command line argument to ascp
  @builder.add_command_line_options([destination_folder])

  @builder.add_env_args(env_args[:env],env_args[:args])

  return env_args
end