configuration.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Mutations
  3. class System::Import::Configuration < BaseMutation
  4. description 'Verify and apply third-party system import configuration'
  5. argument :configuration, Gql::Types::Input::SystemImportConfigurationInputType, description: 'Configuration to validate'
  6. field :success, Boolean, null: false, description: 'Is the configuration valid?'
  7. def self.authorize(...)
  8. true
  9. end
  10. def resolve(configuration:)
  11. klass_name = "Service::System::Import::Apply#{configuration.source.camelize}Configuration"
  12. klass = klass_name.constantize
  13. begin
  14. klass.new(**configuration.to_h.except(:source)).execute
  15. rescue "#{klass_name}::UnreachableError".constantize, "#{klass_name}::TLSError".constantize => e
  16. return { success: false }.merge(error_response({ message: e.message, field: 'url' }))
  17. rescue "#{klass_name}::InaccessibleError".constantize => e
  18. errors = []
  19. %i[secret username].each do |field|
  20. next if !configuration.key?(field)
  21. errors << { message: e.message, field: field.to_s }
  22. end
  23. return { success: false, errors: errors }
  24. end
  25. { success: true }
  26. end
  27. end
  28. end