Skip to content

Commit

Permalink
[57347] Restructured NextcloudConnectionValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
apfohl committed Sep 16, 2024
1 parent b284615 commit 7e69f1a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ def validate
.or { host_url_not_found }
.or { missing_dependencies }
.or { version_mismatch }
.or { request_failed_with_unknown_error }
.or { with_unexpected_content }
.or { group_folder_not_found }
.or { request_failed_with_unknown_error }
.value_or(ConnectionValidation.new(type: :healthy,
error_code: :none,
timestamp: Time.current,
Expand Down Expand Up @@ -151,20 +152,13 @@ def version_mismatch

# rubocop:enable Metrics/AbcSize

def 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" \
"status: #{capabilities.result}\n\t" \
"response: #{capabilities.error_payload}"
)
def group_folder_not_found
return None() if files.result != :not_found

Some(ConnectionValidation.new(type: :error,
error_code: :err_unknown,
error_code: :err_group_folder_not_found,
timestamp: Time.current,
description: I18n.t("storages.health.connection_validation.unknown_error")))
description: I18n.t("storages.health.connection_validation.group_folder_not_found")))
end

# rubocop:disable Metrics/AbcSize
Expand Down Expand Up @@ -199,6 +193,34 @@ def with_unexpected_content

# rubocop:enable Metrics/AbcSize

# rubocop:disable Metrics/AbcSize
def 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" \
"status: #{capabilities.result}\n\t" \
"response: #{capabilities.error_payload}"
)

return None() if files.success?

Rails.logger.error(
"Connection validation failed with unknown error:\n\t" \
"storage: ##{@storage.id} #{@storage.name}\n\t" \
"status: #{files.result}\n\t" \
"response: #{files.error_payload}"
)

Some(ConnectionValidation.new(type: :error,
error_code: :err_unknown,
timestamp: Time.current,
description: I18n.t("storages.health.connection_validation.unknown_error")))
end

# rubocop:enable Metrics/AbcSize

def noop = StorageInteraction::AuthenticationStrategies::Noop.strategy

def userless = Peripherals::Registry.resolve("#{@storage.short_provider_type}.authentication.userless").call
Expand Down
1 change: 1 addition & 0 deletions modules/storages/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ en:
client_secret_wrong: The configured OAuth 2 client secret is invalid. Please check the configuration.
drive_id_wrong: The configured drive id could not be found. Please check the configuration.
group_folder_version_mismatch: The Group Folder version is not supported. Please update your Nextcloud server.
group_folder_not_found: The group folder could not be found.
host_not_found: No Nextcloud server found at the configured host url. Please check the configuration.
missing_dependencies: 'A required dependency is missing on the file storage. Please add the following dependency: %{dependency}.'
not_configured: The connection could not be validated. Please finish configuration first.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,18 @@

before { project_storage }

context "if the request returns not_found" do
let(:files_response) do
Storages::Peripherals::StorageInteraction::Nextcloud::Util.error(:not_found)
end

it "returns a validation failure" do
expect(subject.type).to eq(:error)
expect(subject.error_code).to eq(:err_group_folder_not_found)
expect(subject.description).to eq("The group folder could not be found.")
end
end

context "if the request returns an error" do
let(:files_response) do
Storages::Peripherals::StorageInteraction::Nextcloud::Util.error(:error)
Expand Down

0 comments on commit 7e69f1a

Please sign in to comment.