diff options
author | Tomasz Maczukin <tomasz@maczukin.pl> | 2016-11-21 16:02:08 +0100 |
---|---|---|
committer | Tomasz Maczukin <tomasz@maczukin.pl> | 2016-11-21 19:49:29 +0100 |
commit | 461195665b22291d5e57287efc0567b89a9ee262 (patch) | |
tree | 3c229496caf9c638929741b1771e00faf9f86f27 /lib | |
parent | e3fb0740228219433a4623dc0b9325785e23ae16 (diff) | |
download | gitlab-ce-461195665b22291d5e57287efc0567b89a9ee262.tar.gz |
Add Gitlab::Ci::Build::Credentials module with build credentials abstraction
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/factory.rb | 27 | ||||
-rw-r--r-- | lib/gitlab/ci/build/credentials/registry.rb | 24 |
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/factory.rb b/lib/gitlab/ci/build/credentials/factory.rb new file mode 100644 index 00000000000..2423aa8857d --- /dev/null +++ b/lib/gitlab/ci/build/credentials/factory.rb @@ -0,0 +1,27 @@ +module Gitlab + module Ci + module Build + module Credentials + class Factory + def initialize(build) + @build = build + end + + def create! + credentials.select(&:valid?) + end + + private + + def credentials + providers.map { |provider| provider.new(@build) } + end + + def providers + [Registry] + end + end + end + end + end +end diff --git a/lib/gitlab/ci/build/credentials/registry.rb b/lib/gitlab/ci/build/credentials/registry.rb new file mode 100644 index 00000000000..55eafcaed10 --- /dev/null +++ b/lib/gitlab/ci/build/credentials/registry.rb @@ -0,0 +1,24 @@ +module Gitlab + module Ci + module Build + module Credentials + class Registry < 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 valid? + Gitlab.config.registry.enabled + end + end + end + end + end +end |