From 82fa8a3d1e8466ef36b58604d20fcc145ea12118 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Tue, 10 Mar 2020 09:08:10 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- lib/api/deploy_tokens.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'lib/api/deploy_tokens.rb') 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 -- cgit v1.2.1