-
Notifications
You must be signed in to change notification settings - Fork 74
/
service.rb
52 lines (45 loc) · 1.39 KB
/
service.rb
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# frozen_string_literal: true
module Backend
module ModelExtensions
module Service
def self.included(base)
base.class_eval do
after_commit :update_backend_service, :unless => :destroyed?
end
end
def backend_id
id.to_s
end
def update_backend_service
if account&.has_bought_cinstance?
save_options = {
:id => backend_id,
:provider_key => account.api_key,
:referrer_filters_required => referrer_filters_required,
:backend_version => backend_version,
:default_service => (account.default_service_id == id)
}
ThreeScale::Core::Service.save!(save_options)
end
true
rescue => e
System::ErrorReporting.report_error e
raise e
end
def delete_backend_service
return if account&.missing_api_key?
delete_alert_limits(alert_limits) if account.try(:api_key?)
ThreeScale::Core::Service.delete_by_id!(backend_id)
true
rescue => e
System::ErrorReporting.report_error e
raise e
end
private
def make_default_backend_service
ThreeScale::Core::Service.make_default(backend_id)
account.update!({default_service_id: id}, without_protection: true)
end
end
end
end