2018-08-03 03:15:25 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-10-13 13:21:23 -04:00
|
|
|
module Clusters
|
|
|
|
module Providers
|
2019-03-28 09:17:42 -04:00
|
|
|
class Gcp < ApplicationRecord
|
2019-09-24 02:06:02 -04:00
|
|
|
include Clusters::Concerns::ProviderStatus
|
|
|
|
|
2017-10-23 04:36:35 -04:00
|
|
|
self.table_name = 'cluster_providers_gcp'
|
2017-10-13 13:21:23 -04:00
|
|
|
|
2017-10-23 04:36:35 -04:00
|
|
|
belongs_to :cluster, inverse_of: :provider_gcp, class_name: 'Clusters::Cluster'
|
|
|
|
|
|
|
|
default_value_for :zone, 'us-central1-a'
|
|
|
|
default_value_for :num_nodes, 3
|
2017-11-07 03:46:04 -05:00
|
|
|
default_value_for :machine_type, 'n1-standard-2'
|
2019-09-22 20:06:29 -04:00
|
|
|
default_value_for :cloud_run, false
|
|
|
|
|
|
|
|
scope :cloud_run, -> { where(cloud_run: true) }
|
2017-10-13 13:21:23 -04:00
|
|
|
|
|
|
|
attr_encrypted :access_token,
|
|
|
|
mode: :per_attribute_iv,
|
2018-06-02 05:32:30 -04:00
|
|
|
key: Settings.attr_encrypted_db_key_base_truncated,
|
2017-10-13 13:21:23 -04:00
|
|
|
algorithm: 'aes-256-cbc'
|
|
|
|
|
2017-10-23 04:36:35 -04:00
|
|
|
validates :gcp_project_id,
|
2017-10-13 13:21:23 -04:00
|
|
|
length: 1..63,
|
|
|
|
format: {
|
|
|
|
with: Gitlab::Regex.kubernetes_namespace_regex,
|
|
|
|
message: Gitlab::Regex.kubernetes_namespace_regex_message
|
|
|
|
}
|
|
|
|
|
2017-10-23 04:36:35 -04:00
|
|
|
validates :zone, presence: true
|
2017-10-13 13:21:23 -04:00
|
|
|
|
2017-10-23 04:36:35 -04:00
|
|
|
validates :num_nodes,
|
2017-10-13 13:21:23 -04:00
|
|
|
presence: true,
|
|
|
|
numericality: {
|
|
|
|
only_integer: true,
|
|
|
|
greater_than: 0
|
|
|
|
}
|
|
|
|
|
2019-09-24 02:06:02 -04:00
|
|
|
def api_client
|
|
|
|
return unless access_token
|
2017-10-13 13:21:23 -04:00
|
|
|
|
2019-09-24 02:06:02 -04:00
|
|
|
@api_client ||= GoogleApi::CloudPlatform::Client.new(access_token, nil)
|
2017-10-13 13:21:23 -04:00
|
|
|
end
|
|
|
|
|
2019-09-24 02:06:02 -04:00
|
|
|
def nullify_credentials
|
|
|
|
assign_attributes(
|
|
|
|
access_token: nil,
|
|
|
|
operation_id: nil
|
|
|
|
)
|
2017-10-13 13:21:23 -04:00
|
|
|
end
|
|
|
|
|
2019-09-24 02:06:02 -04:00
|
|
|
def assign_operation_id(operation_id)
|
|
|
|
assign_attributes(operation_id: operation_id)
|
2017-10-13 13:21:23 -04:00
|
|
|
end
|
2019-09-22 20:06:29 -04:00
|
|
|
|
2019-11-13 01:06:38 -05:00
|
|
|
def has_rbac_enabled?
|
|
|
|
!legacy_abac
|
|
|
|
end
|
|
|
|
|
2019-09-22 20:06:29 -04:00
|
|
|
def knative_pre_installed?
|
|
|
|
cloud_run?
|
|
|
|
end
|
2017-10-13 13:21:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|