2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Clusters
|
|
|
|
module Providers
|
|
|
|
class Aws < ApplicationRecord
|
2019-12-26 22:10:19 +05:30
|
|
|
include Gitlab::Utils::StrongMemoize
|
2019-12-21 20:55:43 +05:30
|
|
|
include Clusters::Concerns::ProviderStatus
|
2020-10-24 23:57:45 +05:30
|
|
|
include IgnorableColumns
|
|
|
|
|
|
|
|
ignore_column :created_by_user_id, remove_with: '13.4', remove_after: '2020-08-22'
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
self.table_name = 'cluster_providers_aws'
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
DEFAULT_REGION = 'us-east-1'
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
belongs_to :cluster, inverse_of: :provider_aws, class_name: 'Clusters::Cluster'
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
default_value_for :region, DEFAULT_REGION
|
2019-12-21 20:55:43 +05:30
|
|
|
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
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
def api_client
|
|
|
|
strong_memoize(:api_client) do
|
|
|
|
::Aws::CloudFormation::Client.new(credentials: credentials, region: region)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def credentials
|
|
|
|
strong_memoize(:credentials) do
|
|
|
|
::Aws::Credentials.new(access_key_id, secret_access_key, session_token)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def has_rbac_enabled?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def knative_pre_installed?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def created_by_user
|
|
|
|
cluster.user
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|