summaryrefslogtreecommitdiff
path: root/lib/api/group_variables.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-04-20 14:36:54 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-04-20 14:36:54 +0000
commitf61bb2a16a514b71bf33aabbbb999d6732016a24 (patch)
tree9548caa89e60b4f40b99bbd1dac030420b812aa8 /lib/api/group_variables.rb
parent35fc54e5d261f8898e390aea7c2f5ec5fdf0539d (diff)
downloadgitlab-ce-4a647b2732a66bd1012cef18484571aacad42b5a.tar.gz
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc42
Diffstat (limited to 'lib/api/group_variables.rb')
-rw-r--r--lib/api/group_variables.rb36
1 files changed, 22 insertions, 14 deletions
diff --git a/lib/api/group_variables.rb b/lib/api/group_variables.rb
index 09744fbeda2..8d52a0a5b4e 100644
--- a/lib/api/group_variables.rb
+++ b/lib/api/group_variables.rb
@@ -8,6 +8,8 @@ module API
before { authorize! :admin_group, user_group }
feature_category :continuous_integration
+ helpers Helpers::VariablesHelpers
+
params do
requires :id, type: String, desc: 'The ID of a group'
end
@@ -30,16 +32,13 @@ module API
params do
requires :key, type: String, desc: 'The key of the variable'
end
- # rubocop: disable CodeReuse/ActiveRecord
get ':id/variables/:key' do
- key = params[:key]
- variable = user_group.variables.find_by(key: key)
+ variable = find_variable(user_group, params)
break not_found!('GroupVariable') unless variable
present variable, with: Entities::Ci::Variable
end
- # rubocop: enable CodeReuse/ActiveRecord
desc 'Create a new variable in a group' do
success Entities::Ci::Variable
@@ -50,12 +49,19 @@ module API
optional :protected, type: String, desc: 'Whether the variable is protected'
optional :masked, type: String, desc: 'Whether the variable is masked'
optional :variable_type, type: String, values: ::Ci::GroupVariable.variable_types.keys, desc: 'The type of variable, must be one of env_var or file. Defaults to env_var'
+
+ use :optional_group_variable_params_ee
end
post ':id/variables' do
+ filtered_params = filter_variable_parameters(
+ user_group,
+ declared_params(include_missing: false)
+ )
+
variable = ::Ci::ChangeVariableService.new(
container: user_group,
current_user: current_user,
- params: { action: :create, variable_params: declared_params(include_missing: false) }
+ params: { action: :create, variable_params: filtered_params }
).execute
if variable.valid?
@@ -74,13 +80,19 @@ module API
optional :protected, type: String, desc: 'Whether the variable is protected'
optional :masked, type: String, desc: 'Whether the variable is masked'
optional :variable_type, type: String, values: ::Ci::GroupVariable.variable_types.keys, desc: 'The type of variable, must be one of env_var or file'
+
+ use :optional_group_variable_params_ee
end
- # rubocop: disable CodeReuse/ActiveRecord
put ':id/variables/:key' do
+ filtered_params = filter_variable_parameters(
+ user_group,
+ declared_params(include_missing: false)
+ )
+
variable = ::Ci::ChangeVariableService.new(
container: user_group,
current_user: current_user,
- params: { action: :update, variable_params: declared_params(include_missing: false) }
+ params: { action: :update, variable_params: filtered_params }
).execute
if variable.valid?
@@ -91,7 +103,6 @@ module API
rescue ::ActiveRecord::RecordNotFound
not_found!('GroupVariable')
end
- # rubocop: enable CodeReuse/ActiveRecord
desc 'Delete an existing variable from a group' do
success Entities::Ci::Variable
@@ -99,21 +110,18 @@ module API
params do
requires :key, type: String, desc: 'The key of the variable'
end
- # rubocop: disable CodeReuse/ActiveRecord
delete ':id/variables/:key' do
- variable = user_group.variables.find_by!(key: params[:key])
+ variable = find_variable(user_group, params)
+ break not_found!('GroupVariable') unless variable
destroy_conditionally!(variable) do |target_variable|
::Ci::ChangeVariableService.new(
container: user_group,
current_user: current_user,
- params: { action: :destroy, variable_params: declared_params(include_missing: false) }
+ params: { action: :destroy, variable: variable }
).execute
end
- rescue ::ActiveRecord::RecordNotFound
- not_found!('GroupVariable')
end
- # rubocop: enable CodeReuse/ActiveRecord
end
end
end