Commit 0dd6d25c authored by Mayra Cabrera's avatar Mayra Cabrera

Rename special deploy token to make it more descriptive

Also:
- Includes more specs
- Improves a bit the documentation
parent f17e8365
......@@ -657,7 +657,7 @@ module Ci
def deploy_token_variables
Gitlab::Ci::Variables::Collection.new.tap do |variables|
variables.append(key: 'CI_DEPLOY_USER', value: DeployToken::GITLAB_DEPLOY_TOKEN)
variables.append(key: 'CI_DEPLOY_USER', value: DeployToken::GITLAB_DEPLOY_TOKEN_NAME)
variables.append(key: 'CI_DEPLOY_PASSWORD', value: project.gitlab_deploy_token.token)
end
end
......
......@@ -4,7 +4,7 @@ class DeployToken < ActiveRecord::Base
add_authentication_token_field :token
AVAILABLE_SCOPES = %i(read_repository read_registry).freeze
GITLAB_DEPLOY_TOKEN = 'gitlab-deploy-token'.freeze
GITLAB_DEPLOY_TOKEN_NAME = 'gitlab-deploy-token'.freeze
default_value_for(:expires_at) { Forever.date }
......
......@@ -1881,7 +1881,7 @@ class Project < ActiveRecord::Base
def gitlab_deploy_token
@gitlab_deploy_token ||=
deploy_tokens.active.find_by(name: DeployToken::GITLAB_DEPLOY_TOKEN)
deploy_tokens.active.find_by(name: DeployToken::GITLAB_DEPLOY_TOKEN_NAME)
end
private
......
......@@ -87,8 +87,8 @@ future GitLab releases.**
| **GITLAB_USER_LOGIN** | 10.0 | all | The login username of the user who started the job |
| **GITLAB_USER_NAME** | 10.0 | all | The real name of the user who started the job |
| **RESTORE_CACHE_ATTEMPTS** | 8.15 | 1.9 | Number of attempts to restore the cache running a job |
| **CI_DEPLOY_USER** | 10.8 | all | Name of the GitLab Deploy Token. Only present if the Project has a [GitLab Deploy Token][gitlab-deploy-token] related.|
| **CI_DEPLOY_PASSWORD** | 10.8 | all | Token of the Gitlab Deploy Token. Only present if the Project has a [GitLab Deploy Token][gitlab-deploy-token] related.|
| **CI_DEPLOY_USER** | 10.8 | all | Authentication username of the [GitLab Deploy Token][gitlab-deploy-token], only present if the Project has one related.|
| **CI_DEPLOY_PASSWORD** | 10.8 | all | Authentication password of the [GitLab Deploy Token][gitlab-deploy-token], only present if the Project has one related.|
## 9.0 Renaming
......@@ -564,4 +564,4 @@ These variables are also not supported in a contex of a
[subgroups]: ../../user/group/subgroups/index.md
[builds-policies]: ../yaml/README.md#only-and-except-complex
[dynamic-environments]: ../environments.md#dynamic-environments
[gitlab-deploy-token]: ../../user/project/deploy_tokens/index.md
[gitlab-deploy-token]: ../../user/project/deploy_tokens/index.md#gitlab-deploy-token
......@@ -12,7 +12,7 @@ FactoryBot.define do
end
trait :gitlab_deploy_token do
name DeployToken::GITLAB_DEPLOY_TOKEN
name DeployToken::GITLAB_DEPLOY_TOKEN_NAME
end
trait :expired do
......
......@@ -2041,27 +2041,25 @@ describe Ci::Build do
let(:deploy_token_variables) do
[
{ key: 'CI_DEPLOY_USER', value: DeployToken::GITLAB_DEPLOY_TOKEN, public: true },
{ key: 'CI_DEPLOY_USER', value: DeployToken::GITLAB_DEPLOY_TOKEN_NAME, public: true },
{ key: 'CI_DEPLOY_PASSWORD', value: deploy_token.token, public: true }
]
end
context 'when gitlab-deploy-token exist' do
context 'when gitlab-deploy-token exists' do
before do
project.deploy_tokens << deploy_token
end
it 'should include deploy token variables' do
deploy_token_variables.each do |deploy_token_variable|
is_expected.to include(deploy_token_variable)
end
is_expected.to include(*deploy_token_variables)
end
end
context 'when gitlab-deploy-token does not exist' do
it 'should not include deploy token variables' do
deploy_token_variables.each do |deploy_token_variable|
is_expected.not_to include(deploy_token_variable)
%w(CI_DEPLOY_USER CI_DEPLOY_PASSWORD).each do |deploy_token_key|
expect(subject.find { |v| v[:key] == deploy_token_key}).to be_nil
end
end
end
......
......@@ -3611,5 +3611,11 @@ describe Project do
it { is_expected.to be_nil }
end
context 'when there is a gitlab deploy token associated with a different name' do
let!(:deploy_token) { create(:deploy_token, projects: [project]) }
it { is_expected.to be_nil }
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment