Module: LitaNexusHelper::Remote

Included in:
Lita::Handlers::Nexus
Defined in:
lib/nexushelper/remote.rb

Instance Method Summary collapse

Instance Method Details

#delete_artifact(coordinate) ⇒ Object



73
74
75
76
# File 'lib/nexushelper/remote.rb', line 73

def delete_artifact(coordinate)
  remote = nexus_remote
  remote.delete_artifact(coordinate)
end

#get_artifact_info(coordinate) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/nexushelper/remote.rb', line 29

def get_artifact_info(coordinate)
  remote = nexus_remote
  info = nil
  begin
    info = remote.get_artifact_info(coordinate)
  rescue NexusCli::ArtifactNotFoundException => e
    info = t('msg.info_artifact_not_found')
  end
  #puts "info: #{info}"
  info
end

#get_current_repoObject



78
79
80
# File 'lib/nexushelper/remote.rb', line 78

def get_current_repo
  config.current_repository || config.default_repository
end

#get_license_infoObject



52
53
54
55
56
57
58
59
60
# File 'lib/nexushelper/remote.rb', line 52

def get_license_info
  remote = nexus_remote
  if remote.respond_to? 'get_license_info'
    remote.get_license_info
  else
    #'Only supported on professional version.'
    t('msg.info_only_supported_on_pro_version')
  end
end

#get_repository_info(coordinate) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/nexushelper/remote.rb', line 62

def get_repository_info(coordinate)
  remote = nexus_remote
  info = nil
  begin
    info = remote.get_repository_info(coordinate)
  rescue NexusCli::RepositoryNotFoundException => e
    info = t('msg.info_repository_not_found')
  end
  info
end

#nexus_remoteObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/nexushelper/remote.rb', line 7

def nexus_remote
  begin
    if config.password_plain.nil? || config.password_plain.length <1
      pk_path = config.rsa_private_key
      pk = OpenSSL::PKey::RSA.new File.read(pk_path)
      decrypted_pass = pk.private_decrypt Base64::decode64(config.password_hash)
    else
      decrypted_pass = config.password_plain
    end

    overrides = {
      :url => config.url,
      :repository => get_current_repo,
      :username => config.username,
      :password => decrypted_pass
    }
    nexus_remote ||= NexusCli::RemoteFactory.create(overrides, config.verify_ssl||false)
  rescue NexusCli::NexusCliError => e
    puts e.message
  end
end

#push_artifact(coordinate, file_path) ⇒ Object



82
83
84
85
86
87
88
89
90
# File 'lib/nexushelper/remote.rb', line 82

def push_artifact(coordinate, file_path)
  remote = nexus_remote
  begin
    #boolean result
    success = remote.push_artifact(coordinate, file_path)
  rescue Exception => e
    raise "Failed to push artifact, #{e.message}"
  end
end

#search_for_artifact(coordinate) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/nexushelper/remote.rb', line 41

def search_for_artifact(coordinate)
  begin
    remote = nexus_remote
    nexus = remote.nexus
    #puts nexus.inspect
    info = remote.search_for_artifacts(coordinate)
  rescue Exception => e
    raise "Failed to search: #{e.message}"
  end
end

#search_with_lucene(coordinate) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/nexushelper/remote.rb', line 92

def search_with_lucene(coordinate)
  remote = nexus_remote
  nexus = remote.nexus
  artifact = NexusCli::Artifact.new(coordinate)
  query = {:g => artifact.group_id, :a => artifact.artifact_id, :e => artifact.extension, :v => artifact.version, :r => get_current_repo}
  query.merge!({:c => artifact.classifier}) unless artifact.classifier.nil?
  response = nexus.get(remote.nexus_url("service/local/lucene/search"), query)
  case response.status
    when 200
      return response.content
    else
      raise UnexpectedStatusCodeException.new(response.status)
  end
end