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>2019-10-07 18:05:59 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-07 18:05:59 +0300
commit31040b5bfe48f8d73830f473513164427522b3a6 (patch)
tree6301b395ad45d7a0f84aa0f9c31373889208d09b /lib
parent185f428fa5e6123ffa0f29e307523da138e7b028 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/api/entities.rb7
-rw-r--r--lib/api/helpers/groups_helpers.rb8
-rw-r--r--lib/gitlab/access.rb27
-rw-r--r--lib/gitlab/health_checks/probes/liveness.rb13
-rw-r--r--lib/gitlab/health_checks/probes/readiness.rb53
-rw-r--r--lib/gitlab/health_checks/probes/status.rb14
-rw-r--r--lib/gitlab/metrics/exporter/base_exporter.rb18
7 files changed, 138 insertions, 2 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 16cc20e95c5..6dd2e171d77 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -378,6 +378,13 @@ module API
class Group < BasicGroupDetails
expose :path, :description, :visibility
+ expose :share_with_group_lock
+ expose :require_two_factor_authentication
+ expose :two_factor_grace_period
+ expose :project_creation_level_str, as: :project_creation_level
+ expose :auto_devops_enabled
+ expose :subgroup_creation_level_str, as: :subgroup_creation_level
+ expose :emails_disabled
expose :lfs_enabled?, as: :lfs_enabled
expose :avatar_url do |group, options|
group.avatar_url(only_path: false)
diff --git a/lib/api/helpers/groups_helpers.rb b/lib/api/helpers/groups_helpers.rb
index abe9d457a5b..2cc18acb7ec 100644
--- a/lib/api/helpers/groups_helpers.rb
+++ b/lib/api/helpers/groups_helpers.rb
@@ -11,9 +11,15 @@ module API
optional :visibility, type: String,
values: Gitlab::VisibilityLevel.string_values,
desc: 'The visibility of the group'
+ optional :share_with_group_lock, type: Boolean, desc: 'Prevent sharing a project with another group within this group'
+ optional :require_two_factor_authentication, type: Boolean, desc: 'Require all users in this group to setup Two-factor authentication'
+ optional :two_factor_grace_period, type: Integer, desc: 'Time before Two-factor authentication is enforced'
+ optional :project_creation_level, type: String, values: ::Gitlab::Access.project_creation_string_values, desc: 'Determine if developers can create projects in the group', as: :project_creation_level_str
+ optional :auto_devops_enabled, type: Boolean, desc: 'Default to Auto DevOps pipeline for all projects within this group'
+ optional :subgroup_creation_level, type: String, values: ::Gitlab::Access.subgroup_creation_string_values, desc: 'Allowed to create subgroups', as: :subgroup_creation_level_str
+ optional :emails_disabled, type: Boolean, desc: 'Disable email notifications'
optional :lfs_enabled, type: Boolean, desc: 'Enable/disable LFS for the projects in this group'
optional :request_access_enabled, type: Boolean, desc: 'Allow users to request member access'
- optional :share_with_group_lock, type: Boolean, desc: 'Prevent sharing a project with another group within this group'
end
params :optional_params_ee do
diff --git a/lib/gitlab/access.rb b/lib/gitlab/access.rb
index ed5816482a9..6492ccc286a 100644
--- a/lib/gitlab/access.rb
+++ b/lib/gitlab/access.rb
@@ -103,10 +103,22 @@ module Gitlab
}
end
+ def project_creation_string_options
+ {
+ 'noone' => NO_ONE_PROJECT_ACCESS,
+ 'maintainer' => MAINTAINER_PROJECT_ACCESS,
+ 'developer' => DEVELOPER_MAINTAINER_PROJECT_ACCESS
+ }
+ end
+
def project_creation_values
project_creation_options.values
end
+ def project_creation_string_values
+ project_creation_string_options.keys
+ end
+
def project_creation_level_name(name)
project_creation_options.key(name)
end
@@ -117,6 +129,21 @@ module Gitlab
s_('SubgroupCreationlevel|Maintainers') => MAINTAINER_SUBGROUP_ACCESS
}
end
+
+ def subgroup_creation_string_options
+ {
+ 'owner' => OWNER_SUBGROUP_ACCESS,
+ 'maintainer' => MAINTAINER_SUBGROUP_ACCESS
+ }
+ end
+
+ def subgroup_creation_values
+ subgroup_creation_options.values
+ end
+
+ def subgroup_creation_string_values
+ subgroup_creation_string_options.keys
+ end
end
def human_access
diff --git a/lib/gitlab/health_checks/probes/liveness.rb b/lib/gitlab/health_checks/probes/liveness.rb
new file mode 100644
index 00000000000..b4d346e945e
--- /dev/null
+++ b/lib/gitlab/health_checks/probes/liveness.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module HealthChecks
+ module Probes
+ class Liveness
+ def execute
+ Probes::Status.new(200, status: 'ok')
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/health_checks/probes/readiness.rb b/lib/gitlab/health_checks/probes/readiness.rb
new file mode 100644
index 00000000000..b789cbe1ae6
--- /dev/null
+++ b/lib/gitlab/health_checks/probes/readiness.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module HealthChecks
+ module Probes
+ class Readiness
+ attr_reader :checks
+
+ # This accepts an array of Proc
+ # that returns `::Gitlab::HealthChecks::Result`
+ def initialize(*additional_checks)
+ @checks = ::Gitlab::HealthChecks::CHECKS.map { |check| check.method(:readiness) }
+ @checks += additional_checks
+ end
+
+ def execute
+ readiness = probe_readiness
+ success = all_succeeded?(readiness)
+
+ Probes::Status.new(
+ success ? 200 : 503,
+ status(success).merge(payload(readiness))
+ )
+ end
+
+ private
+
+ def all_succeeded?(readiness)
+ readiness.all? do |name, probes|
+ probes.any?(&:success)
+ end
+ end
+
+ def status(success)
+ { status: success ? 'ok' : 'failed' }
+ end
+
+ def payload(readiness)
+ readiness.transform_values do |probes|
+ probes.map(&:payload)
+ end
+ end
+
+ def probe_readiness
+ checks
+ .flat_map(&:call)
+ .compact
+ .group_by(&:name)
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/health_checks/probes/status.rb b/lib/gitlab/health_checks/probes/status.rb
new file mode 100644
index 00000000000..192e9366001
--- /dev/null
+++ b/lib/gitlab/health_checks/probes/status.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module HealthChecks
+ module Probes
+ Status = Struct.new(:http_status, :json) do
+ # We accept 2xx
+ def success?
+ http_status / 100 == 2
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/metrics/exporter/base_exporter.rb b/lib/gitlab/metrics/exporter/base_exporter.rb
index de7870dfb8c..b56770e224b 100644
--- a/lib/gitlab/metrics/exporter/base_exporter.rb
+++ b/lib/gitlab/metrics/exporter/base_exporter.rb
@@ -31,7 +31,15 @@ module Gitlab
@server = ::WEBrick::HTTPServer.new(
Port: settings.port, BindAddress: settings.address,
Logger: logger, AccessLog: access_log)
- server.mount "/", Rack::Handler::WEBrick, rack_app
+ server.mount_proc '/readiness' do |req, res|
+ render_probe(
+ ::Gitlab::HealthChecks::Probes::Readiness.new, req, res)
+ end
+ server.mount_proc '/liveness' do |req, res|
+ render_probe(
+ ::Gitlab::HealthChecks::Probes::Liveness.new, req, res)
+ end
+ server.mount '/', Rack::Handler::WEBrick, rack_app
server.start
end
@@ -51,6 +59,14 @@ module Gitlab
run -> (env) { [404, {}, ['']] }
end
end
+
+ def render_probe(probe, req, res)
+ result = probe.execute
+
+ res.status = result.http_status
+ res.content_type = 'application/json; charset=utf-8'
+ res.body = result.json.to_json
+ end
end
end
end