Module: Foreman

Defined in:
lib/foreman/password_hash.rb,
lib/foreman.rb,
lib/foreman/cast.rb,
lib/foreman/fips.rb,
lib/foreman/util.rb,
lib/foreman/dynflow.rb,
lib/foreman/logging.rb,
lib/foreman/renderer.rb,
lib/foreman/exception.rb,
lib/foreman/telemetry.rb,
lib/foreman/http_proxy.rb,
lib/foreman/observable.rb,
lib/foreman/renderer/scope.rb,
app/services/foreman/module.rb,
lib/foreman/gettext/support.rb,
lib/foreman/renderer/errors.rb,
lib/foreman/renderer/source.rb,
lib/foreman/silenced_logger.rb,
app/services/foreman/version.rb,
app/registries/foreman/plugin.rb,
lib/foreman/event_subscribers.rb,
app/services/foreman/global_id.rb,
app/models/concerns/foreman/sti.rb,
lib/foreman/renderer/scope/base.rb,
app/services/foreman/deprecation.rb,
lib/foreman/foreman_url_renderer.rb,
lib/foreman/middleware/telemetry.rb,
lib/foreman/renderer/source/base.rb,
lib/foreman/advisory_lock_manager.rb,
lib/foreman/dynflow/configuration.rb,
lib/foreman/renderer/scope/macros.rb,
lib/foreman/renderer/scope/report.rb,
lib/foreman/renderer/base_renderer.rb,
lib/foreman/renderer/configuration.rb,
lib/foreman/renderer/source/string.rb,
lib/foreman/renderer/scope/template.rb,
app/registries/foreman/plugin/assets.rb,
lib/foreman/renderer/scope/partition.rb,
lib/foreman/renderer/scope/variables.rb,
lib/foreman/renderer/source/database.rb,
lib/foreman/renderer/source/snapshot.rb,
app/registries/foreman/access_control.rb,
app/registries/foreman/plugin/logging.rb,
app/services/foreman/parameter_filter.rb,
app/services/foreman/plugin/role_lock.rb,
lib/foreman/renderer/source/directory.rb,
app/services/foreman/parameters/caster.rb,
lib/foreman/renderer/scope/macros/base.rb,
app/registries/foreman/plugin/global_js.rb,
app/services/foreman/client_certificate.rb,
app/subscribers/foreman/base_subscriber.rb,
lib/foreman/renderer/safe_mode_renderer.rb,
lib/foreman/renderer/scope/provisioning.rb,
app/services/foreman/env_settings_loader.rb,
lib/foreman/renderer/scope/macros/inputs.rb,
app/services/foreman/parameters/validator.rb,
lib/foreman/http_proxy/net_http_extension.rb,
lib/foreman/renderer/scope/macros/helpers.rb,
lib/foreman/renderer/scope/macros/loaders.rb,
lib/foreman/renderer/scope/variables/base.rb,
lib/foreman/renderer/unsafe_mode_renderer.rb,
app/models/concerns/foreman/observable_job.rb,
app/models/concerns/foreman/thread_session.rb,
app/registries/foreman/plugin/rbac_support.rb,
app/services/foreman/bruteforce_protection.rb,
app/services/foreman/ipxe/message_renderer.rb,
app/registries/foreman/input_types_registry.rb,
app/registries/foreman/plugin/rbac_registry.rb,
app/models/concerns/foreman/observable_model.rb,
lib/foreman/http_proxy/rest_client_extension.rb,
app/registries/foreman/plugin/search_overrides.rb,
app/services/foreman/template_snapshot_service.rb,
lib/foreman/middleware/catch_json_parse_errors.rb,
lib/foreman/middleware/logging_context_request.rb,
lib/foreman/middleware/logging_context_session.rb,
lib/foreman/renderer/scope/macros/host_template.rb,
lib/foreman/renderer/scope/template_input_values.rb,
app/services/foreman/render_templates_from_folder.rb,
app/services/report_scanner/puppet_report_scanner.rb,
lib/foreman/http_proxy/excon_connection_extension.rb,
lib/foreman/renderer/scope/macros/template_logging.rb,
app/registries/foreman/plugin/graphql_plugin_fields.rb,
lib/foreman/renderer/scope/macros/snippet_rendering.rb,
app/controllers/concerns/foreman/controller/timezone.rb,
app/registries/foreman/plugin/fact_importer_registry.rb,
app/registries/foreman/plugin/graphql_types_registry.rb,
app/registries/foreman/plugin/report_origin_registry.rb,
app/registries/foreman/plugin/report_scanner_registry.rb,
lib/foreman/renderer/doc_templates/basic_ruby_methods.rb,
app/controllers/concerns/foreman/controller/require_ssl.rb,
app/registries/foreman/plugin/medium_providers_registry.rb,
app/services/foreman/unattended_installation/host_finder.rb,
app/controllers/concerns/foreman/controller/topbar_sweeper.rb,
app/services/foreman/unattended_installation/host_verifier.rb,
app/controllers/concerns/foreman/controller/template_rendering.rb,
app/controllers/concerns/foreman/controller/api_csrf_protection.rb,
app/services/foreman/unattended_installation/mac_list_extractor.rb

Overview

In several cases we want to break chain of responsibility in MVC a bit and provide a safe way to access current user (and maybe few more data items). Storing it as

a global variable (or class member) is not thread-safe. Including ThreadSession

UserModel in models and ThreadSession::Controller in the application controller allows this without any concurrent issues.

Idea taken from sentinent_user rails plugin.

github.com/bokmann/sentient_user github.com/astrails/let_my_controller_go rails-bestpractices.com/posts/47-fetch-current-user-in-models

Defined Under Namespace

Modules: AccessControl, Cast, Controller, Dynflow, EventSubscribers, Fips, ForemanUrlRenderer, Gettext, GlobalId, HTTPProxy, HttpProxy, Ipxe, Middleware, Model, Module, Observable, ObservableJob, ObservableModel, Parameters, Provision, Renderer, STI, TelemetryHelper, TelemetrySinks, ThreadSession, UnattendedInstallation, Util Classes: AdvisoryLockManager, AssociationNotFound, BMCFeatureException, BaseSubscriber, BruteforceProtection, ClientCertificate, CyclicGraphException, Deprecation, EnvSettingsLoader, Exception, FingerprintException, ImporterPuppetclass, InputTypesRegistry, LdapException, LoggingImpl, MaintenanceException, MultiException, ParameterFilter, PasswordHash, PermissionMissingException, Plugin, PluginNotFound, PluginRequirementError, PuppetReportScanner, RenderTemplatesFromFolder, SilencedLogger, Telemetry, TemplateSnapshotService, Version, WrappedException

Constant Summary collapse

UUID_REGEXP =
Regexp.new("^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-" +
"([0-9a-f]{4})-([0-9a-f]{12})$")
Logging =
LoggingImpl.send :new

Class Method Summary collapse

Class Method Details

.in_rake?(*rake_tasks) ⇒ Boolean

Returns:

  • (Boolean)

15
16
17
18
19
20
# File 'lib/foreman.rb', line 15

def self.in_rake?(*rake_tasks)
  return false unless defined?(Rake) && Rake.respond_to?(:application)
  Rake.application.top_level_tasks.any? do |running_rake_task|
    rake_tasks.empty? || rake_tasks.any? { |rake_task| running_rake_task.start_with?(rake_task) }
  end
end

.in_setup_db_rake?Boolean

Returns:

  • (Boolean)

22
23
24
# File 'lib/foreman.rb', line 22

def self.in_setup_db_rake?
  in_rake?('db:create', 'db:migrate', 'db:drop')
end

.input_types_registryObject


34
35
36
# File 'lib/foreman.rb', line 34

def self.input_types_registry
  @input_types_registry ||= Foreman::InputTypesRegistry.new
end

.instance_idObject


26
27
28
# File 'lib/foreman.rb', line 26

def self.instance_id
  Setting[:instance_id]
end

.instance_id=(value) ⇒ Object


30
31
32
# File 'lib/foreman.rb', line 30

def self.instance_id=(value)
  Setting[:instance_id] = value
end

.is_uuid?(str) ⇒ Boolean

does this look like a UUID?

Returns:

  • (Boolean)

11
12
13
# File 'lib/foreman.rb', line 11

def self.is_uuid?(str)
  str.is_a?(String) && str.length == 36 && str.match?(UUID_REGEXP)
end

.uuidObject

generate a UUID


4
5
6
# File 'lib/foreman.rb', line 4

def self.uuid
  SecureRandom.uuid
end