Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2024-01-11 21:09:22 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2024-01-11 21:09:22 +0300
commit1bd9d2d9499d0d28e62254a28fcd3d913a8704af (patch)
treeea9969a5a4c3ac77858be20d69869674bed5ca43 /lib
parentd8877c12347443fa02e0ba53ad8d5cd318f6fa28 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/api/api.rb2
-rw-r--r--lib/api/terraform/modules/v1/namespace_packages.rb (renamed from lib/api/terraform/modules/v1/packages.rb)65
-rw-r--r--lib/gitlab/database/partitioning/list/convert_table.rb13
3 files changed, 47 insertions, 33 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb
index 97e09795f49..94b433193dd 100644
--- a/lib/api/api.rb
+++ b/lib/api/api.rb
@@ -330,7 +330,7 @@ module API
mount ::API::Suggestions
mount ::API::SystemHooks
mount ::API::Tags
- mount ::API::Terraform::Modules::V1::Packages
+ mount ::API::Terraform::Modules::V1::NamespacePackages
mount ::API::Terraform::Modules::V1::ProjectPackages
mount ::API::Terraform::State
mount ::API::Terraform::StateVersion
diff --git a/lib/api/terraform/modules/v1/packages.rb b/lib/api/terraform/modules/v1/namespace_packages.rb
index 9e82a849c98..1999fc42aba 100644
--- a/lib/api/terraform/modules/v1/packages.rb
+++ b/lib/api/terraform/modules/v1/namespace_packages.rb
@@ -4,7 +4,7 @@ module API
module Terraform
module Modules
module V1
- class Packages < ::API::Base
+ class NamespacePackages < ::API::Base
include ::API::Helpers::Authentication
helpers ::API::Helpers::PackagesHelpers
helpers ::API::Helpers::Packages::BasicAuthHelpers
@@ -29,8 +29,10 @@ module API
end
helpers do
+ include ::Gitlab::Utils::StrongMemoize
+
params :module_name do
- requires :module_name, type: String, desc: "", regexp: API::NO_SLASH_URL_PART_REGEX
+ requires :module_name, type: String, desc: '', regexp: API::NO_SLASH_URL_PART_REGEX
requires :module_system, type: String, regexp: API::NO_SLASH_URL_PART_REGEX
end
@@ -39,10 +41,9 @@ module API
end
def module_namespace
- strong_memoize(:module_namespace) do
- find_namespace(params[:module_namespace])
- end
+ find_namespace(params[:module_namespace])
end
+ strong_memoize_attr :module_namespace
def finder_params
{
@@ -55,26 +56,23 @@ module API
end
def packages
- strong_memoize(:packages) do
- ::Packages::GroupPackagesFinder.new(
- current_user,
- module_namespace,
- finder_params
- ).execute
- end
+ ::Packages::GroupPackagesFinder.new(
+ current_user,
+ module_namespace,
+ finder_params
+ ).execute
end
+ strong_memoize_attr :packages
def package
- strong_memoize(:package) do
- packages.first
- end
+ packages.first
end
+ strong_memoize_attr :package
def package_file
- strong_memoize(:package_file) do
- package.installable_package_files.first
- end
+ package.installable_package_files.first
end
+ strong_memoize_attr :package_file
end
params do
@@ -82,7 +80,8 @@ module API
includes :module_name
end
- namespace 'packages/terraform/modules/v1/:module_namespace/:module_name/:module_system', requirements: TERRAFORM_MODULE_REQUIREMENTS do
+ namespace 'packages/terraform/modules/v1/:module_namespace/:module_name/:module_system',
+ requirements: TERRAFORM_MODULE_REQUIREMENTS do
authenticate_with do |accept|
accept.token_types(:personal_access_token, :deploy_token, :job_token)
.sent_through(:http_bearer_token)
@@ -118,7 +117,9 @@ module API
get 'download' do
latest_version = packages.order_version.last&.version
- render_api_error!({ error: "No version found for #{params[:module_name]} module" }, :not_found) if latest_version.nil?
+ if latest_version.nil?
+ render_api_error!({ error: "No version found for #{params[:module_name]} module" }, :not_found)
+ end
download_path = api_v4_packages_terraform_modules_v1_module_version_download_path(
{
@@ -145,7 +146,9 @@ module API
get do
latest_package = packages.order_version.last
- render_api_error!({ error: "No version found for #{params[:module_name]} module" }, :not_found) if latest_package&.version.nil?
+ if latest_package&.version.nil?
+ render_api_error!({ error: "No version found for #{params[:module_name]} module" }, :not_found)
+ end
presenter = ::Terraform::ModuleVersionPresenter.new(latest_package, params[:module_system])
present presenter, with: ::API::Entities::Terraform::ModuleVersion
@@ -181,13 +184,18 @@ module API
jwt_token = Gitlab::TerraformRegistryToken.from_token(token_from_namespace_inheritable).encoded
end
- header 'X-Terraform-Get', module_file_path.sub(%r{module_version/file$}, "#{params[:module_version]}/file?token=#{jwt_token}&archive=tgz")
+ header 'X-Terraform-Get',
+ module_file_path.sub(
+ %r{module_version/file$},
+ "#{params[:module_version]}/file?token=#{jwt_token}&archive=tgz"
+ )
status :no_content
end
namespace 'file' do
authenticate_with do |accept|
- accept.token_types(:deploy_token_from_jwt, :job_token_from_jwt, :personal_access_token_from_jwt).sent_through(:token_param)
+ accept.token_types(:deploy_token_from_jwt, :job_token_from_jwt, :personal_access_token_from_jwt)
+ .sent_through(:token_param)
end
desc 'Download specific version of a module' do
@@ -200,9 +208,14 @@ module API
tags %w[terraform_registry]
end
get do
- track_package_event('pull_package', :terraform_module, project: package.project, namespace: module_namespace)
-
- present_carrierwave_file!(package_file.file)
+ track_package_event(
+ 'pull_package',
+ :terraform_module,
+ project: package.project,
+ namespace: module_namespace
+ )
+
+ present_package_file!(package_file)
end
end
diff --git a/lib/gitlab/database/partitioning/list/convert_table.rb b/lib/gitlab/database/partitioning/list/convert_table.rb
index 9889d01be76..542a7d0a78d 100644
--- a/lib/gitlab/database/partitioning/list/convert_table.rb
+++ b/lib/gitlab/database/partitioning/list/convert_table.rb
@@ -22,7 +22,7 @@ module Gitlab
@table_name = table_name
@parent_table_name = parent_table_name
@partitioning_column = partitioning_column
- @zero_partition_value = zero_partition_value
+ @zero_partition_value = Array.wrap(zero_partition_value)
end
def prepare_for_partitioning(async: false)
@@ -126,10 +126,11 @@ module Gitlab
.check_constraints
.including_column(partitioning_column)
- check_body = "CHECK ((#{partitioning_column} = #{zero_partition_value}))"
+ array_prefix = "CHECK ((#{partitioning_column} = ANY "
+ single_prefix = "CHECK ((#{partitioning_column} = #{zero_partition_value.join(',')}))"
constraints_on_column.find do |constraint|
- constraint.definition.start_with?(check_body)
+ constraint.definition.start_with?(array_prefix, single_prefix)
end
end
@@ -138,14 +139,14 @@ module Gitlab
raise UnableToPartition, <<~MSG
Table #{table_name} is not ready for partitioning.
- Before partitioning, a check constraint must enforce that (#{partitioning_column} = #{zero_partition_value})
+ Before partitioning, a check constraint must enforce that (#{partitioning_column} IN (#{zero_partition_value.join(',')}))
MSG
end
def add_partitioning_check_constraint(async: false)
return validate_partitioning_constraint_synchronously if partitioning_constraint.present?
- check_body = "#{partitioning_column} = #{connection.quote(zero_partition_value)}"
+ check_body = "#{partitioning_column} IN (#{zero_partition_value.join(',')})"
# Any constraint name would work. The constraint is found based on its definition before partitioning
migration_context.add_check_constraint(
table_name, check_body, PARTITIONING_CONSTRAINT_NAME,
@@ -214,7 +215,7 @@ module Gitlab
<<~SQL
ALTER TABLE #{quote_table_name(parent_table_name)}
ATTACH PARTITION #{table_name}
- FOR VALUES IN (#{zero_partition_value})
+ FOR VALUES IN (#{zero_partition_value.join(',')})
SQL
end