diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-23 15:08:38 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-23 15:08:38 +0300 |
commit | 5ad0cf26551baff8f08af8562a8d45e6ec14d71a (patch) | |
tree | 57f1a6bad31bcd11efacd3fdfb9cc92f88fb6a86 /lib | |
parent | f47c768fad17d4c876e96524f83f8306f071db66 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/award_emoji.rb | 2 | ||||
-rw-r--r-- | lib/api/entities.rb | 1 | ||||
-rw-r--r-- | lib/api/helpers/notes_helpers.rb | 10 | ||||
-rw-r--r-- | lib/api/helpers/projects_helpers.rb | 2 | ||||
-rw-r--r-- | lib/api/project_snippets.rb | 6 | ||||
-rw-r--r-- | lib/api/snippets.rb | 4 | ||||
-rw-r--r-- | lib/banzai/reference_parser/snippet_parser.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/gpg.rb | 7 | ||||
-rw-r--r-- | lib/gitlab/kubernetes/kube_client.rb | 20 |
9 files changed, 41 insertions, 13 deletions
diff --git a/lib/api/award_emoji.rb b/lib/api/award_emoji.rb index 7a815fa3dde..8e3b3ff8ce5 100644 --- a/lib/api/award_emoji.rb +++ b/lib/api/award_emoji.rb @@ -127,6 +127,8 @@ module API case awardable when Note read_ability(awardable.noteable) + when Snippet, ProjectSnippet + :read_snippet else :"read_#{awardable.class.to_s.underscore}" end diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 52ff819924b..e6bc4ed69a1 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -311,6 +311,7 @@ module API expose(:wiki_access_level) { |project, options| project.project_feature.string_access_level(:wiki) } expose(:builds_access_level) { |project, options| project.project_feature.string_access_level(:builds) } expose(:snippets_access_level) { |project, options| project.project_feature.string_access_level(:snippets) } + expose(:pages_access_level) { |project, options| project.project_feature.string_access_level(:pages) } expose :shared_runners_enabled expose :lfs_enabled?, as: :lfs_enabled diff --git a/lib/api/helpers/notes_helpers.rb b/lib/api/helpers/notes_helpers.rb index 8adfac346f6..2dd95aba6bc 100644 --- a/lib/api/helpers/notes_helpers.rb +++ b/lib/api/helpers/notes_helpers.rb @@ -72,7 +72,15 @@ module API end def noteable_read_ability_name(noteable) - "read_#{noteable.class.to_s.underscore}".to_sym + "read_#{ability_name(noteable)}".to_sym + end + + def ability_name(noteable) + if noteable.respond_to?(:to_ability_name) + noteable.to_ability_name + else + noteable.class.to_s.underscore + end end def find_noteable(parent_type, parent_id, noteable_type, noteable_id) diff --git a/lib/api/helpers/projects_helpers.rb b/lib/api/helpers/projects_helpers.rb index 6333e00daf5..6717f33f3e1 100644 --- a/lib/api/helpers/projects_helpers.rb +++ b/lib/api/helpers/projects_helpers.rb @@ -27,6 +27,7 @@ module API optional :wiki_access_level, type: String, values: %w(disabled private enabled), desc: 'Wiki access level. One of `disabled`, `private` or `enabled`' optional :builds_access_level, type: String, values: %w(disabled private enabled), desc: 'Builds access level. One of `disabled`, `private` or `enabled`' optional :snippets_access_level, type: String, values: %w(disabled private enabled), desc: 'Snippets access level. One of `disabled`, `private` or `enabled`' + optional :pages_access_level, type: String, values: %w(disabled private enabled public), desc: 'Pages access level. One of `disabled`, `private`, `enabled` or `public`' optional :shared_runners_enabled, type: Boolean, desc: 'Flag indication if shared runners are enabled for that project' optional :resolve_outdated_diff_discussions, type: Boolean, desc: 'Automatically resolve merge request diffs discussions on lines changed with a push' @@ -107,6 +108,7 @@ module API :name, :only_allow_merge_if_all_discussions_are_resolved, :only_allow_merge_if_pipeline_succeeds, + :pages_access_level, :path, :printing_merge_request_link_enabled, :public_builds, diff --git a/lib/api/project_snippets.rb b/lib/api/project_snippets.rb index ecada843972..3040c3c27c6 100644 --- a/lib/api/project_snippets.rb +++ b/lib/api/project_snippets.rb @@ -60,7 +60,7 @@ module API mutually_exclusive :code, :content end post ":id/snippets" do - authorize! :create_project_snippet, user_project + authorize! :create_snippet, user_project snippet_params = declared_params(include_missing: false).merge(request: request, api: true) snippet_params[:content] = snippet_params.delete(:code) if snippet_params[:code].present? @@ -97,7 +97,7 @@ module API snippet = snippets_for_current_user.find_by(id: params.delete(:snippet_id)) not_found!('Snippet') unless snippet - authorize! :update_project_snippet, snippet + authorize! :update_snippet, snippet snippet_params = declared_params(include_missing: false) .merge(request: request, api: true) @@ -126,7 +126,7 @@ module API snippet = snippets_for_current_user.find_by(id: params[:snippet_id]) not_found!('Snippet') unless snippet - authorize! :admin_project_snippet, snippet + authorize! :admin_snippet, snippet destroy_conditionally!(snippet) do |snippet| service = ::Snippets::DestroyService.new(current_user, snippet) diff --git a/lib/api/snippets.rb b/lib/api/snippets.rb index a7dab373b7f..b5df036c5ca 100644 --- a/lib/api/snippets.rb +++ b/lib/api/snippets.rb @@ -106,7 +106,7 @@ module API snippet = snippets_for_current_user.find_by_id(params.delete(:id)) break not_found!('Snippet') unless snippet - authorize! :update_personal_snippet, snippet + authorize! :update_snippet, snippet attrs = declared_params(include_missing: false).merge(request: request, api: true) service_response = ::Snippets::UpdateService.new(nil, current_user, attrs).execute(snippet) @@ -132,7 +132,7 @@ module API snippet = snippets_for_current_user.find_by_id(params.delete(:id)) break not_found!('Snippet') unless snippet - authorize! :admin_personal_snippet, snippet + authorize! :admin_snippet, snippet destroy_conditionally!(snippet) do |snippet| service = ::Snippets::DestroyService.new(current_user, snippet) diff --git a/lib/banzai/reference_parser/snippet_parser.rb b/lib/banzai/reference_parser/snippet_parser.rb index 6f6ac08de04..b86c259efbd 100644 --- a/lib/banzai/reference_parser/snippet_parser.rb +++ b/lib/banzai/reference_parser/snippet_parser.rb @@ -12,7 +12,7 @@ module Banzai private def can_read_reference?(user, ref_project, node) - can?(user, :read_project_snippet, referenced_by([node]).first) + can?(user, :read_snippet, referenced_by([node]).first) end end end diff --git a/lib/gitlab/gpg.rb b/lib/gitlab/gpg.rb index 7e6f6a519a6..8166bef4510 100644 --- a/lib/gitlab/gpg.rb +++ b/lib/gitlab/gpg.rb @@ -6,7 +6,7 @@ module Gitlab CleanupError = Class.new(StandardError) BG_CLEANUP_RUNTIME_S = 10 - FG_CLEANUP_RUNTIME_S = 0.5 + FG_CLEANUP_RUNTIME_S = 1 MUTEX = Mutex.new @@ -127,7 +127,10 @@ module Gitlab # error. # Failing to remove the tmp directory could leave the `gpg-agent` process # running forever. - Retriable.retriable(max_elapsed_time: cleanup_time, base_interval: 0.1) do + # + # 15 tries will never complete within the maximum time with exponential + # backoff. So our limit is the runtime, not the number of tries. + Retriable.retriable(max_elapsed_time: cleanup_time, base_interval: 0.1, tries: 15) do FileUtils.remove_entry(tmp_dir) if File.exist?(tmp_dir) end rescue => e diff --git a/lib/gitlab/kubernetes/kube_client.rb b/lib/gitlab/kubernetes/kube_client.rb index 7cb7f46a623..7d2abcdb0a3 100644 --- a/lib/gitlab/kubernetes/kube_client.rb +++ b/lib/gitlab/kubernetes/kube_client.rb @@ -16,6 +16,7 @@ module Gitlab SUPPORTED_API_GROUPS = { core: { group: 'api', version: 'v1' }, rbac: { group: 'apis/rbac.authorization.k8s.io', version: 'v1' }, + apps: { group: 'apis/apps', version: 'v1' }, extensions: { group: 'apis/extensions', version: 'v1beta1' }, istio: { group: 'apis/networking.istio.io', version: 'v1alpha3' }, knative: { group: 'apis/serving.knative.dev', version: 'v1alpha1' } @@ -74,10 +75,6 @@ module Gitlab :update_role_binding, to: :rbac_client - # Deployments resource is currently on the apis/extensions api group - delegate :get_deployments, - to: :extensions_client - # non-entity methods that can only work with the core client # as it uses the pods/log resource delegate :get_pod_log, @@ -103,6 +100,21 @@ module Gitlab validate_url! end + # Deployments resource is currently on the apis/extensions api group + # until Kubernetes 1.15. Kubernetest 1.16+ has deployments resources in + # the apis/apps api group. + # + # As we still support Kubernetes 1.12+, we will need to support both. + def get_deployments(**args) + extensions_client.discover unless extensions_client.discovered + + if extensions_client.respond_to?(:get_deployments) + extensions_client.get_deployments(**args) + else + apps_client.get_deployments(**args) + end + end + def create_or_update_cluster_role_binding(resource) if cluster_role_binding_exists?(resource) update_cluster_role_binding(resource) |