debian-mirror-gitlab/app/services/clusters/update_service.rb
2020-05-30 21:06:31 +05:30

32 lines
730 B
Ruby

# frozen_string_literal: true
module Clusters
class UpdateService
attr_reader :current_user, :params
def initialize(user = nil, params = {})
@current_user, @params = user, params.dup
end
def execute(cluster)
if validate_params(cluster)
token = params.dig(:platform_kubernetes_attributes, :token)
if token.blank?
params[:platform_kubernetes_attributes]&.delete(:token)
end
cluster.update(params)
else
false
end
end
private
def validate_params(cluster)
::Clusters::Management::ValidateManagementProjectPermissionsService.new(current_user)
.execute(cluster, params[:management_project_id])
end
end
end