From f4264fe763127557fe083b0b2dedec08e192b0c6 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 28 Mar 2023 15:28:46 -0300 Subject: [PATCH] feat: generar direcciones tor a demanda #12773 --- app/lib/hidden_service_client.rb | 13 +++++++++++++ app/models/deploy_hidden_service.rb | 12 +++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 app/lib/hidden_service_client.rb diff --git a/app/lib/hidden_service_client.rb b/app/lib/hidden_service_client.rb new file mode 100644 index 00000000..9cf8a1d5 --- /dev/null +++ b/app/lib/hidden_service_client.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'httparty' + +class HiddenServiceClient + include HTTParty + + base_uri ENV.fetch('HIDDEN_SERVICE', 'http://tor:3000') + + def create(name) + self.class.get("/#{name}") + end +end diff --git a/app/models/deploy_hidden_service.rb b/app/models/deploy_hidden_service.rb index 79ff1bae..6b84752f 100644 --- a/app/models/deploy_hidden_service.rb +++ b/app/models/deploy_hidden_service.rb @@ -2,8 +2,12 @@ # Genera una versión onion class DeployHiddenService < DeployWww + store :values, accessors: %i[onion], coder: JSON + + before_create :create_hidden_service! + def fqdn - values[:onion].tap do |onion| + onion.tap do |onion| raise ArgumentError, 'Aun no se generó la dirección .onion' if onion.blank? end end @@ -11,4 +15,10 @@ class DeployHiddenService < DeployWww def url "http://#{fqdn}" end + + private + + def create_hidden_service! + self.onion = HiddenServiceClient.new.create(site.name) + end end