apply_configuration_base.rb 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Service::System::Import::ApplyConfigurationBase < Service::Base
  3. attr_reader :url, :endpoint, :secret, :username, :tls_verify
  4. def initialize(url:, secret: nil, username: nil, tls_verify: true)
  5. super()
  6. @url = url
  7. @endpoint = build_endpoint
  8. @secret = secret
  9. @username = username
  10. @tls_verify = tls_verify
  11. end
  12. def execute
  13. reachable!
  14. accessible! if @secret.present?
  15. end
  16. private
  17. def build_endpoint
  18. raise NotImplementedError
  19. end
  20. def reachable!
  21. raise NotImplementedError
  22. end
  23. def accessible!
  24. raise NotImplementedError
  25. end
  26. def request(url, options = {})
  27. response = UserAgent.request(url, options)
  28. raise TLSError, __('The server presented a certificate that could not be verified.') if response.error&.include?('OpenSSL::SSL::SSLError')
  29. response
  30. end
  31. class UnreachableError < StandardError; end
  32. class InaccessibleError < StandardError; end
  33. class TLSError < StandardError; end
  34. end