summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-10 09:08:10 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-10 09:08:10 +0000
commit82fa8a3d1e8466ef36b58604d20fcc145ea12118 (patch)
treec5c0286537405c2fa7719ecce3ed0d73d947c555 /lib/api
parent232655bf32cd474d54de357b65ef43d77271117c (diff)
downloadgitlab-ce-82fa8a3d1e8466ef36b58604d20fcc145ea12118.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/deploy_tokens.rb32
-rw-r--r--lib/api/entities/deploy_token_with_token.rb9
2 files changed, 41 insertions, 0 deletions
diff --git a/lib/api/deploy_tokens.rb b/lib/api/deploy_tokens.rb
index e10a12b6c46..1631425ec1b 100644
--- a/lib/api/deploy_tokens.rb
+++ b/lib/api/deploy_tokens.rb
@@ -4,6 +4,17 @@ module API
class DeployTokens < Grape::API
include PaginationParams
+ helpers do
+ def scope_params
+ scopes = params.delete(:scopes)
+
+ result_hash = {}
+ result_hash[:read_registry] = scopes.include?('read_registry')
+ result_hash[:read_repository] = scopes.include?('read_repository')
+ result_hash
+ end
+ end
+
desc 'Return all deploy tokens' do
detail 'This feature was introduced in GitLab 12.9.'
success Entities::DeployToken
@@ -33,6 +44,27 @@ module API
present paginate(user_project.deploy_tokens), with: Entities::DeployToken
end
+
+ params do
+ requires :name, type: String, desc: "New deploy token's name"
+ requires :expires_at, type: DateTime, desc: 'Expiration date for the deploy token. Does not expire if no value is provided.'
+ requires :username, type: String, desc: 'Username for deploy token. Default is `gitlab+deploy-token-{n}`'
+ requires :scopes, type: Array[String], values: ::DeployToken::AVAILABLE_SCOPES.map(&:to_s),
+ desc: 'Indicates the deploy token scopes. Must be at least one of "read_repository" or "read_registry".'
+ end
+ desc 'Create a project deploy token' do
+ detail 'This feature was introduced in GitLab 12.9'
+ success Entities::DeployTokenWithToken
+ end
+ post ':id/deploy_tokens' do
+ authorize!(:create_deploy_token, user_project)
+
+ deploy_token = ::Projects::DeployTokens::CreateService.new(
+ user_project, current_user, scope_params.merge(declared(params, include_missing: false, include_parent_namespaces: false))
+ ).execute
+
+ present deploy_token, with: Entities::DeployTokenWithToken
+ end
end
params do
diff --git a/lib/api/entities/deploy_token_with_token.rb b/lib/api/entities/deploy_token_with_token.rb
new file mode 100644
index 00000000000..11efe3720fa
--- /dev/null
+++ b/lib/api/entities/deploy_token_with_token.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class DeployTokenWithToken < Entities::DeployToken
+ expose :token
+ end
+ end
+end