Class: Katello::Provider

Inherits:
Model
  • Object
show all
Includes:
ForemanTasks::Concerns::ActionSubject, Glue, Glue::Provider
Defined in:
app/models/katello/provider.rb

Constant Summary collapse

REDHAT =
'Red Hat'.encode('utf-8')
CUSTOM =
'Custom'.encode('utf-8')
ANONYMOUS =
'Anonymous'.encode('utf-8')
TYPES =
[REDHAT, CUSTOM, ANONYMOUS]

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Glue

included, logger

Methods included from Glue::Provider

included

Methods inherited from Model

#destroy!

Class Method Details

.create_anonymous!(organization) ⇒ Object



36
37
38
39
40
# File 'app/models/katello/provider.rb', line 36

def self.create_anonymous!(organization)
  create!(:name => SecureRandom.uuid, :description => nil,
          :organization => organization, :provider_type => ANONYMOUS,
          :repository_url => nil)
end

Instance Method Details

#anonymous_provider?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'app/models/katello/provider.rb', line 89

def anonymous_provider?
  provider_type == ANONYMOUS
end

#as_json(*args) ⇒ Object



135
136
137
# File 'app/models/katello/provider.rb', line 135

def as_json(*args)
  super.merge('organization_label' => self.organization.label)
end

#available_releasesObject



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'app/models/katello/provider.rb', line 103

def available_releases
  releases = []
  begin
    Util::CdnVarSubstitutor.with_cache do
      self.products.each do |product|
        cdn_var_substitutor = Resources::CDN::CdnResource.new(product.provider[:repository_url],
                                                         :ssl_client_cert => OpenSSL::X509::Certificate.new(product.certificate),
                                                         :ssl_client_key => OpenSSL::PKey::RSA.new(product.key)).substitutor
        product.productContent.each do |pc|
          if url_to_releases = pc.content.contentUrl[/^.*\$releasever/]
            begin
              cdn_var_substitutor.substitute_vars(url_to_releases).each do |(substitutions, _path)|
                releases << Resources::CDN::Utils.parse_version(substitutions['releasever'])[:minor]
              end
            rescue Errors::SecurityViolation => e
              # Some products may not be accessible but these should not impact available releases available
              Rails.logger.info "Skipping unreadable product content: #{e}"
            end
          end
        end
      end
    end
  rescue => e
    raise _("Unable to retrieve release versions from Repository URL %{url}. Error message: %{error}") % {:url => self.repository_url, :error => e.to_s}
  end
  releases.uniq.sort
end

#constraint_redhat_updateObject



59
60
61
62
63
64
65
66
67
# File 'app/models/katello/provider.rb', line 59

def constraint_redhat_update
  if !new_record? && redhat_provider?
    allowed_changes = %w(repository_url task_status_id)
    not_allowed_changes = changes.keys - allowed_changes
    unless not_allowed_changes.empty?
      errors.add(:base, _("the following attributes can not be updated for the Red Hat provider: [ %s ]") % not_allowed_changes.join(", "))
    end
  end
end

#count_providers(type) ⇒ Object



69
70
71
# File 'app/models/katello/provider.rb', line 69

def count_providers(type)
  Provider.where(:organization_id => self.organization_id, :provider_type => type).count(:id)
end

#custom_provider?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'app/models/katello/provider.rb', line 85

def custom_provider?
  provider_type == CUSTOM
end

#manifest_taskObject



131
132
133
# File 'app/models/katello/provider.rb', line 131

def manifest_task
  return task_status
end

#only_one_rhn_providerObject



42
43
44
45
46
47
# File 'app/models/katello/provider.rb', line 42

def only_one_rhn_provider
  # validate only when new record is added (skip explicit valid? calls)
  if new_record? && provider_type == REDHAT && count_providers(REDHAT) != 0
    errors.add(:base, _("Only one Red Hat provider permitted for an Organization"))
  end
end

#prevent_redhat_deletionObject



49
50
51
52
53
54
55
56
57
# File 'app/models/katello/provider.rb', line 49

def prevent_redhat_deletion
  if !being_deleted? && redhat_provider?
    Rails.logger.error _("Red Hat provider can not be deleted")
    false
  else
    # organization that is being deleted via background destroyer can delete rh provider
    true
  end
end

#redhat_provider=(is_rh) ⇒ Object



77
78
79
# File 'app/models/katello/provider.rb', line 77

def redhat_provider=(is_rh)
  is_rh ? REDHAT : ANONYMOUS # Anonymous is the now the default
end

#redhat_provider?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'app/models/katello/provider.rb', line 81

def redhat_provider?
  provider_type == REDHAT
end


147
148
149
# File 'app/models/katello/provider.rb', line 147

def related_resources
  self.organization
end

#serializable_hash(options = {}) ⇒ Object



95
96
97
98
99
100
101
# File 'app/models/katello/provider.rb', line 95

def serializable_hash(options = {})
  options = {} if options.nil?
  hash = super(options)
  hash = hash.merge(:sync_state => self.sync_state,
                    :last_sync => self.last_sync)
  hash
end

#total_productsObject



139
140
141
# File 'app/models/katello/provider.rb', line 139

def total_products
  products.length
end

#total_repositoriesObject



143
144
145
# File 'app/models/katello/provider.rb', line 143

def total_repositories
  repositories.length
end

#yum_repo?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'app/models/katello/provider.rb', line 73

def yum_repo?
  provider_type == CUSTOM || provider_type == ANONYMOUS
end