Module: DTK::Client::PullFromRemoteMixin

Included in:
ModuleMixin
Defined in:
lib/commands/common/thor/pull_from_remote.rb

Defined Under Namespace

Modules: PullFromRemote

Instance Method Summary collapse

Instance Method Details

#pull_from_remote_aux(module_type, module_id, opts = {}) ⇒ Object

Raises:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/commands/common/thor/pull_from_remote.rb', line 20

def pull_from_remote_aux(module_type,module_id,opts={})
  version = opts[:version]
  remote_namespace = opts[:remote_namespace]
  #get remote module info, errors raised if remote is not linked or access errors
  path_to_key = SSHUtil.default_rsa_pub_key_path()
  rsa_pub_key = File.file?(path_to_key) && File.open(path_to_key){|f|f.read}.chomp

  post_body = PostBody.new(
    PullFromRemote.id_field(module_type) => module_id,
    :access_rights => "r",
    :action => "pull",
    :version? => version,
    :remote_namespace? => remote_namespace,
    :rsa_pub_key? => rsa_pub_key
  )
  response = post(rest_url("#{module_type}/get_remote_module_info"),post_body)
  return response unless response.ok?

  module_name,full_module_name, frozen = response.data(:module_name, :full_module_name, :frozen)
  raise DtkError, "You are not allowed to update frozen #{module_type} versions!" if frozen

  remote_params = response.data_hash_form(:remote_repo_url,:remote_repo,:remote_branch)
  remote_params.merge!(:version => version) if version

  # check and import component module dependencies before importing service itself
  unless opts[:skip_recursive_pull]
    import_module_component_dependencies(module_type, module_id, remote_namespace)
  end

  # check whether a local module exists to determine whether pull from local clone or try to pull from server
  # TODO: probably remove OsUtil.print("Pulling changes from remote: #{remote_params[:remote_repo]} @ #{remote_params[:remote_repo_url]}")

  if Helper(:git_repo).local_clone_dir_exists?(module_type, module_name, :full_module_name => full_module_name, :version => version)
    unless rsa_pub_key
      raise DtkError,"No File found at (#{path_to_key}). Path is wrong or it is necessary to generate the public rsa key (e.g., run ssh-keygen -t rsa)"
    end
    opts_perform_locally = remote_params.merge(
      :full_module_name => full_module_name,
      :force => opts[:force],
      :do_not_raise => opts[:do_not_raise],
      :ignore_dependency_merge_conflict => opts[:ignore_dependency_merge_conflict]
    )
    PullFromRemote.perform_locally(self,module_type,module_id,module_name,opts_perform_locally)
  else
    # TODO: see if this works correctly
    PullFromRemote.perform_on_server(self,module_type,module_id,full_module_name,remote_params)
  end
end