2018-07-16 16:31:01 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-10-13 17:21:23 +00:00
|
|
|
module Clusters
|
2018-10-10 23:15:04 +00:00
|
|
|
class UpdateService
|
|
|
|
attr_reader :current_user, :params
|
|
|
|
|
|
|
|
def initialize(user = nil, params = {})
|
|
|
|
@current_user, @params = user, params.dup
|
|
|
|
end
|
|
|
|
|
2017-10-13 17:21:23 +00:00
|
|
|
def execute(cluster)
|
2019-10-24 12:06:03 +00:00
|
|
|
if validate_params(cluster)
|
2020-05-27 21:08:05 +00:00
|
|
|
token = params.dig(:platform_kubernetes_attributes, :token)
|
|
|
|
|
|
|
|
if token.blank?
|
|
|
|
params[:platform_kubernetes_attributes]&.delete(:token)
|
|
|
|
end
|
|
|
|
|
2019-10-24 12:06:03 +00:00
|
|
|
cluster.update(params)
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def validate_params(cluster)
|
2020-04-14 15:09:44 +00:00
|
|
|
::Clusters::Management::ValidateManagementProjectPermissionsService.new(current_user)
|
|
|
|
.execute(cluster, params[:management_project_id])
|
2017-10-13 17:21:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|