Class: KPM::NexusFacade::NexusApiCallsV2
- Inherits:
-
Object
- Object
- KPM::NexusFacade::NexusApiCallsV2
show all
- Defined in:
- lib/kpm/nexus_helper/nexus_api_calls_v2.rb
Overview
This is an extract and slim down of functions needed from nexus_cli to maintain the response expected by the base_artifact.
Constant Summary
collapse
- READ_TIMEOUT_DEFAULT =
60
- OPEN_TIMEOUT_DEFAULT =
60
- ERROR_MESSAGE_404 =
'The artifact you requested information for could not be found. Please ensure it exists inside the Nexus.'
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(configuration, ssl_verify, logger) ⇒ NexusApiCallsV2
Returns a new instance of NexusApiCallsV2.
39
40
41
42
43
|
# File 'lib/kpm/nexus_helper/nexus_api_calls_v2.rb', line 39
def initialize(configuration, ssl_verify, logger)
@configuration = configuration
@ssl_verify = ssl_verify
@logger = logger
end
|
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
35
36
37
|
# File 'lib/kpm/nexus_helper/nexus_api_calls_v2.rb', line 35
def configuration
@configuration
end
|
#logger ⇒ Object
Returns the value of attribute logger.
37
38
39
|
# File 'lib/kpm/nexus_helper/nexus_api_calls_v2.rb', line 37
def logger
@logger
end
|
#ssl_verify ⇒ Object
Returns the value of attribute ssl_verify.
35
36
37
|
# File 'lib/kpm/nexus_helper/nexus_api_calls_v2.rb', line 35
def ssl_verify
@ssl_verify
end
|
#version ⇒ Object
Returns the value of attribute version.
35
36
37
|
# File 'lib/kpm/nexus_helper/nexus_api_calls_v2.rb', line 35
def version
@version
end
|
Instance Method Details
#build_query_params(coordinates, what_parameters = nil) ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/kpm/nexus_helper/nexus_api_calls_v2.rb', line 93
def build_query_params(coordinates, what_parameters = nil)
artifact = parse_coordinates(coordinates)
@version = artifact[:version].to_s.upcase
query = { g: artifact[:group_id], a: artifact[:artifact_id], e: artifact[:extension], v: version, r: configuration[:repository] }
query.merge!(c: artifact[:classifier]) unless artifact[:classifier].nil?
params = what_parameters.nil? ? query : {}
what_parameters.each { |key| params[key] = query[key] unless query[key].nil? } unless what_parameters.nil?
params.map { |key, value| "#{key}=#{value}" }.join('&')
end
|
#get_artifact_info(coordinates) ⇒ Object
60
61
62
|
# File 'lib/kpm/nexus_helper/nexus_api_calls_v2.rb', line 60
def get_artifact_info(coordinates)
get_response_with_retries(coordinates, get_artifact_info_endpoint(coordinates), nil)
end
|
#get_artifact_info_endpoint(_coordinates) ⇒ Object
85
86
87
|
# File 'lib/kpm/nexus_helper/nexus_api_calls_v2.rb', line 85
def get_artifact_info_endpoint(_coordinates)
'/service/local/artifact/maven/resolve'
end
|
#pull_artifact(coordinates, destination) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/kpm/nexus_helper/nexus_api_calls_v2.rb', line 64
def pull_artifact(coordinates, destination)
file_name = get_file_name(coordinates)
destination = File.join(File.expand_path(destination || '.'), file_name)
logger.debug { "Downloading to destination: #{destination}" }
File.open(destination, 'wb') do |io|
io.write(get_response_with_retries(coordinates, pull_artifact_endpoint(coordinates), nil))
end
{
file_name: file_name,
file_path: File.expand_path(destination),
version: version,
size: File.size(File.expand_path(destination))
}
end
|
#pull_artifact_endpoint(_coordinates) ⇒ Object
81
82
83
|
# File 'lib/kpm/nexus_helper/nexus_api_calls_v2.rb', line 81
def pull_artifact_endpoint(_coordinates)
'/service/local/artifact/maven/redirect'
end
|
#search_for_artifact_endpoint(_coordinates) ⇒ Object
89
90
91
|
# File 'lib/kpm/nexus_helper/nexus_api_calls_v2.rb', line 89
def search_for_artifact_endpoint(_coordinates)
'/service/local/lucene/search'
end
|
#search_for_artifacts(coordinates) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/kpm/nexus_helper/nexus_api_calls_v2.rb', line 45
def search_for_artifacts(coordinates)
logger.debug "Entered - Search for artifact, coordinates: #{coordinates}"
response = get_response(coordinates, search_for_artifact_endpoint(coordinates), %i[g a])
case response.code
when '200'
logger.debug "response body: #{response.body}"
response.body
when '404'
raise StandardError, ERROR_MESSAGE_404
else
raise UnexpectedStatusCodeException, response.code
end
end
|