summaryrefslogtreecommitdiff
path: root/app/models/clusters/providers/aws.rb
blob: ae4156896bc5adf7d09b783c074af43463ec4f95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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