Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[#59346] add log warning to unexpected content

Eric Schubert4d62fd27f618
diff --git a/modules/storages/app/common/storages/peripherals/nextcloud_connection_validator.rb b/modules/storages/app/common/storages/peripherals/nextcloud_connection_validator.rb
index 371d24b18cc..e66a7f32753 100644
--- a/modules/storages/app/common/storages/peripherals/nextcloud_connection_validator.rb
+++ b/modules/storages/app/common/storages/peripherals/nextcloud_connection_validator.rb
@@ -31,6 +31,7 @@
module Storages
module Peripherals
class NextcloudConnectionValidator
+ include TaggedLogging
include Dry::Monads[:maybe]
using ServiceResultRefinements
@@ -40,13 +41,15 @@ module Storages
end
def validate
- maybe_is_not_configured
- .or { has_base_configuration_error? }
- .or { has_ampf_configuration_error? }
- .value_or(ConnectionValidation.new(type: :healthy,
- error_code: :none,
- timestamp: Time.current,
- description: nil))
+ with_tagged_logger do
+ maybe_is_not_configured
+ .or { has_base_configuration_error? }
+ .or { has_ampf_configuration_error? }
+ .value_or(ConnectionValidation.new(type: :healthy,
+ error_code: :none,
+ timestamp: Time.current,
+ description: nil))
+ end
end
private
@@ -55,7 +58,7 @@ module Storages
host_url_not_found
.or { missing_dependencies }
.or { version_mismatch }
- .or { with_unexpected_content }
+ # .or { with_unexpected_content }
.or { capabilities_request_failed_with_unknown_error }
end
@@ -194,6 +197,11 @@ module Storages
unexpected_files = files.result.files.reject { |file| expected_folder_ids.include?(file.id) }
return None() if unexpected_files.empty?
+ file_representation = unexpected_files.map do |file|
+ "Name: #{file.name}, ID: #{file.id}, Location: #{file.location}"
+ end
+ warn "Unexpected files/folder found in group folder:\n\t#{file_representation.join("\n\t")}"
+
Some(
ConnectionValidation.new(
type: :warning,
@@ -209,13 +217,11 @@ module Storages
def capabilities_request_failed_with_unknown_error
return None() if capabilities.success?
- Rails.logger.error(
- "Connection validation failed with unknown error:\n\t" \
- "storage: ##{@storage.id} #{@storage.name}\n\t" \
- "request: Nextcloud capabilities\n\t" \
- "status: #{capabilities.result}\n\t" \
- "response: #{capabilities.error_payload}"
- )
+ error "Connection validation failed with unknown error:\n\t" \
+ "storage: ##{@storage.id} #{@storage.name}\n\t" \
+ "request: Nextcloud capabilities\n\t" \
+ "status: #{capabilities.result}\n\t" \
+ "response: #{capabilities.error_payload}"
Some(ConnectionValidation.new(type: :error,
error_code: :err_unknown,
@@ -226,13 +232,11 @@ module Storages
def files_request_failed_with_unknown_error
return None() if files.success?
- Rails.logger.error(
- "Connection validation failed with unknown error:\n\t" \
- "storage: ##{@storage.id} #{@storage.name}\n\t" \
- "request: Group folder content\n\t" \
- "status: #{files.result}\n\t" \
- "response: #{files.error_payload}"
- )
+ error "Connection validation failed with unknown error:\n\t" \
+ "storage: ##{@storage.id} #{@storage.name}\n\t" \
+ "request: Group folder content\n\t" \
+ "status: #{files.result}\n\t" \
+ "response: #{files.error_payload}"
Some(ConnectionValidation.new(type: :error,
error_code: :err_unknown,
diff --git a/modules/storages/app/common/storages/peripherals/one_drive_connection_validator.rb b/modules/storages/app/common/storages/peripherals/one_drive_connection_validator.rb
index 911f8280f51..5c62084e37d 100644
--- a/modules/storages/app/common/storages/peripherals/one_drive_connection_validator.rb
+++ b/modules/storages/app/common/storages/peripherals/one_drive_connection_validator.rb
@@ -31,6 +31,7 @@
module Storages
module Peripherals
class OneDriveConnectionValidator
+ include TaggedLogging
include Dry::Monads[:maybe]
using ServiceResultRefinements
@@ -40,17 +41,19 @@ module Storages
end
def validate
- maybe_is_not_configured
- .or { tenant_id_wrong }
- .or { client_id_wrong }
- .or { client_secret_wrong }
- .or { drive_id_wrong }
- .or { request_failed_with_unknown_error }
- .or { drive_with_unexpected_content }
- .value_or(ConnectionValidation.new(type: :healthy,
- error_code: :none,
- timestamp: Time.current,
- description: nil))
+ with_tagged_logger do
+ maybe_is_not_configured
+ .or { tenant_id_wrong }
+ .or { client_id_wrong }
+ .or { client_secret_wrong }
+ .or { drive_id_wrong }
+ .or { request_failed_with_unknown_error }
+ .or { drive_with_unexpected_content }
+ .value_or(ConnectionValidation.new(type: :healthy,
+ error_code: :none,
+ timestamp: Time.current,
+ description: nil))
+ end
end
private
@@ -146,6 +149,11 @@ module Storages
unexpected_files = query.result.files.reject { |file| expected_folder_ids.include?(file.id) }
return None() if unexpected_files.empty?
+ file_representation = unexpected_files.map do |file|
+ "Name: #{file.name}, ID: #{file.id}, Location: #{file.location}"
+ end
+ warn "Unexpected files/folder found in group folder:\n\t#{file_representation.join("\n\t")}"
+
Some(ConnectionValidation.new(type: :warning,
error_code: :wrn_unexpected_content,
timestamp: Time.current,
@@ -157,10 +165,10 @@ module Storages
def request_failed_with_unknown_error
return None() if query.success?
- Rails.logger.error("Connection validation failed with unknown error:\n\t" \
- "storage: ##{@storage.id} #{@storage.name}\n\t" \
- "status: #{query.result}\n\t" \
- "response: #{query.error_payload}")
+ error "Connection validation failed with unknown error:\n\t" \
+ "storage: ##{@storage.id} #{@storage.name}\n\t" \
+ "status: #{query.result}\n\t" \
+ "response: #{query.error_payload}"
Some(ConnectionValidation.new(type: :error,
error_code: :err_unknown,
diff --git a/modules/storages/app/common/storages/tagged_logging.rb b/modules/storages/app/common/storages/tagged_logging.rb
index 28d18c4884f..2a5e353435e 100644
--- a/modules/storages/app/common/storages/tagged_logging.rb
+++ b/modules/storages/app/common/storages/tagged_logging.rb
@@ -30,7 +30,7 @@
module Storages
module TaggedLogging
- delegate :info, :error, to: :logger
+ delegate :info, :warn, :error, to: :logger
# @param tag [Class, String, Array<Class, String>] the tag or list of tags to annotate the logs with
# @yield [Logger]