redhat_access 2.2.10 → 2.2.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67e8e666255e81f7ceb89434135c64a904a772adad60369a9d24e0770000c1ae
4
- data.tar.gz: 99124c4b5f76163caff0d015f0d0344210283e40421a5175696419b3f297edfa
3
+ metadata.gz: 9f89c7faa75f59562806c09d6c4dc210e754bcf2fe0148c3adc8e4017790df0e
4
+ data.tar.gz: e775c96ab698eb7ab8cc7969f8423a1b323a749ff9a86b4adfe57addb704e059
5
5
  SHA512:
6
- metadata.gz: 187cc7495cc438df0c718dcb0a809c4ec48170e3d1fee9afcf731d0734d67429a92ea615ee69a08815a8d4ce8d5b1722f148dd98c56388f0a2a48991824b04ec
7
- data.tar.gz: '089e0155d72b586a7cb3b988842e07c05e160103e3620e33163ac875d22005ec5dfbe9079005b2e6c7cb44693270be91012b1360f3d519c74ffbef491554d267'
6
+ metadata.gz: 84ea9bc59d80cb132a2e833ee2c47c6c38db1ede55c2fb28fd974f06c5b51fe9be3647cb1fd17b4456c8a49a3a046914f10fa25b106a6e3e39ada41364436ee7
7
+ data.tar.gz: cdb8bae03acecdc24d49fe1228ad8c0fc78ccbec51389057f0c986af2e55e14454aaecf10549310edd62f846913394c2cc08e85f9fbb7e7cd1fe132352f4e9bf
@@ -42,8 +42,8 @@ module RedhatAccess
42
42
  end
43
43
 
44
44
  def proxy_upload
45
- original_method = request.method
46
- original_params = add_branch_to_params(request.query_parameters)
45
+ original_method = request.method
46
+ original_params = add_branch_to_params(request.query_parameters)
47
47
  original_payload = request.request_parameters[controller_name]
48
48
  if not params[:id] and params[:test]
49
49
  resource = "uploads/"
@@ -58,27 +58,31 @@ module RedhatAccess
58
58
  #Overwrite payload if sending a file
59
59
  original_payload = get_file_data(params)
60
60
  end
61
-
61
+
62
62
  client = get_api_client
63
63
  Rails.logger.debug("Proxy upload original_payload : #{original_payload}")
64
64
  res = client.call_tapi(original_method, URI.escape(resource), original_params, original_payload, {timeout: get_upload_timeout}, use_subsets)
65
- render status: res[:code] , json: res[:data]
65
+ render status: res[:code], json: res[:data]
66
66
  end
67
67
 
68
68
  def get_branch_info
69
69
  uuid = User.current.login
70
70
  begin
71
71
  org = get_organization(uuid)
72
- major,minor,build = get_plugin_parent_version.scan(/\d+/)
73
- client_id = {:remote_leaf => uuid ,
74
- :remote_branch => get_branch_id_for_uuid(uuid),
72
+ labels = get_labels_for_host(uuid)
73
+ major, minor, build = get_plugin_parent_version.scan(/\d+/)
74
+ client_id = {:remote_leaf => uuid,
75
+ :remote_branch => get_branch_id_for_org(org),
75
76
  :display_name => org.name,
76
77
  :hostname => request.host,
77
78
  :product => {:type => get_plugin_parent_name,
78
79
  :major_version => major,
79
80
  :minor_version => minor
80
- }
81
- }
81
+ },
82
+ :organization_id => org.id,
83
+ :satellite_instance_id => get_foreman_instance_id,
84
+ :labels => labels
85
+ }
82
86
  render :json => client_id.to_json
83
87
  rescue RedhatAccess::Telemetry::LookUps::RecordNotFound => e
84
88
  http_error_response(e.message, 400)
@@ -86,7 +90,6 @@ module RedhatAccess
86
90
  end
87
91
 
88
92
 
89
-
90
93
  protected
91
94
 
92
95
  def use_subsets
@@ -112,6 +115,91 @@ module RedhatAccess
112
115
  def get_branch_id
113
116
  get_branch_id_for_uuid(User.current.login)
114
117
  end
118
+
119
+ def get_labels_for_host(uuid)
120
+ host = get_content_host(uuid)
121
+ org = get_organization(host)
122
+
123
+ # get organization
124
+ labels = [{
125
+ :namespace => "Satellite",
126
+ :key => "Organization",
127
+ :value => org.name
128
+ }]
129
+
130
+ # get locations - one tag for each location element
131
+ location = host.location
132
+ unless location.nil?
133
+ location.title.split('/').each do |title|
134
+ labels += [{
135
+ :namespace => "Satellite",
136
+ :key => "Location",
137
+ :value => title
138
+ }]
139
+ end
140
+ end
141
+
142
+ # get hostgroup and config groups
143
+ hostgroup = host.hostgroup_id.nil? ? nil : ::Hostgroup.unscoped.find(host.hostgroup_id)
144
+ unless hostgroup.nil?
145
+ hostgroup.title.split('/').each do |title|
146
+ labels += [{
147
+ :namespace => "Satellite",
148
+ :key => "Host Group",
149
+ :value => title
150
+ }]
151
+ end
152
+
153
+ # We're leaving these out for the moment....
154
+
155
+ # # seems like this is missing parent config groups...
156
+ # hostgroup.all_config_groups.each do |config_group|
157
+ # labels += [{
158
+ # :namespace => "Satellite",
159
+ # :key => "Config Group",
160
+ # :value => config_group.name
161
+ # }]
162
+ # end
163
+ end
164
+
165
+ # get host_collections
166
+ host.host_collections.each do |collection|
167
+ labels += [{
168
+ :namespace => "Satellite",
169
+ :key => "Host Collection",
170
+ :value => collection.name
171
+ }]
172
+ end
173
+
174
+ # get parameters - perhaps we should only include parameter.searchable_value == true?
175
+ include_parameter_tags = get_include_parameter_tags # true, false or list
176
+ if include_parameter_tags
177
+ host.host_inherited_params_objects.each do |parameter|
178
+ # check to see if parameter.name is in list (if it *is* a list...)
179
+ if include_parameter_tags.respond_to?(:none?)
180
+ # skip tag if no match in list
181
+ next if include_parameter_tags.none? do |pattern|
182
+ begin
183
+ parameter.name.match?(pattern)
184
+ rescue RegexpError => e
185
+ Rails.logger.debug("Skipping bad parameter expression: #{e}")
186
+ # remove the bad pattern from the list so we don't keep iterating over it
187
+ include_parameter_tags.delete(pattern)
188
+ next
189
+ end
190
+ end
191
+ end
192
+ # add tag to list of labels
193
+ labels += [{
194
+ :namespace => "SatelliteParameter",
195
+ :key => parameter.name,
196
+ :value => parameter.value
197
+ }]
198
+ end
199
+ end
200
+
201
+ return labels
202
+ end
115
203
  end
116
204
  end
117
205
  end
@@ -118,7 +118,7 @@ module RedhatAccess
118
118
 
119
119
  client = get_api_client
120
120
  res = client.call_tapi(original_method, URI.escape(resource), original_params, original_payload, {timeout: get_tapi_timeout}, use_subsets)
121
- #401 erros means our proxy is not configured right.
121
+ #401 errors means our proxy is not configured right.
122
122
  #Change it to 502 to distinguish with local applications 401 errors
123
123
  resp_data = res[:data]
124
124
  if res[:code] == 401
@@ -136,6 +136,9 @@ module RedhatAccess
136
136
  if resp_data.headers[:x_resource_count]
137
137
  response.headers['x-resource-count'] = resp_data.headers[:x_resource_count]
138
138
  end
139
+ if resp_data.headers[:x_rh_insights_request_id]
140
+ response.headers['x_rh_insights_request_id'] = resp_data.headers[:x_rh_insights_request_id]
141
+ end
139
142
  render status: res[:code], json: resp_data
140
143
  else
141
144
  render status: res[:code], json: resp_data
@@ -12,7 +12,7 @@ module RedhatAccess
12
12
  def search_by_plan_id(key, operator, value)
13
13
  insights_plan_runner = ForemanAnsible::InsightsPlanRunner.new(Organization.current, value.to_i)
14
14
  hostname_rules_relation = insights_plan_runner.hostname_rules(insights_plan_runner.playbook)
15
- host_ids = Host::Managed.where(:name => hostname_rules_relation.keys).pluck(:id)
15
+ host_ids = Host::Managed.where(:name => hostname_rules_relation.keys.map{|h| h.downcase}).pluck(:id)
16
16
  { :conditions => " hosts.id IN(#{host_ids.join(',')})" }
17
17
  end
18
18
  end
@@ -168,8 +168,13 @@ module RedhatAccess
168
168
  get_branch_id_for_org org
169
169
  end
170
170
 
171
- def get_organization(uuid)
172
- system = get_content_host(uuid)
171
+ def get_organization(uuid_or_host)
172
+ # this takes either a host object or a uuid string
173
+ if uuid_or_host.is_a?(::Host::Managed)
174
+ return uuid_or_host.nil? ? nil : uuid_or_host.organization
175
+ end
176
+
177
+ system = get_content_host(uuid_or_host)
173
178
  system.nil? ? nil : system.organization
174
179
  end
175
180
 
@@ -191,21 +196,56 @@ module RedhatAccess
191
196
  end
192
197
  end
193
198
 
199
+ def get_foreman_instance_id
200
+ Foreman.respond_to?(:instance_id) ? Foreman.instance_id : nil
201
+ end
202
+
194
203
  def get_portal_http_proxy
195
- proxy = nil
196
- if SETTINGS[:katello][:cdn_proxy] && SETTINGS[:katello][:cdn_proxy][:host]
197
- proxy_config = SETTINGS[:katello][:cdn_proxy]
198
- scheme = URI.parse(proxy_config[:host]).scheme
199
- uri = URI('')
200
- uri.scheme = 'proxy' if scheme == 'http'
201
- uri.scheme = 'proxys' if scheme == 'https'
202
- uri.host = URI.parse(proxy_config[:host]).host
203
- uri.port = proxy_config[:port] if proxy_config[:port]
204
- uri.user = CGI.escape(proxy_config[:user]) if proxy_config[:user]
205
- uri.password = CGI.escape(proxy_config[:password]) if proxy_config[:password]
206
- proxy = uri.to_s
204
+ begin
205
+ @http_proxy_string ||=
206
+ begin
207
+ proxy_uri = URI('')
208
+
209
+ if Setting[:content_default_http_proxy].present?
210
+ proxy_config = HttpProxy.default_global_content_proxy
211
+ proxy_uri = URI(proxy_config&.url)
212
+ if proxy_config&.username.present?
213
+ proxy_uri.user = CGI.escape(proxy_config&.username)
214
+ if proxy_config&.password.present?
215
+ proxy_uri.password = CGI.escape(proxy_config&.password)
216
+ end
217
+ end
218
+ end
219
+
220
+ if proxy_uri.to_s.blank?
221
+ if SETTINGS[:katello][:cdn_proxy] && SETTINGS[:katello][:cdn_proxy][:host]
222
+ proxy_config = SETTINGS[:katello][:cdn_proxy]
223
+ proxy_uri.scheme = URI.parse(proxy_config[:host]).scheme
224
+ proxy_uri.host = URI.parse(proxy_config[:host]).host
225
+ proxy_uri.port = proxy_config[:port] if proxy_config[:port]
226
+ if proxy_config[:user].present?
227
+ proxy_uri.user = CGI.escape(proxy_config[:user]) if proxy_config[:user]
228
+ if proxy_config[:password].present?
229
+ proxy_uri.password = CGI.escape(proxy_config[:password])
230
+ end
231
+ end
232
+ end
233
+ end
234
+
235
+ # Ruby's uri parser doesn't handle encoded characters so Katello added two new schemes to handle proxy
236
+ # passwords. See https://github.com/Katello/katello/blob/master/app/lib/katello/util/proxy_uri.rb
237
+ proxy_uri.scheme = 'proxy' if proxy_uri.scheme == 'http'
238
+ proxy_uri.scheme = 'proxys' if proxy_uri.scheme == 'https'
239
+
240
+ proxy_uri.to_s
241
+ end
242
+
243
+ Rails.logger.debug("Insights proxy url = #{@http_proxy_string}")
244
+ @http_proxy_string
245
+ rescue
246
+ Rails.logger.debug("insights plugin: Something bad happened trying to get the proxy url")
247
+ raise
207
248
  end
208
- proxy
209
249
  end
210
250
 
211
251
  def get_http_user_agent
@@ -239,6 +279,11 @@ module RedhatAccess
239
279
  REDHAT_ACCESS_CONFIG[:telemetry_upload_timeout_s] || 120
240
280
  end
241
281
 
282
+ # list of parameters to include as tags (or 'true' for all of them)
283
+ def get_include_parameter_tags
284
+ REDHAT_ACCESS_CONFIG[:include_parameter_tags] || false
285
+ end
286
+
242
287
  def user_login_to_hash(login)
243
288
  Digest::SHA1.hexdigest(login)
244
289
  end
@@ -161,8 +161,8 @@ module RedhatAccess
161
161
  end
162
162
  res = new_api_client(add_user_header).call_tapi(options[:method],
163
163
  URI.escape(options[:resource]),
164
- #{:branch_id => @branch_id}.merge(options[:params]),
165
- options[:params],
164
+ {:branch_id => @branch_id}.merge(options[:params]),
165
+ # options[:params],
166
166
  options[:payload],
167
167
  {timeout: get_tapi_timeout},
168
168
  options[:use_subsets])
@@ -1,3 +1,3 @@
1
1
  module RedhatAccess
2
- VERSION = "2.2.10"
2
+ VERSION = "2.2.15"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redhat_access
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.10
4
+ version: 2.2.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lindani Phiri
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-01-27 00:00:00.000000000 Z
12
+ date: 2020-06-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redhat_access_lib