Page Menu
Home
GRNET
Search
Configure Global Search
Log In
Files
F1615243
api_controller.rb
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Mar 21, 10:06 PM
Size
1 KB
Mime Type
text/x-ruby
Expires
Mon, Mar 23, 10:06 PM (1 d, 1 h)
Engine
blob
Format
Raw Data
Handle
354335
Attached To
rWEBDNS WebDNS (edet4)
api_controller.rb
View Options
class
ApiController
<
ApplicationController
rescue_from
ActiveRecord
::
RecordNotFound
,
with
:
:record_not_found
rescue_from
ActionController
::
ParameterMissing
,
with
:
:parameter_missing
# This a private trusted API
skip_before_action
:verify_authenticity_token
before_action
:authenticate_token
before_action
:domain
,
only
:
[
:list
,
:bulk
]
# GET /ping
def
ping
render
json
:
{
ok
:
true
,
response
:
:pong
}
end
# GET /whoami
def
whoami
render
json
:
{
ok
:
true
,
response
:
current_user
.
to_api
}
end
# GET domain/<name>/list
def
list
records
=
Record
.
smart_order
(
@domain
.
records
)
.
map
(
&
:to_api
)
render
json
:
{
ok
:
true
,
response
:
records
}
end
# POST domain/<name>/list
def
bulk
api_params
=
params
.
require
(
:api
)
.
permit!
ops
,
err
,
bulk_ops
=
domain
.
api_bulk
(
api_params
)
if
err
.
empty?
notify_record_bulk
(
domain
,
bulk_ops
)
render
json
:
{
ok
:
true
,
response
:
{
operations
:
ops
}
}
else
render
json
:
{
ok
:
false
,
errors
:
err
,
response
:
{
operations
:
ops
}
}
end
end
private
def
authenticate_token
if
user
=
User
.
find_by_token
(
params
.
require
(
:token
))
warden
.
set_user
(
user
,
store
:
false
)
else
head
(
403
)
end
end
def
domain
if
params
[
:domain
]
=~
/^[0-9]+$/
params
[
:domain_id
]
=
params
[
:domain
]
else
params
[
:domain_id
]
=
Domain
.
find_by_name!
(
params
[
:domain
]
)
.
id
end
super
end
def
record_not_found
render
json
:
{
ok
:
false
,
error
:
:record_not_found
}
end
def
parameter_missing
render
json
:
{
ok
:
false
,
error
:
:parameter_missing
}
end
def
notify_record_bulk
(
*
args
)
notification
.
notify_record_bulk
(
current_user
,
*
args
)
if
WebDNS
.
settings
[
:notifications
]
end
end
Event Timeline
Log In to Comment