1
0
Fork 0

added logging to token refresh, added user column to log and log display

Dieser Commit ist enthalten in:
Robert Barrow 2019-06-16 12:49:51 +01:00
Ursprung c6fed81d28
Commit 7efaf25572
6 geänderte Dateien mit 41 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -260,14 +260,20 @@
<div class="log-list">
<table class="wizard-api-log-table">
<th>Datetime</th>
<th>User</th>
<th>Status</th>
<th>Endpoint</th>
<th>URL</th>
<th>Error</th>
{{#each api.log as |logentry|}}
<tr>
<td>{{logentry.time}}</td>
<td class="user-image">
<div class="user-image-inner">
<a href="{{unbound logentry.userpath}}" data-user-card="{{unbound logentry.username}}">{{avatar logentry imageSize="large"}}</a>
</div>
</td>
<td>{{logentry.status}}</td>
<td>{{logentry.endpoint_url}}</td>
<td>{{logentry.url}}</td>
<td>{{logentry.error}}</td>
</tr>
{{/each}}

Datei anzeigen

@ -116,8 +116,14 @@ class CustomWizard::Api::Authorization
:method => 'GET',
:query => URI.encode_www_form(body)
)
result = connection.request()
begin
result = connection.request()
log_params = {time: Time.now, user_id: 0, status: 'SUCCESS', url: token_url, error: ""}
CustomWizard::Api::LogEntry.set(name, log_params)
rescue
log_params = {time: Time.now, user_id: 0, status: 'FAILURE', url: token_url, error: "Token refresh request failed"}
CustomWizard::Api::LogEntry.set(name, log_params)
end
self.handle_token_result(name, result)
end

Datei anzeigen

@ -62,7 +62,7 @@ class CustomWizard::Api::Endpoint
end
end
def self.request(api_name, endpoint_id, body)
def self.request(user, api_name, endpoint_id, body)
endpoint = self.get(api_name, endpoint_id)
auth = CustomWizard::Api::Authorization.get_header_authorization_string(api_name)
@ -87,12 +87,13 @@ class CustomWizard::Api::Endpoint
begin
response = connection.request(params)
log_params = {time: Time.now, status: 'SUCCESS', endpoint_url: endpoint.url, error: ""}
log_params = {time: Time.now, user_id: user.id, status: 'SUCCESS', url: endpoint.url, error: ""}
CustomWizard::Api::LogEntry.set(api_name, log_params)
return JSON.parse(response.body)
rescue
# TODO: improve error detail
log_params = {time: Time.now, status: 'FAILURE', endpoint_url: endpoint.url, error: "API request failed"}
log_params = {time: Time.now, user_id: user.id, status: 'FAILURE', url: endpoint.url, error: "API request failed"}
CustomWizard::Api::LogEntry.set(api_name, log_params)
return JSON.parse "[{\"error\":\"API request failed\"}]"
end

Datei anzeigen

@ -3,9 +3,14 @@ class CustomWizard::Api::LogEntry
attr_accessor :log_id,
:time,
:user_id,
:status,
:endpoint_url,
:error
:url,
:error,
:username,
:userpath,
:name,
:avatar_template
def initialize(api_name, data={})
@api_name = api_name
@ -58,6 +63,12 @@ class CustomWizard::Api::LogEntry
api_name = record['plugin_name'].sub("custom_wizard_api_", "")
data = ::JSON.parse(record['value'])
data[:log_id] = record['key'].split('_').last
this_user = User.find_by(id: data['user_id'])
data[:user_id] = this_user.id || nil
data[:username] = this_user.username || ""
data[:userpath] = "/u/#{this_user.username_lower}/activity"
data[:name] = this_user.name || ""
data[:avatar_template] = "/user_avatar/default/#{this_user.username_lower}/97/#{this_user.uploaded_avatar_id}.png"
self.new(api_name, data)
end
end

Datei anzeigen

@ -406,7 +406,7 @@ class CustomWizard::Builder
api_body = CustomWizard::Builder.fill_placeholders(JSON.generate(api_body_parsed), user, data)
end
result = CustomWizard::Api::Endpoint.request(action['api'], action['api_endpoint'], api_body)
result = CustomWizard::Api::Endpoint.request(user, action['api'], action['api_endpoint'], api_body)
if error = result['error'] || (result[0] && result[0]['error'])
error = error['message'] || error

Datei anzeigen

@ -2,6 +2,11 @@ class CustomWizard::Api::LogSerializer < ApplicationSerializer
attributes :log_id,
:time,
:status,
:endpoint_url,
:error
:url,
:error,
:user_id,
:username,
:userpath,
:name,
:avatar_template
end