diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/ci/build/credentials.rb | 16 | ||||
-rw-r--r-- | lib/gitlab/ci/build/credentials/base.rb | 13 | ||||
-rw-r--r-- | lib/gitlab/ci/build/credentials/docker_registry.rb | 24 | ||||
-rw-r--r-- | lib/gitlab/ci/build/credentials/factory.rb | 27 |
4 files changed, 64 insertions, 16 deletions
diff --git a/lib/gitlab/ci/build/credentials.rb b/lib/gitlab/ci/build/credentials.rb deleted file mode 100644 index 14f9e8d7244..00000000000 --- a/lib/gitlab/ci/build/credentials.rb +++ /dev/null @@ -1,16 +0,0 @@ -module Gitlab - module Ci - module Build - class Credentials - attr_accessor :type, :url, :username, :password - - def initialize(type, url, username, password) - @type = type - @url = url - @username = username - @password = password - end - end - end - end -end diff --git a/lib/gitlab/ci/build/credentials/base.rb b/lib/gitlab/ci/build/credentials/base.rb new file mode 100644 index 00000000000..29a7a27c963 --- /dev/null +++ b/lib/gitlab/ci/build/credentials/base.rb @@ -0,0 +1,13 @@ +module Gitlab + module Ci + module Build + module Credentials + class Base + def type + self.class.name.demodulize.underscore + end + end + end + end + end +end diff --git a/lib/gitlab/ci/build/credentials/docker_registry.rb b/lib/gitlab/ci/build/credentials/docker_registry.rb new file mode 100644 index 00000000000..9301320d936 --- /dev/null +++ b/lib/gitlab/ci/build/credentials/docker_registry.rb @@ -0,0 +1,24 @@ +module Gitlab + module Ci + module Build + module Credentials + class DockerRegistry < Base + attr_reader :username, :password + + def initialize(build) + @username = 'gitlab-ci-token' + @password = build.token + end + + def url + Gitlab.config.registry.host_port + end + + def present? + Gitlab.config.registry.enabled + end + end + end + end + end +end diff --git a/lib/gitlab/ci/build/credentials/factory.rb b/lib/gitlab/ci/build/credentials/factory.rb new file mode 100644 index 00000000000..65b84037407 --- /dev/null +++ b/lib/gitlab/ci/build/credentials/factory.rb @@ -0,0 +1,27 @@ +module Gitlab + module Ci + module Build + module Credentials + class Factory + PROVIDERS = [ + DockerRegistry, + ] + + def initialize(build) + @build = build + end + + def create! + credentials.select(&:present?) + end + + private + + def credentials + PROVIDERS.map { |provider| provider.new(@build) } + end + end + end + end + end +end |