Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api/variables.rb')
-rw-r--r--lib/api/variables.rb47
1 files changed, 29 insertions, 18 deletions
diff --git a/lib/api/variables.rb b/lib/api/variables.rb
index 50d137ec7c1..cea0cb3a19c 100644
--- a/lib/api/variables.rb
+++ b/lib/api/variables.rb
@@ -30,18 +30,18 @@ module API
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
desc 'Get project variables' do
- success Entities::Variable
+ success Entities::Ci::Variable
end
params do
use :pagination
end
get ':id/variables' do
variables = user_project.variables
- present paginate(variables), with: Entities::Variable
+ present paginate(variables), with: Entities::Ci::Variable
end
desc 'Get a specific variable from a project' do
- success Entities::Variable
+ success Entities::Ci::Variable
end
params do
requires :key, type: String, desc: 'The key of the variable'
@@ -51,12 +51,12 @@ module API
variable = find_variable(params)
not_found!('Variable') unless variable
- present variable, with: Entities::Variable
+ present variable, with: Entities::Ci::Variable
end
# rubocop: enable CodeReuse/ActiveRecord
desc 'Create a new variable in a project' do
- success Entities::Variable
+ success Entities::Ci::Variable
end
params do
requires :key, type: String, desc: 'The key of the variable'
@@ -67,20 +67,21 @@ module API
optional :environment_scope, type: String, desc: 'The environment_scope of the variable'
end
post ':id/variables' do
- variable_params = declared_params(include_missing: false)
- variable_params = filter_variable_parameters(variable_params)
-
- variable = user_project.variables.create(variable_params)
+ variable = ::Ci::ChangeVariableService.new(
+ container: user_project,
+ current_user: current_user,
+ params: { action: :create, variable_params: filter_variable_parameters(declared_params(include_missing: false)) }
+ ).execute
if variable.valid?
- present variable, with: Entities::Variable
+ present variable, with: Entities::Ci::Variable
else
render_validation_error!(variable)
end
end
desc 'Update an existing variable from a project' do
- success Entities::Variable
+ success Entities::Ci::Variable
end
params do
optional :key, type: String, desc: 'The key of the variable'
@@ -96,11 +97,18 @@ module API
variable = find_variable(params)
not_found!('Variable') unless variable
- variable_params = declared_params(include_missing: false).except(:key, :filter)
- variable_params = filter_variable_parameters(variable_params)
+ variable_params = filter_variable_parameters(
+ declared_params(include_missing: false)
+ .except(:key, :filter)
+ )
+ variable = ::Ci::ChangeVariableService.new(
+ container: user_project,
+ current_user: current_user,
+ params: { action: :update, variable: variable, variable_params: variable_params }
+ ).execute
- if variable.update(variable_params)
- present variable, with: Entities::Variable
+ if variable.valid?
+ present variable, with: Entities::Ci::Variable
else
render_validation_error!(variable)
end
@@ -108,7 +116,7 @@ module API
# rubocop: enable CodeReuse/ActiveRecord
desc 'Delete an existing variable from a project' do
- success Entities::Variable
+ success Entities::Ci::Variable
end
params do
requires :key, type: String, desc: 'The key of the variable'
@@ -119,8 +127,11 @@ module API
variable = find_variable(params)
not_found!('Variable') unless variable
- # Variables don't have a timestamp. Therefore, destroy unconditionally.
- variable.destroy
+ ::Ci::ChangeVariableService.new(
+ container: user_project,
+ current_user: current_user,
+ params: { action: :destroy, variable: variable }
+ ).execute
no_content!
end