diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-14 03:07:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-14 03:07:42 +0300 |
commit | 0c2b535267434504ea93a0c76ce1ac4ea7f2319e (patch) | |
tree | 36cb908ee96f27fe3d76689dd3f3dfb6794e29f7 /lib/gitlab | |
parent | 314ed8700b3dcc6a353abd6d68d75979dc191d37 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab')
10 files changed, 129 insertions, 39 deletions
diff --git a/lib/gitlab/auth/saml/config.rb b/lib/gitlab/auth/saml/config.rb index e6c9f04eff5..7524d8b9f85 100644 --- a/lib/gitlab/auth/saml/config.rb +++ b/lib/gitlab/auth/saml/config.rb @@ -8,21 +8,6 @@ module Gitlab def enabled? ::AuthHelper.saml_providers.any? end - - def default_attribute_statements - defaults = OmniAuth::Strategies::SAML.default_options[:attribute_statements].to_hash.deep_symbolize_keys - defaults[:nickname] = %w[username nickname] - defaults[:name] << 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name' - defaults[:name] << 'http://schemas.microsoft.com/ws/2008/06/identity/claims/name' - defaults[:email] << 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress' - defaults[:email] << 'http://schemas.microsoft.com/ws/2008/06/identity/claims/emailaddress' - defaults[:first_name] << 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname' - defaults[:first_name] << 'http://schemas.microsoft.com/ws/2008/06/identity/claims/givenname' - defaults[:last_name] << 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname' - defaults[:last_name] << 'http://schemas.microsoft.com/ws/2008/06/identity/claims/surname' - - defaults - end end DEFAULT_PROVIDER_NAME = 'saml' diff --git a/lib/gitlab/encrypted_command_base.rb b/lib/gitlab/encrypted_command_base.rb index 679d9d8e31a..5e483fa2b15 100644 --- a/lib/gitlab/encrypted_command_base.rb +++ b/lib/gitlab/encrypted_command_base.rb @@ -41,7 +41,11 @@ module Gitlab encrypted.change do |contents| contents = encrypted_file_template unless File.exist?(encrypted.content_path) File.write(temp_file.path, contents) - system(ENV['EDITOR'], temp_file.path) + + edit_success = system(*editor_args, temp_file.path) + + raise "Unable to run $EDITOR: #{editor_args}" unless edit_success + changes = File.read(temp_file.path) contents_changed = contents != changes validate_contents(changes) @@ -99,6 +103,10 @@ module Gitlab def encrypted_file_template raise NotImplementedError end + + def editor_args + ENV['EDITOR']&.split + end end end end diff --git a/lib/gitlab/omniauth_initializer.rb b/lib/gitlab/omniauth_initializer.rb index 0bcd5b1196a..81ad7a7f9e1 100644 --- a/lib/gitlab/omniauth_initializer.rb +++ b/lib/gitlab/omniauth_initializer.rb @@ -29,8 +29,6 @@ module Gitlab { authorize_params: { gl_auth_type: 'login' } } - when ->(provider_name) { AuthHelper.saml_providers.include?(provider_name.to_sym) } - { attribute_statements: ::Gitlab::Auth::Saml::Config.default_attribute_statements } else {} end @@ -63,7 +61,7 @@ module Gitlab provider_arguments.concat arguments provider_arguments << defaults unless defaults.empty? when Hash, GitlabSettings::Options - hash_arguments = merge_hash_defaults_and_args(defaults, arguments) + hash_arguments = arguments.deep_symbolize_keys.deep_merge(defaults) normalized = normalize_hash_arguments(hash_arguments) # A Hash from the configuration will be passed as is. @@ -82,13 +80,6 @@ module Gitlab provider_arguments end - def merge_hash_defaults_and_args(defaults, arguments) - return arguments.to_hash if defaults.empty? - return defaults.deep_merge(arguments.deep_symbolize_keys) if Feature.enabled?(:invert_omniauth_args_merging) - - arguments.to_hash.deep_symbolize_keys.deep_merge(defaults) - end - def normalize_hash_arguments(args) args.deep_symbolize_keys! diff --git a/lib/gitlab/usage/metrics/instrumentations/bulk_imports_users_metric.rb b/lib/gitlab/usage/metrics/instrumentations/bulk_imports_users_metric.rb new file mode 100644 index 00000000000..453e9a13765 --- /dev/null +++ b/lib/gitlab/usage/metrics/instrumentations/bulk_imports_users_metric.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Gitlab + module Usage + module Metrics + module Instrumentations + class BulkImportsUsersMetric < DatabaseMetric + operation :distinct_count, column: :user_id + + relation do + ::BulkImport + end + end + end + end + end +end diff --git a/lib/gitlab/usage/metrics/instrumentations/csv_imports_users_metric.rb b/lib/gitlab/usage/metrics/instrumentations/csv_imports_users_metric.rb new file mode 100644 index 00000000000..16f498fbc5a --- /dev/null +++ b/lib/gitlab/usage/metrics/instrumentations/csv_imports_users_metric.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Gitlab + module Usage + module Metrics + module Instrumentations + class CsvImportsUsersMetric < DatabaseMetric + operation :distinct_count, column: :user_id + + relation do + ::Issues::CsvImport + end + end + end + end + end +end diff --git a/lib/gitlab/usage/metrics/instrumentations/group_imports_users_metric.rb b/lib/gitlab/usage/metrics/instrumentations/group_imports_users_metric.rb new file mode 100644 index 00000000000..a1207300c2a --- /dev/null +++ b/lib/gitlab/usage/metrics/instrumentations/group_imports_users_metric.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Gitlab + module Usage + module Metrics + module Instrumentations + class GroupImportsUsersMetric < DatabaseMetric + operation :distinct_count, column: :user_id + + relation do + ::GroupImportState + end + end + end + end + end +end diff --git a/lib/gitlab/usage/metrics/instrumentations/jira_imports_users_metric.rb b/lib/gitlab/usage/metrics/instrumentations/jira_imports_users_metric.rb new file mode 100644 index 00000000000..239df5605ae --- /dev/null +++ b/lib/gitlab/usage/metrics/instrumentations/jira_imports_users_metric.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Gitlab + module Usage + module Metrics + module Instrumentations + class JiraImportsUsersMetric < DatabaseMetric + operation :distinct_count, column: :user_id + + relation do + ::JiraImportState + end + end + end + end + end +end diff --git a/lib/gitlab/usage/metrics/instrumentations/project_imports_creators_metric.rb b/lib/gitlab/usage/metrics/instrumentations/project_imports_creators_metric.rb new file mode 100644 index 00000000000..f34bd6dbfe3 --- /dev/null +++ b/lib/gitlab/usage/metrics/instrumentations/project_imports_creators_metric.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Gitlab + module Usage + module Metrics + module Instrumentations + class ProjectImportsCreatorsMetric < DatabaseMetric + operation :distinct_count, column: :creator_id + + relation do + ::Project.where.not(import_type: nil) + end + end + end + end + end +end diff --git a/lib/gitlab/usage/metrics/instrumentations/unique_users_all_imports_metric.rb b/lib/gitlab/usage/metrics/instrumentations/unique_users_all_imports_metric.rb new file mode 100644 index 00000000000..931859bf7fa --- /dev/null +++ b/lib/gitlab/usage/metrics/instrumentations/unique_users_all_imports_metric.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +module Gitlab + module Usage + module Metrics + module Instrumentations + class UniqueUsersAllImportsMetric < NumbersMetric + IMPORTS_METRICS = [ + ProjectImportsCreatorsMetric, + BulkImportsUsersMetric, + JiraImportsUsersMetric, + CsvImportsUsersMetric, + GroupImportsUsersMetric + ].freeze + + operation :add + + data do |time_frame| + IMPORTS_METRICS.map { |metric| metric.new(time_frame: time_frame).value } + end + + # overwriting instrumentation to generate the appropriate sql query + def instrumentation + metric_queries = IMPORTS_METRICS.map do |metric| + "(#{metric.new(time_frame: time_frame).instrumentation})" + end.join(' + ') + + "SELECT #{metric_queries}" + end + end + end + end + end +end diff --git a/lib/gitlab/usage_data.rb b/lib/gitlab/usage_data.rb index 5f819f060e4..bd0252dd15b 100644 --- a/lib/gitlab/usage_data.rb +++ b/lib/gitlab/usage_data.rb @@ -365,7 +365,6 @@ module Gitlab users_created: count(::User.where(time_period), start: minimum_id(User), finish: maximum_id(User)), omniauth_providers: filtered_omniauth_provider_names.reject { |name| name == 'group_saml' }, user_auth_by_provider: distinct_count_user_auth_by_provider(time_period), - unique_users_all_imports: unique_users_all_imports(time_period), bulk_imports: { gitlab_v1: count(::BulkImport.where(**time_period, source_type: :gitlab)) }, @@ -565,18 +564,6 @@ module Gitlab end # rubocop:disable CodeReuse/ActiveRecord - def unique_users_all_imports(time_period) - project_imports = distinct_count(::Project.where(time_period).where.not(import_type: nil), :creator_id) - bulk_imports = distinct_count(::BulkImport.where(time_period), :user_id) - jira_issue_imports = distinct_count(::JiraImportState.where(time_period), :user_id) - csv_issue_imports = distinct_count(::Issues::CsvImport.where(time_period), :user_id) - group_imports = distinct_count(::GroupImportState.where(time_period), :user_id) - - add(project_imports, bulk_imports, jira_issue_imports, csv_issue_imports, group_imports) - end - # rubocop:enable CodeReuse/ActiveRecord - - # rubocop:disable CodeReuse/ActiveRecord def distinct_count_user_auth_by_provider(time_period) counts = auth_providers_except_ldap.index_with do |provider| distinct_count( |