5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-20 02:16:22 +00:00

chore: rubocop

This commit is contained in:
f 2024-02-17 14:11:17 -03:00
parent b24f49fe26
commit b4117d7c34
No known key found for this signature in database
5 changed files with 26 additions and 23 deletions

View file

@ -18,13 +18,14 @@ module Api
def token def token
@token ||= @token ||=
begin begin
_headers = request.headers header = request.headers
_token ||= _headers['X-Gitlab-Token'].presence token = header['X-Social-Inbox'].presence
_token ||= token_from_signature(_headers['X-Gitea-Signature'].presence) token ||= header['X-Gitlab-Token'].presence
_token ||= token_from_signature(_headers['X-Hub-Signature-256'].presence, 'sha256=') token ||= token_from_signature(header['X-Gitea-Signature'].presence)
_token token ||= token_from_signature(header['X-Hub-Signature-256'].presence, 'sha256=')
token
ensure ensure
raise ActiveRecord::RecordNotFound, 'Proveedor no soportado' if _token.blank? raise ActiveRecord::RecordNotFound, 'Proveedor no soportado' if token.blank?
end end
end end

View file

@ -14,8 +14,8 @@ class Deploy < ApplicationRecord
has_many :build_stats, dependent: :destroy has_many :build_stats, dependent: :destroy
DEPENDENCIES = [] DEPENDENCIES = [].freeze
SOFT_DEPENDENCIES = [] SOFT_DEPENDENCIES = [].freeze
def deploy(**) def deploy(**)
raise NotImplementedError raise NotImplementedError
@ -74,7 +74,7 @@ class Deploy < ApplicationRecord
'HOME' => home_dir, 'HOME' => home_dir,
'PATH' => paths.join(':'), 'PATH' => paths.join(':'),
'JEKYLL_ENV' => Rails.env, 'JEKYLL_ENV' => Rails.env,
'LANG' => ENV['LANG'], 'LANG' => ENV.fetch('LANG', nil)
}) })
end end
@ -139,7 +139,7 @@ class Deploy < ApplicationRecord
# provisto con el archivo como parámetro # provisto con el archivo como parámetro
# #
# @param :content [String] # @param :content [String]
def with_tempfile(content, &block) def with_tempfile(content)
Tempfile.create(SecureRandom.hex) do |file| Tempfile.create(SecureRandom.hex) do |file|
file.write content.to_s file.write content.to_s
file.rewind file.rewind

View file

@ -5,7 +5,7 @@ require 'distributed_press/v1/social/client'
# Publicar novedades al Fediverso # Publicar novedades al Fediverso
class DeploySocialDistributedPress < Deploy class DeploySocialDistributedPress < Deploy
# Solo luego de publicar remotamente # Solo luego de publicar remotamente
DEPENDENCIES = %i[deploy_distributed_press deploy_rsync deploy_full_rsync] DEPENDENCIES = %i[deploy_distributed_press deploy_rsync deploy_full_rsync].freeze
after_save :create_hooks! after_save :create_hooks!
@ -70,17 +70,21 @@ class DeploySocialDistributedPress < Deploy
# @return [nil] # @return [nil]
def create_hooks! def create_hooks!
hook_client = site.social_inbox.hook hook_client = site.social_inbox.hook
webhook_class = DistributedPress::V1::Social::Schemas::Webhook
hook_client.class::EVENTS.each do |event| hook_client.class::EVENTS.each do |event|
event_url = :"v1_site_webhooks_social_inbox_#{event}_url" event_url = :"v1_site_webhooks_social_inbox_#{event}_url"
webhook = DistributedPress::V1::Social::Schemas::Webhook.new.call({ webhook =
method: 'POST', webhook_class.new.call({
url: Rails.application.routes.url_helpers.public_send(event_url, site_id: site.name, host: api_hostname), method: 'POST',
headers: { url: Rails.application.routes.url_helpers.public_send(
'X-Social-Inbox': rol.token event_url, site_id: site.name, host: api_hostname
} ),
}) headers: {
'X-Social-Inbox': rol.token
}
})
raise ArgumentError, webhook.errors.messages if webhook.failure? raise ArgumentError, webhook.errors.messages if webhook.failure?

View file

@ -25,7 +25,8 @@ class Site
def generate_private_key_pem! def generate_private_key_pem!
self.private_key_pem ||= DistributedPress::V1::Social::Client.new( self.private_key_pem ||= DistributedPress::V1::Social::Client.new(
public_key_url: nil, public_key_url: nil,
key_size: 2048).private_key.export key_size: 2048
).private_key.export
end end
end end
end end

View file

@ -50,9 +50,6 @@ class SocialInbox
def hostname def hostname
@hostname ||= @hostname ||=
begin site.config.dig('activity_pub', 'hostname') || site.hostname
host = site.config.dig('activity_pub', 'hostname')
host ||= site.hostname
end
end end
end end