Class: Katello::AlternateContentSource

Inherits:
Model
  • Object
show all
Includes:
Encryptable, ForemanTasks::Concerns::ActionSubject, Katello::Authorization::AlternateContentSource, Ext::LabelFromName, ScopedSearchExtensions
Defined in:
app/models/katello/alternate_content_source.rb

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

Methods included from Katello::Authorization::AlternateContentSource

#deletable?, #editable?, #readable?

Methods included from Ext::LabelFromName

included, #label_not_changed, #setup_label_from_name

Methods inherited from Model

#destroy!

Class Method Details

.humanize_class_name(_name = nil) ⇒ Object



125
126
127
# File 'app/models/katello/alternate_content_source.rb', line 125

def self.humanize_class_name(_name = nil)
  "Alternate Content Sources"
end

.search_by_subpath(_key, operator, value) ⇒ Object



107
108
109
110
# File 'app/models/katello/alternate_content_source.rb', line 107

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



98
99
100
101
# File 'app/models/katello/alternate_content_source.rb', line 98

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



103
104
105
# File 'app/models/katello/alternate_content_source.rb', line 103

def self.with_type(content_type)
  where(content_type: content_type)
end

Instance Method Details

#audit_refreshObject



117
118
119
# File 'app/models/katello/alternate_content_source.rb', line 117

def audit_refresh
  write_audit(action: AUDIT_REFRESH_ACTION, comment: _('Successfully refreshed.'), audited_changes: {})
end

#audit_updated_products(old_product_ids) ⇒ Object



121
122
123
# File 'app/models/katello/alternate_content_source.rb', line 121

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



82
83
84
# File 'app/models/katello/alternate_content_source.rb', line 82

def backend_service(smart_proxy, repository = nil)
  @service ||= ::Katello::Pulp3::AlternateContentSource.new(self, smart_proxy, repository)
end

#constraint_acs_updateObject

Disallow static properties from being modified on update



130
131
132
133
134
135
136
137
# File 'app/models/katello/alternate_content_source.rb', line 130

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

Returns:

  • (Boolean)


86
87
88
# File 'app/models/katello/alternate_content_source.rb', line 86

def custom?
  alternate_content_source_type == 'custom'
end

#latest_dynflow_refresh_taskObject



112
113
114
115
# File 'app/models/katello/alternate_content_source.rb', line 112

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

Returns:

  • (Boolean)


94
95
96
# File 'app/models/katello/alternate_content_source.rb', line 94

def rhui?
  alternate_content_source_type == 'rhui'
end

#simplified?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'app/models/katello/alternate_content_source.rb', line 90

def simplified?
  alternate_content_source_type == 'simplified'
end

#validate_ssl_idsObject

Validate ssl-* ids which require complex/custom error messages



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
165
# File 'app/models/katello/alternate_content_source.rb', line 140

def validate_ssl_ids
  # Simplified ACS's should never have ssl-* params populated
  if simplified?
    if changes.keys.include? "ssl_ca_cert_id"
      errors.add(:ssl_ca_cert, "must be blank")
    end
    if changes.keys.include? "ssl_client_cert_id"
      errors.add(:ssl_client_cert, "must be blank")
    end
    if changes.keys.include? "ssl_client_key_id"
      errors.add(:ssl_client_key, "must be blank")
    end

  # Custom and RHUI ACS's should have valid keys where populated
  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