Class: Katello::AlternateContentSource
Constant Summary
collapse
- ACS_TYPES =
%w(custom simplified rhui).freeze
- CONTENT_TYPES =
[::Katello::Repository::YUM_TYPE, ::Katello::Repository::FILE_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
124
125
126
|
# File 'app/models/katello/alternate_content_source.rb', line 124
def self.humanize_class_name(_name = nil)
"Alternate Content Sources"
end
|
.search_by_subpath(_key, operator, value) ⇒ Object
106
107
108
109
|
# File 'app/models/katello/alternate_content_source.rb', line 106
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
97
98
99
100
|
# File 'app/models/katello/alternate_content_source.rb', line 97
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
102
103
104
|
# File 'app/models/katello/alternate_content_source.rb', line 102
def self.with_type(content_type)
where(content_type: content_type)
end
|
Instance Method Details
#audit_refresh ⇒ Object
116
117
118
|
# File 'app/models/katello/alternate_content_source.rb', line 116
def audit_refresh
write_audit(action: AUDIT_REFRESH_ACTION, comment: _('Successfully refreshed.'), audited_changes: {})
end
|
#audit_updated_products(old_product_ids) ⇒ Object
120
121
122
|
# File 'app/models/katello/alternate_content_source.rb', line 120
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
81
82
83
|
# File 'app/models/katello/alternate_content_source.rb', line 81
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
129
130
131
132
133
134
135
136
|
# File 'app/models/katello/alternate_content_source.rb', line 129
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
85
86
87
|
# File 'app/models/katello/alternate_content_source.rb', line 85
def custom?
alternate_content_source_type == 'custom'
end
|
#latest_dynflow_refresh_task ⇒ Object
111
112
113
114
|
# File 'app/models/katello/alternate_content_source.rb', line 111
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
93
94
95
|
# File 'app/models/katello/alternate_content_source.rb', line 93
def rhui?
alternate_content_source_type == 'rhui'
end
|
#simplified? ⇒ Boolean
89
90
91
|
# File 'app/models/katello/alternate_content_source.rb', line 89
def simplified?
alternate_content_source_type == 'simplified'
end
|
#validate_products ⇒ Object
166
167
168
169
170
|
# File 'app/models/katello/alternate_content_source.rb', line 166
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
# File 'app/models/katello/alternate_content_source.rb', line 139
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
|