Class: Katello::AlternateContentSource
Constant Summary
collapse
- ACS_TYPES =
%w(custom simplified rhui).freeze
- CONTENT_TYPES =
[
::Katello::Repository::YUM_TYPE,
::Katello::Repository::FILE_TYPE,
::Katello::Repository::DEB_TYPE,
].freeze
- AUDIT_REFRESH_ACTION =
'refresh'.freeze
Class Method Summary
collapse
Instance Method Summary
collapse
#deletable?, #editable?, #readable?
included, #label_not_changed, #setup_label_from_name
Methods inherited from Model
#destroy!
Class Method Details
.humanize_class_name(_name = nil) ⇒ Object
137
138
139
|
# File 'app/models/katello/alternate_content_source.rb', line 137
def self.humanize_class_name(_name = nil)
"Alternate Content Sources"
end
|
.search_by_subpath(_key, operator, value) ⇒ Object
119
120
121
122
|
# File 'app/models/katello/alternate_content_source.rb', line 119
def self.search_by_subpath(_key, operator, value)
conditions = sanitize_sql_for_conditions(["? #{operator} ANY (subpaths)", value_to_sql(operator, value)])
{ conditions: conditions }
end
|
.with_products(products) ⇒ Object
110
111
112
113
|
# File 'app/models/katello/alternate_content_source.rb', line 110
def self.with_products(products)
products = [products] unless products.is_a?(Array)
joins(:alternate_content_source_products).where('katello_alternate_content_source_products.product_id in (:product_ids)', product_ids: products.pluck(:id))
end
|
.with_type(content_type) ⇒ Object
115
116
117
|
# File 'app/models/katello/alternate_content_source.rb', line 115
def self.with_type(content_type)
where(content_type: content_type)
end
|
Instance Method Details
#audit_refresh ⇒ Object
129
130
131
|
# File 'app/models/katello/alternate_content_source.rb', line 129
def audit_refresh
write_audit(action: AUDIT_REFRESH_ACTION, comment: _('Successfully refreshed.'), audited_changes: {})
end
|
#audit_updated_products(old_product_ids) ⇒ Object
133
134
135
|
# File 'app/models/katello/alternate_content_source.rb', line 133
def audit_updated_products(old_product_ids)
write_audit(action: 'update', comment: _('Products updated.'), audited_changes: { 'product_ids' => [old_product_ids, product_ids] })
end
|
#backend_service(smart_proxy, repository = nil) ⇒ Object
90
91
92
|
# File 'app/models/katello/alternate_content_source.rb', line 90
def backend_service(smart_proxy, repository = nil)
@service ||= ::Katello::Pulp3::AlternateContentSource.new(self, smart_proxy, repository)
end
|
#constraint_acs_update ⇒ Object
Disallow static properties from being modified on update
142
143
144
145
146
147
148
149
|
# File 'app/models/katello/alternate_content_source.rb', line 142
def constraint_acs_update
if changes.keys.include? "content_type"
errors.add(:content_type, "cannot be modified once an ACS is created")
end
if changes.keys.include? "alternate_content_source_type"
errors.add(:alternate_content_source_type, "cannot be modified once an ACS is created")
end
end
|
#custom? ⇒ Boolean
94
95
96
|
# File 'app/models/katello/alternate_content_source.rb', line 94
def custom?
alternate_content_source_type == 'custom'
end
|
#deb? ⇒ Boolean
106
107
108
|
# File 'app/models/katello/alternate_content_source.rb', line 106
def deb?
content_type == ::Katello::Repository::DEB_TYPE
end
|
#deb_constraints ⇒ Object
185
186
187
188
189
190
191
192
193
|
# File 'app/models/katello/alternate_content_source.rb', line 185
def deb_constraints
return unless deb?
releases = deb_releases.to_s.split(/[,\s]+/).map(&:strip).reject(&:blank?)
if custom? && releases.empty?
errors.add(:deb_releases, 'must be provided for deb alternate content sources')
end
end
|
#deb_fields_xor_subpaths ⇒ Object
195
196
197
198
199
200
201
202
203
204
205
206
207
|
# File 'app/models/katello/alternate_content_source.rb', line 195
def deb_fields_xor_subpaths
return if simplified?
if deb?
if subpaths.present? && Array(subpaths).reject { |s| s.to_s.strip.blank? }.any?
errors.add(:subpaths, 'must be empty for deb alternate content sources')
end
else
if deb_releases.present? || deb_components.present? || deb_architectures.present?
errors.add(:base, 'deb_* fields can only be set for deb alternate content sources')
end
end
end
|
#latest_dynflow_refresh_task ⇒ Object
124
125
126
127
|
# File 'app/models/katello/alternate_content_source.rb', line 124
def latest_dynflow_refresh_task
@latest_dynflow_refresh_task ||= ForemanTasks::Task::DynflowTask.where(:label => Actions::Katello::AlternateContentSource::Refresh.name).
for_resource(self).order(:started_at).last
end
|
#rhui? ⇒ Boolean
102
103
104
|
# File 'app/models/katello/alternate_content_source.rb', line 102
def rhui?
alternate_content_source_type == 'rhui'
end
|
#simplified? ⇒ Boolean
98
99
100
|
# File 'app/models/katello/alternate_content_source.rb', line 98
def simplified?
alternate_content_source_type == 'simplified'
end
|
#validate_products ⇒ Object
179
180
181
182
183
|
# File 'app/models/katello/alternate_content_source.rb', line 179
def validate_products
if (custom? || rhui?) && products.present?
errors.add(:product_ids, "cannot be set for custom or rhui ACS")
end
end
|
#validate_ssl_ids ⇒ Object
Validate ssl-* ids which require complex/custom error messages
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
# File 'app/models/katello/alternate_content_source.rb', line 152
def validate_ssl_ids
if simplified?
if changes.keys.include? "ssl_ca_cert_id"
errors.add(:ssl_ca_cert, "cannot be set for simplified ACS")
end
if changes.keys.include? "ssl_client_cert_id"
errors.add(:ssl_client_cert, "cannot be set for simplified ACS")
end
if changes.keys.include? "ssl_client_key_id"
errors.add(:ssl_client_key, "cannot be set for simplified ACS")
end
else
if ssl_ca_cert_id.present? && ssl_ca_cert.nil?
errors.add(:ssl_ca_cert, "with ID '#{ssl_ca_cert_id}' couldn't be found")
end
if ssl_client_cert_id.present? && ssl_client_cert.nil?
errors.add(:ssl_client_cert, "with ID '#{ssl_client_cert_id}' couldn't be found")
end
if ssl_client_key_id.present? && ssl_client_key.nil?
errors.add(:ssl_client_key, "with ID '#{ssl_client_key_id}' couldn't be found")
end
end
end
|