Skip to content

Commit

Permalink
fixes #37474 - feat: enable updating ansible override values via api
Browse files Browse the repository at this point in the history
Signed-off-by: gardar <[email protected]>
  • Loading branch information
gardar committed May 16, 2024
1 parent 8c6be4f commit d8176a0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
23 changes: 23 additions & 0 deletions app/controllers/api/v2/ansible_override_values_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ def create
render 'api/v2/ansible_override_values/show'
end

api :PUT, "/ansible_override_values", N_("Update an override value")
param :ansible_variable_id, :identifier, :required => true
param_group :ansible_override_value, :as => :update

def update
@ansible_variable = AnsibleVariable.authorized(:edit_ansible_variables).
find_by(:id => params[:ansible_variable_id].to_i)
@override_value = @ansible_variable.lookup_values.find_by(:match => lookup_value_params['override_value']['match'])

if @override_value
@override_value.update(lookup_value_params['override_value'])
render 'api/v2/ansible_override_values/show'
else
not_found
end
end

api :DELETE, "/ansible_override_values/:id", N_("Destroy an override value")
param :id, :identifier, :required => true

Expand All @@ -45,6 +62,12 @@ def destroy
end
end

private

def lookup_value_params
params.permit(:ansible_variable_id, override_value: [:match, :value])
end

def resource_name
'ansible_variable'
end
Expand Down
6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@
end
end

resources :ansible_override_values, :only => [:create, :destroy]
resources :ansible_override_values, :only => [:create, :destroy] do
collection do
put :update
end
end

resources :ansible_inventories, :only => [] do
collection do
Expand Down

0 comments on commit d8176a0

Please sign in to comment.