cnvrg 0.3.6 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/cnvrg.gemspec +1 -0
- data/lib/cnvrg/api.rb +26 -8
- data/lib/cnvrg/auth.rb +5 -0
- data/lib/cnvrg/cli.rb +964 -477
- data/lib/cnvrg/data.rb +42 -8
- data/lib/cnvrg/datafiles.rb +168 -145
- data/lib/cnvrg/dataset.rb +124 -17
- data/lib/cnvrg/experiment.rb +7 -4
- data/lib/cnvrg/files.rb +52 -67
- data/lib/cnvrg/helpers.rb +20 -0
- data/lib/cnvrg/project.rb +0 -6
- data/lib/cnvrg/version.rb +1 -1
- metadata +16 -2
    
        data/lib/cnvrg/dataset.rb
    CHANGED
    
    | @@ -5,7 +5,7 @@ module Cnvrg | |
| 5 5 |  | 
| 6 6 | 
             
                RemoteURL ||= "https://cnvrg.io"
         | 
| 7 7 | 
             
                IDXParallelThreads ||= 15
         | 
| 8 | 
            -
             | 
| 8 | 
            +
                IDXParallelProcesses ||= Parallel.processor_count
         | 
| 9 9 |  | 
| 10 10 | 
             
                def initialize(project_home)
         | 
| 11 11 | 
             
                  begin
         | 
| @@ -18,7 +18,12 @@ module Cnvrg | |
| 18 18 | 
             
                  rescue => e
         | 
| 19 19 |  | 
| 20 20 | 
             
                  end
         | 
| 21 | 
            +
                end
         | 
| 21 22 |  | 
| 23 | 
            +
             | 
| 24 | 
            +
                def self.delete(dataset_slug,owner)
         | 
| 25 | 
            +
                  response = Cnvrg::API.request("users/#{owner}/datasets/#{dataset_slug}/delete", 'DELETE')
         | 
| 26 | 
            +
                  return response
         | 
| 22 27 | 
             
                end
         | 
| 23 28 |  | 
| 24 29 | 
             
                def last_local_commit
         | 
| @@ -50,6 +55,26 @@ module Cnvrg | |
| 50 55 | 
             
                  "#{url}/#{self.owner}/projects/#{self.slug}"
         | 
| 51 56 | 
             
                end
         | 
| 52 57 |  | 
| 58 | 
            +
                def self.verify_cnvrgignore_exist(dataset_name,remote)
         | 
| 59 | 
            +
                  path = ".cnvrgignore"
         | 
| 60 | 
            +
                  if !File.exist? path
         | 
| 61 | 
            +
                    path = "#{dataset_name}/.cnvrgignore"
         | 
| 62 | 
            +
                  end
         | 
| 63 | 
            +
                  ignore_exits = File.exist? path
         | 
| 64 | 
            +
                  if !ignore_exits
         | 
| 65 | 
            +
                    begin
         | 
| 66 | 
            +
                      list_files = [
         | 
| 67 | 
            +
                          path
         | 
| 68 | 
            +
                      ]
         | 
| 69 | 
            +
                      FileUtils.touch list_files
         | 
| 70 | 
            +
                      cnvrgignore = Helpers.cnvrgignore_content
         | 
| 71 | 
            +
                      File.open(path, "w+") { |f| f.write cnvrgignore }
         | 
| 72 | 
            +
                    rescue => e
         | 
| 73 | 
            +
                      return false
         | 
| 74 | 
            +
                    end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                  end
         | 
| 77 | 
            +
                end
         | 
| 53 78 | 
             
                def update_ignore_list(new_ignore)
         | 
| 54 79 |  | 
| 55 80 | 
             
                  if new_ignore.nil? or new_ignore.empty?
         | 
| @@ -97,9 +122,14 @@ module Cnvrg | |
| 97 122 | 
             
                    list_dirs = [".cnvrg"
         | 
| 98 123 | 
             
                    ]
         | 
| 99 124 | 
             
                    list_files = [
         | 
| 100 | 
            -
                        ".cnvrgignore",
         | 
| 101 125 | 
             
                        ".cnvrg/config.yml"
         | 
| 102 126 | 
             
                    ]
         | 
| 127 | 
            +
                    create_ignore = false
         | 
| 128 | 
            +
                    if !File.exist? ".cnvrgignore"
         | 
| 129 | 
            +
                      list_files << ".cnvrgignore"
         | 
| 130 | 
            +
                      create_ignore  = true
         | 
| 131 | 
            +
                    end
         | 
| 132 | 
            +
             | 
| 103 133 |  | 
| 104 134 | 
             
                    cnvrgignore = Helpers.cnvrgignore_content
         | 
| 105 135 | 
             
                    begin
         | 
| @@ -111,22 +141,30 @@ module Cnvrg | |
| 111 141 | 
             
                      config = {dataset_name: dataset_name,
         | 
| 112 142 | 
             
                                dataset_slug: dataset_slug,
         | 
| 113 143 | 
             
                                owner: owner}
         | 
| 144 | 
            +
             | 
| 114 145 | 
             
                      FileUtils.mkdir_p list_dirs
         | 
| 115 146 | 
             
                      FileUtils.touch list_files
         | 
| 116 147 | 
             
                      File.open(".cnvrg/config.yml", "w+") { |f| f.write config.to_yaml }
         | 
| 117 | 
            -
                      File.open(".cnvrgignore", "w+") { |f| f.write cnvrgignore } unless  | 
| 148 | 
            +
                      File.open(".cnvrgignore", "w+") { |f| f.write cnvrgignore } unless !create_ignore
         | 
| 118 149 | 
             
                    rescue => e
         | 
| 119 150 | 
             
                      return false
         | 
| 120 151 | 
             
                    end
         | 
| 121 152 | 
             
                    return true
         | 
| 122 153 | 
             
                end
         | 
| 154 | 
            +
             | 
| 155 | 
            +
             | 
| 156 | 
            +
                def clone( commit)
         | 
| 157 | 
            +
             | 
| 158 | 
            +
             | 
| 159 | 
            +
                  return response
         | 
| 160 | 
            +
                end
         | 
| 161 | 
            +
             | 
| 123 162 | 
             
                def self.clone(owner, dataset_name,dataset_slug)
         | 
| 124 163 |  | 
| 125 164 | 
             
                  begin
         | 
| 126 165 | 
             
                    list_dirs = [ dataset_name, "#{dataset_name}/.cnvrg"
         | 
| 127 166 | 
             
                    ]
         | 
| 128 167 | 
             
                    list_files = [
         | 
| 129 | 
            -
                        "#{dataset_name}/.cnvrgignore",
         | 
| 130 168 | 
             
                        "#{dataset_name}/.cnvrg/config.yml"
         | 
| 131 169 | 
             
                    ]
         | 
| 132 170 |  | 
| @@ -135,11 +173,9 @@ module Cnvrg | |
| 135 173 | 
             
                              owner: owner}
         | 
| 136 174 |  | 
| 137 175 |  | 
| 138 | 
            -
                    cnvrgignore = Helpers.cnvrgignore_content
         | 
| 139 176 | 
             
                    FileUtils.mkdir_p list_dirs
         | 
| 140 177 | 
             
                    FileUtils.touch list_files
         | 
| 141 178 | 
             
                    File.open("#{dataset_name}/.cnvrg/config.yml", "w+") { |f| f.write config.to_yaml }
         | 
| 142 | 
            -
                    File.open("#{dataset_name}/.cnvrgignore", "w+") { |f| f.write cnvrgignore } unless File.exist? ".cnvrgignore"
         | 
| 143 179 | 
             
                  rescue => e
         | 
| 144 180 | 
             
                    puts "Exception in clone request:#{e.message}"
         | 
| 145 181 | 
             
                    return false
         | 
| @@ -189,11 +225,8 @@ module Cnvrg | |
| 189 225 |  | 
| 190 226 | 
             
                  tree_idx = Hash.new(0)
         | 
| 191 227 |  | 
| 192 | 
            -
                  list = Dir.glob("#{self.local_path} | 
| 193 | 
            -
                if list_ignore.nil?
         | 
| 228 | 
            +
                  list = Dir.glob("#{self.local_path}/**/*", File::FNM_DOTMATCH).reject { |x| (x =~ /\/\.{1,2}$/) or (x =~ /^#{self.local_path}\/\.cnvrg\/*/) or (x =~/^#{self.local_path}\/\.cnvrgignore.conflict*/) and not (x =~/^#{self.local_path}\/\.cnvrgignore/) }
         | 
| 194 229 | 
             
                  list_ignore = self.get_ignore_list()
         | 
| 195 | 
            -
                end
         | 
| 196 | 
            -
             | 
| 197 230 | 
             
                  Parallel.map(list, in_threads: IDXParallelThreads) do |e|
         | 
| 198 231 | 
             
                    label = e.gsub(self.local_path + "/", "")
         | 
| 199 232 | 
             
                    if File.directory? e
         | 
| @@ -215,11 +248,16 @@ module Cnvrg | |
| 215 248 | 
             
                      end
         | 
| 216 249 | 
             
                    end
         | 
| 217 250 | 
             
                  end
         | 
| 251 | 
            +
                  if !old_idx.nil? and !old_idx[:next_commit].nil? and  !old_idx[:next_commit].empty?
         | 
| 252 | 
            +
                    idx = {commit: old_idx.to_h[:commit], tree: tree_idx, next_commit:old_idx[:next_commit] }
         | 
| 253 | 
            +
                  else
         | 
| 254 | 
            +
                    idx = {commit: old_idx.to_h[:commit], tree: tree_idx}
         | 
| 218 255 |  | 
| 219 | 
            -
                   | 
| 256 | 
            +
                  end
         | 
| 257 | 
            +
                  idx_yaml = idx.to_yaml
         | 
| 220 258 |  | 
| 221 | 
            -
                  File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') { |f| f.write  | 
| 222 | 
            -
                  return  | 
| 259 | 
            +
                  File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') { |f| f.write idx_yaml }
         | 
| 260 | 
            +
                  return idx
         | 
| 223 261 | 
             
                end
         | 
| 224 262 | 
             
                def create_volume
         | 
| 225 263 | 
             
                  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/volumes/create", 'POST')
         | 
| @@ -233,17 +271,45 @@ module Cnvrg | |
| 233 271 | 
             
                  CLI.is_response_success(response,false)
         | 
| 234 272 | 
             
                  return response
         | 
| 235 273 | 
             
                end
         | 
| 236 | 
            -
                def compare_idx(new_branch, commit=last_local_commit,local_idx=nil)
         | 
| 274 | 
            +
                def compare_idx(new_branch, commit=last_local_commit,local_idx=nil,force = false, next_commit = nil)
         | 
| 275 | 
            +
                  if local_idx.nil?
         | 
| 276 | 
            +
                    local_idx =  self.generate_idx
         | 
| 277 | 
            +
                  end
         | 
| 278 | 
            +
                  ignore_list = self.get_ignore_list()
         | 
| 279 | 
            +
                  if force
         | 
| 280 | 
            +
                    added = []
         | 
| 281 | 
            +
                    if local_idx[:tree]
         | 
| 282 | 
            +
                      added << local_idx[:tree].keys
         | 
| 283 | 
            +
                      added.flatten!
         | 
| 284 | 
            +
                    end
         | 
| 237 285 |  | 
| 286 | 
            +
                    response ={"result"=> {"commit"=>next_commit,"tree"=> {"added"=> added,
         | 
| 287 | 
            +
                                                                   "updated_on_server"=> [],
         | 
| 288 | 
            +
                                                                   "updated_on_local"=> [],
         | 
| 289 | 
            +
                                                                   "deleted"=> [],
         | 
| 290 | 
            +
                                                                   "conflicts"=> []} } }
         | 
| 291 | 
            +
                    return response
         | 
| 292 | 
            +
             | 
| 293 | 
            +
                  end
         | 
| 294 | 
            +
                  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/status", 'POST', {idx: local_idx, new_branch: new_branch, current_commit: commit, ignore:ignore_list, next_commit: next_commit})
         | 
| 295 | 
            +
                  CLI.is_response_success(response,false)
         | 
| 296 | 
            +
                  return response
         | 
| 297 | 
            +
                end
         | 
| 298 | 
            +
                def compare_idx_download(commit=last_local_commit,local_idx=nil,all=false)
         | 
| 238 299 | 
             
                  if local_idx.nil?
         | 
| 239 300 | 
             
                    local_idx =  self.generate_idx
         | 
| 240 301 | 
             
                  end
         | 
| 241 302 | 
             
                  ignore_list = self.send_ignore_list()
         | 
| 242 | 
            -
             | 
| 243 | 
            -
                  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/status", 'POST', {idx: local_idx, new_branch: new_branch, current_commit: commit, ignore:ignore_list})
         | 
| 303 | 
            +
                  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/download_status", 'POST', {idx: local_idx,  current_commit: commit, ignore:ignore_list,all_files:all})
         | 
| 244 304 | 
             
                  CLI.is_response_success(response,false)
         | 
| 245 305 | 
             
                  return response
         | 
| 246 306 | 
             
                end
         | 
| 307 | 
            +
                def current_status(new_branch)
         | 
| 308 | 
            +
                    commit=last_local_commit
         | 
| 309 | 
            +
                    response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/status_current", 'POST', {current_commit: commit,new_branch: new_branch})
         | 
| 310 | 
            +
                    CLI.is_response_success(response,true)
         | 
| 311 | 
            +
                    return response
         | 
| 312 | 
            +
                end
         | 
| 247 313 | 
             
                def send_ignore_list()
         | 
| 248 314 | 
             
                  begin
         | 
| 249 315 | 
             
                    ignore_list = []
         | 
| @@ -277,7 +343,45 @@ module Cnvrg | |
| 277 343 | 
             
                  CLI.is_response_success(response,false)
         | 
| 278 344 | 
             
                  return response
         | 
| 279 345 | 
             
                end
         | 
| 346 | 
            +
                def set_next_commit(commit_sha1)
         | 
| 347 | 
            +
                  if  !File.exist? "#{self.local_path}/.cnvrg/idx.yml"
         | 
| 348 | 
            +
                    idx_hash = Hash.new()
         | 
| 349 | 
            +
                    idx_hash[:commit] = ""
         | 
| 350 | 
            +
                    idx_hash[:tree] = ""
         | 
| 351 | 
            +
                  else
         | 
| 352 | 
            +
                    idx_hash = YAML.load_file("#{self.local_path}/.cnvrg/idx.yml")
         | 
| 280 353 |  | 
| 354 | 
            +
                  end
         | 
| 355 | 
            +
                  idx_hash[:next_commit] = commit_sha1
         | 
| 356 | 
            +
                  File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') { |f| f.write idx_hash.to_yaml }
         | 
| 357 | 
            +
                  return true
         | 
| 358 | 
            +
             | 
| 359 | 
            +
                end
         | 
| 360 | 
            +
                def get_next_commit()
         | 
| 361 | 
            +
                  if  !File.exist? "#{self.local_path}/.cnvrg/idx.yml"
         | 
| 362 | 
            +
                    return nil
         | 
| 363 | 
            +
                  end
         | 
| 364 | 
            +
                  idx_hash = YAML.load_file("#{self.local_path}/.cnvrg/idx.yml")
         | 
| 365 | 
            +
                  return idx_hash[:next_commit]
         | 
| 366 | 
            +
             | 
| 367 | 
            +
                end
         | 
| 368 | 
            +
                def remove_next_commit()
         | 
| 369 | 
            +
                  if  !File.exist? "#{self.local_path}/.cnvrg/idx.yml"
         | 
| 370 | 
            +
                    return nil
         | 
| 371 | 
            +
                  end
         | 
| 372 | 
            +
                  idx_hash = YAML.load_file("#{self.local_path}/.cnvrg/idx.yml")
         | 
| 373 | 
            +
                  idx = Hash.new()
         | 
| 374 | 
            +
                  idx[:commit] = idx_hash[:next_commit]
         | 
| 375 | 
            +
                  idx[:tree] = idx_hash[:tree]
         | 
| 376 | 
            +
                  File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') { |f| f.write idx.to_yaml }
         | 
| 377 | 
            +
             | 
| 378 | 
            +
             | 
| 379 | 
            +
                end
         | 
| 380 | 
            +
                def list_files(commit, json)
         | 
| 381 | 
            +
                  response = Cnvrg::API.request("users/#{self.owner}/datasets/#{self.slug}/list", 'GET', {commit_sha1:commit, as_json:json})
         | 
| 382 | 
            +
                  CLI.is_response_success(response,true)
         | 
| 383 | 
            +
                  return response
         | 
| 384 | 
            +
                end
         | 
| 281 385 | 
             
                def compare_commit(commit)
         | 
| 282 386 | 
             
                    if commit.nil? or commit.empty?
         | 
| 283 387 | 
             
                      commit = last_local_commit
         | 
| @@ -289,11 +393,14 @@ module Cnvrg | |
| 289 393 | 
             
                  end
         | 
| 290 394 |  | 
| 291 395 | 
             
                  def update_idx_with_files_commits!(files, commit_time)
         | 
| 292 | 
            -
             | 
| 396 | 
            +
                    files.flatten!
         | 
| 293 397 | 
             
                    idx_hash = YAML.load_file("#{self.local_path}/.cnvrg/idx.yml")
         | 
| 398 | 
            +
                    # idx_hash[:commit] = commit
         | 
| 399 | 
            +
             | 
| 294 400 | 
             
                    files.each do |path|
         | 
| 295 401 | 
             
                      idx_hash[:tree].to_h[path].to_h[:commit_time] = commit_time
         | 
| 296 402 | 
             
                    end
         | 
| 403 | 
            +
                    idx_hash[:next_commit] = idx_hash[:next_commit]
         | 
| 297 404 | 
             
                    File.open("#{self.local_path}/.cnvrg/idx.yml", 'w') { |f| f.write idx_hash.to_yaml }
         | 
| 298 405 |  | 
| 299 406 | 
             
                    return true
         | 
    
        data/lib/cnvrg/experiment.rb
    CHANGED
    
    | @@ -83,7 +83,7 @@ module Cnvrg | |
| 83 83 |  | 
| 84 84 | 
             
                end
         | 
| 85 85 |  | 
| 86 | 
            -
                def exec_remote(command, commit_to_run, instance_type, image_slug,scheduling_query,local_timestamp, grid,path_to_cmd,data, data_commit)
         | 
| 86 | 
            +
                def exec_remote(command, commit_to_run, instance_type, image_slug,scheduling_query,local_timestamp, grid,path_to_cmd,data, data_commit,periodic_sync, sync_before_terminate, max_time, ds_sync_options=0)
         | 
| 87 87 | 
             
                  response = Cnvrg::API.request("users/#{@owner}/projects/#{@project_slug}/experiment/remote", 'POST', {command: command, image_slug: image_slug,
         | 
| 88 88 | 
             
                                                                                                                        commit_sha1: commit_to_run,
         | 
| 89 89 | 
             
                                                                                                                        instance_type: instance_type,
         | 
| @@ -91,12 +91,15 @@ module Cnvrg | |
| 91 91 | 
             
                                                                                                                        local_timestamp:local_timestamp,
         | 
| 92 92 | 
             
                                                                                                                        grid: grid,
         | 
| 93 93 | 
             
                                                                                                                        path_to_cmd:path_to_cmd,dataset_slug:data,
         | 
| 94 | 
            -
                                                                                                                        dataset_commit: data_commit | 
| 94 | 
            +
                                                                                                                        dataset_commit: data_commit,max_time:max_time,
         | 
| 95 | 
            +
                                                                                                                        periodic_sync:periodic_sync, sync_before_terminate:sync_before_terminate,
         | 
| 96 | 
            +
                                                                                                                        dataset_sync_options:ds_sync_options})
         | 
| 95 97 | 
             
                  return response
         | 
| 96 98 | 
             
                end
         | 
| 97 | 
            -
                def remote_notebook(instance_type, commit, data, data_commit, notebook_type)
         | 
| 99 | 
            +
                def remote_notebook(instance_type, commit, data, data_commit, notebook_type,ds_sync_options=0)
         | 
| 98 100 | 
             
                  response = Cnvrg::API.request("users/#{@owner}/projects/#{@project_slug}/notebook/remote", 'POST', {instance_type: instance_type,dataset_slug:data,
         | 
| 99 | 
            -
                                                                                                                      dataset_commit: data_commit, | 
| 101 | 
            +
                                                                                                                      dataset_commit: data_commit,
         | 
| 102 | 
            +
                                                                                                                      commit:commit,notebook_type:notebook_type,dataset_sync_options:ds_sync_options})
         | 
| 100 103 | 
             
                  return response
         | 
| 101 104 | 
             
                end
         | 
| 102 105 |  | 
    
        data/lib/cnvrg/files.rb
    CHANGED
    
    | @@ -59,8 +59,8 @@ module Cnvrg | |
| 59 59 | 
             
                                                                                                         file_name: file_name, log_date: log_date,
         | 
| 60 60 | 
             
                                                                                                         file_size: file_size, file_content_type: content_type})
         | 
| 61 61 | 
             
                  if Cnvrg::CLI.is_response_success(upload_resp, false)
         | 
| 62 | 
            -
             | 
| 63 | 
            -
             | 
| 62 | 
            +
                   s3_res = upload_large_files_s3(upload_resp, absolute_path)
         | 
| 63 | 
            +
             | 
| 64 64 | 
             
                  end
         | 
| 65 65 | 
             
                  if s3_res
         | 
| 66 66 | 
             
                    return true
         | 
| @@ -130,8 +130,7 @@ module Cnvrg | |
| 130 130 | 
             
                                                                                                              is_base: is_base})
         | 
| 131 131 | 
             
                    # puts upload_resp
         | 
| 132 132 | 
             
                    if Cnvrg::CLI.is_response_success(upload_resp, false)
         | 
| 133 | 
            -
                       | 
| 134 | 
            -
                      s3_res = upload_small_files_s3(path, absolute_path, content_type)
         | 
| 133 | 
            +
                      s3_res = upload_large_files_s3(upload_resp, absolute_path)
         | 
| 135 134 | 
             
                      if s3_res
         | 
| 136 135 | 
             
                        commit_resp = Cnvrg::API.request("users/#{owner}/images/#{upload_resp["result"]["id"]}/" + "commit", 'GET')
         | 
| 137 136 | 
             
                        if Cnvrg::CLI.is_response_success(commit_resp, false)
         | 
| @@ -161,6 +160,7 @@ module Cnvrg | |
| 161 160 | 
             
                                                                                                              })
         | 
| 162 161 | 
             
                    # puts upload_resp
         | 
| 163 162 | 
             
                    if Cnvrg::CLI.is_response_success(upload_resp, false)
         | 
| 163 | 
            +
                      path = upload_resp["result"]["path"]
         | 
| 164 164 | 
             
                      s3_res = upload_large_files_s3(upload_resp, absolute_path)
         | 
| 165 165 | 
             
                      if s3_res
         | 
| 166 166 | 
             
                          return true
         | 
| @@ -254,50 +254,14 @@ module Cnvrg | |
| 254 254 |  | 
| 255 255 | 
             
                def upload_large_files_s3(upload_resp, file_path)
         | 
| 256 256 | 
             
                  begin
         | 
| 257 | 
            -
                    # speed_uri = URI.parse("https://s3-us-west-2.amazonaws.com/cnvrgw2-dev/speedtest-cli")
         | 
| 258 | 
            -
                    # speed_http_object = Net::HTTP.new(speed_uri.host, speed_uri.port)
         | 
| 259 | 
            -
                    # speed_http_object.use_ssl = true if speed_uri.scheme == 'https'
         | 
| 260 | 
            -
                    # speed_request = Net::HTTP::Get.new("https://s3-us-west-2.amazonaws.com/cnvrgw2-dev/speedtest-cli")
         | 
| 261 | 
            -
                    #
         | 
| 262 | 
            -
                    # speed_body = ""
         | 
| 263 | 
            -
                    # speed_http_object.start do |http|
         | 
| 264 | 
            -
                    #   response = http.request speed_request
         | 
| 265 | 
            -
                    #   speed_body = response.read_body
         | 
| 266 | 
            -
                    # end
         | 
| 267 | 
            -
                    # speed_tmp = Tempfile.new('speed')
         | 
| 268 | 
            -
                    # speed_tmp << speed_body
         | 
| 269 | 
            -
                    # speed_tmp.flush
         | 
| 270 | 
            -
                    # speed_tmp.close
         | 
| 271 | 
            -
                    # count = 0
         | 
| 272 | 
            -
                    # sum = 0
         | 
| 273 | 
            -
                    # speed_res = `python #{speed_tmp.path} --json`
         | 
| 274 | 
            -
                    # if !speed_res.nil? and !speed_res.empty?
         | 
| 275 | 
            -
                    #   upload = JSON.parse(speed_res)["upload"]
         | 
| 276 | 
            -
                    #   if !upload.nil?
         | 
| 277 | 
            -
                    #     up_spped = (upload/1000000).round(2)
         | 
| 278 | 
            -
                    #   end
         | 
| 279 | 
            -
                    #
         | 
| 280 | 
            -
                    #
         | 
| 281 | 
            -
                    #   file_size = File.size(file_path)/1048576
         | 
| 282 | 
            -
                    #   est_up = ((file_size*8)/up_spped)/60
         | 
| 283 | 
            -
                    #   puts est_up
         | 
| 284 | 
            -
                    # end
         | 
| 285 | 
            -
             | 
| 286 | 
            -
             | 
| 287 257 | 
             
                      sts_path = upload_resp["result"]["path_sts"]
         | 
| 288 258 |  | 
| 289 | 
            -
                       | 
| 290 | 
            -
             | 
| 291 | 
            -
                       | 
| 292 | 
            -
             | 
| 293 | 
            -
             | 
| 294 | 
            -
                      request = Net::HTTP::Get.new(sts_path)
         | 
| 295 | 
            -
             | 
| 296 | 
            -
                      body = ""
         | 
| 297 | 
            -
                      http_object.start do |http|
         | 
| 298 | 
            -
                        response = http.request request
         | 
| 299 | 
            -
                        body = response.read_body
         | 
| 259 | 
            +
                      if !Helpers.is_verify_ssl
         | 
| 260 | 
            +
                        body = open(sts_path, {ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE}).read
         | 
| 261 | 
            +
                      else
         | 
| 262 | 
            +
                        body = open(sts_path).read
         | 
| 300 263 | 
             
                      end
         | 
| 264 | 
            +
             | 
| 301 265 | 
             
                      split = body.split("\n")
         | 
| 302 266 | 
             
                      key = split[0]
         | 
| 303 267 | 
             
                      iv = split[1]
         | 
| @@ -310,18 +274,30 @@ module Cnvrg | |
| 310 274 | 
             
                      region =  Cnvrg::Helpers.decrypt(key,iv, upload_resp["result"]["region"])
         | 
| 311 275 |  | 
| 312 276 | 
             
                      bucket =  Cnvrg::Helpers.decrypt(key,iv, upload_resp["result"]["bucket"])
         | 
| 313 | 
            -
             | 
| 277 | 
            +
                      is_s3 = upload_resp["result"]["is_s3"]
         | 
| 278 | 
            +
                      if is_s3 or is_s3.nil?
         | 
| 279 | 
            +
                        use_accelerate_endpoint =true
         | 
| 314 280 | 
             
                      client = Aws::S3::Client.new(
         | 
| 315 281 | 
             
                            :access_key_id =>access,
         | 
| 316 282 | 
             
                            :secret_access_key => secret,
         | 
| 317 283 | 
             
                            :session_token => session,
         | 
| 318 284 | 
             
                            :region => region,
         | 
| 319 | 
            -
             | 
| 320 | 
            -
             | 
| 285 | 
            +
                      :http_open_timeout => 60, :retry_limit => 20)
         | 
| 286 | 
            +
                      else
         | 
| 287 | 
            +
                        endpoint = Cnvrg::Helpers.decrypt(key,iv, upload_resp["result"]["endpoint"])
         | 
| 288 | 
            +
                        use_accelerate_endpoint = false
         | 
| 289 | 
            +
                        client = Aws::S3::Client.new(
         | 
| 290 | 
            +
                            :access_key_id =>access,
         | 
| 291 | 
            +
                            :secret_access_key => secret,
         | 
| 292 | 
            +
                            :region => region,
         | 
| 293 | 
            +
                            :endpoint=> endpoint,:force_path_style=> true,:ssl_verify_peer=>false,
         | 
| 294 | 
            +
                            :http_open_timeout => 60, :retry_limit => 20)
         | 
| 295 | 
            +
                      end
         | 
| 296 | 
            +
             | 
| 321 297 | 
             
                        s3 = Aws::S3::Resource.new(client: client)
         | 
| 322 298 | 
             
                        resp = s3.bucket(bucket).
         | 
| 323 299 | 
             
                            object(upload_resp["result"]["path"]+"/"+File.basename(file_path)).
         | 
| 324 | 
            -
                            upload_file(file_path, {:use_accelerate_endpoint =>  | 
| 300 | 
            +
                            upload_file(file_path, {:use_accelerate_endpoint => use_accelerate_endpoint, :server_side_encryption => 'AES256'})
         | 
| 325 301 |  | 
| 326 302 | 
             
                      return resp
         | 
| 327 303 |  | 
| @@ -344,6 +320,9 @@ module Cnvrg | |
| 344 320 | 
             
                    body = file.read
         | 
| 345 321 | 
             
                    begin
         | 
| 346 322 | 
             
                      Net::HTTP.start(url.host) do |http|
         | 
| 323 | 
            +
                        if !Helpers.is_verify_ssl
         | 
| 324 | 
            +
                          http.verify_mode = OpenSSL::SSL::VERIFY_NONE
         | 
| 325 | 
            +
                        end
         | 
| 347 326 | 
             
                        http.send_request("PUT", url.request_uri, body, {
         | 
| 348 327 | 
             
                            "content-type" => content_type,
         | 
| 349 328 | 
             
                        })
         | 
| @@ -394,15 +373,10 @@ module Cnvrg | |
| 394 373 |  | 
| 395 374 | 
             
                        absolute_path += ".conflict" if conflict
         | 
| 396 375 | 
             
                        sts_path = download_resp["result"]["path_sts"]
         | 
| 397 | 
            -
                         | 
| 398 | 
            -
             | 
| 399 | 
            -
                         | 
| 400 | 
            -
             | 
| 401 | 
            -
             | 
| 402 | 
            -
                        body = ""
         | 
| 403 | 
            -
                        http_object.start do |http|
         | 
| 404 | 
            -
                          response = http.request request
         | 
| 405 | 
            -
                          body = response.read_body
         | 
| 376 | 
            +
                        if !Helpers.is_verify_ssl
         | 
| 377 | 
            +
                          body = open(sts_path, {ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE}).read
         | 
| 378 | 
            +
                        else
         | 
| 379 | 
            +
                          body = open(sts_path).read
         | 
| 406 380 | 
             
                        end
         | 
| 407 381 | 
             
                        split = body.split("\n")
         | 
| 408 382 | 
             
                        key = split[0]
         | 
| @@ -416,18 +390,29 @@ module Cnvrg | |
| 416 390 | 
             
                        region =  Cnvrg::Helpers.decrypt(key,iv, download_resp["result"]["region"])
         | 
| 417 391 |  | 
| 418 392 | 
             
                        bucket =  Cnvrg::Helpers.decrypt(key,iv, download_resp["result"]["bucket"])
         | 
| 419 | 
            -
                         | 
| 393 | 
            +
                        file_key =  Cnvrg::Helpers.decrypt(key,iv, download_resp["result"]["key"])
         | 
| 394 | 
            +
             | 
| 395 | 
            +
                        is_s3 = download_resp["result"]["is_s3"]
         | 
| 396 | 
            +
                        if is_s3 or is_s3.nil?
         | 
| 397 | 
            +
                          client = Aws::S3::Client.new(
         | 
| 398 | 
            +
                              :access_key_id =>access,
         | 
| 399 | 
            +
                              :secret_access_key => secret,
         | 
| 400 | 
            +
                              :session_token => session,
         | 
| 401 | 
            +
                              :region => region,
         | 
| 402 | 
            +
                              :http_open_timeout => 60, :retry_limit => 20)
         | 
| 403 | 
            +
                        else
         | 
| 404 | 
            +
                          endpoint = Cnvrg::Helpers.decrypt(key,iv, download_resp["result"]["endpoint_url"])
         | 
| 405 | 
            +
                          client = Aws::S3::Client.new(
         | 
| 406 | 
            +
                              :access_key_id =>access,
         | 
| 407 | 
            +
                              :secret_access_key => secret,
         | 
| 408 | 
            +
                              :region => region,
         | 
| 409 | 
            +
                              :endpoint=> endpoint,:force_path_style=> true,:ssl_verify_peer=>false,
         | 
| 410 | 
            +
                              :http_open_timeout => 60, :retry_limit => 20)
         | 
| 411 | 
            +
                        end
         | 
| 420 412 |  | 
| 421 | 
            -
                        client = Aws::S3::Client.new(
         | 
| 422 | 
            -
                            :access_key_id =>access,
         | 
| 423 | 
            -
                            :secret_access_key => secret,
         | 
| 424 | 
            -
                            :session_token => session,
         | 
| 425 | 
            -
                            :region => region,
         | 
| 426 | 
            -
                            :http_open_timeout => 60, :retry_limit => 20
         | 
| 427 | 
            -
                        )
         | 
| 428 413 | 
             
                        File.open(project_home+"/"+absolute_path, 'w+') do |file|
         | 
| 429 414 | 
             
                          resp = client.get_object({bucket:bucket,
         | 
| 430 | 
            -
                                                key: | 
| 415 | 
            +
                                                key:file_key}, target: file)
         | 
| 431 416 | 
             
                        end
         | 
| 432 417 | 
             
                        return true
         | 
| 433 418 | 
             
                      end
         |