http_options.rb 959 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class ExternalDataSource
  3. class HttpOptions
  4. def initialize(options)
  5. @options = options
  6. end
  7. def build
  8. output = { json: true, log: { facility: 'ExternalDataSource' } }
  9. add_basic_auth(output)
  10. add_bearer_token_auth(output)
  11. add_verify_ssl(output)
  12. output
  13. end
  14. def add_verify_ssl(output)
  15. return if @options[:verify_ssl].nil?
  16. output[:verify_ssl] = @options[:verify_ssl]
  17. end
  18. def add_basic_auth(output)
  19. return if @options[:http_basic_auth_username].blank? && @options[:http_basic_auth_password].blank?
  20. output[:user] = @options[:http_basic_auth_username]
  21. output[:password] = @options[:http_basic_auth_password]
  22. end
  23. def add_bearer_token_auth(output)
  24. return if @options[:bearer_token_auth].blank?
  25. output[:bearer_token] = @options[:bearer_token_auth]
  26. end
  27. end
  28. end