Skip to content

Commit

Permalink
Fixes #23635 - Centralize use of facter
Browse files Browse the repository at this point in the history
We have a bundler group for facter. That implies it's optional but
before this change it wasn't With this change it's only required if no
domain and fqdn are set. This is still the default so in most cases it's
no difference, but at least we have centralized all use of facter to one
place.
  • Loading branch information
ekohl authored and mmoll committed May 22, 2018
1 parent 2ce888d commit a653e38
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 14 deletions.
3 changes: 1 addition & 2 deletions app/models/setting/auth.rb
@@ -1,7 +1,6 @@
require 'facter'
class Setting::Auth < Setting
def self.default_settings
fqdn = Facter.value(:fqdn) || SETTINGS[:fqdn]
fqdn = SETTINGS[:fqdn]
lower_fqdn = fqdn.downcase
ssl_cert = "#{SETTINGS[:puppetssldir]}/certs/#{lower_fqdn}.pem"
ssl_ca_file = "#{SETTINGS[:puppetssldir]}/certs/ca.pem"
Expand Down
2 changes: 0 additions & 2 deletions app/models/setting/email.rb
@@ -1,5 +1,3 @@
require 'facter'

class Setting::Email < Setting
NON_EMAIL_YAML_SETTINGS = %w(send_welcome_email email_reply_address email_subject_prefix)

Expand Down
3 changes: 1 addition & 2 deletions app/models/setting/general.rb
@@ -1,12 +1,11 @@
require 'facter'
class Setting::General < Setting
include UrlValidator

def self.default_settings
protocol = SETTINGS[:require_ssl] ? 'https' : 'http'
domain = SETTINGS[:domain]
administrator = "root@#{domain}"
foreman_url = "#{protocol}://#{Facter.value(:fqdn) || SETTINGS[:fqdn]}"
foreman_url = "#{protocol}://#{SETTINGS[:fqdn]}"

[
self.set('administrator', N_("The default administrator email address"), administrator, N_('Administrator email address')),
Expand Down
3 changes: 1 addition & 2 deletions app/models/setting/provisioning.rb
@@ -1,4 +1,3 @@
require 'facter'
class Setting::Provisioning < Setting
def self.default_global_labels
TemplateKind::PXE.map do |pxe_kind|
Expand Down Expand Up @@ -33,7 +32,7 @@ def self.local_boot_labels
'vovsbr*'
]
def self.default_settings
fqdn = Facter.value(:fqdn) || SETTINGS[:fqdn]
fqdn = SETTINGS[:fqdn]
unattended_url = "http://#{fqdn}"
select = [{:name => _("Users"), :class => 'user', :scope => 'visible', :value_method => 'id_and_type', :text_method => 'login'},
{:name => _("Usergroup"), :class => 'usergroup', :scope => 'visible', :value_method => 'id_and_type', :text_method => 'name'}]
Expand Down
8 changes: 6 additions & 2 deletions config/settings.rb
@@ -1,6 +1,5 @@
require_relative 'boot_settings'
require_relative '../app/services/foreman/version'
require 'facter'

root = File.expand_path(File.dirname(__FILE__) + "/..")
settings_file = Rails.env.test? ? 'config/settings.yaml.test' : 'config/settings.yaml'
Expand All @@ -13,9 +12,14 @@
SETTINGS[:puppetvardir] ||= '/var/lib/puppet'
SETTINGS[:puppetssldir] ||= "#{SETTINGS[:puppetvardir]}/ssl"
SETTINGS[:rails] = '%.1f' % SETTINGS[:rails] if SETTINGS[:rails].is_a?(Float) # unquoted YAML value
SETTINGS[:domain] ||= Facter.value(:domain) || Facter.value(:hostname)
SETTINGS[:hsts_enabled] = true unless SETTINGS.has_key?(:hsts_enabled)

unless SETTINGS[:domain] && SETTINGS[:fqdn]
require 'facter'
SETTINGS[:domain] ||= Facter.value(:domain) || Facter.value(:hostname)
SETTINGS[:fqdn] ||= Facter.value(:fqdn)
end

# Load plugin config, if any
Dir["#{root}/config/settings.plugins.d/*.yaml"].each do |f|
SETTINGS.merge! YAML.load(ERB.new(File.read(f)).result)
Expand Down
3 changes: 1 addition & 2 deletions db/migrate/20100419151910_add_owner_to_hosts.rb
@@ -1,4 +1,3 @@
require 'facter'
class AddOwnerToHosts < ActiveRecord::Migration[4.2]
class User < ApplicationRecord; end
class Host < ApplicationRecord; end
Expand All @@ -9,7 +8,7 @@ def up

Host.reset_column_information

email = SETTINGS[:administrator] || "root@#{Facter.value(:domain)}"
email = SETTINGS[:administrator] || "root@#{SETTINGS[:domain]}"
owner = User.find_by_mail email
owner ||= User.where(:admin => true).first
unless owner.nil? || owner.id.nil?
Expand Down
1 change: 0 additions & 1 deletion db/migrate/20100628123400_add_internal_auth.rb
@@ -1,4 +1,3 @@
require 'facter'
class AddInternalAuth < ActiveRecord::Migration[4.2]
def up
add_column :users, :password_hash, :string, :limit => 128
Expand Down
1 change: 0 additions & 1 deletion lib/tasks/reset_permissions.rake
@@ -1,4 +1,3 @@
require 'facter'
namespace :permissions do
desc <<-END_DESC
Create or reset "admin" user permissions to defaults. Alternatively, you may
Expand Down

0 comments on commit a653e38

Please sign in to comment.