Class: Clusters::Applications::BaseService

Inherits:
Object
  • Object
show all
Defined in:
app/services/clusters/applications/base_service.rb

Direct Known Subclasses

CreateService, DestroyService, UpdateService

Constant Summary collapse

InvalidApplicationError =
Class.new(StandardError)
FLUENTD_KNOWN_ATTRS =
%i[host protocol port waf_log_enabled cilium_log_enabled].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cluster, user, params = {}) ⇒ BaseService

Returns a new instance of BaseService.


12
13
14
15
16
# File 'app/services/clusters/applications/base_service.rb', line 12

def initialize(cluster, user, params = {})
  @cluster = cluster
  @current_user = user
  @params = params.dup
end

Instance Attribute Details

#clusterObject (readonly)

Returns the value of attribute cluster


10
11
12
# File 'app/services/clusters/applications/base_service.rb', line 10

def cluster
  @cluster
end

#current_userObject (readonly)

Returns the value of attribute current_user


10
11
12
# File 'app/services/clusters/applications/base_service.rb', line 10

def current_user
  @current_user
end

#paramsObject (readonly)

Returns the value of attribute params


10
11
12
# File 'app/services/clusters/applications/base_service.rb', line 10

def params
  @params
end

Instance Method Details

#execute(request) ⇒ Object


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
53
54
55
56
57
58
# File 'app/services/clusters/applications/base_service.rb', line 18

def execute(request)
  instantiate_application.tap do |application|
    if application.has_attribute?(:hostname)
      application.hostname = params[:hostname]
    end

    if application.has_attribute?(:email)
      application.email = params[:email]
    end

    if application.has_attribute?(:stack)
      application.stack = params[:stack]
    end

    if application.has_attribute?(:modsecurity_enabled)
      application.modsecurity_enabled = params[:modsecurity_enabled] || false
    end

    if application.has_attribute?(:modsecurity_mode)
      application.modsecurity_mode = params[:modsecurity_mode] || 0
    end

    apply_fluentd_related_attributes(application)

    if application.respond_to?(:oauth_application)
      application.oauth_application = create_oauth_application(application, request)
    end

    if application.instance_of?(Knative)
      Serverless::AssociateDomainService
        .new(application, pages_domain_id: params[:pages_domain_id], creator: current_user)
        .execute
    end

    worker = worker_class(application)

    application.make_scheduled!

    worker.perform_async(application.name, application.id)
  end
end