Skip to content

Commit

Permalink
Remove rabl dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargron committed Dec 6, 2017
1 parent d68868c commit 86434b9
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 49 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ gem 'oj', '~> 3.3'
gem 'ostatus2', '~> 2.0'
gem 'ox', '~> 2.8'
gem 'pundit', '~> 1.1'
gem 'rabl', '~> 0.13'
gem 'rack-attack', '~> 5.0'
gem 'rack-cors', '~> 0.4', require: 'rack/cors'
gem 'rack-timeout', '~> 0.4'
Expand Down
3 changes: 0 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,6 @@ GEM
puma (3.11.0)
pundit (1.1.0)
activesupport (>= 3.0.0)
rabl (0.13.1)
activesupport (>= 2.3.14)
rack (2.0.3)
rack-attack (5.0.1)
rack
Expand Down Expand Up @@ -606,7 +604,6 @@ DEPENDENCIES
pry-rails (~> 0.3)
puma (~> 3.10)
pundit (~> 1.1)
rabl (~> 0.13)
rack-attack (~> 5.0)
rack-cors (~> 0.4)
rack-timeout (~> 0.4)
Expand Down
19 changes: 1 addition & 18 deletions app/controllers/well_known/webfinger_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ class WebfingerController < ApplicationController

def show
@account = Account.find_local!(username_from_resource)
@canonical_account_uri = @account.to_webfinger_s
@magic_key = pem_to_magic_key(@account.keypair.public_key)

respond_to do |format|
format.any(:json, :html) do
render formats: :json, content_type: 'application/jrd+json'
render json: @account, serializer: WebfingerSerializer, content_type: 'application/jrd+json'
end

format.xml do
Expand All @@ -35,21 +33,6 @@ def username_from_resource
WebfingerResource.new(resource_user).username
end

def pem_to_magic_key(public_key)
modulus, exponent = [public_key.n, public_key.e].map do |component|
result = []

until component.zero?
result << [component % 256].pack('C')
component >>= 8
end

result.reverse.join
end

(['RSA'] + [modulus, exponent].map { |n| Base64.urlsafe_encode64(n) }).join('.')
end

def resource_param
params.require(:resource)
end
Expand Down
15 changes: 15 additions & 0 deletions app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,21 @@ def keypair
@keypair ||= OpenSSL::PKey::RSA.new(private_key || public_key)
end

def magic_key
modulus, exponent = [keypair.public_key.n, keypair.public_key.e].map do |component|
result = []

until component.zero?
result << [component % 256].pack('C')
component >>= 8
end

result.reverse.join
end

(['RSA'] + [modulus, exponent].map { |n| Base64.urlsafe_encode64(n) }).join('.')
end

def subscription(webhook_url)
@subscription ||= OStatus2::Subscription.new(remote_url, secret: secret, webhook: webhook_url, hub: hub_url)
end
Expand Down
26 changes: 26 additions & 0 deletions app/serializers/webfinger_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

class WebfingerSerializer < ActiveModel::Serializer
include RoutingHelper

attributes :subject, :aliases, :links

def subject
object.to_webfinger_s
end

def aliases
[short_account_url(object), account_url(object)]
end

def links
[
{ rel: 'http://webfinger.net/rel/profile-page', type: 'text/html', href: short_account_url(object) },
{ rel: 'http://schemas.google.com/g/2010#updates-from', type: 'application/atom+xml', href: account_url(object, format: 'atom') },
{ rel: 'self', type: 'application/activity+json', href: account_url(object) },
{ rel: 'salmon', href: api_salmon_url(object.id) },
{ rel: 'magic-public-key', href: "data:application/magic-public-key,#{object.magic_key}" },
{ rel: 'http://ostatus.org/schema/1.0/subscribe', template: "#{authorize_follow_url}?acct={uri}" },
]
end
end
18 changes: 0 additions & 18 deletions app/views/well_known/webfinger/show.json.rabl

This file was deleted.

4 changes: 2 additions & 2 deletions app/views/well_known/webfinger/show.xml.ruby
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Nokogiri::XML::Builder.new do |xml|
xml.XRD(xmlns: 'http://docs.oasis-open.org/ns/xri/xrd-1.0') do
xml.Subject @canonical_account_uri
xml.Subject @account.to_webfinger_s
xml.Alias short_account_url(@account)
xml.Alias account_url(@account)
xml.Link(rel: 'http://webfinger.net/rel/profile-page', type: 'text/html', href: short_account_url(@account))
xml.Link(rel: 'http://schemas.google.com/g/2010#updates-from', type: 'application/atom+xml', href: account_url(@account, format: 'atom'))
xml.Link(rel: 'self', type: 'application/activity+json', href: account_url(@account))
xml.Link(rel: 'salmon', href: api_salmon_url(@account.id))
xml.Link(rel: 'magic-public-key', href: "data:application/magic-public-key,#{@magic_key}")
xml.Link(rel: 'magic-public-key', href: "data:application/magic-public-key,#{@account.magic_key}")
xml.Link(rel: 'http://ostatus.org/schema/1.0/subscribe', template: "#{authorize_follow_url}?acct={uri}")
end
end.to_xml
7 changes: 0 additions & 7 deletions config/initializers/rabl_init.rb

This file was deleted.

0 comments on commit 86434b9

Please sign in to comment.