Class: Gitlab::QA::Component::LDAP
- Inherits:
-
Object
- Object
- Gitlab::QA::Component::LDAP
- Includes:
- Scenario::Actable
- Defined in:
- lib/gitlab/qa/component/ldap.rb
Constant Summary collapse
- LDAP_IMAGE =
'osixia/openldap'.freeze
- LDAP_IMAGE_TAG =
'latest'.freeze
- LDAP_USER =
'tanuki'.freeze
- LDAP_PASSWORD =
'password'.freeze
- BOOTSTRAP_LDIF =
'/container/service/slapd/assets/config/bootstrap/ldif/custom'.freeze
- FIXTURE_PATH =
File.('../../../../fixtures/ldap'.freeze, __dir__)
Instance Attribute Summary collapse
-
#docker ⇒ Object
readonly
Returns the value of attribute docker.
-
#environment ⇒ Object
Returns the value of attribute environment.
- #name ⇒ Object
-
#network ⇒ Object
Returns the value of attribute network.
-
#volumes ⇒ Object
Returns the value of attribute volumes.
Instance Method Summary collapse
- #add_network_alias(name) ⇒ Object
- #hostname ⇒ Object
-
#initialize ⇒ LDAP
constructor
A new instance of LDAP.
- #instance ⇒ Object
- #password ⇒ Object
- #prepare ⇒ Object
- #pull ⇒ Object
- #restart ⇒ Object
- #set_gitlab_credentials ⇒ Object
- #start ⇒ Object
- #teardown ⇒ Object
-
#tls=(status) ⇒ Object
LDAP_TLS is true by default.
- #username ⇒ Object
Methods included from Scenario::Actable
Constructor Details
#initialize ⇒ LDAP
Returns a new instance of LDAP.
32 33 34 35 36 37 38 39 |
# File 'lib/gitlab/qa/component/ldap.rb', line 32 def initialize @docker = Docker::Engine.new @environment = {} @volumes = {} @network_aliases = [] @volumes[FIXTURE_PATH] = BOOTSTRAP_LDIF end |
Instance Attribute Details
#docker ⇒ Object (readonly)
Returns the value of attribute docker.
28 29 30 |
# File 'lib/gitlab/qa/component/ldap.rb', line 28 def docker @docker end |
#environment ⇒ Object
Returns the value of attribute environment.
29 30 31 |
# File 'lib/gitlab/qa/component/ldap.rb', line 29 def environment @environment end |
#name ⇒ Object
65 66 67 |
# File 'lib/gitlab/qa/component/ldap.rb', line 65 def name @name ||= "openldap-#{SecureRandom.hex(4)}" end |
#network ⇒ Object
Returns the value of attribute network.
29 30 31 |
# File 'lib/gitlab/qa/component/ldap.rb', line 29 def network @network end |
#volumes ⇒ Object
Returns the value of attribute volumes.
29 30 31 |
# File 'lib/gitlab/qa/component/ldap.rb', line 29 def volumes @volumes end |
Instance Method Details
#add_network_alias(name) ⇒ Object
61 62 63 |
# File 'lib/gitlab/qa/component/ldap.rb', line 61 def add_network_alias(name) @network_aliases.push(name) end |
#hostname ⇒ Object
69 70 71 |
# File 'lib/gitlab/qa/component/ldap.rb', line 69 def hostname "#{name}.#{network}" end |
#instance ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/gitlab/qa/component/ldap.rb', line 73 def instance raise 'Please provide a block!' unless block_given? prepare start yield self ensure teardown end |
#password ⇒ Object
57 58 59 |
# File 'lib/gitlab/qa/component/ldap.rb', line 57 def password LDAP_PASSWORD end |
#prepare ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/gitlab/qa/component/ldap.rb', line 84 def prepare @docker.pull(LDAP_IMAGE, LDAP_IMAGE_TAG) return if @docker.network_exists?(network) @docker.network_create(network) end |
#pull ⇒ Object
126 127 128 |
# File 'lib/gitlab/qa/component/ldap.rb', line 126 def pull @docker.pull(LDAP_IMAGE, LDAP_IMAGE_TAG) end |
#restart ⇒ Object
115 116 117 |
# File 'lib/gitlab/qa/component/ldap.rb', line 115 def restart @docker.restart(name) end |
#set_gitlab_credentials ⇒ Object
130 131 132 133 |
# File 'lib/gitlab/qa/component/ldap.rb', line 130 def set_gitlab_credentials ::Gitlab::QA::Runtime::Env.ldap_username = username ::Gitlab::QA::Runtime::Env.ldap_password = password end |
#start ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/gitlab/qa/component/ldap.rb', line 92 def start # copy-service needed for bootstraping LDAP user: # https://github.com/osixia/docker-openldap#seed-ldap-database-with-ldif docker.run(LDAP_IMAGE, LDAP_IMAGE_TAG, '--copy-service') do |command| command << '-d ' command << "--name #{name}" command << "--net #{network}" command << "--hostname #{hostname}" @volumes.to_h.each do |to, from| command.volume(to, from, 'Z') end @environment.to_h.each do |key, value| command.env(key, value) end @network_aliases.to_a.each do |network_alias| command << "--network-alias #{network_alias}" end end end |
#teardown ⇒ Object
119 120 121 122 123 124 |
# File 'lib/gitlab/qa/component/ldap.rb', line 119 def teardown raise 'Invalid instance name!' unless name @docker.stop(name) @docker.remove(name) end |
#tls=(status) ⇒ Object
LDAP_TLS is true by default
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/gitlab/qa/component/ldap.rb', line 42 def tls=(status) if status @environment['LDAP_TLS_CRT_FILENAME'] = "#{hostname}.crt" @environment['LDAP_TLS_KEY_FILENAME'] = "#{hostname}.key" @environment['LDAP_TLS_ENFORCE'] = 'true' @environment['LDAP_TLS_VERIFY_CLIENT'] = 'never' else @environment['LDAP_TLS'] = 'false' end end |
#username ⇒ Object
53 54 55 |
# File 'lib/gitlab/qa/component/ldap.rb', line 53 def username LDAP_USER end |