diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-17 00:07:22 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-17 00:07:22 +0300 |
commit | e924e9e7cb9df21b3bc3d51d5f955da28ba3a225 (patch) | |
tree | 598ccb6f09e55ad06e628a90d27628f20ae693fe /app/models | |
parent | 8e45d25f7dde6508839ffee719c0ddc2cf6b12d3 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/aws/role.rb | 17 | ||||
-rw-r--r-- | app/models/clusters/cluster.rb | 19 | ||||
-rw-r--r-- | app/models/clusters/concerns/provider_status.rb | 4 | ||||
-rw-r--r-- | app/models/clusters/providers/aws.rb | 47 | ||||
-rw-r--r-- | app/models/project_services/jira_service.rb | 8 | ||||
-rw-r--r-- | app/models/user.rb | 1 |
6 files changed, 90 insertions, 6 deletions
diff --git a/app/models/aws/role.rb b/app/models/aws/role.rb new file mode 100644 index 00000000000..836107435ad --- /dev/null +++ b/app/models/aws/role.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Aws + class Role < ApplicationRecord + self.table_name = 'aws_roles' + + belongs_to :user, inverse_of: :aws_role + + validates :role_external_id, uniqueness: true, length: { in: 1..64 } + validates :role_arn, + length: 1..2048, + format: { + with: Gitlab::Regex.aws_arn_regex, + message: Gitlab::Regex.aws_arn_regex_message + } + end +end diff --git a/app/models/clusters/cluster.rb b/app/models/clusters/cluster.rb index c49d5063f8b..d6f5d7c3f93 100644 --- a/app/models/clusters/cluster.rb +++ b/app/models/clusters/cluster.rb @@ -35,6 +35,7 @@ module Clusters # we force autosave to happen when we save `Cluster` model has_one :provider_gcp, class_name: 'Clusters::Providers::Gcp', autosave: true + has_one :provider_aws, class_name: 'Clusters::Providers::Aws', autosave: true has_one :platform_kubernetes, class_name: 'Clusters::Platforms::Kubernetes', inverse_of: :cluster, autosave: true @@ -96,14 +97,20 @@ module Clusters enum provider_type: { user: 0, - gcp: 1 + gcp: 1, + aws: 2 } scope :enabled, -> { where(enabled: true) } scope :disabled, -> { where(enabled: false) } - scope :user_provided, -> { where(provider_type: ::Clusters::Cluster.provider_types[:user]) } - scope :gcp_provided, -> { where(provider_type: ::Clusters::Cluster.provider_types[:gcp]) } + + scope :user_provided, -> { where(provider_type: :user) } + scope :gcp_provided, -> { where(provider_type: :gcp) } + scope :aws_provided, -> { where(provider_type: :aws) } + scope :gcp_installed, -> { gcp_provided.joins(:provider_gcp).merge(Clusters::Providers::Gcp.with_status(:created)) } + scope :aws_installed, -> { aws_provided.joins(:provider_aws).merge(Clusters::Providers::Aws.with_status(:created)) } + scope :managed, -> { where(managed: true) } scope :default_environment, -> { where(environment_scope: DEFAULT_ENVIRONMENT) } @@ -140,7 +147,11 @@ module Clusters end def provider - return provider_gcp if gcp? + if gcp? + provider_gcp + elsif aws? + provider_aws + end end def platform diff --git a/app/models/clusters/concerns/provider_status.rb b/app/models/clusters/concerns/provider_status.rb index 4d1974777ea..2da1ee7aabb 100644 --- a/app/models/clusters/concerns/provider_status.rb +++ b/app/models/clusters/concerns/provider_status.rb @@ -42,6 +42,10 @@ module Clusters def on_creation? scheduled? || creating? end + + def assign_operation_id(_) + # Implemented by individual providers if operation ID is supported. + end end end end diff --git a/app/models/clusters/providers/aws.rb b/app/models/clusters/providers/aws.rb new file mode 100644 index 00000000000..ae4156896bc --- /dev/null +++ b/app/models/clusters/providers/aws.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +module Clusters + module Providers + class Aws < ApplicationRecord + include Clusters::Concerns::ProviderStatus + + self.table_name = 'cluster_providers_aws' + + belongs_to :cluster, inverse_of: :provider_aws, class_name: 'Clusters::Cluster' + belongs_to :created_by_user, class_name: 'User' + + default_value_for :region, 'us-east-1' + default_value_for :num_nodes, 3 + default_value_for :instance_type, 'm5.large' + + attr_encrypted :secret_access_key, + mode: :per_attribute_iv, + key: Settings.attr_encrypted_db_key_base_truncated, + algorithm: 'aes-256-gcm' + + validates :role_arn, + length: 1..2048, + format: { + with: Gitlab::Regex.aws_arn_regex, + message: Gitlab::Regex.aws_arn_regex_message + } + + validates :num_nodes, + numericality: { + only_integer: true, + greater_than: 0 + } + + validates :key_name, :region, :instance_type, :security_group_id, length: { in: 1..255 } + validates :subnet_ids, presence: true + + def nullify_credentials + assign_attributes( + access_key_id: nil, + secret_access_key: nil, + session_token: nil + ) + end + end + end +end diff --git a/app/models/project_services/jira_service.rb b/app/models/project_services/jira_service.rb index 2bc6567ca15..ba61810e26f 100644 --- a/app/models/project_services/jira_service.rb +++ b/app/models/project_services/jira_service.rb @@ -122,9 +122,13 @@ class JiraService < IssueTrackerService end alias_method :original_url, :url - def url - original_url&.chomp('/') + original_url&.delete_suffix('/') + end + + alias_method :original_api_url, :api_url + def api_url + original_api_url&.delete_suffix('/') end def execute(push) diff --git a/app/models/user.rb b/app/models/user.rb index c4075f06dff..42a5f6cebeb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -99,6 +99,7 @@ class User < ApplicationRecord has_many :u2f_registrations, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent has_many :chat_names, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent has_one :user_synced_attributes_metadata, autosave: true + has_one :aws_role, class_name: 'Aws::Role' # Groups has_many :members |