debian-mirror-gitlab/app/models/clusters/providers/gcp.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

67 lines
1.6 KiB
Ruby
Raw Normal View History

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