2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
module Clusters
|
2018-12-13 13:39:08 +05:30
|
|
|
class UpdateService
|
|
|
|
attr_reader :current_user, :params
|
|
|
|
|
|
|
|
def initialize(user = nil, params = {})
|
2021-04-29 21:17:54 +05:30
|
|
|
@current_user = user
|
|
|
|
@params = params.dup
|
2018-12-13 13:39:08 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def execute(cluster)
|
2019-12-26 22:10:19 +05:30
|
|
|
if validate_params(cluster)
|
2020-05-30 21:06:31 +05:30
|
|
|
token = params.dig(:platform_kubernetes_attributes, :token)
|
|
|
|
|
|
|
|
if token.blank?
|
|
|
|
params[:platform_kubernetes_attributes]&.delete(:token)
|
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
cluster.update(params)
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def validate_params(cluster)
|
2020-04-22 19:07:51 +05:30
|
|
|
::Clusters::Management::ValidateManagementProjectPermissionsService.new(current_user)
|
|
|
|
.execute(cluster, params[:management_project_id])
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|