Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #37474 - feat: enable updating ansible override values via api #719

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
gardar marked this conversation as resolved.
Show resolved Hide resolved
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
gardar marked this conversation as resolved.
Show resolved Hide resolved

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