Commit a2d18870 authored by Sanad Liaquat's avatar Sanad Liaquat

Merge branch 'create-deploy-token-resource-api' into 'master'

Fabricate project deploy token resource via API

See merge request gitlab-org/gitlab!74901
parents e62256ab a4082b26
...@@ -2,25 +2,13 @@ ...@@ -2,25 +2,13 @@
module QA module QA
module Resource module Resource
class DeployToken < Base class ProjectDeployToken < Base
attr_accessor :name, :expires_at attr_accessor :name, :expires_at
attr_writer :scopes attr_writer :scopes
attribute :username do attribute :id
Page::Project::Settings::Repository.perform do |repository_page| attribute :token
repository_page.expand_deploy_tokens do |token| attribute :username
token.token_username
end
end
end
attribute :password do
Page::Project::Settings::Repository.perform do |repository_page|
repository_page.expand_deploy_tokens do |token|
token.token_password
end
end
end
attribute :project do attribute :project do
Project.fabricate! do |resource| Project.fabricate! do |resource|
...@@ -29,6 +17,35 @@ module QA ...@@ -29,6 +17,35 @@ module QA
end end
end end
def fabricate_via_api!
super
end
def api_get_path
"/projects/#{project.id}/deploy_tokens"
end
def api_post_path
api_get_path
end
def api_post_body
{
name: @name,
scopes: @scopes
}
end
def api_delete_path
"/projects/#{project.id}/deploy_tokens/#{id}"
end
def resource_web_url(resource)
super
rescue ResourceURLMissingError
# this particular resource does not expose a web_url property
end
def fabricate! def fabricate!
project.visit! project.visit!
......
...@@ -14,15 +14,15 @@ module QA ...@@ -14,15 +14,15 @@ module QA
end end
let(:project_deploy_token) do let(:project_deploy_token) do
Resource::DeployToken.fabricate_via_browser_ui! do |deploy_token| Resource::ProjectDeployToken.fabricate_via_api! do |deploy_token|
deploy_token.name = 'registry-deploy-token' deploy_token.name = 'registry-deploy-token'
deploy_token.project = project deploy_token.project = project
deploy_token.scopes = [ deploy_token.scopes = %w[
:read_repository, read_repository
:read_package_registry, read_package_registry
:write_package_registry, write_package_registry
:read_registry, read_registry
:write_registry write_registry
] ]
end end
end end
...@@ -60,7 +60,7 @@ module QA ...@@ -60,7 +60,7 @@ module QA
when :personal_access_token when :personal_access_token
"\"#{personal_access_token}\"" "\"#{personal_access_token}\""
when :project_deploy_token when :project_deploy_token
"\"#{project_deploy_token.password}\"" "\"#{project_deploy_token.token}\""
when :ci_job_token when :ci_job_token
'$CI_JOB_TOKEN' '$CI_JOB_TOKEN'
end end
......
...@@ -88,7 +88,7 @@ module QA ...@@ -88,7 +88,7 @@ module QA
when :ci_job_token when :ci_job_token
'${CI_JOB_TOKEN}' '${CI_JOB_TOKEN}'
when :project_deploy_token when :project_deploy_token
project_deploy_token.password project_deploy_token.token
end end
end end
......
...@@ -97,7 +97,7 @@ module QA ...@@ -97,7 +97,7 @@ module QA
when :ci_job_token when :ci_job_token
'System.getenv("CI_JOB_TOKEN")' 'System.getenv("CI_JOB_TOKEN")'
when :project_deploy_token when :project_deploy_token
"\"#{project_deploy_token.password}\"" "\"#{project_deploy_token.token}\""
end end
end end
......
...@@ -142,7 +142,7 @@ module QA ...@@ -142,7 +142,7 @@ module QA
when :ci_job_token when :ci_job_token
'${env.CI_JOB_TOKEN}' '${env.CI_JOB_TOKEN}'
when :project_deploy_token when :project_deploy_token
project_deploy_token.password project_deploy_token.token
end end
end end
......
...@@ -16,13 +16,13 @@ module QA ...@@ -16,13 +16,13 @@ module QA
end end
let(:project_deploy_token) do let(:project_deploy_token) do
Resource::DeployToken.fabricate_via_browser_ui! do |deploy_token| Resource::ProjectDeployToken.fabricate_via_api! do |deploy_token|
deploy_token.name = 'npm-deploy-token' deploy_token.name = 'npm-deploy-token'
deploy_token.project = project deploy_token.project = project
deploy_token.scopes = [ deploy_token.scopes = %w[
:read_repository, read_repository
:read_package_registry, read_package_registry
:write_package_registry write_package_registry
] ]
end end
end end
...@@ -151,7 +151,7 @@ module QA ...@@ -151,7 +151,7 @@ module QA
when :ci_job_token when :ci_job_token
'${CI_JOB_TOKEN}' '${CI_JOB_TOKEN}'
when :project_deploy_token when :project_deploy_token
"\"#{project_deploy_token.password}\"" "\"#{project_deploy_token.token}\""
end end
end end
......
...@@ -16,13 +16,13 @@ module QA ...@@ -16,13 +16,13 @@ module QA
end end
let(:project_deploy_token) do let(:project_deploy_token) do
Resource::DeployToken.fabricate_via_browser_ui! do |deploy_token| Resource::ProjectDeployToken.fabricate_via_api! do |deploy_token|
deploy_token.name = 'npm-deploy-token' deploy_token.name = 'npm-deploy-token'
deploy_token.project = project deploy_token.project = project
deploy_token.scopes = [ deploy_token.scopes = %w[
:read_repository, read_repository
:read_package_registry, read_package_registry
:write_package_registry write_package_registry
] ]
end end
end end
...@@ -129,7 +129,7 @@ module QA ...@@ -129,7 +129,7 @@ module QA
when :ci_job_token when :ci_job_token
'${CI_JOB_TOKEN}' '${CI_JOB_TOKEN}'
when :project_deploy_token when :project_deploy_token
"\"#{project_deploy_token.password}\"" "\"#{project_deploy_token.token}\""
end end
end end
......
...@@ -9,14 +9,14 @@ module QA ...@@ -9,14 +9,14 @@ module QA
deploy_token_name = 'deploy token name' deploy_token_name = 'deploy token name'
one_week_from_now = Date.today + 7 one_week_from_now = Date.today + 7
deploy_token = Resource::DeployToken.fabricate_via_browser_ui! do |resource| deploy_token = Resource::ProjectDeployToken.fabricate_via_api! do |resource|
resource.name = deploy_token_name resource.name = deploy_token_name
resource.expires_at = one_week_from_now resource.expires_at = one_week_from_now
resource.scopes = [:read_repository] resource.scopes = %w[read_repository]
end end
expect(deploy_token.username.length).to be > 0 expect(deploy_token.username.length).to be > 0
expect(deploy_token.password.length).to be > 0 expect(deploy_token.token.length).to be > 0
end end
end end
end end
......
...@@ -42,13 +42,13 @@ module QA ...@@ -42,13 +42,13 @@ module QA
end end
let(:project_deploy_token) do let(:project_deploy_token) do
Resource::DeployToken.fabricate_via_browser_ui! do |deploy_token| Resource::ProjectDeployToken.fabricate_via_api! do |deploy_token|
deploy_token.name = 'package-deploy-token' deploy_token.name = 'package-deploy-token'
deploy_token.project = package_project deploy_token.project = package_project
deploy_token.scopes = [ deploy_token.scopes = %w[
:read_repository, read_repository
:read_package_registry, read_package_registry
:write_package_registry write_package_registry
] ]
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