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

Show storage configuration in health status download

Jan Sandbrinkb0ce2dcc78e9
diff --git a/modules/storages/app/controllers/storages/admin/health_status_controller.rb b/modules/storages/app/controllers/storages/admin/health_status_controller.rb
index 40fd6984346..688f811fa69 100644
--- a/modules/storages/app/controllers/storages/admin/health_status_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/health_status_controller.rb
@@ -78,6 +78,7 @@ module Storages
{
storage: @storage.name,
storage_type: @storage.to_s,
+ configuration: @storage.non_confidential_configuration,
ran_at: timestamp
}.merge(@report.to_h).to_yaml(stringify_names: true)
end
diff --git a/modules/storages/app/models/storages/nextcloud_storage.rb b/modules/storages/app/models/storages/nextcloud_storage.rb
index 76eacb81bb0..b0ab260e9fc 100644
--- a/modules/storages/app/models/storages/nextcloud_storage.rb
+++ b/modules/storages/app/models/storages/nextcloud_storage.rb
@@ -42,7 +42,6 @@ module Storages
AUTHENTICATION_METHOD_OAUTH2_SSO = "oauth2_sso"
].freeze
- store_attribute :provider_fields, :automatically_managed, :boolean
store_attribute :provider_fields, :username, :string
store_attribute :provider_fields, :password, :string
store_attribute :provider_fields, :group, :string
@@ -53,6 +52,10 @@ module Storages
def self.short_provider_name = :nextcloud
+ def self.non_confidential_provider_fields
+ super + %i[username group group_folder authentication_method storage_audience token_exchange_scope]
+ end
+
def oauth_configuration
Adapters::Providers::Nextcloud::OAuthConfiguration.new(self)
end
diff --git a/modules/storages/app/models/storages/one_drive_storage.rb b/modules/storages/app/models/storages/one_drive_storage.rb
index 9417323e497..ac89308be3b 100644
--- a/modules/storages/app/models/storages/one_drive_storage.rb
+++ b/modules/storages/app/models/storages/one_drive_storage.rb
@@ -41,6 +41,10 @@ module Storages
def self.short_provider_name = :one_drive
+ def self.non_confidential_provider_fields
+ super + %i[tenant_id drive_id]
+ end
+
def self.allowed_by_enterprise_token?
EnterpriseToken.allows_to?(:one_drive_sharepoint_file_storage)
end
diff --git a/modules/storages/app/models/storages/share_point_storage.rb b/modules/storages/app/models/storages/share_point_storage.rb
index 3370cac228b..3306fa75244 100644
--- a/modules/storages/app/models/storages/share_point_storage.rb
+++ b/modules/storages/app/models/storages/share_point_storage.rb
@@ -45,9 +45,12 @@ module Storages
Rails.env.local?
end
- store_attribute :provider_fields, :tenant_id, :string
-
def self.short_provider_name = :share_point
+
+ def self.non_confidential_provider_fields
+ super + %i[tenant_id]
+ end
+
def audience = nil
def authenticate_via_idp? = false
diff --git a/modules/storages/app/models/storages/storage.rb b/modules/storages/app/models/storages/storage.rb
index 2d07c894523..68cd16c4446 100644
--- a/modules/storages/app/models/storages/storage.rb
+++ b/modules/storages/app/models/storages/storage.rb
@@ -104,6 +104,10 @@ module Storages
split_reason = text.split(/[|:]/)
split_reason[index].strip if split_reason.length > index
end
+
+ def non_confidential_provider_fields
+ %i[automatically_managed health_notifications_enabled]
+ end
end
delegate :short_provider_name, :allowed_by_enterprise_token?, :disallowed_by_enterprise_token?, to: :class
@@ -170,6 +174,16 @@ module Storages
def provider_fields_defaults = raise Errors::SubclassResponsibility
+ def non_confidential_configuration
+ provider_fields.symbolize_keys
+ .slice(*self.class.non_confidential_provider_fields)
+ .merge(
+ host:,
+ oauth_client_id: oauth_client&.client_id,
+ oauth_application_client_id: oauth_application&.uid
+ )
+ end
+
def provider_type_nextcloud?
is_a?(NextcloudStorage)
end
diff --git a/modules/storages/spec/controllers/storages/admin/health_status_controller_spec.rb b/modules/storages/spec/controllers/storages/admin/health_status_controller_spec.rb
index ca70c167a07..08fd7264700 100644
--- a/modules/storages/spec/controllers/storages/admin/health_status_controller_spec.rb
+++ b/modules/storages/spec/controllers/storages/admin/health_status_controller_spec.rb
@@ -83,6 +83,7 @@ RSpec.describe Storages::Admin::HealthStatusController do
expect(yaml["storage"]).to eq storage.name
expect(yaml["storage_type"]).to eq storage.to_s
expect(yaml.dig("base_configuration", "storage_configured", "state")).to eq("failure")
+ expect(yaml.dig("configuration", "host")).to eq(storage.host)
end
end
diff --git a/modules/storages/spec/factories/storage_factory.rb b/modules/storages/spec/factories/storage_factory.rb
index a3edbca5036..5bc728561b2 100644
--- a/modules/storages/spec/factories/storage_factory.rb
+++ b/modules/storages/spec/factories/storage_factory.rb
@@ -94,6 +94,13 @@ FactoryBot.define do
authentication_method { "two_way_oauth2" }
storage_audience { nil }
+ trait :with_oauth_configured do
+ after(:create) do |storage, _evaluator|
+ create(:oauth_client, integration: storage)
+ create(:oauth_application, integration: storage)
+ end
+ end
+
trait :oidc_sso_enabled do
storage_audience { "nextcloud" }
authentication_method { "oauth2_sso" }
diff --git a/modules/storages/spec/models/storages/nextcloud_storage_spec.rb b/modules/storages/spec/models/storages/nextcloud_storage_spec.rb
index cd79151931f..c437e245526 100644
--- a/modules/storages/spec/models/storages/nextcloud_storage_spec.rb
+++ b/modules/storages/spec/models/storages/nextcloud_storage_spec.rb
@@ -235,4 +235,35 @@ RSpec.describe Storages::NextcloudStorage do
expect(storage.provider_fields_defaults).to eq({ automatic_management_enabled: true, username: "OpenProject" })
end
end
+
+ describe "#non_confidential_configuration" do
+ subject { storage.non_confidential_configuration }
+
+ let(:storage) { create(:nextcloud_storage, :with_oauth_configured) }
+
+ it "returns the expected hash" do
+ expect(subject).to eq(
+ authentication_method: "two_way_oauth2",
+ health_notifications_enabled: true,
+ host: storage.host,
+ oauth_application_client_id: storage.oauth_application.uid,
+ oauth_client_id: storage.oauth_client.client_id
+ )
+ end
+
+ context "when the storage is set-up for SSO" do
+ let(:storage) { create(:nextcloud_storage, :oidc_sso_enabled) }
+
+ it "returns the expected hash" do
+ expect(subject).to eq(
+ authentication_method: "oauth2_sso",
+ health_notifications_enabled: true,
+ host: storage.host,
+ storage_audience: "nextcloud",
+ oauth_application_client_id: nil,
+ oauth_client_id: nil
+ )
+ end
+ end
+ end
end
diff --git a/modules/storages/spec/models/storages/one_drive_storage_spec.rb b/modules/storages/spec/models/storages/one_drive_storage_spec.rb
index 142a76eb8bb..5cb0974bbf9 100644
--- a/modules/storages/spec/models/storages/one_drive_storage_spec.rb
+++ b/modules/storages/spec/models/storages/one_drive_storage_spec.rb
@@ -72,4 +72,22 @@ RSpec.describe Storages::OneDriveStorage do
end
end
end
+
+ describe "#non_confidential_configuration" do
+ subject { storage.non_confidential_configuration }
+
+ let(:storage) { create(:one_drive_storage_configured) }
+
+ it "returns the expected hash" do
+ expect(subject).to eq(
+ automatically_managed: false,
+ health_notifications_enabled: true,
+ host: storage.host,
+ drive_id: storage.drive_id,
+ tenant_id: storage.tenant_id,
+ oauth_application_client_id: storage.oauth_application.uid,
+ oauth_client_id: storage.oauth_client.client_id
+ )
+ end
+ end
end