2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-24 18:46:33 +05:30
|
|
|
class Projects::VariablesController < Projects::ApplicationController
|
2016-04-02 18:10:28 +05:30
|
|
|
before_action :authorize_admin_build!
|
2015-10-24 18:46:33 +05:30
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
feature_category :secrets_management
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
urgency :low, [:show, :update]
|
|
|
|
|
2015-10-24 18:46:33 +05:30
|
|
|
def show
|
2018-03-17 18:26:18 +05:30
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
2020-07-28 23:09:34 +05:30
|
|
|
render status: :ok, json: { variables: ::Ci::VariableSerializer.new.represent(@project.variables) }
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2020-10-24 23:57:45 +05:30
|
|
|
update_result = Ci::ChangeVariablesService.new(
|
|
|
|
container: @project, current_user: current_user,
|
|
|
|
params: variables_params
|
|
|
|
).execute
|
|
|
|
|
|
|
|
if update_result
|
2018-03-17 18:26:18 +05:30
|
|
|
respond_to do |format|
|
2018-10-15 14:42:47 +05:30
|
|
|
format.json { render_variables }
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
else
|
2018-03-17 18:26:18 +05:30
|
|
|
respond_to do |format|
|
|
|
|
format.json { render_error }
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
private
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def render_variables
|
2020-07-28 23:09:34 +05:30
|
|
|
render status: :ok, json: { variables: ::Ci::VariableSerializer.new.represent(@project.variables) }
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def render_error
|
|
|
|
render status: :bad_request, json: @project.errors.full_messages
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def variables_params
|
2022-08-27 11:52:29 +05:30
|
|
|
params.permit(variables_attributes: Array(variable_params_attributes))
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def variable_params_attributes
|
2023-03-04 22:38:38 +05:30
|
|
|
%i[id variable_type key secret_value protected masked raw environment_scope _destroy]
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|