13
14
15
16
17
18
19
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/fastlane/plugin/dynatrace/helper/dynatrace_helper.rb', line 13
def self.get_dss_client(params)
dynatraceDir = "dynatrace"
dtxDssClientBin = "DTXDssClient"
versionFilePath = "#{dynatraceDir}/version"
dtxDssClientPath = "#{dynatraceDir}/#{dtxDssClientBin}"
if params.all_keys.include? :dtxDssClientPath and not params[:dtxDssClientPath].nil?
UI.important "DEPRECATION WARNING: dtxDssClientPath doesn't need to be specified anymore, the #{dtxDssClientBin} is downloaded and updated automatically."
return params[:dtxDssClientPath]
end
clientUri = URI("#{self.without_trailing_slash(params[:server])}/api/config/v1/symfiles/dtxdss-download?Api-Token=#{params[:apitoken]}")
response = Net::HTTP.get_response(clientUri)
if not response.kind_of? Net::HTTPSuccess
error_msg = "Couldn't update #{dtxDssClientBin} (invalid response: #{response.message} (#{response.code})) for URL: #{self.to_redacted_api_token_string(clientUri)})"
self.check_fallback_or_raise(dtxDssClientPath, error_msg)
return dtxDssClientPath
end
begin
responseJson = JSON.parse(response.body)
rescue JSON::GeneratorError,
JSON::JSONError,
JSON::NestingError,
JSON::ParserError
error_msg = "Error parsing response body: #{response.body} from URL (#{self.to_redacted_api_token_string(clientUri)}), failed with error #{$!}"
self.check_fallback_or_raise(dtxDssClientPath, error_msg)
return dtxDssClientPath
end
remoteClientUrl = responseJson["dssClientUrl"]
if remoteClientUrl.nil? or remoteClientUrl.empty?
error_msg = "No value for dssClientUrl in response body (#{response.body})."
self.check_fallback_or_raise(dtxDssClientPath, error_msg)
return dtxDssClientPath
end
UI.message "Remote DSS client: #{remoteClientUrl}"
if !File.directory?(dynatraceDir)
Dir.mkdir(dynatraceDir)
end
if !(File.exists?(versionFilePath) and
File.exists?(dtxDssClientPath) and
File.read(versionFilePath) == remoteClientUrl and
File.size(dtxDssClientPath) > 0)
updatedClient = false
zipped_tmp = self.save_to_tempfile(remoteClientUrl)
if File.size(zipped_tmp) <= 0
error_msg = "Downloaded symbolication client archive is empty (0 bytes)."
self.check_fallback_or_raise(dtxDssClientPath, error_msg)
return dtxDssClientPath
end
begin
UI.message "Unzipping fetched file with MD5 hash: #{Digest::MD5.new << IO.read(zipped_tmp)}"
Zip::InputStream.open(zipped_tmp) do |unzipped|
entry = unzipped.get_next_entry
if (entry.name == dtxDssClientBin)
UI.message "Found a different remote #{dtxDssClientBin} client. Removing local version and updating."
File.delete(versionFilePath) if File.exist?(versionFilePath)
File.delete(dtxDssClientPath) if File.exist?(dtxDssClientPath)
File.write(versionFilePath, remoteClientUrl)
IO.copy_stream(entry.get_input_stream, dtxDssClientPath)
FileUtils.chmod("+x", dtxDssClientPath)
updatedClient = true
end
end
rescue Zip::DecompressionError,
Zip::DestinationFileExistsError,
Zip::EntryExistsError,
Zip::EntryNameError,
Zip::EntrySizeError,
Zip::GPFBit3Error,
Zip::InternalError,
Zip::CompressionMethodError
error_msg = "Could not update/extract #{dtxDssClientBin}, please try again."
self.check_fallback_or_raise(dtxDssClientPath, error_msg)
return dtxDssClientPath
end
if updatedClient
UI.success "Successfully updated DTXDssClient."
else
error_msg = "#{dtxDssClientBin} not found in served archive, please try again."
self.check_fallback_or_raise(dtxDssClientPath, error_msg)
return dtxDssClientPath
end
end
return dtxDssClientPath
end
|