Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomasz Maczukin <tomasz@maczukin.pl>2016-11-21 18:02:08 +0300
committerTomasz Maczukin <tomasz@maczukin.pl>2016-11-21 21:49:29 +0300
commit461195665b22291d5e57287efc0567b89a9ee262 (patch)
tree3c229496caf9c638929741b1771e00faf9f86f27 /lib/gitlab/ci/build
parente3fb0740228219433a4623dc0b9325785e23ae16 (diff)
Add Gitlab::Ci::Build::Credentials module with build credentials abstraction
Diffstat (limited to 'lib/gitlab/ci/build')
-rw-r--r--lib/gitlab/ci/build/credentials.rb16
-rw-r--r--lib/gitlab/ci/build/credentials/base.rb13
-rw-r--r--lib/gitlab/ci/build/credentials/factory.rb27
-rw-r--r--lib/gitlab/ci/build/credentials/registry.rb24
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