Commit 82add03f 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 5d9cc6c1
...@@ -661,7 +661,7 @@ module Ci ...@@ -661,7 +661,7 @@ module Ci
def deploy_token_variables def deploy_token_variables
Gitlab::Ci::Variables::Collection.new.tap do |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) variables.append(key: 'CI_DEPLOY_PASSWORD', value: project.gitlab_deploy_token.token)
end end
end end
......
...@@ -4,7 +4,7 @@ class DeployToken < ActiveRecord::Base ...@@ -4,7 +4,7 @@ class DeployToken < ActiveRecord::Base
add_authentication_token_field :token add_authentication_token_field :token
AVAILABLE_SCOPES = %i(read_repository read_registry).freeze 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 } default_value_for(:expires_at) { Forever.date }
......
...@@ -1891,7 +1891,7 @@ class Project < ActiveRecord::Base ...@@ -1891,7 +1891,7 @@ class Project < ActiveRecord::Base
def gitlab_deploy_token def gitlab_deploy_token
@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 end
private private
......
...@@ -90,8 +90,8 @@ future GitLab releases.** ...@@ -90,8 +90,8 @@ future GitLab releases.**
| **RESTORE_CACHE_ATTEMPTS** | 8.15 | 1.9 | Number of attempts to restore the cache running a job | | **RESTORE_CACHE_ATTEMPTS** | 8.15 | 1.9 | Number of attempts to restore the cache running a job |
| **CHAT_INPUT** | 10.6 | all | Additional arguments passed in the [ChatOps](../chatops/README.md) command. | | **CHAT_INPUT** | 10.6 | all | Additional arguments passed in the [ChatOps](../chatops/README.md) command. |
| **CHAT_CHANNEL** | 10.6 | all | Source chat channel which triggered the [ChatOps](../chatops/README.md) command. | | **CHAT_CHANNEL** | 10.6 | all | Source chat channel which triggered the [ChatOps](../chatops/README.md) command. |
| **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_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 | Token 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 | Authentication password of the [GitLab Deploy Token][gitlab-deploy-token], only present if the Project has one related.|
## 9.0 Renaming ## 9.0 Renaming
...@@ -606,4 +606,4 @@ my-job: ...@@ -606,4 +606,4 @@ my-job:
[builds-policies]: ../yaml/README.md#only-and-except-complex [builds-policies]: ../yaml/README.md#only-and-except-complex
[dynamic-environments]: ../environments.md#dynamic-environments [dynamic-environments]: ../environments.md#dynamic-environments
[trigger-job-token]: ../triggers/README.md#ci-job-token [trigger-job-token]: ../triggers/README.md#ci-job-token
[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 ...@@ -12,7 +12,7 @@ FactoryBot.define do
end end
trait :gitlab_deploy_token do trait :gitlab_deploy_token do
name DeployToken::GITLAB_DEPLOY_TOKEN name DeployToken::GITLAB_DEPLOY_TOKEN_NAME
end end
trait :expired do trait :expired do
......
...@@ -2061,27 +2061,25 @@ describe Ci::Build do ...@@ -2061,27 +2061,25 @@ describe Ci::Build do
let(:deploy_token_variables) 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 } { key: 'CI_DEPLOY_PASSWORD', value: deploy_token.token, public: true }
] ]
end end
context 'when gitlab-deploy-token exist' do context 'when gitlab-deploy-token exists' do
before do before do
project.deploy_tokens << deploy_token project.deploy_tokens << deploy_token
end end
it 'should include deploy token variables' do it 'should include deploy token variables' do
deploy_token_variables.each do |deploy_token_variable| is_expected.to include(*deploy_token_variables)
is_expected.to include(deploy_token_variable)
end
end end
end end
context 'when gitlab-deploy-token does not exist' do context 'when gitlab-deploy-token does not exist' do
it 'should not include deploy token variables' do it 'should not include deploy token variables' do
deploy_token_variables.each do |deploy_token_variable| %w(CI_DEPLOY_USER CI_DEPLOY_PASSWORD).each do |deploy_token_key|
is_expected.not_to include(deploy_token_variable) expect(subject.find { |v| v[:key] == deploy_token_key}).to be_nil
end end
end end
end end
......
...@@ -4001,5 +4001,11 @@ describe Project do ...@@ -4001,5 +4001,11 @@ describe Project do
it { is_expected.to be_nil } it { is_expected.to be_nil }
end 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
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