forked from cloudfoundry/cloud_controller_ng
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_create.rb
More file actions
38 lines (30 loc) · 921 Bytes
/
stack_create.rb
File metadata and controls
38 lines (30 loc) · 921 Bytes
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
require 'repositories/stack_event_repository'
module VCAP::CloudController
class StackCreate
class Error < ::StandardError
end
def initialize(user_audit_info)
@user_audit_info = user_audit_info
end
def create(message)
stack = VCAP::CloudController::Stack.create(
name: message.name,
description: message.description,
state: message.state,
state_reason: message.state_reason
)
MetadataUpdate.update(stack, message)
Repositories::StackEventRepository.new.record_stack_create(stack, @user_audit_info, message.audit_hash)
stack
rescue Sequel::ValidationFailed => e
validation_error!(e)
end
def validation_error!(error)
error!('Name must be unique') if error.errors.on(:name)&.include?(:unique)
error!(error.message)
end
def error!(message)
raise Error.new(message)
end
end
end