blob: 8c30e247fdc4e16d6878431bfb36a04754851296 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
module Clusters
class CreateService < BaseService
attr_reader :access_token
def execute(access_token)
@access_token = access_token
create_cluster.tap do |cluster|
ClusterProvisionWorker.perform_async(cluster.id) if cluster.persisted?
end
end
private
def create_cluster
cluster = nil
ActiveRecord::Base.transaction do
cluster = Clusters::Cluster.create!(cluster_params)
cluster.projects << project
end
cluster
rescue ActiveRecord::RecordInvalid => e
e.record
end
def cluster_params
return @cluster_params if defined?(@cluster_params)
params[:provider_gcp_attributes].try do |h|
h[:access_token] = access_token
end
@cluster_params = params.merge(user: current_user)
end
end
end
|