5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-18 00:26:21 +00:00

Merge branch 'issue-14696' of https://0xacab.org/sutty/sutty into 17.3.alpine.panel.sutty.nl

This commit is contained in:
Sutty 2023-11-23 21:47:40 +00:00
commit 90ebb29650
3 changed files with 2 additions and 63 deletions

View file

@ -44,7 +44,6 @@ gem 'devise'
gem 'devise-i18n' gem 'devise-i18n'
gem 'devise_invitable' gem 'devise_invitable'
gem 'distributed-press-api-client', '~> 0.3.0rc0' gem 'distributed-press-api-client', '~> 0.3.0rc0'
gem 'njalla-api-client', '~> 0.2.0'
gem 'email_address', git: 'https://github.com/fauno/email_address', branch: 'i18n' gem 'email_address', git: 'https://github.com/fauno/email_address', branch: 'i18n'
gem 'exception_notification' gem 'exception_notification'
gem 'fast_blank' gem 'fast_blank'

View file

@ -359,9 +359,6 @@ GEM
net-ssh (7.1.0) net-ssh (7.1.0)
netaddr (2.0.6) netaddr (2.0.6)
nio4r (2.5.9-x86_64-linux-musl) nio4r (2.5.9-x86_64-linux-musl)
njalla-api-client (0.2.0)
dry-schema
httparty (~> 0.18)
nokogiri (1.15.4-x86_64-linux-musl) nokogiri (1.15.4-x86_64-linux-musl)
mini_portile2 (~> 2.8.2) mini_portile2 (~> 2.8.2)
racc (~> 1.4) racc (~> 1.4)
@ -623,7 +620,6 @@ DEPENDENCIES
mini_magick mini_magick
mobility mobility
net-ssh net-ssh
njalla-api-client (~> 0.2.0)
nokogiri nokogiri
pg pg
pg_search pg_search

View file

@ -1,7 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
require 'distributed_press/v1/client/site' require 'distributed_press/v1/client/site'
require 'njalla/v1'
# Soportar Distributed Press APIv1 # Soportar Distributed Press APIv1
# #
@ -15,8 +14,8 @@ require 'njalla/v1'
class DeployDistributedPress < Deploy class DeployDistributedPress < Deploy
store :values, accessors: %i[hostname remote_site_id remote_info distributed_press_publisher_id], coder: JSON store :values, accessors: %i[hostname remote_site_id remote_info distributed_press_publisher_id], coder: JSON
before_create :create_remote_site!, :create_njalla_records! before_create :create_remote_site!
before_destroy :delete_remote_site!, :delete_njalla_records! before_destroy :delete_remote_site!
DEPENDENCIES = %i[deploy_local] DEPENDENCIES = %i[deploy_local]
@ -31,17 +30,12 @@ class DeployDistributedPress < Deploy
time_start time_start
create_remote_site! if remote_site_id.blank? create_remote_site! if remote_site_id.blank?
create_njalla_records!
save save
if remote_site_id.blank? if remote_site_id.blank?
raise DeployJob::DeployException, 'El sitio no se creó en Distributed Press' raise DeployJob::DeployException, 'El sitio no se creó en Distributed Press'
end end
if create_njalla_records? && remote_info[:njalla].blank?
raise DeployJob::DeployException, 'No se pudieron crear los registros necesarios en Njalla'
end
site_client.tap do |c| site_client.tap do |c|
stdout = Thread.new(publisher.logger_out) do |io| stdout = Thread.new(publisher.logger_out) do |io|
until io.eof? until io.eof?
@ -149,29 +143,6 @@ class DeployDistributedPress < Deploy
nil nil
end end
# Crea los registros en Njalla
#
# XXX: Esto depende de nuestro DNS actual, cuando lo migremos hay
# que eliminarlo.
#
# @return [nil]
def create_njalla_records!
return unless create_njalla_records?
self.remote_info ||= {}
self.remote_info[:njalla] ||= {}
self.remote_info[:njalla][:a] ||= njalla.add_record(name: site.name, type: 'CNAME', content: "#{Site.domain}.").to_h
self.remote_info[:njalla][:cname] ||= njalla.add_record(name: "www.#{site.name}", type: 'CNAME', content: "#{Site.domain}.").to_h
self.remote_info[:njalla][:ns] ||= njalla.add_record(name: "_dnslink.#{site.name}", type: 'NS', content: "#{publisher.hostname}.").to_h
nil
rescue HTTParty::Error => e
ExceptionNotifier.notify_exception(e, data: { site: site.name })
self.remote_info.delete :njalla
ensure
nil
end
# Registra lo que sucedió # Registra lo que sucedió
# #
# @param status [Bool] # @param status [Bool]
@ -189,31 +160,4 @@ class DeployDistributedPress < Deploy
ExceptionNotifier.notify_exception(e, data: { site: site.name }) ExceptionNotifier.notify_exception(e, data: { site: site.name })
nil nil
end end
def delete_njalla_records!
return unless create_njalla_records?
%w[a ns cname].each do |type|
next if (id = remote_info.dig('njalla', type, 'id')).blank?
njalla.remove_record(id: id.to_i)
end
end
# Actualizar registros en Njalla
#
# @return [Njalla::V1::Domain]
def njalla
@njalla ||=
begin
client = Njalla::V1::Client.new(token: Rails.application.credentials.njalla)
Njalla::V1::Domain.new(domain: Site.domain, client: client)
end
end
# Detecta si tenemos que crear registros en Njalla
def create_njalla_records?
!site.name.end_with?('.')
end
end end