From 6b9c4be36aa4fd782d1fdc717be6e5e9d9a004b1 Mon Sep 17 00:00:00 2001 From: Geoff Wilson Date: Fri, 13 Sep 2024 09:40:07 -0400 Subject: [PATCH] WIP for class method services --- app/interactors/authenticate_identity.rb | 2 +- app/interactors/obtain_cert.rb | 2 +- app/interactors/refresh_domain.rb | 2 +- app/lib/services/app_registry_service.rb | 4 ++++ app/lib/services/auth_service.rb | 4 ++++ app/lib/services/certificate_service.rb | 6 ++++++ app/lib/services/domain_ownership_service.rb | 6 ++++++ app/lib/services/vault_service.rb | 7 ++++++- 8 files changed, 29 insertions(+), 4 deletions(-) diff --git a/app/interactors/authenticate_identity.rb b/app/interactors/authenticate_identity.rb index 8626708..b7462e8 100644 --- a/app/interactors/authenticate_identity.rb +++ b/app/interactors/authenticate_identity.rb @@ -8,7 +8,7 @@ class AuthenticateIdentity end def call - if identity = Services::AuthService.new.authenticate!(context.token) + if identity = Services::AuthService.authenticate!(context.token) context.identity = identity else context.fail!(message: "Invalid token") diff --git a/app/interactors/obtain_cert.rb b/app/interactors/obtain_cert.rb index 8cd9b87..54c893a 100644 --- a/app/interactors/obtain_cert.rb +++ b/app/interactors/obtain_cert.rb @@ -3,7 +3,7 @@ class ObtainCert include FailOnError def call - if cert = Services::CertificateService.new.issue_cert(context.request) + if cert = Services::CertificateService.issue_cert(context.request) context.cert = cert else context.fail!(message: "Failed to issue certificate") diff --git a/app/interactors/refresh_domain.rb b/app/interactors/refresh_domain.rb index 9ecbfbb..bae405a 100644 --- a/app/interactors/refresh_domain.rb +++ b/app/interactors/refresh_domain.rb @@ -2,7 +2,7 @@ class RefreshDomain include Interactor def call - domain_info = Services::DomainOwnershipService.new.get_domain_info(context.request.common_name) + domain_info = Services::DomainOwnershipService.get_domain_info(context.request.common_name) domain_record = Domain.find_or_create_by!(fqdn: context.request.common_name) if !domain_info domain_record.destroy! diff --git a/app/lib/services/app_registry_service.rb b/app/lib/services/app_registry_service.rb index 2cd8671..b28fb2c 100644 --- a/app/lib/services/app_registry_service.rb +++ b/app/lib/services/app_registry_service.rb @@ -17,6 +17,10 @@ def get_domain_info(fqdn) rescue Faraday::ResourceNotFound => e nil end + + def self.get_domain_info(fqdn) + new.get_domain_info(fqdn) + end private diff --git a/app/lib/services/auth_service.rb b/app/lib/services/auth_service.rb index dc5a983..1fb8f3d 100644 --- a/app/lib/services/auth_service.rb +++ b/app/lib/services/auth_service.rb @@ -13,6 +13,10 @@ def authenticate!(token) identity end + def self.authenticate!(token) + new.authenticate!(token) + end + private def decode(token) diff --git a/app/lib/services/certificate_service.rb b/app/lib/services/certificate_service.rb index 785e6a6..0f53d2a 100644 --- a/app/lib/services/certificate_service.rb +++ b/app/lib/services/certificate_service.rb @@ -2,6 +2,12 @@ module Services class CertificateService attr_reader :impl + def self.issue_cert(cert_issue_request) + new.issue_cert(cert_issue_request) + end + + private + def initialize # TODO this should select an implementation service based on config @impl = VaultService.new diff --git a/app/lib/services/domain_ownership_service.rb b/app/lib/services/domain_ownership_service.rb index cc494ca..689a48f 100644 --- a/app/lib/services/domain_ownership_service.rb +++ b/app/lib/services/domain_ownership_service.rb @@ -2,6 +2,12 @@ module Services class DomainOwnershipService attr_reader :impl + def self.get_domain_info(fqdn) + new.get_domain_info(fqdn) + end + + private + def initialize # TODO this should select an implementation service based on config @impl = AppRegistryService.new diff --git a/app/lib/services/vault_service.rb b/app/lib/services/vault_service.rb index 3f15518..c855f6d 100644 --- a/app/lib/services/vault_service.rb +++ b/app/lib/services/vault_service.rb @@ -1,7 +1,12 @@ module Services class VaultService + def self.issue_cert(cert_issue_request) + new.issue_cert(cert_issue_request) + end + + private attr_reader :client - + def initialize # TODO create a new token for use in the session @client = Vault::Client.new(