lib/gitlab/qa/component/ldap.rb in gitlab-qa-5.13.3 vs lib/gitlab/qa/component/ldap.rb in gitlab-qa-5.13.4
- old
+ new
@@ -13,29 +13,20 @@
# that looks for custom LDIF files in the BOOTSTRAP_LDIF directory. Note that the LDIF
# files must have a "changetype" option specified for the script to work.
module Gitlab
module QA
module Component
- class LDAP
- include Scenario::Actable
-
- LDAP_IMAGE = 'osixia/openldap'.freeze
- LDAP_IMAGE_TAG = 'latest'.freeze
+ class LDAP < Base
+ DOCKER_IMAGE = 'osixia/openldap'.freeze
+ DOCKER_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.expand_path('../../../../fixtures/ldap'.freeze, __dir__)
- attr_reader :docker
- attr_accessor :volumes, :network, :environment
- attr_writer :name
-
def initialize
- @docker = Docker::Engine.new
- @environment = {}
- @volumes = {}
- @network_aliases = []
+ super
@volumes[FIXTURE_PATH] = BOOTSTRAP_LDIF
end
# LDAP_TLS is true by default
@@ -56,45 +47,25 @@
def password
LDAP_PASSWORD
end
- def add_network_alias(name)
- @network_aliases.push(name)
- end
-
def name
@name ||= "openldap-#{SecureRandom.hex(4)}"
end
- def hostname
- "#{name}.#{network}"
- end
-
def instance
raise 'Please provide a block!' unless block_given?
- prepare
- start
-
- yield self
- ensure
- teardown
+ super
end
- def prepare
- @docker.pull(LDAP_IMAGE, LDAP_IMAGE_TAG)
-
- return if @docker.network_exists?(network)
-
- @docker.network_create(network)
- end
-
+ # rubocop:disable Metrics/AbcSize
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|
+ docker.run(image, tag, '--copy-service') do |command|
command << '-d '
command << "--name #{name}"
command << "--net #{network}"
command << "--hostname #{hostname}"
@@ -109,24 +80,10 @@
@network_aliases.to_a.each do |network_alias|
command << "--network-alias #{network_alias}"
end
end
end
-
- def restart
- @docker.restart(name)
- end
-
- def teardown
- raise 'Invalid instance name!' unless name
-
- @docker.stop(name)
- @docker.remove(name)
- end
-
- def pull
- @docker.pull(LDAP_IMAGE, LDAP_IMAGE_TAG)
- end
+ # rubocop:enable Metrics/AbcSize
def set_gitlab_credentials
::Gitlab::QA::Runtime::Env.ldap_username = username
::Gitlab::QA::Runtime::Env.ldap_password = password
end