Class: Gitlab::QA::Runtime::OmnibusConfiguration
- Inherits:
-
Object
- Object
- Gitlab::QA::Runtime::OmnibusConfiguration
- Defined in:
- lib/gitlab/qa/runtime/omnibus_configuration.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#<<(config) ⇒ Object
rubocop:enable Metrics/AbcSize.
- #configuration ⇒ Object
-
#exec_commands ⇒ Object
Commands to execute before GitLab boots.
-
#initialize ⇒ OmnibusConfiguration
constructor
A new instance of OmnibusConfiguration.
-
#prepare ⇒ Object
Before hook for any additional configuration This would usually be a container that needs to be running.
-
#sanitize! ⇒ Object
Ensures no duplicate entries rubocop:disable Metrics/AbcSize.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ OmnibusConfiguration
Returns a new instance of OmnibusConfiguration.
9 10 11 |
# File 'lib/gitlab/qa/runtime/omnibus_configuration.rb', line 9 def initialize @config = ["# Generated by GitLab QA Omnibus Configurator at #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}"] end |
Instance Method Details
#<<(config) ⇒ Object
rubocop:enable Metrics/AbcSize
64 65 66 |
# File 'lib/gitlab/qa/runtime/omnibus_configuration.rb', line 64 def <<(config) @config << config.strip unless config.strip.empty? end |
#configuration ⇒ Object
17 18 19 |
# File 'lib/gitlab/qa/runtime/omnibus_configuration.rb', line 17 def configuration raise NotImplementedError end |
#exec_commands ⇒ Object
Commands to execute before GitLab boots
27 28 29 |
# File 'lib/gitlab/qa/runtime/omnibus_configuration.rb', line 27 def exec_commands [] end |
#prepare ⇒ Object
Before hook for any additional configuration This would usually be a container that needs to be running
24 |
# File 'lib/gitlab/qa/runtime/omnibus_configuration.rb', line 24 def prepare; end |
#sanitize! ⇒ Object
Ensures no duplicate entries rubocop:disable Metrics/AbcSize
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/gitlab/qa/runtime/omnibus_configuration.rb', line 34 def sanitize! sanitized = @config.map do |config| next config if config.start_with?('#') || config.match(/\w+\(/) # allow for comments and method invocations # sometimes "=" is part of a Hash. Only split based on the first "=" k, v = config.split("=", 2) # make sure each config is well-formed # e.g., gitlab_rails['packages_enabled'] = true # NOT gitlab_rails['packages_enabled']=true v.nil? ? k.strip : "#{k.strip} = #{v.strip.tr('"', "'")}".strip end.uniq errors = [] # check for duplicates duplicate_keys = [] duplicates = sanitized.reject do |n| key = n.split('=').first duplicate_keys << key unless duplicate_keys.include?(key) end duplicates.each { |duplicate| errors << "Duplicate entry found: `#{duplicate}`" } raise "Errors exist within the Omnibus Configuration!\n#{errors.join(',')}" if errors.any? @config = sanitized end |
#to_s ⇒ Object
13 14 15 |
# File 'lib/gitlab/qa/runtime/omnibus_configuration.rb', line 13 def to_s sanitize!.join("\n") end |