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:
authorMayra Cabrera <mcabrera@gitlab.com>2018-04-20 18:05:16 +0300
committerMayra Cabrera <mcabrera@gitlab.com>2018-04-20 20:18:41 +0300
commitcdac54e2a2abe4b93bd5a96603b9d6d8745d277e (patch)
tree458a5b8eddfbe8cf3bde2771460eaefa7dd7ff07 /app/models
parent800ee75aa5f65fc41f32c8d7f3519256cd37c645 (diff)
Refactor deploy token methods on Ci::Build
Also include a class method for retriving the gitlab_deploy_token on DeployTokens
Diffstat (limited to 'app/models')
-rw-r--r--app/models/ci/build.rb7
-rw-r--r--app/models/deploy_token.rb4
-rw-r--r--app/models/project.rb3
3 files changed, 9 insertions, 5 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 8db07553665..9000ad860e9 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -605,8 +605,7 @@ module Ci
.append(key: 'CI_REGISTRY_USER', value: CI_REGISTRY_USER)
.append(key: 'CI_REGISTRY_PASSWORD', value: token, public: false)
.append(key: 'CI_REPOSITORY_URL', value: repo_url, public: false)
-
- variables.concat(deploy_token_variables) if gitlab_deploy_token
+ .concat(deploy_token_variables)
end
end
@@ -659,8 +658,10 @@ module Ci
def deploy_token_variables
Gitlab::Ci::Variables::Collection.new.tap do |variables|
+ break variables unless gitlab_deploy_token
+
variables.append(key: 'CI_DEPLOY_USER', value: gitlab_deploy_token.name)
- variables.append(key: 'CI_DEPLOY_PASSWORD', value: gitlab_deploy_token.token)
+ variables.append(key: 'CI_DEPLOY_PASSWORD', value: gitlab_deploy_token.token, public: false)
end
end
diff --git a/app/models/deploy_token.rb b/app/models/deploy_token.rb
index 4e450d0bdc8..5082dc45368 100644
--- a/app/models/deploy_token.rb
+++ b/app/models/deploy_token.rb
@@ -18,6 +18,10 @@ class DeployToken < ActiveRecord::Base
scope :active, -> { where("revoked = false AND expires_at >= NOW()") }
+ def self.gitlab_deploy_token
+ active.find_by(name: GITLAB_DEPLOY_TOKEN_NAME)
+ end
+
def revoke!
update!(revoked: true)
end
diff --git a/app/models/project.rb b/app/models/project.rb
index 2684a02caba..c293b0b8cf4 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -1880,8 +1880,7 @@ class Project < ActiveRecord::Base
end
def gitlab_deploy_token
- @gitlab_deploy_token ||=
- deploy_tokens.active.find_by(name: DeployToken::GITLAB_DEPLOY_TOKEN_NAME)
+ @gitlab_deploy_token ||= deploy_tokens.gitlab_deploy_token
end
private