-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove moonrope but maintain legacy API actions
- Loading branch information
Showing
13 changed files
with
448 additions
and
442 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# frozen_string_literal: true | ||
|
||
module LegacyAPI | ||
class BaseController < ActionController::Base | ||
|
||
before_action :start_timer | ||
before_action :authenticate_as_server | ||
|
||
private | ||
|
||
def start_timer | ||
@start_time = Time.now.to_f | ||
end | ||
|
||
def authenticate_as_server | ||
key = request.headers["X-Server-API-Key"] | ||
if key.blank? | ||
render_error "AccessDenied", | ||
message: "Must be authenticated as a server." | ||
return | ||
end | ||
|
||
credential = Credential.where(type: "API", key: key).first | ||
if credential.nil? | ||
render_error "InvalidServerAPIKey", | ||
message: "The API token provided in X-Server-API-Key was not valid.", | ||
token: key | ||
return | ||
end | ||
|
||
if credential.server.suspended? | ||
render_error "ServerSuspended" | ||
return | ||
end | ||
|
||
credential.use | ||
@current_credential = credential | ||
end | ||
|
||
def render_success(data) | ||
render json: { status: "success", | ||
time: Time.now.to_f - @start_time, | ||
flags: {}, | ||
data: data } | ||
end | ||
|
||
def render_error(code, data = {}) | ||
render json: { status: "error", | ||
time: Time.now.to_f - @start_time, | ||
flags: {}, | ||
data: data.merge(code: code) } | ||
end | ||
|
||
def render_parameter_error(message) | ||
render json: { status: "parameter-error", | ||
time: Time.now.to_f - @start_time, | ||
flags: {}, | ||
data: { message: message } } | ||
end | ||
|
||
end | ||
end |
Oops, something went wrong.