2020-06-03 04:14:39 +00:00
|
|
|
class ArsesController < ApplicationController
|
|
|
|
|
|
|
|
|
|
respond_to :json
|
|
|
|
|
|
|
|
|
|
# create or update a client_artifact row
|
|
|
|
|
def get_or_create
|
|
|
|
|
name = params[:name]
|
|
|
|
|
provider = params[:provider]
|
|
|
|
|
active = params[:active]
|
2020-06-05 22:56:17 +00:00
|
|
|
ip = params[:ip]
|
|
|
|
|
username = params[:username]
|
|
|
|
|
password = params[:password]
|
2020-10-18 18:57:32 +00:00
|
|
|
topology = params[:topology]
|
|
|
|
|
ars_id = params[:ars_id]
|
|
|
|
|
puts "TOPOLOGY #{topology}"
|
2020-06-03 04:14:39 +00:00
|
|
|
|
2020-10-18 18:57:32 +00:00
|
|
|
if ars_id
|
|
|
|
|
ars = Ars.find_by_id_int(ars_id)
|
|
|
|
|
end
|
2020-06-03 04:14:39 +00:00
|
|
|
if ars.nil?
|
|
|
|
|
ars = Ars.new
|
|
|
|
|
ars.name = name
|
2021-04-27 20:07:56 +00:00
|
|
|
ars.id_int = ars_id if !ars_id.nil?
|
2020-06-03 04:14:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
ars.provider = provider
|
|
|
|
|
ars.active = active
|
2020-06-05 22:56:17 +00:00
|
|
|
ars.ip = ip
|
|
|
|
|
ars.password = password
|
|
|
|
|
ars.username = username
|
2020-10-18 18:57:32 +00:00
|
|
|
if topology
|
|
|
|
|
ars.city = topology['city']
|
|
|
|
|
ars.country = topology['country']
|
|
|
|
|
ars.continent = topology['continent']
|
|
|
|
|
ars.latitude = topology['latitude']
|
|
|
|
|
ars.longitude = topology['longitude']
|
|
|
|
|
ars.subdivision = topology['subdivision']
|
|
|
|
|
end
|
2020-06-03 04:14:39 +00:00
|
|
|
ars.save
|
|
|
|
|
|
|
|
|
|
@ars = ars
|
|
|
|
|
unless @ars.errors.any?
|
|
|
|
|
@ars = Ars.find_by_name(name)
|
2020-06-05 22:56:17 +00:00
|
|
|
render :json => {id_int: @ars.id_int, id: @ars.id, name: @ars.name, provider: @ars.provider, active: @ars.active, ip: @ars.ip}, :status => :ok
|
2020-06-03 04:14:39 +00:00
|
|
|
else
|
|
|
|
|
response.status = :unprocessable_entity
|
|
|
|
|
respond_with @ars
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
end
|