redhat_access 2.2.10 → 2.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67e8e666255e81f7ceb89434135c64a904a772adad60369a9d24e0770000c1ae
4
- data.tar.gz: 99124c4b5f76163caff0d015f0d0344210283e40421a5175696419b3f297edfa
3
+ metadata.gz: e94c4f74c8bf19599836bcfa836469540b00cb9680dad9c9a21aaaddb2ef4c4f
4
+ data.tar.gz: ec9a734f1907e2ebe6317accdaaa5b23d218eddc60ac2730f38040bd6f204dad
5
5
  SHA512:
6
- metadata.gz: 187cc7495cc438df0c718dcb0a809c4ec48170e3d1fee9afcf731d0734d67429a92ea615ee69a08815a8d4ce8d5b1722f148dd98c56388f0a2a48991824b04ec
7
- data.tar.gz: '089e0155d72b586a7cb3b988842e07c05e160103e3620e33163ac875d22005ec5dfbe9079005b2e6c7cb44693270be91012b1360f3d519c74ffbef491554d267'
6
+ metadata.gz: 3119df6ee719a94587de96ed060c8f505fce193c9c40d67555471a8a3176a000501d96a1b725c1bac132fe3e6edd1d9c8ed6f2717982e509bc0974fa7b6e75b6
7
+ data.tar.gz: 180a8b8c3b4a528f4d16d7fa3b117851ce527ed646a51491c4928947136608799e49f8dd37858158e732125e5fa53256ac320dcced2e4b5407559d6f9ab965ec
@@ -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
@@ -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,12 +196,18 @@ 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
204
  proxy = nil
196
205
  if SETTINGS[:katello][:cdn_proxy] && SETTINGS[:katello][:cdn_proxy][:host]
197
206
  proxy_config = SETTINGS[:katello][:cdn_proxy]
198
207
  scheme = URI.parse(proxy_config[:host]).scheme
199
208
  uri = URI('')
209
+ # Ruby's uri parser doesn't handle encoded characters so Katello added two new schemes to handle proxy
210
+ # passwords. See https://github.com/Katello/katello/blob/master/app/lib/katello/util/proxy_uri.rb
200
211
  uri.scheme = 'proxy' if scheme == 'http'
201
212
  uri.scheme = 'proxys' if scheme == 'https'
202
213
  uri.host = URI.parse(proxy_config[:host]).host
@@ -239,6 +250,11 @@ module RedhatAccess
239
250
  REDHAT_ACCESS_CONFIG[:telemetry_upload_timeout_s] || 120
240
251
  end
241
252
 
253
+ # list of parameters to include as tags (or 'true' for all of them)
254
+ def get_include_parameter_tags
255
+ REDHAT_ACCESS_CONFIG[:include_parameter_tags] || false
256
+ end
257
+
242
258
  def user_login_to_hash(login)
243
259
  Digest::SHA1.hexdigest(login)
244
260
  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.11"
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.11
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-02-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redhat_access_lib