diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-05 00:09:24 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-05 00:09:24 +0000 |
commit | 7ff2de7c12d71873a3c0e85cc6fbcd5d5f05b5c1 (patch) | |
tree | f6b2dc4c2c294d21c99aba8011566d856648d84d /app/models | |
parent | 6609e5ea75a9e119651e19574c30c11ce19c62d0 (diff) | |
download | gitlab-ce-7ff2de7c12d71873a3c0e85cc6fbcd5d5f05b5c1.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/active_session.rb | 50 | ||||
-rw-r--r-- | app/models/ci/pipeline.rb | 10 | ||||
-rw-r--r-- | app/models/environment.rb | 28 | ||||
-rw-r--r-- | app/models/project.rb | 1 |
4 files changed, 31 insertions, 58 deletions
diff --git a/app/models/active_session.rb b/app/models/active_session.rb index 823685f78f4..a0e74c7f48e 100644 --- a/app/models/active_session.rb +++ b/app/models/active_session.rb @@ -42,13 +42,6 @@ class ActiveSession device_type&.titleize end - # This is not the same as Rack::Session::SessionId#public_id, but we - # need to preserve this for backwards compatibility. - # TODO: remove in 13.7 - def public_id - Gitlab::CryptoHelper.aes256_gcm_encrypt(session_id) - end - def self.set(user, request) Gitlab::Redis::SharedState.with do |redis| session_private_id = request.session.id.private_id @@ -63,8 +56,6 @@ class ActiveSession device_type: client.device_type, created_at: user.current_sign_in_at || timestamp, updated_at: timestamp, - # TODO: remove in 13.7 - session_id: request.session.id.public_id, session_private_id: session_private_id, is_impersonated: request.session[:impersonator_id].present? ) @@ -80,20 +71,10 @@ class ActiveSession lookup_key_name(user.id), session_private_id ) - - # We remove the ActiveSession stored by using public_id to avoid - # duplicate entries - remove_deprecated_active_sessions_with_public_id(redis, user.id, request.session.id.public_id) end end end - # TODO: remove in 13.7 - private_class_method def self.remove_deprecated_active_sessions_with_public_id(redis, user_id, rack_session_public_id) - redis.srem(lookup_key_name(user_id), rack_session_public_id) - redis.del(key_name(user_id, rack_session_public_id)) - end - def self.list(user) Gitlab::Redis::SharedState.with do |redis| cleaned_up_lookup_entries(redis, user).map do |raw_session| @@ -109,18 +90,6 @@ class ActiveSession end end - # TODO: remove in 13.7 - # After upgrade there might be a duplicate ActiveSessions: - # - one with the public_id stored in #session_id - # - another with private_id stored in #session_private_id - def self.destroy_with_rack_session_id(user, rack_session_id) - return unless rack_session_id - - Gitlab::Redis::SharedState.with do |redis| - destroy_sessions(redis, user, [rack_session_id.public_id, rack_session_id.private_id]) - end - end - def self.destroy_sessions(redis, user, session_ids) key_names = session_ids.map { |session_id| key_name(user.id, session_id) } @@ -132,19 +101,11 @@ class ActiveSession end end - # TODO: remove in 13.7 - # After upgrade, .destroy might be called with the session id encrypted - # by .public_id. - def self.destroy_with_deprecated_encryption(user, session_id) + def self.destroy_session(user, session_id) return unless session_id - decrypted_session_id = decrypt_public_id(session_id) - rack_session_private_id = if decrypted_session_id - Rack::Session::SessionId.new(decrypted_session_id).private_id - end - Gitlab::Redis::SharedState.with do |redis| - destroy_sessions(redis, user, [session_id, decrypted_session_id, rack_session_private_id].compact) + destroy_sessions(redis, user, [session_id].compact) end end @@ -275,11 +236,4 @@ class ActiveSession entries.compact end - - # TODO: remove in 13.7 - private_class_method def self.decrypt_public_id(public_id) - Gitlab::CryptoHelper.aes256_gcm_decrypt(public_id) - rescue - nil - end end diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 2a584200baa..7418a091407 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -693,14 +693,6 @@ module Ci .exists? end - # TODO: this logic is duplicate with Pipeline::Chain::Config::Content - # we should persist this is `ci_pipelines.config_path` - def config_path - return unless repository_source? || unknown_source? - - project.ci_config_path_or_default - end - def has_yaml_errors? yaml_errors.present? end @@ -786,8 +778,6 @@ module Ci variables.append(key: 'CI_PIPELINE_IID', value: iid.to_s) variables.append(key: 'CI_PIPELINE_SOURCE', value: source.to_s) - variables.append(key: 'CI_CONFIG_PATH', value: config_path) - variables.concat(predefined_commit_variables) if merge_request? diff --git a/app/models/environment.rb b/app/models/environment.rb index ea1073c810a..3ac7e63bae3 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -39,6 +39,7 @@ class Environment < ApplicationRecord before_validation :generate_slug, if: ->(env) { env.slug.blank? } before_save :set_environment_type + before_save :ensure_environment_tier after_save :clear_reactive_cache! validates :name, @@ -87,6 +88,7 @@ class Environment < ApplicationRecord end scope :for_project, -> (project) { where(project_id: project) } + scope :for_tier, -> (tier) { where(tier: tier).where('tier IS NOT NULL') } scope :with_deployment, -> (sha) { where('EXISTS (?)', Deployment.select(1).where('deployments.environment_id = environments.id').where(sha: sha)) } scope :unfoldered, -> { where(environment_type: nil) } scope :with_rank, -> do @@ -94,6 +96,14 @@ class Environment < ApplicationRecord end scope :for_id, -> (id) { where(id: id) } + enum tier: { + production: 0, + staging: 1, + testing: 2, + development: 3, + other: 4 + } + state_machine :state, initial: :available do event :start do transition stopped: :available @@ -429,6 +439,24 @@ class Environment < ApplicationRecord def generate_slug self.slug = Gitlab::Slug::Environment.new(name).generate end + + def ensure_environment_tier + return unless ::Feature.enabled?(:environment_tier, project, default_enabled: :yaml) + + self.tier ||= guess_tier + end + + # Guessing the tier of the environment if it's not explicitly specified by users. + # See https://en.wikipedia.org/wiki/Deployment_environment for industry standard deployment environments + def guess_tier + case name + when %r{dev|review|trunk}i then self.class.tiers[:development] + when %r{test|qc}i then self.class.tiers[:testing] + when %r{st(a|)g|mod(e|)l|pre|demo}i then self.class.tiers[:staging] + when %r{pr(o|)d|live}i then self.class.tiers[:production] + else self.class.tiers[:other] + end + end end Environment.prepend_if_ee('EE::Environment') diff --git a/app/models/project.rb b/app/models/project.rb index 7e0b43e69ac..18f22ce7942 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1987,6 +1987,7 @@ class Project < ApplicationRecord .append(key: 'CI_PROJECT_REPOSITORY_LANGUAGES', value: repository_languages.map(&:name).join(',').downcase) .append(key: 'CI_DEFAULT_BRANCH', value: default_branch) .append(key: 'CI_PROJECT_CONFIG_PATH', value: ci_config_path_or_default) + .append(key: 'CI_CONFIG_PATH', value: ci_config_path_or_default) end def predefined_ci_server_variables |